Expand description
A small and easy crate to mutate or read u8 slices.
Reads or writes any number using the byte order “big-endian”.
§Read a slice
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());
§Write to a slice
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());
Structs§
- Bytes
- A slice wrapper that implements BytesRead.
- Bytes
Array - A array wrapper that implements BytesWrite and BytesRead
- Bytes
Mut - A mutable slice wrapper that implements BytesWrite
- Bytes
Owned - A Vec wrapper that implements BytesWrite and BytesRead
- Cursor
- A generic struct implementing BytesRead, BytesWrite and BytesSeek for different types.
- Offset
- A struct which holds a specific offset for any BytesRead, BytesWrite or BytesSeek implementation.
- Read
Error - Get’s returned when there is not enough space to read everything. If this get’s returned nothing was read.
- Seek
Error - Get’s returned when there is not enough data left to seek to the position.
- Write
Error - Get’s returned when there is not enough space to write everything. If this get’s returned nothing should be written.
Traits§
- Bytes
Read - Read bytes or numbers.
- Bytes
Read Ref - Read bytes while keeping the original reference.
- Bytes
Seek - Sets the internal position for writing or reading.
- Bytes
Write - Write bytes or numbers.