Expand description
Simple tools for reading and writing crc-checked frames of bytes.
- Uses crc32fast for a 4-byte crc
- Uses varint for frame sizing
- Tested against libfuzzer
The varint
module is also public for direct use.
Modules§
- varint
- Variable-length encoding of
u64
Structs§
- Decoder
- A simple decoder that will parse data from the
inner
Read
as a crc’ed frame. Suitable for stacking with other decoders for decompression or deserialization etc… - Encoder
- A simple encoder that will wrap any passed data into a crc’ed frame, suitable for stacking with other encoders for compression or serialization etc…
Functions§
- frame_
header - Return an array which contains the crc and varint for
a given buffer, and a
usize
that is the length of the provided array which corresponds to the valid varint and crc. Returns an array instead of a Vecto avoid allocations. - parse_
frame - Reads a header out of an arbitrary buffer, checks the crc, and if the crc matches the corresponding bytes, returns the start and end offsets in the buffer for the inner bytes. The end offset of the buffer is also the end offset for this entire frame, so you may advance any cursors to this point for reading the next frame in a sequence of bytes etc…
- read_
frame_ at - Read a frame out of the provided
File
- read_
frame_ from_ reader_ into_ writer - Read a frame out of the provided
Read
implementation. This callsstd::io::Read::read_exact
many times under the hood, so it’s a good idea to use a buffered source of data to avoid high numbers of syscalls. - write_
frame_ at - Write a crc’d frame into the provided
File
at the given offset. Returns the number of bytes written in total, including the varint size and crc. - write_
frame_ into - Write a crc’d frame into the provided
Write
instance. Returns the number of bytes written in total, including the varint size and crc. This is always equivalent to astd::io::Write::write_all
call due to the impossibility to write partial frames.