MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encode_to

Method encode_to

nodedb-array/src/segment/format/header.rs:48–57  ·  view source on GitHub ↗

Write the header to `out`, appending CRC32C of the preceding 28 bytes. Returns the total bytes written (always [`HEADER_SIZE`]).

(&self, out: &mut Vec<u8>)

Source from the content-addressed store, hash-verified

46 /// Write the header to `out`, appending CRC32C of the preceding 28
47 /// bytes. Returns the total bytes written (always [`HEADER_SIZE`]).
48 pub fn encode_to(&self, out: &mut Vec<u8>) -> usize {
49 let start = out.len();
50 out.extend_from_slice(&HEADER_MAGIC);
51 out.extend_from_slice(&self.version.to_le_bytes());
52 out.extend_from_slice(&self.flags.to_le_bytes());
53 out.extend_from_slice(&self.schema_hash.to_le_bytes());
54 let crc = crc32c::crc32c(&out[start..start + 20]);
55 out.extend_from_slice(&crc.to_le_bytes());
56 HEADER_SIZE
57 }
58
59 pub fn decode(bytes: &[u8]) -> ArrayResult<Self> {
60 if bytes.len() < HEADER_SIZE {

Callers 5

newMethod · 0.45
finishMethod · 0.45
header_round_tripFunction · 0.45
header_rejects_bad_crcFunction · 0.45

Calls 1

lenMethod · 0.45

Tested by 3

header_round_tripFunction · 0.36
header_rejects_bad_crcFunction · 0.36