Kagome
Polkadot Runtime Engine in C++17
protobuf.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_ADAPTERS_PROTOBUF
7 #define KAGOME_ADAPTERS_PROTOBUF
8 
9 #include <boost/system/error_code.hpp>
10 #include <functional>
11 #include <gsl/span>
12 #include <memory>
13 
15 #include "network/protobuf/api.v1.pb.h"
16 #include "outcome/outcome.hpp"
17 
18 namespace kagome::network {
19 
20  template <typename T>
22 
23  template <typename T>
24  inline std::vector<uint8_t>::iterator appendToVec(
25  const T &msg,
26  std::vector<uint8_t> &out,
27  std::vector<uint8_t>::iterator loaded) {
28  const size_t distance_was = std::distance(out.begin(), loaded);
29  const size_t was_size = out.size();
30 
31  out.resize(was_size + msg.ByteSizeLong());
32  msg.SerializeToArray(&out[was_size], msg.ByteSizeLong());
33 
34  auto res_it = out.begin();
35  std::advance(res_it, std::min(distance_was, was_size));
36  return res_it;
37  }
38 
39 } // namespace kagome::network
40 
41 #endif // KAGOME_ADAPTERS_PROTOBUF
std::vector< uint8_t >::iterator appendToVec(const T &msg, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
Definition: protobuf.hpp:24