endianness

Crates.ioendianness
lib.rsendianness
version0.2.0
sourcesrc
created_at2016-02-28 13:59:18.682047
updated_at2016-03-24 15:19:51.497895
descriptionRust library for reading numbers in big-endian and little-endian.
homepagehttps://github.com/igrslv/rust-endianness
repositoryhttps://github.com/igrslv/rust-endianness.git
max_upload_size
id4321
size11,164
Ihar Salauyou (igrslv)

documentation

http://igrslv.github.io/rustdoc/endianness/

README

rust-endianness

Library provides functions to read numbers from a stream of bytes either in big-endian or little-endian. Functions return Result type.

Build Status

Installation

Add the package to your Cargo.toml:

[dependencies]
endianness = "0.2"

and then import it:

extern crate endianness;
use endianness::*;

Usage

Read signed 16-bit integers:

let v = vec![0, 128, 128, 0];

assert_eq!(-32768, read_i16(&v[0..2], ByteOrder::LittleEndian).unwrap());
assert_eq!(-32768, read_i16(&v[2..4], ByteOrder::BigEndian).unwrap());

Read a signed 32-bit integer:

let v = vec![0, 128, 128, 0];

match read_i32(&v, ByteOrder::LittleEndian) {
    Ok(n) => println!("Read value {}", n), // 8421376
    Err(err) => println!("Error: {}", err),
}

Read a single-precision floating point number:

let v = vec![194, 255, 0, 0];
assert_eq!(-127.5, read_f32(&v[0..4], ByteOrder::BigEndian).unwrap());
Commit count: 32

cargo fmt