Documentation ¶
Overview ¶
Package delimited implements a reader and writer for simple streams of length-delimited byte records. Each record is written as a varint-encoded length in bytes, followed immediately by the record itself.
A stream consists of a sequence of such records packed consecutively without additional padding. There are no checksums or compression.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader consumes length-delimited records from a byte source.
Usage:
rd := delimited.NewReader(r) for { rec, err := rd.Next() if err == io.EOF { break } else if err != nil { log.Fatal(err) } doStuffWith(rec) }
func (*Reader) Next ¶
Next returns the next length-delimited record from the input, or io.EOF if there are no more records available. Returns io.ErrUnexpectedEOF if a short record is found, with a length of n but fewer than n bytes of data. Because there is no resynchronization mechanism, it is generally not possible to recover from a short record in this format.
The slice returned is valid only until a subsequent call to Next.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer outputs delimited records to an io.Writer.
Basic usage:
wr := delimited.NewWriter(w) for record := range records { if err := wr.Put(record); err != nil { log.Fatal(err) } }
func (Writer) Put ¶
Put writes the specified record to the writer. It equivalent to WriteRecord, but discards the number of bytes written.