dotnet-io-binary 0.1.0-alpha.9

dotnet System.IO.BinaryReader/BinaryWriter functionality.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::slice::_7bit_code::split_7bc;

#[derive(Debug, thiserror::Error)]
pub enum SplitError {
    #[error("unable to split length of str")]
    Length(#[from] super::_7bit_code::SplitError),
    #[error("unexpected end of input")]
    End,
}

pub fn split_dotnet_str(buf: &[u8]) -> Result<(&[u8], &[u8]), SplitError> {
    let (len, buf): (u32, _) = split_7bc(buf)?;
    let a = buf.split_at_checked(len as _).ok_or(SplitError::End)?;
    Ok(a)
}