tree-buf 0.10.0

A prototype binary serialization protocol for data
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use crate::prelude::*;

#[cfg(feature = "decode")]
pub fn decode_bytes<'a>(len: usize, bytes: &'a [u8], offset: &'_ mut usize) -> DecodeResult<&'a [u8]> {
    let start = *offset;
    let end = start.checked_add(len).ok_or(DecodeError::InvalidFormat)?;
    if end > bytes.len() {
        return Err(DecodeError::InvalidFormat);
    }
    *offset = end;
    Ok(&bytes[start..end])
}