byteio
byteio is a simple crate that exposes lightweight abstractions for read/write operations on contiguous slices of memory.
The crate is based around two core traits: ReadBytes and
WriteBytes. Two extension traits which add functionality for
reading and writing numbers also have blanket implementations for any types
that implement the core traits.
Installation
To start using byteio add it to your Cargo.toml like so:
[]
= "0.2"
By default this will active the std feature which enables functionality in
the crate which is only available when compiling with the standard library.
To use the crate in a no_std environment you just need to disable this
feature. This can be done by adjusting your Cargo.toml:
[]
= { = "0.2", = false }
The crate has a final feature: alloc. This should be used when you are
building in a no_std environment, have an allocator, and want
functionality for working with Vec<u8>. You can activate this by adjusting
your Cargo.toml again:
[]
= { = "0.2", = false, = ["alloc"] }
Usage
Manual serialization and deserialization of a simple network packet:
use TryInto;
use *; // ReadBytes, ReadBytesExt, WriteBytes, WriteBytesExt
/// A packet whose payload is encoded as `[n_msb, n_lsb, b_0, b_1, ..., b_n-1]`.
#
#
#