MCPcopy Create free account
hub / github.com/category-labs/monad / serialize_node_to_buffer

Function serialize_node_to_buffer

category/mpt/node.cpp:637–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635}
636
637void serialize_node_to_buffer(
638 unsigned char *write_pos, unsigned bytes_to_append, Node const &node,
639 uint32_t const disk_size, unsigned const offset)
640{
641 MONAD_ASSERT(disk_size > 0 && disk_size <= Node::max_disk_size);
642 if (offset < Node::disk_size_bytes) { // serialize node disk size
643 MONAD_ASSERT(bytes_to_append <= disk_size - offset);
644 unsigned const written =
645 std::min(bytes_to_append, Node::disk_size_bytes - offset);
646 memcpy(write_pos, (unsigned char *)&disk_size + offset, written);
647 bytes_to_append -= written;
648 write_pos += written;
649 }
650
651 if (bytes_to_append) { // serialize node
652 unsigned const offset_within_node = offset >= Node::disk_size_bytes
653 ? offset - Node::disk_size_bytes
654 : 0;
655 memcpy(
656 write_pos,
657 (unsigned char *)&node + offset_within_node,
658 bytes_to_append);
659 }
660}
661
662int64_t calc_min_version(Node const &node)
663{

Callers 1

async_write_nodeFunction · 0.85

Calls 1

minFunction · 0.50

Tested by

no test coverage detected