Bond
 
Loading...
Searching...
No Matches
bond.h
Go to the documentation of this file.
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
5#pragma once
6
7#include <bond/core/config.h>
8#include <bond/core/detail/recursionguard.h>
9
10#include "apply.h"
11#include "select_protocol.h"
12
14namespace bond
15{
16
19template <typename Protocols = BuiltInProtocols, typename T, typename Writer>
20inline void Serialize(const T& obj, Writer& output)
21{
22 Apply<Protocols>(Serializer<Writer, Protocols>(output), obj);
23}
24
25
27template <typename Protocols = BuiltInProtocols, typename Reader, typename T>
28inline void Deserialize(Reader input, T& obj)
29{
30 Apply<Protocols>(To<T, Protocols>(obj), bonded<T, Reader&>(input));
31}
32
33
35template <typename T, typename Protocols = BuiltInProtocols, typename Reader>
36inline T Deserialize(Reader input)
37{
38 T tmp;
39 Apply<Protocols>(To<T, Protocols>(tmp), bonded<T, Reader&>(input));
40 return tmp;
41}
42
43
45template <typename Protocols = BuiltInProtocols, typename Reader, typename T>
46inline void Deserialize(Reader input, T& obj, const RuntimeSchema& schema)
47{
48 Apply<Protocols>(To<T, Protocols>(obj), bonded<void, Reader&>(input, schema));
49}
50
51
53template <typename T, typename Protocols = BuiltInProtocols, typename Reader>
54inline T Deserialize(Reader input, const RuntimeSchema& schema)
55{
56 T tmp;
57 Apply<Protocols>(To<T, Protocols>(tmp), bonded<void, Reader&>(input, schema));
58 return tmp;
59}
60
61
63template <typename Protocols, typename T, typename Writer>
64inline void Marshal(const T& obj, Writer& output)
65{
66 Apply<Protocols>(Marshaler<Writer, Protocols>(output), obj);
67}
68
69
71template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
72inline void Unmarshal(Buffer input, T& obj)
73{
74 SelectProtocolAndApply<T, Protocols>(input, To<T, Protocols>(obj));
75}
76
77
79template <typename T, typename Protocols = BuiltInProtocols, typename Buffer>
80inline T Unmarshal(Buffer input)
81{
82 T tmp;
83 SelectProtocolAndApply<T, Protocols>(input, To<T, Protocols>(tmp));
84 return tmp;
85}
86
87
89template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
90inline void Unmarshal(Buffer input, bonded<T>& obj)
91{
92 SelectProtocolAndApply<T, Protocols>(input, boost::ref(obj));
93}
94
95
97template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
98inline void Unmarshal(Buffer input, T& obj, const RuntimeSchema& schema)
99{
100 SelectProtocolAndApply<Protocols>(schema, input, To<T, Protocols>(obj));
101}
102
103
105template <typename T, typename Protocols = BuiltInProtocols, typename Buffer>
106inline T Unmarshal(Buffer input, const RuntimeSchema& schema)
107{
108 T tmp;
109 SelectProtocolAndApply<Protocols>(schema, input, To<T, Protocols>(tmp));
110 return tmp;
111}
112
113
116template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
117inline void Unmarshal(Buffer input, bonded<T>& obj, const RuntimeSchema& schema)
118{
119 SelectProtocolAndApply<Protocols>(schema, input, boost::ref(obj));
120}
121
122
125template <typename Protocols = BuiltInProtocols, typename T, typename Reader, typename Writer>
126inline void Merge(const T& obj, Reader input, Writer& output)
127{
128 Apply<Protocols>(Merger<T, Writer, Protocols>(obj, output), bonded<T>(input));
129}
130
132inline void SetDeserializeMaxDepth(uint32_t value)
133{
135}
136
137}
Represents runtime schema See User's Manual
Definition runtime_schema.h:26
Represents data for a struct T known at compile-time.
Definition bonded.h:63
static void SetMaxDepth(uint32_t value)
Sets the maximum recursion depth permitted.
Definition recursionguard.h:52
namespace bond
Definition apply.h:17
void Serialize(const T &obj, Writer &output)
Serialize an object using a protocol writer.
Definition bond.h:20
void Deserialize(Reader input, T &obj)
Deserialize an object from a protocol reader.
Definition bond.h:28
void Marshal(const T &obj, Writer &output)
Marshal an object using a protocol writer.
Definition bond.h:64
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:126
void SetDeserializeMaxDepth(uint32_t value)
Sets the maximum recursion depth permitted for deserialization operations.
Definition bond.h:132
void Unmarshal(Buffer input, T &obj)
Unmarshal an object from data stream.
Definition bond.h:72