Skip to content

Rust library for reading and writing numbers with specific endianness.

License

Notifications You must be signed in to change notification settings

kerhong/endianrw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]);

About

Rust library for reading and writing numbers with specific endianness.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages