Kagome
Polkadot Runtime Engine in C++17
protobuf_state_request.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_ADAPTERS_PROTOBUF_STATE_REQUEST
7 #define KAGOME_ADAPTERS_PROTOBUF_STATE_REQUEST
8 
10 
11 #include <gsl/span>
12 #include <libp2p/multi/uvarint.hpp>
13 
14 #include "common/visitor.hpp"
17 #include "primitives/common.hpp"
18 
19 namespace kagome::network {
20 
21  template <>
23  static size_t size(const StateRequest &t) {
24  return 0;
25  }
26 
27  static std::vector<uint8_t>::iterator write(
28  const StateRequest &t,
29  std::vector<uint8_t> &out,
30  std::vector<uint8_t>::iterator loaded) {
31  ::api::v1::StateRequest msg;
32 
33  msg.set_block(t.hash.toString());
34  for (const auto &start : t.start) {
35  msg.add_start(start.toString());
36  }
37  msg.set_no_proof(t.no_proof);
38 
39  return appendToVec(msg, out, loaded);
40  }
41 
42  static outcome::result<std::vector<uint8_t>::const_iterator> read(
43  StateRequest &out,
44  const std::vector<uint8_t> &src,
45  std::vector<uint8_t>::const_iterator from) {
46  const auto remains = src.size() - std::distance(src.begin(), from);
47  assert(remains >= size(out));
48 
49  ::api::v1::StateRequest msg;
50  if (!msg.ParseFromArray(from.base(), remains)) {
52  }
53 
54  auto hash = primitives::BlockHash::fromString(msg.block());
55  if (hash.has_error()) {
57  }
58  out.hash = std::move(hash.value());
59 
60  for (const auto &strt : msg.start()) {
61  out.start.push_back(common::Buffer::fromString(strt));
62  }
63 
64  out.no_proof = msg.no_proof();
65 
66  std::advance(from, msg.ByteSizeLong());
67  return from;
68  }
69  };
70 
71 } // namespace kagome::network
72 
73 #endif // KAGOME_ADAPTERS_PROTOBUF_STATE_REQUEST
std::vector< common::Buffer > start
primitives::BlockHash hash
Block header hash.
std::vector< uint8_t >::iterator appendToVec(const T &msg, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
Definition: protobuf.hpp:24
static outcome::result< std::vector< uint8_t >::const_iterator > read(StateRequest &out, const std::vector< uint8_t > &src, std::vector< uint8_t >::const_iterator from)
static std::vector< uint8_t >::iterator write(const StateRequest &t, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
std::string toString() const noexcept
Definition: blob.hpp:153
static outcome::result< Blob< size_ > > fromString(std::string_view data)
Definition: blob.hpp:169
static SLBuffer fromString(const std::string_view &src)
stores content of a string to byte array
Definition: buffer.hpp:205