Encode a slice of i64 values using FOR + bit-packing.
(values: &[i64])
| 46 | |
| 47 | /// Encode a slice of i64 values using FOR + bit-packing. |
| 48 | pub fn encode(values: &[i64]) -> Vec<u8> { |
| 49 | let total_count = values.len() as u32; |
| 50 | let block_count = if values.is_empty() { |
| 51 | 0u16 |
| 52 | } else { |
| 53 | values.len().div_ceil(BLOCK_SIZE) as u16 |
| 54 | }; |
| 55 | |
| 56 | let mut out = Vec::with_capacity(GLOBAL_HEADER_SIZE + values.len() * 5); |
| 57 | |
| 58 | // Global header. |
| 59 | out.extend_from_slice(&total_count.to_le_bytes()); |
| 60 | out.extend_from_slice(&block_count.to_le_bytes()); |
| 61 | |
| 62 | // Encode each block. |
| 63 | for chunk in values.chunks(BLOCK_SIZE) { |
| 64 | encode_block(chunk, &mut out); |
| 65 | } |
| 66 | |
| 67 | out |
| 68 | } |
| 69 | |
| 70 | /// Decode FOR + bit-packed bytes back to i64 values. |
| 71 | pub fn decode(data: &[u8]) -> Result<Vec<i64>, CodecError> { |