endianrw

Crates.ioendianrw
lib.rsendianrw
version0.2.2
sourcesrc
created_at2015-09-24 19:16:39.455424
updated_at2016-09-12 10:05:03.682203
descriptionReading and writing numbers with specific endianness
homepage
repositoryhttps://github.com/kerhong/endianrw
max_upload_size
id3100
size10,579
Edgars Baduns (kerhong)

documentation

https://kerhong.github.io/endianrw

README

endianrw

Rust library for reading and writing numbers with specific endianness.

Heavily influenced by byteorder, but with more generic API.

Build Status Crates.io Coveralls.io

License

MIT

Documentation

https://kerhong.github.io/endianrw

Examples

Read

use endianrw::{BigEndian, LittleEndian, EndianReadExt};

let data: Vec<u8> = vec![0x01, 0x23, 0x45, 0x67];

assert_eq!(0x01234567, (&data[..]).read_as::<BigEndian, u32>().unwrap());
assert_eq!(0x67452301, (&data[..]).read_as::<LittleEndian, u32>().unwrap());

Write

use endianrw::{BigEndian, LittleEndian, EndianWriteExt};

let val = 0x01234567;
let mut data: Vec<u8> = vec![0; 4];
(&mut data[..]).write_as::<BigEndian, u32>(val).unwrap();
assert_eq!(0x01, data[0]);

(&mut data[..]).write_as::<LittleEndian, u32>(val).unwrap();
assert_eq!(0x67, data[0]);
Commit count: 24

cargo fmt