#bytes #read #write #io

simple-bytes

A small and easy crate to mutate or read u8 slices

15 releases

0.2.14 Jul 17, 2023
0.2.13 Jun 24, 2023
0.2.11 Jun 12, 2022
0.2.9 Jan 22, 2022
0.1.1 Nov 24, 2020

#404 in Network programming

Download history 63/week @ 2023-10-29 42/week @ 2023-11-05 782/week @ 2023-11-12 234/week @ 2023-11-19 120/week @ 2023-11-26 63/week @ 2023-12-03 141/week @ 2023-12-10 289/week @ 2023-12-17 143/week @ 2023-12-24 111/week @ 2023-12-31 145/week @ 2024-01-07 121/week @ 2024-01-14 145/week @ 2024-01-21 72/week @ 2024-01-28 141/week @ 2024-02-04 155/week @ 2024-02-11

561 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

47KB
1.5K SLoC

CI crates.io docs.rs

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());

lib.rs:

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());

No runtime deps