19 #include <co/object.h> 20 #include <co/objectVersion.h> 21 #include <servus/serializable.h> 31 const uint64_t nElems = str.length();
32 _write(&nElems,
sizeof(nElems));
34 _write(str.c_str(), nElems);
50 void DataOStream::_writeSerializable(
const T&
object,
const boost::true_type&)
52 const auto& data =
object.toBinary();
53 (*this) << data.size << Array<const void>(data.ptr.get(), data.size);
57 inline void DataOStream::_writeArray(
const Array<void> array,
58 const boost::false_type&)
60 _write(array.data, array.getNumBytes());
64 inline void DataOStream::_writeArray(
const Array<const void> array,
65 const boost::false_type&)
67 _write(array.data, array.getNumBytes());
72 inline DataOStream& DataOStream::operator<<(const lunchbox::RefPtr<T>& ptr)
74 return *
this << ptr.get();
78 inline DataOStream& DataOStream::operator<<(const lunchbox::Buffer<T>& buffer)
80 return (*
this) << buffer.getSize()
81 << Array<const T>(buffer.getData(), buffer.getSize());
85 inline DataOStream& DataOStream::operator<<(const std::vector<T>& value)
87 const uint64_t nElems = value.size();
89 for (uint64_t i = 0; i < nElems; ++i)
94 template <
class K,
class V>
95 inline DataOStream& DataOStream::operator<<(const std::map<K, V>& value)
97 const uint64_t nElems = value.size();
99 for (
typename std::map<K, V>::const_iterator it = value.begin();
100 it != value.end(); ++it)
102 *
this << it->first << it->second;
108 inline DataOStream& DataOStream::operator<<(const std::set<T>& value)
110 const uint64_t nElems = value.size();
112 for (
typename std::set<T>::const_iterator it = value.begin();
113 it != value.end(); ++it)
120 template <
class K,
class V>
122 const std::unordered_map<K, V>& value)
124 const uint64_t nElems = value.size();
126 for (
const auto& elem : value)
127 *
this << elem.first << elem.second;
132 inline DataOStream& DataOStream::operator<<(const std::unordered_set<T>& value)
134 const uint64_t nElems = value.size();
136 for (
const auto& elem : value)
141 template <
typename C>
142 inline void DataOStream::serializeChildren(
const std::vector<C*>& children)
144 const uint64_t nElems = children.size();
147 for (
typename std::vector<C*>::const_iterator i = children.begin();
148 i != children.end(); ++i)
152 LBASSERTINFO(!child || child->isAttached(),
153 "Found unmapped object during serialization");
160 inline DataOStream& DataOStream::operator<<(const std::vector<uint8_t>& value)
162 return _writeFlatVector(value);
167 inline DataOStream& DataOStream::operator<<(const std::vector<uint16_t>& value)
169 return _writeFlatVector(value);
174 inline DataOStream& DataOStream::operator<<(const std::vector<int16_t>& value)
176 return _writeFlatVector(value);
181 inline DataOStream& DataOStream::operator<<(const std::vector<uint32_t>& value)
183 return _writeFlatVector(value);
188 inline DataOStream& DataOStream::operator<<(const std::vector<int32_t>& value)
190 return _writeFlatVector(value);
195 inline DataOStream& DataOStream::operator<<(const std::vector<uint64_t>& value)
197 return _writeFlatVector(value);
202 inline DataOStream& DataOStream::operator<<(const std::vector<int64_t>& value)
204 return _writeFlatVector(value);
209 inline DataOStream& DataOStream::operator<<(const std::vector<float>& value)
211 return _writeFlatVector(value);
216 inline DataOStream& DataOStream::operator<<(const std::vector<double>& value)
218 return _writeFlatVector(value);
224 const std::vector<ObjectVersion>& value)
226 return _writeFlatVector(value);
DataOStream & operator<<(const T &value)
Write a plain data item by copying it to the stream.
A helper struct bundling an object identifier and version.
CO_API bool isAttached() const
A std::ostream-like interface for object serialization.
Object-oriented network library.