commit | 14b1b0892e0ee72f658c28cfa926ff7a94e55439 | [log] [tgz] |
---|---|---|
author | Andrew Gallant <jamslam@gmail.com> | Wed Mar 25 19:33:38 2015 -0400 |
committer | Andrew Gallant <jamslam@gmail.com> | Wed Mar 25 19:33:38 2015 -0400 |
tree | 6445acf3e8565cff36444d79128091bef6c1a0f9 | |
parent | 59426dedef2cb435ee138505a6230c6c752d6a6e [diff] |
rustup. Unfortunately, revert the dependency on bswap because I need a working crate. Revert "Replaced read_num_bytes!/write_num_bytes! with rust-bswap decode/encode functions." This reverts commit 718f3a8e0981e88189fbd7c35f3ed92104c32bae. # Conflicts: # Cargo.toml # src/lib.rs
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.
This crate currently supports both the std::io
and std::old_io
modules.
Licensed under 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 is to your Cargo.toml
like so:
[dependencies] byteorder = "*"
If you want to augment existing Reader
and Writer
types, then import the extension methods like so:
extern crate byteorder; use byteorder::{ReaderBytesExt, WriterBytesExt, BigEndian, LittleEndian};
Or use the ReadBytesExt
/WriteBytesExt
traits if you're using the new std::io
module.
For example:
use std::old_io::MemReader; use byteorder::{BigEndian, ReaderBytesExt}; let mut rdr = MemReader::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());