22 #ifndef CO_DATAOSTREAM_H 23 #define CO_DATAOSTREAM_H 26 #include <co/global.h> 29 #include <lunchbox/array.h> 31 #include <boost/noncopyable.hpp> 32 #include <boost/type_traits.hpp> 35 #include <unordered_map> 36 #include <unordered_set> 45 namespace DataStreamTest
62 CO_API
void disable();
71 CO_API
bool hasSentData()
const;
81 const uint64_t dataSize);
84 uint64_t getCompressedDataSize()
const;
93 _write(value, boost::has_trivial_copy<T>());
101 _writeArray(array, boost::has_trivial_copy<T>());
110 DataOStream& operator<<(const lunchbox::RefPtr<T>& ptr);
114 DataOStream& operator<<(const lunchbox::Buffer<T>& buffer);
120 return (*
this) << request.getID();
125 DataOStream& operator<<(const std::vector<T>& value);
128 template <
class K,
class V>
129 DataOStream& operator<<(const std::map<K, V>& value);
136 template <
class K,
class V>
137 DataOStream& operator<<(const std::unordered_map<K, V>& value);
141 DataOStream& operator<<(const std::unordered_set<T>& value);
149 template <
typename C>
150 void serializeChildren(
const std::vector<C*>& children);
153 CO_API
static std::ostream& printStatistics(std::ostream&);
154 CO_API
static void clearStatistics();
159 explicit DataOStream(DataOStream& rhs);
160 virtual CO_API ~DataOStream();
163 CO_API lunchbox::Bufferb& getBuffer();
166 void _setCompressor(
const pression::data::CompressorInfo& info);
169 CO_API
void _enable();
172 void flush(
const bool last);
177 void _setupConnections(
const Nodes& receivers);
179 void _setupConnections(
const Connections& connections);
182 void _setupConnection(
NodePtr node,
const bool useMulticast);
186 friend class DataStreamTest::Sender;
191 void _clearConnections();
196 virtual void sendData(
const void* buffer,
const uint64_t size,
197 const bool last) = 0;
201 virtual CO_API
void reset();
204 detail::DataOStream*
const _impl;
207 CO_API uint64_t _getCompressedData(
const uint8_t** chunks,
208 uint64_t* chunkSizes)
const;
211 CO_API
void _write(
const void* data, uint64_t size);
214 void _sendData(
const void* data,
const uint64_t size);
221 DataOStream& _writeFlatVector(
const std::vector<T>& value)
223 const uint64_t nElems = value.size();
224 _write(&nElems,
sizeof(nElems));
226 _write(&value.front(), nElems *
sizeof(T));
232 void _write(
const T& value,
const boost::true_type&)
234 _write(&value,
sizeof(value));
239 void _write(
const T& value,
const boost::false_type&)
241 _writeSerializable(value, boost::is_base_of<servus::Serializable, T>());
246 void _writeSerializable(
const T& value,
const boost::true_type&);
250 void _writeArray(
const Array<T> array,
const boost::true_type&)
252 _write(array.data, array.getNumBytes());
257 void _writeArray(
const Array<T> array,
const boost::false_type&)
259 for (
size_t i = 0; i < array.num; ++i)
260 *
this << array.data[i];
264 void _sendFooter(
const void* buffer,
const uint64_t size);
268 #include "dataOStream.ipp" 270 #endif // CO_DATAOSTREAM_H Defines export visibility macros for library Collage.
DataOStream & operator<<(const T &value)
Write a plain data item by copying it to the stream.
static CO_API uint32_t getObjectBufferSize()
A std::ostream-like interface for object serialization.
Object-oriented network library.
std::vector< NodePtr > Nodes
A vector of NodePtr's.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.