Decompress Zstd-compressed bytes.
(data: &[u8])
| 54 | |
| 55 | /// Decompress Zstd-compressed bytes. |
| 56 | pub fn decode(data: &[u8]) -> Result<Vec<u8>, CodecError> { |
| 57 | if data.len() < HEADER_SIZE { |
| 58 | return Err(CodecError::Truncated { |
| 59 | expected: HEADER_SIZE, |
| 60 | actual: data.len(), |
| 61 | }); |
| 62 | } |
| 63 | |
| 64 | let uncompressed_size = u32::from_le_bytes([data[0], data[1], data[2], data[3]]) as usize; |
| 65 | // Byte 4 is level — informational only, not needed for decompression. |
| 66 | let frame = &data[HEADER_SIZE..]; |
| 67 | |
| 68 | decompress_native(frame, uncompressed_size) |
| 69 | } |
| 70 | |
| 71 | /// Get the uncompressed size from the header without decompressing. |
| 72 | pub fn uncompressed_size(data: &[u8]) -> Result<usize, CodecError> { |