Documentation
¶
Overview ¶
Package wire writes and reads the binary form of protobuf, the part of it the schema of learner-model uses, on Go's standard library alone: varints, 64-bit fixed numbers in little-endian, and length-delimited strings, messages and packed lists. What the fields mean, in what order they go and which are required is the caller's.
Index ¶
- Constants
- Variables
- type Reader
- func (r *Reader) Bool() (bool, error)
- func (r *Reader) Bytes() ([]byte, error)
- func (r *Reader) Done() bool
- func (r *Reader) Double() (float64, error)
- func (r *Reader) Int32() (int32, error)
- func (r *Reader) Int64() (int64, error)
- func (r *Reader) Next() (field, wireType int, err error)
- func (r *Reader) PackedInt64() ([]int64, error)
- func (r *Reader) Skip(wireType int) error
- type Writer
- func (w *Writer) Bool(field int, v bool)
- func (w *Writer) Bytes() []byte
- func (w *Writer) Double(field int, v float64)
- func (w *Writer) Int64(field int, v int64)
- func (w *Writer) Message(field int, body func(*Writer))
- func (w *Writer) PackedInt64(field int, values []int64)
- func (w *Writer) String(field int, s string)
- func (w *Writer) Uint64(field int, v uint64)
Constants ¶
const ( Varint = 0 Fixed64 = 1 Bytes = 2 )
The wire types the schema uses; 3 and 4, the groups, and 5, the 32-bit numbers, it does not.
Variables ¶
var ErrCorrupt = errors.New("corrupt bytes")
ErrCorrupt is bytes that break the binary form: cut short, a varint past 10 bytes, a length past the end, a field number of 0 or a wire type the form does not have.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads the fields of one message in turn.
func (*Reader) Bytes ¶
Bytes reads the value of a length-delimited field: a string, a message or a packed list.
func (*Reader) Int32 ¶
Int32 reads the value of an int32 or enum field, refusing one outside the int32 range.
func (*Reader) PackedInt64 ¶
PackedInt64 reads the value of a packed list of varints.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer appends fields to a buffer. A caller writes them in ascending order of their numbers.
func (*Writer) Double ¶
Double writes a double field: its eight IEEE bytes in little-endian, as they are, −0 too. The caller refuses NaN and the infinities first.
func (*Writer) Int64 ¶
Int64 writes an int64 or int32 field: a negative number is ten bytes, as protobuf has it.
func (*Writer) Message ¶
Message writes a message field: the bytes body writes into a writer of its own.
func (*Writer) PackedInt64 ¶
PackedInt64 writes a packed list of int32, int64 or enum values; an empty list, nothing.