6#include <bond/core/config.h>
10#include <bond/core/bond_version.h>
11#include <bond/core/traits.h>
13#include <boost/call_traits.hpp>
14#include <boost/noncopyable.hpp>
79template <
typename BufferT>
80class SimpleBinaryWriter;
84template <
typename BufferT,
typename MarshaledBondedProtocolsT>
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
168 detail::ReadStringData(_input, var, length);
173 void Read(blob& var, uint32_t size)
175 _input.Read(var, size);
180 template <
typename T>
181 typename boost::disable_if<is_string_type<T> >::type
184 _input.Skip(
sizeof(T));
188 template <
typename T>
189 void Skip(
const bonded<T, SimpleBinaryReader&>& bonded);
193 template <
typename T>
194 typename boost::enable_if<is_string_type<T> >::type
200 _input.Skip(length *
sizeof(
typename detail::string_char_int_type<T>::type));
204 void Skip(BondDataType type)
211 _input.Skip(
sizeof(uint8_t));
216 _input.Skip(
sizeof(uint16_t));
221 _input.Skip(
sizeof(uint32_t));
226 _input.Skip(
sizeof(uint64_t));
230 _input.Skip(
sizeof(
float));
234 _input.Skip(
sizeof(
double));
242 Skip<std::wstring>();
251 template <
typename T>
252 void ReadContainerBegin(uint32_t& size, T&)
257 void ReadContainerEnd()
261 void ReadSize(uint32_t& size)
266 ReadVariableUnsigned(_input, size);
270 template <
typename Input,
typename MarshaledBondedProtocols,
typename Output>
272 bool is_protocol_version_same(
const SimpleBinaryReader<Input, MarshaledBondedProtocols>&,
273 const SimpleBinaryWriter<Output>&);
280template <
typename BufferT,
typename MarshaledBondedProtocolsT>
281BOND_CONSTEXPR_OR_CONST uint16_t SimpleBinaryReader<BufferT, MarshaledBondedProtocolsT>::magic;
285template <
typename BufferT>
290 typedef BufferT Buffer;
295 uint16_t version = default_version<Reader>::value)
299 BOOST_ASSERT(_version <= Reader::version);
303 typename boost::call_traits<Buffer>::reference
311 _output.Write(Reader::magic);
312 _output.Write(_version);
315 void WriteStructBegin(
const Metadata& ,
bool )
318 void WriteStructEnd(
bool =
false)
321 void WriteFieldBegin(BondDataType , uint16_t ,
const Metadata& )
324 void WriteFieldBegin(BondDataType , uint16_t )
332 template <
typename T>
333 void WriteContainerBegin(uint32_t size, T)
340 void WriteContainerEnd()
343 template <
typename T>
344 void WriteField(uint16_t ,
const bond::Metadata& ,
const T& value)
349 void WriteFieldOmitted(BondDataType type, uint16_t ,
const Metadata& metadata);
352 template <
typename T>
353 typename boost::disable_if<is_string_type<T> >::type
354 Write(
const T& value)
356 _output.Write(value);
360 template <
typename T>
361 typename boost::enable_if<is_string_type<T> >::type
362 Write(
const T& value)
364 uint32_t length = string_length(value);
367 detail::WriteStringData(_output, value, length);
371 void Write(
const blob& value)
373 _output.Write(value);
377 void WriteSize(uint32_t& size)
382 WriteVariableUnsigned(_output, size);
385 template <
typename Input,
typename MarshaledBondedProtocols,
typename Output>
387 bool is_protocol_version_same(
const SimpleBinaryReader<Input, MarshaledBondedProtocols>&,
388 const SimpleBinaryWriter<Output>&);
395template <
typename Input,
typename MarshaledBondedProtocols>
struct
396protocol_has_multiple_versions<SimpleBinaryReader<Input, MarshaledBondedProtocols> >
400template <
typename Input,
typename MarshaledBondedProtocols,
typename Output>
401bool is_protocol_version_same(
const SimpleBinaryReader<Input, MarshaledBondedProtocols>& reader,
402 const SimpleBinaryWriter<Output>& writer)
404 return reader._version == writer._version;
407template <
typename Output>
struct
408may_omit_fields<SimpleBinaryWriter<Output> >
409 : std::false_type {};
Reader for Simple Binary protocol.
Definition: simple_binary.h:86
boost::call_traits< Buffer >::const_reference GetBuffer() const
Access to underlying buffer.
Definition: simple_binary.h:125
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
bool operator==(const SimpleBinaryReader &rhs) const
Comparison operator.
Definition: simple_binary.h:117
SimpleBinaryReader(const SimpleBinaryReader &that) BOND_NOEXCEPT
Copy constructor.
Definition: simple_binary.h:110
boost::call_traits< Buffer >::reference GetBuffer()
Access to underlying buffer.
Definition: simple_binary.h:133
Writer for Simple Binary protocol.
Definition: simple_binary.h:288
boost::call_traits< Buffer >::reference GetBuffer()
Access to underlying buffer.
Definition: simple_binary.h:304
SimpleBinaryWriter(Buffer &output, uint16_t version=default_version< Reader >::value)
Construct from output buffer/stream.
Definition: simple_binary.h:294
namespace bond
Definition: apply.h:17