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

Function decode

nodedb-codec/src/zstd_codec.rs:56–69  ·  view source on GitHub ↗

Decompress Zstd-compressed bytes.

(data: &[u8])

Source from the content-addressed store, hash-verified

54
55/// Decompress Zstd-compressed bytes.
56pub fn decode(data: &[u8]) -> Result<Vec<u8>, CodecError> {
57 if data.len() < HEADER_SIZE {
58 return Err(CodecError::Truncated {
59 expected: HEADER_SIZE,
60 actual: data.len(),
61 });
62 }
63
64 let uncompressed_size = u32::from_le_bytes([data[0], data[1], data[2], data[3]]) as usize;
65 // Byte 4 is level — informational only, not needed for decompression.
66 let frame = &data[HEADER_SIZE..];
67
68 decompress_native(frame, uncompressed_size)
69}
70
71/// Get the uncompressed size from the header without decompressing.
72pub fn uncompressed_size(data: &[u8]) -> Result<usize, CodecError> {

Callers 5

decode_allMethod · 0.70
empty_dataFunction · 0.70
small_data_roundtripFunction · 0.70
large_data_roundtripFunction · 0.70
streaming_encoderFunction · 0.70

Calls 2

decompress_nativeFunction · 0.85
lenMethod · 0.45

Tested by 4

empty_dataFunction · 0.56
small_data_roundtripFunction · 0.56
large_data_roundtripFunction · 0.56
streaming_encoderFunction · 0.56