Crate endianrw [] [src]

Library that allows to read and write primitive types from byte array with specified endianess.

Implements read_as and write_as for: std::io::Write and std::io::Read

Supported types: u8 u16 u32 u64 i8 i16 i32 i64 f32 f64

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, 0x23, 0x45, 0x67], &data[..]);

(&mut data[..]).write_as::<LittleEndian, u32>(val).unwrap();
assert_eq!(&[0x67, 0x45, 0x23, 0x01], &data[..]);

Enums

BigEndian

Big endian byte order

LittleEndian

Little endian byte order

Traits

ByteTransform

Tranform primitive types to and from buffer.

EndianReadExt

Extension trait that allows to read endian specified primitive types from it

EndianWriteExt

Extension trait that allows to write endian specified primitive types to it

Type Definitions

NativeByteOrder
NetworkByteOrder

Network byte order