1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 08:34:07 +02:00

add main to readme example

This commit is contained in:
Robin Appelman 2025-05-23 23:27:02 +02:00
commit 4799d26f0b

View file

@ -52,23 +52,25 @@ struct ComplexType {
third: bool, third: bool,
} }
let bytes = vec![ fn main() -> Result<(), Box<dyn std::error::Error>> {
let bytes = vec![
0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001, 0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111 0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
]; ];
let buffer = BitReadBuffer::new(&bytes, LittleEndian); let buffer = BitReadBuffer::new(&bytes, LittleEndian);
let mut stream = BitReadStream::new(buffer); let mut stream = BitReadStream::new(buffer);
let value: u8 = stream.read_int(7)?; let value: u8 = stream.read_int(7)?;
let complex: ComplexType = stream.read()?; let complex: ComplexType = stream.read()?;
let mut write_bytes = vec![]; let mut write_bytes = vec![];
let mut write_stream = BitWriteStream::new(&mut write_bytes, LittleEndian); let mut write_stream = BitWriteStream::new(&mut write_bytes, LittleEndian);
write_stream.write_int(12, 7)?; write_stream.write_int(12, 7)?;
write_stream.write(&ComplexType { write_stream.write(&ComplexType {
first: 55, first: 55,
second: 12, second: 12,
third: true third: true
})?; })?;
}
``` ```
## License ## License