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

Function decode_i64

nodedb-codec/src/pcodec.rs:106–142  ·  view source on GitHub ↗

Decompress Pcodec i64 data.

(data: &[u8])

Source from the content-addressed store, hash-verified

104
105/// Decompress Pcodec i64 data.
106pub fn decode_i64(data: &[u8]) -> Result<Vec<i64>, CodecError> {
107 if data.len() < 5 {
108 return Err(CodecError::Truncated {
109 expected: 5,
110 actual: data.len(),
111 });
112 }
113
114 let tag = data[0];
115 if tag != TAG_I64 {
116 return Err(CodecError::Corrupt {
117 detail: format!("pcodec expected i64 tag (1), got {tag}"),
118 });
119 }
120
121 let count = u32::from_le_bytes([data[1], data[2], data[3], data[4]]) as usize;
122 if count == 0 {
123 return Ok(Vec::new());
124 }
125
126 let values: Vec<i64> = pco::standalone::simple_decompress(&data[5..]).map_err(|e| {
127 CodecError::DecompressFailed {
128 detail: format!("pcodec i64: {e}"),
129 }
130 })?;
131
132 if values.len() != count {
133 return Err(CodecError::Corrupt {
134 detail: format!(
135 "pcodec i64 count mismatch: header says {count}, got {}",
136 values.len()
137 ),
138 });
139 }
140
141 Ok(values)
142}
143
144#[cfg(test)]
145mod tests {

Callers 3

decode_i64_pipelineFunction · 0.85
i64_emptyFunction · 0.85
i64_roundtripFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by 2

i64_emptyFunction · 0.68
i64_roundtripFunction · 0.68