Crate crc_frame

Source
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 Vec to 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 calls std::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 a std::io::Write::write_all call due to the impossibility to write partial frames.