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
9#include "apply.h"
10#include "select_protocol.h"
11
13namespace bond
14{
15
18template <typename Protocols = BuiltInProtocols, typename T, typename Writer>
19inline void Serialize(const T& obj, Writer& output)
20{
21 Apply<Protocols>(Serializer<Writer, Protocols>(output), obj);
22}
23
24
26template <typename Protocols = BuiltInProtocols, typename Reader, typename T>
27inline void Deserialize(Reader input, T& obj)
28{
29 Apply<Protocols>(To<T, Protocols>(obj), bonded<T, Reader&>(input));
30}
31
32
34template <typename T, typename Protocols = BuiltInProtocols, typename Reader>
35inline T Deserialize(Reader input)
36{
37 T tmp;
38 Apply<Protocols>(To<T, Protocols>(tmp), bonded<T, Reader&>(input));
39 return tmp;
40}
41
42
44template <typename Protocols = BuiltInProtocols, typename Reader, typename T>
45inline void Deserialize(Reader input, T& obj, const RuntimeSchema& schema)
46{
47 Apply<Protocols>(To<T, Protocols>(obj), bonded<void, Reader&>(input, schema));
48}
49
50
52template <typename T, typename Protocols = BuiltInProtocols, typename Reader>
53inline T Deserialize(Reader input, const RuntimeSchema& schema)
54{
55 T tmp;
56 Apply<Protocols>(To<T, Protocols>(tmp), bonded<void, Reader&>(input, schema));
57 return tmp;
58}
59
60
62template <typename Protocols, typename T, typename Writer>
63inline void Marshal(const T& obj, Writer& output)
64{
65 Apply<Protocols>(Marshaler<Writer, Protocols>(output), obj);
66}
67
68
70template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
71inline void Unmarshal(Buffer input, T& obj)
72{
73 SelectProtocolAndApply<T, Protocols>(input, To<T, Protocols>(obj));
74}
75
76
78template <typename T, typename Protocols = BuiltInProtocols, typename Buffer>
79inline T Unmarshal(Buffer input)
80{
81 T tmp;
82 SelectProtocolAndApply<T, Protocols>(input, To<T, Protocols>(tmp));
83 return tmp;
84}
85
86
88template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
89inline void Unmarshal(Buffer input, bonded<T>& obj)
90{
91 SelectProtocolAndApply<T, Protocols>(input, boost::ref(obj));
92}
93
94
96template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
97inline void Unmarshal(Buffer input, T& obj, const RuntimeSchema& schema)
98{
99 SelectProtocolAndApply<Protocols>(schema, input, To<T, Protocols>(obj));
100}
101
102
104template <typename T, typename Protocols = BuiltInProtocols, typename Buffer>
105inline T Unmarshal(Buffer input, const RuntimeSchema& schema)
106{
107 T tmp;
108 SelectProtocolAndApply<Protocols>(schema, input, To<T, Protocols>(tmp));
109 return tmp;
110}
111
112
115template <typename Protocols = BuiltInProtocols, typename Buffer, typename T>
116inline void Unmarshal(Buffer input, bonded<T>& obj, const RuntimeSchema& schema)
117{
118 SelectProtocolAndApply<Protocols>(schema, input, boost::ref(obj));
119}
120
121
124template <typename Protocols = BuiltInProtocols, typename T, typename Reader, typename Writer>
125inline void Merge(const T& obj, Reader input, Writer& output)
126{
127 Apply<Protocols>(Merger<T, Writer, Protocols>(obj, output), bonded<T>(input));
128}
129
130}
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
namespace bond
Definition: apply.h:17
void Serialize(const T &obj, Writer &output)
Serialize an object using a protocol writer.
Definition: bond.h:19
void Deserialize(Reader input, T &obj)
Deserialize an object from a protocol reader.
Definition: bond.h:27
void Marshal(const T &obj, Writer &output)
Marshal an object using a protocol writer.
Definition: bond.h:63
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
void Unmarshal(Buffer input, T &obj)
Unmarshal an object from data stream.
Definition: bond.h:71