Documentation ¶
Overview ¶
Package lengthprefixed implements a Reader and Writer for reading, and writing, data in length-prefixed frames.
Each frame contains three parts: a varint representing the length of the data, N bytes of data, and 8 bytes (uint64) of checksum for the data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrChecksum = errors.New("lengthprefixed: invalid checksum")
ErrChecksum is returned when frame data's computed checksum match the provided checksum
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader is a wrapper designed to read frames from an underlying io.Reader.
func (*Reader) ReadFrame ¶
ReadFrame returns the data component of length-prefixed frames. It first reads a varint from the io.Reader to determine how many bytes to return in the byteslice. Then, it reads that many bytes into a byteslice and checksums against the following int64 via xxhash. If the checksum matches, the byteslice will be returned to the caller. Otherwise, an ErrChecksum will be returned.
Note: The caller takes responsibility for watching for io.EOF, which will be bubbled up from the underlying reader.