Decode FOR + bit-packed bytes back to i64 values.
(data: &[u8])
| 69 | |
| 70 | /// Decode FOR + bit-packed bytes back to i64 values. |
| 71 | pub fn decode(data: &[u8]) -> Result<Vec<i64>, CodecError> { |
| 72 | if data.len() < GLOBAL_HEADER_SIZE { |
| 73 | return Err(CodecError::Truncated { |
| 74 | expected: GLOBAL_HEADER_SIZE, |
| 75 | actual: data.len(), |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | let total_count = u32::from_le_bytes([data[0], data[1], data[2], data[3]]) as usize; |
| 80 | let block_count = u16::from_le_bytes([data[4], data[5]]) as usize; |
| 81 | |
| 82 | if total_count == 0 { |
| 83 | return Ok(Vec::new()); |
| 84 | } |
| 85 | |
| 86 | let mut values = Vec::with_capacity(total_count); |
| 87 | let mut offset = GLOBAL_HEADER_SIZE; |
| 88 | |
| 89 | for block_idx in 0..block_count { |
| 90 | offset = decode_block(data, offset, &mut values, block_idx)?; |
| 91 | } |
| 92 | |
| 93 | if values.len() != total_count { |
| 94 | return Err(CodecError::Corrupt { |
| 95 | detail: format!( |
| 96 | "value count mismatch: header says {total_count}, decoded {}", |
| 97 | values.len() |
| 98 | ), |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | Ok(values) |
| 103 | } |
| 104 | |
| 105 | /// Compute byte offsets for each block in an encoded stream. |
| 106 | /// |