Skip to content

Commit

Permalink
readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaldino committed May 30, 2024
1 parent 39879f8 commit 863faed
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# BitCursor

BitCursor is similar to std::io::Cursor, but allows reading various amounts of bits from a given buffer in addition
to byte-sized chunks. It's built on top of the [ux](https://crates.io/crates/ux) crate for types.
to byte-sized chunks. It's built on top of the [ux](https://crates.io/crates/ux) crate for types and leverages
[bitvec](https://docs.rs/bitvec/latest/bitvec/) to provide a more complete implementation.

# Examples

```rust
let data: Vec<u8> = vec![0b11100000, 0b11101111];
let mut cursor = BitCursor::from_vec(data);

// Read any non-standard-width type from the cursor
let u3_val = cursor.read_u3().unwrap();
assert_eq!(u3_val, ux::u3::new(0b111));
// Sizes larger than 8 bits require a byte order argument
let u13_val = cursor
.read_u13::<crate::byte_order::NetworkOrder>()
.unwrap();
assert_eq!(u13_val, ux::u13::new(0b0000011101111));
```

# Design

Expand All @@ -20,6 +36,3 @@ to byte-sized chunks. It's built on top of the [ux](https://crates.io/crates/ux

### `BitCursor`
`BitCursor` is analgous to the [`std::io::Cursor`](https://doc.rust-lang.org/std/io/struct.Cursor.html) type, but its API is defined in terms of bits instead of bytes.

### `BitSlice`/`BitSliceMut`
The `std::io` types' APIs often use the `&[u8]` type for 'slices', so `BitCursor`'s equivalent would be to use a slice of `u1`: `&[u1]`, but, for ergonomic reasons, we instead use `BitSlice`/`BitSliceMut` types to mimic `&[u1]` and `&mut [u1]`.

0 comments on commit 863faed

Please sign in to comment.