With meepmorp you can read and write on streams very efficiently. This lib attempt to be parralell with all previous standard implementation you can often see in C or C++, simple to use, reinterpreted with some cool Rust tools.
Before reading whatever you want, someone had too write the data, like that:
``rust
// This create you a stream with a
usize` a
// temporary register
let mut e_stream = BitEstream::new(len).unwrap();
// Add N bits in temp register // ( You can go up to 64 bits on x64 // and obviously to 32 bits if x86 ) estream.addbits(usized, 3).unwrap(); estream.addbits(usized, 1).unwrap(); estream.addbits(usized, 5).unwrap(); estream.addbits(usized, 5).unwrap();
// Flush temp register, store bits into the final stream estream.flushbits();
// Close the stream and you're done (that put an endMark // and flush the latest remainings bits from the temp // container ) estream.closestream().unwrap();
let vec: Vec
Read is also easy to do.
``rust
// This create you a stream with a
usize` a
// temporary register
let vec: Vec
// Or even from a closed (or not) encoder stream let mut dstream = Bitdstream::tryfrom(e_stream).unwrap();
// Add N bits in temp register // ( You can go up to 64 bits on x64 // and obviously to 32 bits if x86 ) dstream.readbits(3).unwrap(); dstream.readbits(1).unwrap(); dstream.readbits(5).unwrap(); dstream.readbits(5).unwrap();
// Flush temp register, store bits into the final stream dstream.reloadcontainer(); ```
Speed, speed, speed.
In the unit tests you can see that kind of code: ```rust let buffer = Vec::withcapacity(len); // this is randomly filled as used in tests let mut estream = BitEstream::new(len + 1).unwrap();
for (i, byte) in buffer.iter().enumerate() { if i > 0 && i % CTNRBYTESSIZE == 0 { estream.flushbits(); } estream.addbits(*byte as usize, BYTELEN).unwrap(); } estream.close_stream().unwrap(); ```
I choose to bench a complete writing and reading process with 10kb on my
labtop. Here is the criterion report graph and I get a value really similar to
the bitstream-io crate.
Check on your favorit computer with thecommand cargo bench
.
In addition, you! developer! If you're looking for a complete swiss knife library for your bitstreaming, you probably be better with the bitstream-io. All depend of your needs =-) (Sorry, I put that message at the end of the documentation)
I want to give the possiblity to work with iterator instead of already allocated vectors. For the moment there is no plan or milestones.
This development is under MIT License,