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

Function encode_with_level

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

Compress raw bytes using Zstd at a specific level (1-22).

(data: &[u8], level: i32)

Source from the content-addressed store, hash-verified

41
42/// Compress raw bytes using Zstd at a specific level (1-22).
43pub fn encode_with_level(data: &[u8], level: i32) -> Result<Vec<u8>, CodecError> {
44 let level = level.clamp(1, 22);
45
46 let compressed = compress_native(data, level)?;
47
48 let mut out = Vec::with_capacity(HEADER_SIZE + compressed.len());
49 out.extend_from_slice(&(data.len() as u32).to_le_bytes());
50 out.push(level as u8);
51 out.extend_from_slice(&compressed);
52 Ok(out)
53}
54
55/// Decompress Zstd-compressed bytes.
56pub fn decode(data: &[u8]) -> Result<Vec<u8>, CodecError> {

Callers 5

encodeFunction · 0.85
finishMethod · 0.85
high_compression_levelFunction · 0.85
header_metadataFunction · 0.85
level_clampingFunction · 0.85

Calls 3

compress_nativeFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45

Tested by 3

high_compression_levelFunction · 0.68
header_metadataFunction · 0.68
level_clampingFunction · 0.68