6#include <bond/core/config.h>
8#include "pass_through.h"
11#include <bond/core/customize.h>
12#include <bond/core/null.h>
13#include <bond/core/protocol.h>
14#include <bond/core/traits.h>
15#include <bond/stream/input_buffer.h>
27template <
typename Writer,
typename Protocols>
35template <
typename T,
typename Schema,
typename Transform>
40 _Parser(
const Transform& transform,
const Schema& schema)
41 : _transform(transform),
46 template <
typename Reader>
47 typename boost::enable_if<is_protocol_enabled<typename std::remove_const<Reader>::type>,
bool>::type
48 operator()(Reader& reader)
const
51 return Apply(_transform, reader, _schema,
false);
54 template <
typename Reader>
55 typename boost::disable_if<is_protocol_enabled<typename std::remove_const<Reader>::type>,
bool>::type
56 operator()(Reader& )
const
63 template <
typename Reader,
typename Writer,
typename Protocols>
65 typename boost::enable_if_c<is_protocol_same<Reader, Writer>::value
66 && protocol_has_multiple_versions<Reader>::value,
bool>::type
67 Apply(
const Serializer<Writer, Protocols>& transform, Reader& reader,
const Schema& schema,
bool base)
69 if (is_protocol_version_same(reader, transform._output))
70 return FastPassThrough(reader, transform._output, schema);
72 return typename Reader::Parser(reader, base).Apply(transform, schema);
75 template <
typename Reader,
typename Writer,
typename Protocols>
77 typename boost::enable_if_c<is_protocol_same<Reader, Writer>::value
78 && !protocol_has_multiple_versions<Reader>::value,
bool>::type
79 Apply(
const Serializer<Writer, Protocols>& transform, Reader& reader,
const Schema& schema,
bool base)
84 BOOST_ASSERT(is_protocol_version_same(reader, transform._output));
85 return FastPassThrough(reader, transform._output, schema);
88 template <
typename TransformT,
typename Reader>
90 bool Apply(
const TransformT& transform, Reader& reader,
const Schema& schema,
bool base)
92 return typename Reader::Parser(reader, base).Apply(transform, schema);
96 template <
typename Reader,
typename Writer,
typename SchemaT>
98 bool FastPassThrough(Reader& reader, Writer& writer,
const SchemaT&)
100 bonded<T, Reader&> value(reader);
101 PassThrough(value, reader, writer);
105 template <
typename Reader,
typename Writer>
107 bool FastPassThrough(Reader& reader, Writer& writer,
const RuntimeSchema& schema)
109 bonded<void, Reader&> value(reader, schema);
110 PassThrough(value, reader, writer);
114 const Transform& _transform;
115 const Schema& _schema;
119template <
typename T,
typename Schema,
typename Transform,
typename Enable =
void>
121 :
public _Parser<T, Schema, Transform>
124 Parser(
const Transform& transform,
const Schema& schema)
125 : _Parser<T, Schema, Transform>(transform, schema)
128 using _Parser<T, Schema, Transform>::operator();
130 bool operator()(ValueReader& value)
const
133 BOOST_VERIFY(value.pointer == NULL);
139template <
typename T,
typename Schema,
typename Transform>
140class Parser<T, Schema, Transform, typename boost::enable_if_c<is_serializing_transform<Transform>::value && !std::is_same<T, void>::value>::type>
141 :
public _Parser<T, Schema, Transform>
144 Parser(
const Transform& transform,
const Schema& schema)
145 : _Parser<T, Schema, Transform>(transform, schema)
148 using _Parser<T, Schema, Transform>::operator();
150 bool operator()(ValueReader& value)
const
153 BOOST_ASSERT(value.pointer);
156 BOOST_ASSERT(has_schema<T>::value);
157 return StaticParser<const T&>(*
static_cast<const T*
>(value.pointer)).Apply(_transform,
typename schema_for_passthrough<T>::type());
161 using _Parser<T, Schema, Transform>::_transform;
165template <
typename Reader,
typename T>
166inline void Skip(Reader& reader,
const bonded<T, Reader&>& bonded)
172template <
typename T,
template <
typename BufferT,
typename MarshaledBondedProtocolsT>
class Reader,
typename Buffer,
typename MarshaledBondedProtocols>
173inline void Skip(
const bonded<T, Reader<Buffer, MarshaledBondedProtocols>&>& bonded)
176 Apply<MarshaledBondedProtocols>(Null(), bonded);
180template <
typename Reader,
typename T>
181BOND_NO_INLINE
void Skip(Reader& reader,
const bonded<T, Reader&>& bonded,
const std::nothrow_t&) BOND_NOEXCEPT
185 Skip(reader, bonded);
192void Skip(SchemaReader&,
const bonded<T, SchemaReader&>&,
const std::nothrow_t&) BOND_NOEXCEPT
197inline void Skip(ProtocolReader& ,
const bonded<T>& ) BOND_NOEXCEPT
204inline void Skip(ProtocolReader& ,
const bonded<T>& ,
const std::nothrow_t&) BOND_NOEXCEPT
210template <
typename T,
typename Protocols,
typename Transform,
typename Reader,
typename Schema>
211inline bool Parse(
const Transform& transform, Reader& reader,
const Schema& schema,
const RuntimeSchema* runtime_schema,
bool base)
213 BOOST_VERIFY(!runtime_schema);
214 return Parser<T, Schema, Transform>::Apply(transform, reader, schema, base);
217template <
typename T,
typename Protocols,
typename Transform,
typename Reader,
typename Schema>
218inline bool Parse(
const Transform& transform, Reader& reader,
const Schema& schema, std::nullptr_t,
bool base)
220 return Parser<T, Schema, Transform>::Apply(transform, reader, schema, base);
223template <
typename T,
typename Protocols,
typename Transform,
typename Schema>
224inline bool Parse(
const Transform& transform, ProtocolReader& reader,
const Schema& schema)
228 Parser<T, Schema, Transform> parser(transform, schema);
230 if (
auto&& result = reader.template Visit<Protocols
231#
if defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION) || defined(BOND_NO_CXX14_GENERIC_LAMBDAS)
239 UnknownProtocolException();
242template <
typename T,
typename Protocols,
typename Transform,
typename Schema>
243inline bool Parse(
const Transform& transform, ProtocolReader reader,
const Schema& schema,
const RuntimeSchema* runtime_schema,
bool base)
249 return Parse<void, Protocols>(transform, reader, *runtime_schema);
253 return Parse<T, Protocols>(transform, reader, schema);
257template <
typename T,
typename Protocols,
typename Transform,
typename Schema>
258inline bool Parse(
const Transform& transform, ProtocolReader reader,
const Schema& schema, std::nullptr_t,
bool base)
261 return Parse<T, Protocols>(transform, reader, schema);
266template <
typename T,
typename Buffer>
271 InsituMerge(
const T& var, ProtocolReader& reader)
277 template <
typename Reader>
278 typename boost::enable_if<is_protocol_enabled<typename std::remove_const<Reader>::type> >::type
279 operator()(Reader& reader)
const
282 typename get_protocol_writer<Reader, Buffer>::type writer(merged);
284 Merge(_var, reader, writer);
286 _reader = Reader(merged.GetBuffer());
289 template <
typename Reader>
290 typename boost::disable_if<is_protocol_enabled<typename std::remove_const<Reader>::type> >::type
291 operator()(Reader& )
const
298 void operator()(ValueReader&)
const
306 ProtocolReader& _reader;
310template <
typename Protocols,
typename Buffer = OutputBuffer,
typename T>
311inline void Merge(
const T& var, ProtocolReader& reader)
313 if (!reader.template Visit<Protocols
314#
if defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION) || defined(BOND_NO_CXX14_GENERIC_LAMBDAS)
317 >(InsituMerge<T, Buffer>(var, reader)))
319 UnknownProtocolException();
namespace bond
Definition: apply.h:17
void Merge(const T &obj, Reader input, Writer &output)
Merge an object with serialize data and write the result using a protocol writer.
Definition: bond.h:125