00001 // @author Alexander Rykovanov 2012 00010 00011 #include "binary_serialization.h" 00012 00013 #include <opc/ua/protocol/binary/stream.h> 00014 #include <opc/ua/protocol/types.h> 00015 #include <opc/ua/protocol/data_value.h> 00016 00017 #include <algorithm> 00018 #include <functional> 00019 #include <memory> 00020 #include <stdexcept> 00021 #include <string> 00022 00023 namespace OpcUa 00024 { 00025 00026 namespace Binary 00027 { 00028 00029 template<> 00030 std::size_t RawSize<DataValue>(const DataValue& val) 00031 { 00032 std::size_t size = RawSize(val.Encoding); 00033 if (val.Encoding & DATA_VALUE) 00034 { 00035 size += RawSize(val.Value); 00036 } 00037 if (val.Encoding & DATA_VALUE_STATUS_CODE) 00038 { 00039 size += RawSize(val.Status); 00040 } 00041 if (val.Encoding & DATA_VALUE_SOURCE_TIMESTAMP) 00042 { 00043 size += RawSize(val.SourceTimestamp); 00044 } 00045 if (val.Encoding & DATA_VALUE_Server_TIMESTAMP) 00046 { 00047 size += RawSize(val.ServerTimestamp); 00048 } 00049 if (val.Encoding & DATA_VALUE_SOURCE_PICOSECONDS) 00050 { 00051 size += RawSize(val.SourcePicoseconds); 00052 } 00053 if (val.Encoding & DATA_VALUE_Server_PICOSECONDS) 00054 { 00055 size += RawSize(val.ServerPicoseconds); 00056 } 00057 return size; 00058 } 00059 00060 template<> 00061 void DataSerializer::Serialize<DataValue>(const DataValue& val) 00062 { 00063 *this << val.Encoding; 00064 if (val.Encoding & DATA_VALUE) 00065 { 00066 *this << val.Value; 00067 } 00068 if (val.Encoding & DATA_VALUE_STATUS_CODE) 00069 { 00070 *this << val.Status; 00071 } 00072 if (val.Encoding & DATA_VALUE_SOURCE_TIMESTAMP) 00073 { 00074 *this << val.SourceTimestamp; 00075 } 00076 if (val.Encoding & DATA_VALUE_SOURCE_PICOSECONDS) 00077 { 00078 *this << val.SourcePicoseconds; 00079 } 00080 if (val.Encoding & DATA_VALUE_Server_TIMESTAMP) 00081 { 00082 *this << val.ServerTimestamp; 00083 } 00084 if (val.Encoding & DATA_VALUE_Server_PICOSECONDS) 00085 { 00086 *this << val.ServerPicoseconds; 00087 } 00088 } 00089 00090 template<> 00091 void DataDeserializer::Deserialize<DataValue>(DataValue& val) 00092 { 00093 *this >> val.Encoding; 00094 if (val.Encoding & DATA_VALUE) 00095 { 00096 *this >> val.Value; 00097 } 00098 if (val.Encoding & DATA_VALUE_STATUS_CODE) 00099 { 00100 *this >> val.Status; 00101 } 00102 if (val.Encoding & DATA_VALUE_SOURCE_TIMESTAMP) 00103 { 00104 *this >> val.SourceTimestamp; 00105 } 00106 if (val.Encoding & DATA_VALUE_SOURCE_PICOSECONDS) 00107 { 00108 *this >> val.SourcePicoseconds; 00109 } 00110 if (val.Encoding & DATA_VALUE_Server_TIMESTAMP) 00111 { 00112 *this >> val.ServerTimestamp; 00113 } 00114 if (val.Encoding & DATA_VALUE_Server_PICOSECONDS) 00115 { 00116 *this >> val.ServerPicoseconds; 00117 } 00118 } 00119 } // namespace Binary 00120 } // namespace OpcUa 00121