Crates.io | byteordered |
lib.rs | byteordered |
version | 0.6.0 |
source | src |
created_at | 2018-11-22 16:22:04.214757 |
updated_at | 2021-08-03 14:20:19.132862 |
description | Abstraction for reading and writing data with implicit byte order awareness |
homepage | |
repository | https://github.com/Enet4/byteordered |
max_upload_size | |
id | 98179 |
size | 93,361 |
A library for reading and writing data in some byte order.
While byteorder
is well established in the Rust ecosystem, it relies on immaterial zero-constructor types for declaring the intended byte order. As such, it lacks a construct for reading and writing data in an endianness that is not originally known at compile time. For example, there are file formats in which the encoding may be either in little endian or in big endian order.
In addition, some users feel that adding the type parameter on each read/write method call is unnecessarily verbose and ugly.
Rather than building yet another new library, this crate aims to provide an alternative public API to byteorder
, so that it becomes suitable for this particular case while preserving its familiarity and core capabilities.
An example follows. Please see the documentation for more information.
use byteordered::{ByteOrdered, Endianness};
let mut rd = ByteOrdered::le(get_data_source()?);
// read 1st byte
let b1 = rd.read_u8()?;
// choose to read the following data in Little Endian if it's 0,
// otherwise read in Big Endian
let endianness = Endianness::le_iff(b1 != 0);
let mut rd = rd.into_endianness(endianness);
let value: u32 = rd.read_u32()?;
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.