Documentation ¶
Overview ¶
Package recordio implements a basic RecordIO reader and writer.
Each RecordIO frame begins with a Uvarint ( http://golang.org/pkg/encoding/binary/#Uvarint) containing the size of the frame, followed by that many bytes of frame data.
The frame protocol does not handle data integrity; that is left to the outer protocol or medium which uses the frame.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFrameTooLarge = fmt.Errorf("frame: frame size exceeds maximum")
ErrFrameTooLarge is an error that is returned if a frame that is larger than the maximum allowed size (not including the frame header) is read.
Functions ¶
func FrameHeaderSize ¶
FrameHeaderSize calculates the size of the RecordIO frame header for a given amount of data.
A RecordIO frame header is a Uvarint containing the length. Uvarint values contain 7 bits of size data and 1 continuation bit (see encoding/binary).
Types ¶
type Reader ¶
type Reader interface { // ReadFrame reads the next frame, returning the frame's size and an io.Reader // for that frame's data. The io.Reader is restricted such that it cannot read // past the frame. // // The frame must be fully read before another Reader call can be made. // Failure to do so will cause the Reader to become unsynchronized. ReadFrame() (int64, io.Reader, error) // ReadFrame returns the contents of the next frame. If there are no more // frames available, ReadFrame will return io.EOF. ReadFrameAll() ([]byte, error) }
Reader reads individual frames from a frame-formatted input Reader.
type Writer ¶
type Writer interface { io.Writer // Flush writes the buffered frame Flush() error // Reset clears the writer state and attaches it to a new inner Writer // instance. Reset(io.Writer) }
Writer implements the io.Writer interface. Data written to the Writer is translated into a series of frames. Each frame is spearated by a call to Flush.
Frame boundaries are created by calling Flush. Flush will always write a frame, even if the frame's data size is zero.
Data written over consecutive Write calls belongs to the same frame. It is buffered until a frame boundary is created via Flush().