88 typedef BufferT Buffer;
89 typedef StaticParser<SimpleBinaryReader&> Parser;
92 BOND_STATIC_CONSTEXPR uint16_t magic = SIMPLE_PROTOCOL;
93 BOND_STATIC_CONSTEXPR uint16_t version = v2;
98 uint16_t version_value = default_version<SimpleBinaryReader>::value)
100 _version(version_value)
102 BOOST_ASSERT(_version <= SimpleBinaryReader::version);
111 : _input(that._input),
112 _version(that._version)
119 return _input == rhs._input;
124 typename boost::call_traits<Buffer>::const_reference
132 typename boost::call_traits<Buffer>::reference
141 uint16_t magic_value;
143 _input.Read(magic_value);
144 _input.Read(_version);
146 return magic_value == SimpleBinaryReader::magic
147 && _version <= SimpleBinaryReader::version;
152 template <
typename T>
153 typename boost::disable_if<is_string_type<T> >::type
161 template <
typename T>
162 typename boost::enable_if<is_string_type<T> >::type
169 constexpr uint8_t charSize =
static_cast<uint8_t
>(
sizeof(
typename detail::string_char_int_type<T>::type));
170 uint32_t numStringBytes = detail::checked_multiply(length, charSize);
171 if (!_input.CanRead(numStringBytes))
173 OutOfBoundStringSizeException();
176 detail::ReadStringData(_input, var, length);
181 void Read(blob& var, uint32_t size)
183 _input.Read(var, size);
188 bool CanReadArray(uint32_t num_elems)
195#pragma warning(disable:4127)
198 BOND_IF_CONSTEXPR(is_string_type<T>::value)
200 BOND_IF_CONSTEXPR(version == v1)
203 return _input.CanRead(detail::checked_multiply(num_elems, 4));
209 return _input.CanRead(num_elems);
212 else BOND_IF_CONSTEXPR(boost::is_same<T, bool>::value)
215 return _input.CanRead(num_elems);
221 uint64_t num_bytes =
static_cast<uint64_t
>(num_elems) *
sizeof(T);
224 return (num_bytes >> 32 == 0) && _input.CanRead(num_bytes & 0xffffffff);
234 template <
typename T>
235 typename boost::disable_if<is_string_type<T> >::type
238 _input.Skip(
sizeof(T));
242 template <
typename T>
243 void Skip(
const bonded<T, SimpleBinaryReader&>& bonded);
247 template <
typename T>
248 typename boost::enable_if<is_string_type<T> >::type
254 _input.Skip(length *
sizeof(
typename detail::string_char_int_type<T>::type));
258 void Skip(BondDataType type)
265 _input.Skip(
sizeof(uint8_t));
270 _input.Skip(
sizeof(uint16_t));
275 _input.Skip(
sizeof(uint32_t));
280 _input.Skip(
sizeof(uint64_t));
284 _input.Skip(
sizeof(
float));
288 _input.Skip(
sizeof(
double));
296 Skip<std::wstring>();
305 template <
typename T>
306 void ReadContainerBegin(uint32_t& size, T&)
311 void ReadContainerEnd()
315 void ReadSize(uint32_t& size)
320 ReadVariableUnsigned(_input, size);
324 template <
typename Input,
typename MarshaledBondedProtocols,
typename Output>
327 const SimpleBinaryWriter<Output>&);
344 typedef BufferT Buffer;
349 uint16_t version = default_version<Reader>::value)
353 BOOST_ASSERT(_version <= Reader::version);
357 typename boost::call_traits<Buffer>::reference
365 _output.Write(Reader::magic);
366 _output.Write(_version);
369 void WriteStructBegin(
const Metadata& ,
bool )
372 void WriteStructEnd(
bool =
false)
375 void WriteFieldBegin(BondDataType , uint16_t ,
const Metadata& )
378 void WriteFieldBegin(BondDataType , uint16_t )
386 template <
typename T>
387 void WriteContainerBegin(uint32_t size, T)
394 void WriteContainerEnd()
397 template <
typename T>
398 void WriteField(uint16_t ,
const bond::Metadata& ,
const T& value)
403 void WriteFieldOmitted(BondDataType type, uint16_t ,
const Metadata& metadata);
406 template <
typename T>
407 typename boost::disable_if<is_string_type<T> >::type
408 Write(
const T& value)
410 _output.Write(value);
414 template <
typename T>
415 typename boost::enable_if<is_string_type<T> >::type
416 Write(
const T& value)
418 uint32_t length = string_length(value);
421 detail::WriteStringData(_output, value, length);
425 void Write(
const blob& value)
427 _output.Write(value);
431 void WriteSize(uint32_t& size)
436 WriteVariableUnsigned(_output, size);
439 template <
typename Input,
typename MarshaledBondedProtocols,
typename Output>
441 bool is_protocol_version_same(
const SimpleBinaryReader<Input, MarshaledBondedProtocols>&,
SimpleBinaryReader(typename boost::call_traits< Buffer >::param_type input, uint16_t version_value=default_version< SimpleBinaryReader >::value)
Construct from input buffer/stream containing serialized data.
Definition simple_binary.h:97
SimpleBinaryWriter(Buffer &output, uint16_t version=default_version< Reader >::value)
Construct from output buffer/stream.
Definition simple_binary.h:348