#byte #endian #big-endian #little-endian #binary

byteordered

Abstraction for reading and writing data with implicit byte order awareness

8 releases (4 breaking)

0.5.0 Dec 2, 2019
0.4.1 Nov 26, 2019
0.4.0 Jan 15, 2019
0.3.1 Dec 14, 2018
0.1.0 Nov 22, 2018

#95 in Encoding

Download history 86/week @ 2019-12-01 194/week @ 2019-12-08 72/week @ 2019-12-15 14/week @ 2019-12-22 10/week @ 2019-12-29 58/week @ 2020-01-05 57/week @ 2020-01-12 38/week @ 2020-01-19 31/week @ 2020-01-26 54/week @ 2020-02-02 34/week @ 2020-02-09 52/week @ 2020-02-16 90/week @ 2020-02-23 69/week @ 2020-03-01 47/week @ 2020-03-08 83/week @ 2020-03-15

436 downloads per month
Used in 11 crates (6 directly)

MIT/Apache

55KB
762 lines

byteordered

Latest Version Build Status Minimum Rust Version 1.31 dependency status

A library for reading and writing data in some byte order.

Why yet another data parsing crate

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.

Using

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

License

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.

Dependencies

~105KB