OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
util/serialization/format.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "format.hpp"
7
8namespace cbdc {
9 auto operator<<(serializer& packet, std::byte b) -> serializer& {
10 packet << static_cast<uint8_t>(b);
11 return packet;
12 }
13
14 auto operator>>(serializer& packet, std::byte& b) -> serializer& {
15 uint8_t val{};
16
17 if(packet >> val) {
18 b = static_cast<std::byte>(val);
19 }
20
21 return packet;
22 }
23
24 auto operator<<(serializer& ser, const buffer& b) -> serializer& {
25 ser << static_cast<uint64_t>(b.size());
26 ser.write(b.data(), b.size());
27 return ser;
28 }
29
30 auto operator>>(serializer& deser, buffer& b) -> serializer& {
31 uint64_t sz{};
32 deser >> sz;
33 b.extend(sz);
34 deser.read(b.data(), sz);
35 return deser;
36 }
37}
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Interface for serializing objects into and out of raw bytes representations.
auto operator>>(serializer &deser, parsec::agent::rpc::request &req) -> serializer &
auto operator<<(serializer &ser, const parsec::agent::rpc::request &req) -> serializer &