commit | ea6a2edf1025b128cd6e80bb392acee7cad69e18 | [log] [tgz] |
---|---|---|
author | Andrew Gallant <jamslam@gmail.com> | Thu Mar 24 18:57:17 2016 -0400 |
committer | Andrew Gallant <jamslam@gmail.com> | Thu Mar 24 18:57:17 2016 -0400 |
tree | eb1fc85b8457a3adfa4defad356dde76a06c9eae | |
parent | 3708ed38fe82a3afe61da5649f5822ce280f2fa1 [diff] |
0.5.1
This crate provides convenience methods for encoding and decoding numbers in either big-endian or little-endian order. This is meant to replace the old methods defined on the standard library Reader
and Writer
traits.
Dual-licensed under MIT or the UNLICENSE.
http://burntsushi.net/rustdoc/byteorder/.
The documentation includes examples.
This crate works with Cargo and is on crates.io. The package is regularly updated. Add it to your Cargo.toml
like so:
[dependencies] byteorder = "0.4"
If you want to augment existing Read
and Write
traits, then import the extension methods like so:
extern crate byteorder; use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian, LittleEndian};
For example:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![2, 5, 3, 0]); // Note that we use type parameters to indicate which kind of byte order // we want! assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap()); assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());