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

Function encode

nodedb-codec/src/delta.rs:90–109  ·  view source on GitHub ↗

Encode a slice of i64 values using Delta + ZigZag-varint compression.

(values: &[i64])

Source from the content-addressed store, hash-verified

88
89/// Encode a slice of i64 values using Delta + ZigZag-varint compression.
90pub fn encode(values: &[i64]) -> Vec<u8> {
91 let count = values.len() as u32;
92 // Estimate: header(4) + first_value(8) + ~2 bytes per delta.
93 let mut out = Vec::with_capacity(12 + values.len() * 2);
94
95 out.extend_from_slice(&count.to_le_bytes());
96
97 if values.is_empty() {
98 return out;
99 }
100
101 out.extend_from_slice(&values[0].to_le_bytes());
102
103 for i in 1..values.len() {
104 let delta = values[i].wrapping_sub(values[i - 1]);
105 write_varint(&mut out, zigzag_encode(delta));
106 }
107
108 out
109}
110
111/// Decode Delta-compressed bytes back to i64 values.
112pub fn decode(data: &[u8]) -> Result<Vec<i64>, CodecError> {

Callers 13

finishMethod · 0.70
empty_roundtripFunction · 0.70
single_valueFunction · 0.70
monotonic_counterFunction · 0.70
counter_resetFunction · 0.70
non_monotonic_gaugeFunction · 0.70
negative_valuesFunction · 0.70
large_valuesFunction · 0.70
boundary_valuesFunction · 0.70
streaming_decoderFunction · 0.70

Calls 4

write_varintFunction · 0.70
zigzag_encodeFunction · 0.70
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by 12

empty_roundtripFunction · 0.56
single_valueFunction · 0.56
monotonic_counterFunction · 0.56
counter_resetFunction · 0.56
non_monotonic_gaugeFunction · 0.56
negative_valuesFunction · 0.56
large_valuesFunction · 0.56
boundary_valuesFunction · 0.56
streaming_decoderFunction · 0.56
compression_vs_rawFunction · 0.56