Decompress Pcodec f64 data.
(data: &[u8])
| 46 | |
| 47 | /// Decompress Pcodec f64 data. |
| 48 | pub 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 |