Bond
 
Loading...
Searching...
No Matches
marshaled_bonded.h
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
4#pragma once
5
6#include <bond/core/config.h>
7
8#include <bond/protocol/compact_binary.h>
9#include <bond/stream/stream_interface.h>
10
11namespace bond
12{
13namespace detail
14{
15
16template <typename Reader>
17auto ReadBlob(Reader& reader)
18#if defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION)
19 -> decltype(GetBufferRange(GetCurrentBuffer(reader.GetBuffer()), GetCurrentBuffer(reader.GetBuffer())))
20#endif
21{
22 uint32_t size;
23 reader.Read(size);
24
25 auto before = GetCurrentBuffer(reader.GetBuffer());
26 reader.GetBuffer().Skip(size);
27 auto after = GetCurrentBuffer(reader.GetBuffer());
28
29 return GetBufferRange(before, after);
30}
31
32
33template <typename Protocols, typename T, typename Writer>
34void MarshalToBlob(const T& obj, Writer& writer)
35{
36 auto output = CreateOutputBuffer(writer.GetBuffer());
37 CompactBinaryWriter<decltype(output)> cbw(output);
38
39 Marshal<Protocols>(obj, cbw);
40 auto data = std::move(output).GetBuffer();
41
42 writer.Write(static_cast<uint32_t>(data.size()));
43 writer.GetBuffer().Write(data);
44}
45
46
47} // namespace detail
48} // namespace bond
namespace bond
Definition: apply.h:17