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

  • Variable-length encoding of u64

Structs

  • 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…
  • 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

  • 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.
  • 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 a frame out of the provided File
  • 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 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 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.