Crates.io | endianrw |
lib.rs | endianrw |
version | 0.2.2 |
source | src |
created_at | 2015-09-24 19:16:39.455424 |
updated_at | 2016-09-12 10:05:03.682203 |
description | Reading and writing numbers with specific endianness |
homepage | |
repository | https://github.com/kerhong/endianrw |
max_upload_size | |
id | 3100 |
size | 10,579 |
Rust library for reading and writing numbers with specific endianness.
Heavily influenced by byteorder, but with more generic API.
MIT
https://kerhong.github.io/endianrw
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());
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]);