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 );
56 template<>
inline void DataOStream::_writeArray(
const Array< void > array,
57 const boost::false_type& )
59 _write( array.data, array.getNumBytes( ));
62 template<>
inline void DataOStream::_writeArray(
const Array< const void > array,
63 const boost::false_type& )
65 _write( array.data, array.getNumBytes( ));
69 template<
class T >
inline
70 DataOStream& DataOStream::operator << ( const lunchbox::RefPtr< T >& ptr )
72 return *
this << ptr.get();
75 template<
class T >
inline
76 DataOStream& DataOStream::operator << ( const lunchbox::Buffer< T >& buffer )
78 return (*
this) << buffer.getSize()
79 << Array< const T >( buffer.getData(), buffer.getSize());
82 template<
class T >
inline
83 DataOStream& DataOStream::operator << ( const std::vector< T >& value )
85 const uint64_t nElems = value.size();
87 for( uint64_t i = 0; i < nElems; ++i )
92 template<
class K,
class V >
inline
93 DataOStream& DataOStream::operator << ( const std::map< K, V >& value )
95 const uint64_t nElems = value.size();
97 for(
typename std::map< K, V >::const_iterator it = value.begin();
98 it != value.end(); ++it )
100 *
this << it->first << it->second;
105 template<
class T >
inline
106 DataOStream& DataOStream::operator << ( const std::set< T >& value )
108 const uint64_t nElems = value.size();
110 for(
typename std::set< T >::const_iterator it = value.begin();
111 it != value.end(); ++it )
118 template<
class K,
class V >
inline
119 DataOStream& DataOStream::operator << ( const stde::hash_map< K, V >& value )
121 const uint64_t nElems = value.size();
123 for(
typename stde::hash_map< K, V >::const_iterator it = value.begin();
124 it != value.end(); ++it )
126 *
this << it->first << it->second;
131 template<
class T >
inline
132 DataOStream& DataOStream::operator << ( const stde::hash_set< T >& value )
134 const uint64_t nElems = value.size();
136 for(
typename stde::hash_set< T >::const_iterator it = value.begin();
137 it != value.end(); ++it )
144 template<
typename C >
inline
145 void DataOStream::serializeChildren(
const std::vector<C*>& children )
147 const uint64_t nElems = children.size();
150 for(
typename std::vector< C* >::const_iterator i = children.begin();
151 i != children.end(); ++i )
154 (*this) << ObjectVersion( child );
155 LBASSERTINFO( !child || child->isAttached(),
156 "Found unmapped object during serialization" );
163 DataOStream& DataOStream::operator << ( const std::vector< uint8_t >& value )
164 {
return _writeFlatVector( value ); }
168 DataOStream& DataOStream::operator << ( const std::vector< uint16_t >& value )
169 {
return _writeFlatVector( value ); }
173 DataOStream& DataOStream::operator << ( const std::vector< int16_t >& value )
174 {
return _writeFlatVector( value ); }
178 DataOStream& DataOStream::operator << ( const std::vector< uint32_t >& value )
179 {
return _writeFlatVector( value ); }
183 DataOStream& DataOStream::operator << ( const std::vector< int32_t >& value )
184 {
return _writeFlatVector( value ); }
188 DataOStream& DataOStream::operator << ( const std::vector< uint64_t >& value )
189 {
return _writeFlatVector( value ); }
193 DataOStream& DataOStream::operator << ( const std::vector< int64_t >& value )
194 {
return _writeFlatVector( value ); }
198 DataOStream& DataOStream::operator << ( const std::vector< float >& value )
199 {
return _writeFlatVector( value ); }
203 DataOStream& DataOStream::operator << ( const std::vector< double >& value )
204 {
return _writeFlatVector( value ); }
208 DataOStream::operator << ( const std::vector< ObjectVersion >& value )
209 {
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.