Crates.io | simple-bytes |
lib.rs | simple-bytes |
version | 0.2.14 |
source | src |
created_at | 2020-11-24 21:28:57.758583 |
updated_at | 2023-07-17 12:56:51.847248 |
description | A small and easy crate to mutate or read u8 slices |
homepage | |
repository | https://github.com/soerenmeier/simple-bytes |
max_upload_size | |
id | 316031 |
size | 59,559 |
A small and easy crate to mutate or read u8 slices.
Reads or writes any number using the byte order "big-endian".
use simple_bytes::{Bytes, BytesRead};
let bytes: Vec<u8> = (0..255).collect();
let mut slice: Bytes = bytes.as_slice().into();
assert_eq!(0, slice.read_u8());
assert_eq!(1, slice.read_u8());
assert_eq!(515, slice.read_u16());
use simple_bytes::{BytesMut, BytesRead, BytesWrite};
let mut bytes = [0u8; 10];
let mut slice = BytesMut::from(bytes.as_mut());
slice.write_u8(1);
slice.write_f32(1.234);
slice.write(&[1u8, 2u8]);
assert_eq!(3, slice.remaining().len());