commit | 4b3042026b42e6069d97fc4e73ae05ee823a00b9 | [log] [tgz] |
---|---|---|
author | Treehugger Robot <treehugger-gerrit@google.com> | Wed Jun 15 22:28:38 2022 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Wed Jun 15 22:28:38 2022 +0000 |
tree | e3933097052d8a1cdb33ab394e8e34cc6c80fcd2 | |
parent | 707f63a1e12d994183446d3c8dd5c1acc8d29325 [diff] | |
parent | 52328412bafa5d40a20be13af8e1374d6116cdc4 [diff] |
Merge "Update TEST_MAPPING" am: ec43e1fbfc am: 86b7dc4d1a am: eee4584b96 am: 52328412ba Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/byteorder/+/2124537 Change-Id: I3863da28d4264987653bbf4d7144997a2115d1ed Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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:
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.