Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __OPC_UA_BINARY_SERIALIZATION_TOOLS_H__
00012 #define __OPC_UA_BINARY_SERIALIZATION_TOOLS_H__
00013
00014 #include <algorithm>
00015 #include <stdint.h>
00016
00017
00018 namespace OpcUa
00019 {
00020 template<class Stream, class Container>
00021 inline void SerializeContainer(Stream& out, const Container& c, uint32_t emptySizeValue = ~uint32_t())
00022 {
00023 if (c.empty())
00024 {
00025 out.Serialize(emptySizeValue);
00026 }
00027 else
00028 {
00029 out.Serialize(static_cast<uint32_t>(c.size()));
00030 std::for_each(c.begin(), c.end(), [&](typename Container::value_type const& v) { out.Serialize(v); });
00031 }
00032 }
00033
00034 template<class Stream, class Container>
00035 inline void DeserializeContainer(Stream& in, Container& c)
00036 {
00037 uint32_t size = 0;
00038 in.Deserialize(size);
00039
00040 c.clear();
00041 if (!size || size == ~uint32_t())
00042 {
00043 return;
00044 }
00045
00046 for (uint32_t i = 0; i < size; ++i)
00047 {
00048 typename Container::value_type val;
00049 in.Deserialize(val);
00050 c.push_back(val);
00051 }
00052 }
00053 }
00054
00055 #endif // __OPC_UA_BINARY_SERIALIZATION_TOOLS_H__
00056