commit | 666b4679235fbd8a2024626abee625267a8fce29 | [log] [tgz] |
---|---|---|
author | Xin Li <delphij@google.com> | Wed Oct 30 14:24:45 2019 -0700 |
committer | android-build-merger <android-build-merger@google.com> | Wed Oct 30 14:24:45 2019 -0700 |
tree | 236cad670aa0ee2d57c2bf389554957d9e7e0a21 | |
parent | 6c8e4604cbfc9e92118d0a4d84306d8015115842 [diff] | |
parent | ba84d82c1d80abd16b655a07f1d94e83576c0a33 [diff] |
[automerger skipped] DO NOT MERGE - qt-qpr1-dev-plus-aosp-without-vendor@5915889 into stage-aosp-master am: 6787a06471 am: ba84d82c1d -s ours am skip reason: subject contains skip directive Change-Id: If564d0fccc8f3dd23a37804985429a291ec8f303
This crate provides convenience methods for encoding and decoding numbers in either big-endian or little-endian order.
Dual-licensed under MIT or the UNLICENSE.
This crate works with Cargo and is on crates.io. Add it to your Cargo.toml
like so:
[dependencies] byteorder = "1"
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());
no_std
cratesThis crate has a feature, std
, that is enabled by default. To use this crate in a no_std
context, add the following to your Cargo.toml
:
[dependencies] byteorder = { version = "1", default-features = false }
Note that as of Rust 1.32, the standard numeric types provide built-in methods like to_le_bytes
and from_le_bytes
, which support some of the same use cases.