wire

package
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 NewReader

func NewReader(b []byte) *Reader

NewReader reads b.

func (*Reader) Bool

func (r *Reader) Bool() (bool, error)

Bool reads the value of a bool field, refusing a varint other than 0 and 1.

func (*Reader) Bytes

func (r *Reader) Bytes() ([]byte, error)

Bytes reads the value of a length-delimited field: a string, a message or a packed list.

func (*Reader) Done

func (r *Reader) Done() bool

Done tells whether every field has been read.

func (*Reader) Double

func (r *Reader) Double() (float64, error)

Double reads the value of a double field.

func (*Reader) Int32

func (r *Reader) Int32() (int32, error)

Int32 reads the value of an int32 or enum field, refusing one outside the int32 range.

func (*Reader) Int64

func (r *Reader) Int64() (int64, error)

Int64 reads the value of an int64 field.

func (*Reader) Next

func (r *Reader) Next() (field, wireType int, err error)

Next reads the tag of the next field: its number and wire type.

func (*Reader) PackedInt64

func (r *Reader) PackedInt64() ([]int64, error)

PackedInt64 reads the value of a packed list of varints.

func (*Reader) Skip

func (r *Reader) Skip(wireType int) error

Skip passes over the value of a field this version does not know, by its wire type.

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) Bool

func (w *Writer) Bool(field int, v bool)

Bool writes a bool field.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes is what has been written.

func (*Writer) Double

func (w *Writer) Double(field int, v float64)

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

func (w *Writer) Int64(field int, v int64)

Int64 writes an int64 or int32 field: a negative number is ten bytes, as protobuf has it.

func (*Writer) Message

func (w *Writer) Message(field int, body func(*Writer))

Message writes a message field: the bytes body writes into a writer of its own.

func (*Writer) PackedInt64

func (w *Writer) PackedInt64(field int, values []int64)

PackedInt64 writes a packed list of int32, int64 or enum values; an empty list, nothing.

func (*Writer) String

func (w *Writer) String(field int, s string)

String writes a string field.

func (*Writer) Uint64

func (w *Writer) Uint64(field int, v uint64)

Uint64 writes a varint field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL