commit | 1212d7aadb14261e59558c6eaa97f7a2f89da89c | [log] [tgz] |
---|---|---|
author | Xin Li <[email protected]> | Mon Apr 29 11:50:31 2024 -0700 |
committer | Xin Li <[email protected]> | Mon Apr 29 11:50:31 2024 -0700 |
tree | 243037fd02a49b4da66e5eab487066b2038b3166 | |
parent | 91fdb20c0fd1d0d42bd7f9b879f58f96b9b825ae [diff] | |
parent | a10ee9216f5add878778d5b93d38e8d6e7f02723 [diff] |
Empty merge of Android 24Q2 Release (ab/11526283) to aosp-main-future Bug: 337098550 Merged-In: I89277ab97dda318cbc40453115fc9cdc139299d9 Change-Id: Ic10793e1bfc6e49a7dc93d26cc3daa532b32ee81
BitReader is a helper type to extract strings of bits from a slice of bytes.
Here is how you read first a single bit, then three bits and finally four bits from a byte buffer:
use bitreader::BitReader; let slice_of_u8 = &[0b1000_1111]; let mut reader = BitReader::new(slice_of_u8); // You obviously should use try! or some other error handling mechanism here let a_single_bit = reader.read_u8(1).unwrap(); // 1 let more_bits = reader.read_u8(3).unwrap(); // 0 let last_bits_of_byte = reader.read_u8(4).unwrap(); // 0b1111
You can naturally read bits from longer buffer of data than just a single byte.
As you read bits, the internal cursor of BitReader moves on along the stream of bits. Big endian format is assumed when reading the multi-byte values. BitReader supports reading maximum of 64 bits at a time (with read_u64).
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.