6 #ifndef KAGOME_ADAPTERS_PROTOBUF_BLOCK_REQUEST 7 #define KAGOME_ADAPTERS_PROTOBUF_BLOCK_REQUEST 12 #include <libp2p/multi/uvarint.hpp> 26 static std::vector<uint8_t>::iterator
write(
28 std::vector<uint8_t> &out,
29 std::vector<uint8_t>::iterator loaded) {
30 ::api::v1::BlockRequest msg;
32 msg.set_fields(htobe32(t.
fields));
34 kagome::visit_in_place(
37 msg.set_hash(block_hash.toString());
40 uint32_t n = htole32(block_number);
41 msg.set_number(&n, sizeof(n));
44 msg.set_direction(static_cast<::api::v1::Direction>(t.
direction));
46 if (t.
max.has_value()) {
47 msg.set_max_blocks(t.
max.value());
53 static outcome::result<std::vector<uint8_t>::const_iterator>
read(
55 const std::vector<uint8_t> &src,
56 std::vector<uint8_t>::const_iterator from) {
57 const auto remains = src.size() - std::distance(src.begin(), from);
58 assert(remains >= size(out));
60 ::api::v1::BlockRequest msg;
61 if (!msg.ParseFromArray(from.base(), remains)) {
66 out.
direction =
static_cast<decltype(out.direction)
>(msg.direction());
68 switch (msg.from_block_case()) {
78 std::min(
sizeof(n), msg.number().size()));
87 if (msg.max_blocks() > 0) {
88 out.
max.emplace(msg.max_blocks());
91 std::advance(from, msg.ByteSizeLong());
98 #endif // KAGOME_ADAPTERS_PROTOBUF_BLOCK_REQUEST static size_t size(const BlocksRequest &t)
std::vector< uint8_t >::iterator appendToVec(const T &msg, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
BlockAttributes fields
bits, showing, which parts of BlockData to return
static outcome::result< Blob< size_ > > fromString(std::string_view data)
constexpr void load(T value)
primitives::BlockId from
start from this block
static outcome::result< std::vector< uint8_t >::const_iterator > read(BlocksRequest &out, const std::vector< uint8_t > &src, std::vector< uint8_t >::const_iterator from)
std::optional< uint32_t > max
static std::vector< uint8_t >::iterator write(const BlocksRequest &t, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
Direction direction
sequence direction