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

Function decode_f64

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

Decompress Pcodec f64 data.

(data: &[u8])

Source from the content-addressed store, hash-verified

46
47/// Decompress Pcodec f64 data.
48pub fn decode_f64(data: &[u8]) -> Result<Vec<f64>, CodecError> {
49 if data.len() < 5 {
50 return Err(CodecError::Truncated {
51 expected: 5,
52 actual: data.len(),
53 });
54 }
55
56 let tag = data[0];
57 if tag != TAG_F64 {
58 return Err(CodecError::Corrupt {
59 detail: format!("pcodec expected f64 tag (0), got {tag}"),
60 });
61 }
62
63 let count = u32::from_le_bytes([data[1], data[2], data[3], data[4]]) as usize;
64 if count == 0 {
65 return Ok(Vec::new());
66 }
67
68 let values: Vec<f64> = pco::standalone::simple_decompress(&data[5..]).map_err(|e| {
69 CodecError::DecompressFailed {
70 detail: format!("pcodec f64: {e}"),
71 }
72 })?;
73
74 if values.len() != count {
75 return Err(CodecError::Corrupt {
76 detail: format!(
77 "pcodec f64 count mismatch: header says {count}, got {}",
78 values.len()
79 ),
80 });
81 }
82
83 Ok(values)
84}
85
86// ---------------------------------------------------------------------------
87// i64 encode / decode

Callers 6

decode_f64_pipelineFunction · 0.70
f64_emptyFunction · 0.70
f64_roundtripFunction · 0.70
f64_special_valuesFunction · 0.70
f64_roundtripFunction · 0.50
decode_attr_colFunction · 0.50

Calls 1

lenMethod · 0.45

Tested by 4

f64_emptyFunction · 0.56
f64_roundtripFunction · 0.56
f64_special_valuesFunction · 0.56
f64_roundtripFunction · 0.40