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

Method encode

nodedb-array/src/segment/format/framing.rs:21–28  ·  view source on GitHub ↗

Append `[len_u32_le | payload | crc32c_u32_le]` to `out`. Returns total bytes written.

(payload: &[u8], out: &mut Vec<u8>)

Source from the content-addressed store, hash-verified

19 /// Append `[len_u32_le | payload | crc32c_u32_le]` to `out`. Returns
20 /// total bytes written.
21 pub fn encode(payload: &[u8], out: &mut Vec<u8>) -> usize {
22 let len = payload.len() as u32;
23 out.extend_from_slice(&len.to_le_bytes());
24 out.extend_from_slice(payload);
25 let crc = crc32c::crc32c(payload);
26 out.extend_from_slice(&crc.to_le_bytes());
27 FRAMING_OVERHEAD + payload.len()
28 }
29
30 /// Decode a framed block at the start of `bytes`. Returns
31 /// `(payload_slice, total_bytes_consumed)`.

Callers 1

extract_cell_bytesFunction · 0.45

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected