Documentation ¶
Index ¶
- Constants
- Variables
- func AppendBytes(b []byte, v []byte) []byte
- func AppendFixed32(b []byte, v uint32) []byte
- func AppendFixed64(b []byte, v uint64) []byte
- func AppendGroup(b []byte, num Number, v []byte) []byte
- func AppendString(b []byte, v string) []byte
- func AppendTag(b []byte, num Number, typ Type) []byte
- func AppendVarint(b []byte, v uint64) []byte
- func ConsumeBytes(b []byte) (v []byte, n int)
- func ConsumeField(b []byte) (Number, Type, int)
- func ConsumeFieldValue(num Number, typ Type, b []byte) (n int)
- func ConsumeFixed32(b []byte) (v uint32, n int)
- func ConsumeFixed64(b []byte) (v uint64, n int)
- func ConsumeGroup(num Number, b []byte) (v []byte, n int)
- func ConsumeString(b []byte) (v string, n int)
- func ConsumeTag(b []byte) (Number, Type, int)
- func ConsumeVarint(b []byte) (v uint64, n int)
- func DecodeBool(x uint64) bool
- func DecodeTag(x uint64) (Number, Type)
- func DecodeVarint(b []byte) (uint64, int)
- func DecodeZigZag(x uint64) int64
- func EncodeBool(x bool) uint64
- func EncodeTag(num Number, typ Type) uint64
- func EncodeVarint(v uint64) []byte
- func EncodeZigZag(x int64) uint64
- func ParseError(n int) error
- func SizeBytes(n int) int
- func SizeFixed32() int
- func SizeFixed64() int
- func SizeGroup(num Number, n int) int
- func SizeTag(num Number) int
- func SizeVarint(v uint64) int
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Consume()
- func (b *Buffer) ConsumeFieldValue(num Number, t Type) error
- func (b *Buffer) Continue() bool
- func (b *Buffer) DecodeFixed32() (uint64, error)
- func (b *Buffer) DecodeFixed64() (uint64, error)
- func (b *Buffer) DecodeRawBytes(alloc bool) ([]byte, error)
- func (b *Buffer) DecodeStringBytes() (string, error)
- func (b *Buffer) DecodeTag() (Number, Type, error)
- func (b *Buffer) DecodeVarint() (uint64, error)
- func (b *Buffer) DecodeZigzag32() (uint64, error)
- func (b *Buffer) DecodeZigzag64() (uint64, error)
- func (b *Buffer) EOF() bool
- func (b *Buffer) EncodeFixed32(v uint64)
- func (b *Buffer) EncodeFixed64(v uint64)
- func (b *Buffer) EncodeRawBytes(v []byte)
- func (b *Buffer) EncodeStringBytes(v string)
- func (b *Buffer) EncodeTag(field Number, typ Type) *Buffer
- func (b *Buffer) EncodeVarint(v uint64)
- func (b *Buffer) EncodeZigzag32(v uint64)
- func (b *Buffer) EncodeZigzag64(v uint64)
- func (b *Buffer) Error() error
- func (b *Buffer) Finish() []byte
- func (b *Buffer) ReadBool() bool
- func (b *Buffer) ReadFloat32() float32
- func (b *Buffer) ReadFloat32ZigZag() float32
- func (b *Buffer) ReadFloat64() float64
- func (b *Buffer) ReadFloat64ZigZag() float64
- func (b *Buffer) ReadInt16() int16
- func (b *Buffer) ReadInt16ZigZag() int16
- func (b *Buffer) ReadInt32() int32
- func (b *Buffer) ReadInt32Zigzag() int32
- func (b *Buffer) ReadInt64() int64
- func (b *Buffer) ReadInt64ZigZag() int64
- func (b *Buffer) ReadInt8() int8
- func (b *Buffer) ReadString() string
- func (b *Buffer) ReadUint16() uint16
- func (b *Buffer) ReadUint16ZigZag() uint16
- func (b *Buffer) ReadUint32() uint32
- func (b *Buffer) ReadUint32ZigZag() uint32
- func (b *Buffer) ReadUint64() uint64
- func (b *Buffer) ReadUint64ZigZag() uint64
- func (b *Buffer) ReadUint8() uint8
- func (b *Buffer) Reset()
- func (b *Buffer) SetBuf(buf []byte)
- func (b *Buffer) SetDeterministic(deterministic bool)
- func (b *Buffer) Unread() []byte
- func (b *Buffer) WriteBool(field Number, v bool)
- func (b *Buffer) WriteFixed32Float32(field Number, v float32)
- func (b *Buffer) WriteFixed32Float64(field Number, v float64)
- func (b *Buffer) WriteFixed32Int16(field Number, v int16)
- func (b *Buffer) WriteFixed32Int32(field Number, v int32)
- func (b *Buffer) WriteFixed32Int64(field Number, v int64)
- func (b *Buffer) WriteFixed32Int8(field Number, v int8)
- func (b *Buffer) WriteFixed32Uint16(field Number, v uint16)
- func (b *Buffer) WriteFixed32Uint32(field Number, v uint32)
- func (b *Buffer) WriteFixed32Uint64(field Number, v uint64)
- func (b *Buffer) WriteFixed32Uint8(field Number, v uint8)
- func (b *Buffer) WriteFixed64Float32(field Number, v float32)
- func (b *Buffer) WriteFixed64Float64(field Number, v float64)
- func (b *Buffer) WriteFixed64Int16(field Number, v int16)
- func (b *Buffer) WriteFixed64Int32(field Number, v int32)
- func (b *Buffer) WriteFixed64Int64(field Number, v int64)
- func (b *Buffer) WriteFixed64Int8(field Number, v int8)
- func (b *Buffer) WriteFixed64Uint16(field Number, v uint16)
- func (b *Buffer) WriteFixed64Uint32(field Number, v uint32)
- func (b *Buffer) WriteFixed64Uint64(field Number, v uint64)
- func (b *Buffer) WriteFixed64Uint8(field Number, v uint8)
- func (b *Buffer) WriteHeader(typ uint16)
- func (b *Buffer) WriteString(field Number, v string)
- func (b *Buffer) WriteUvarint16(field Number, v uint16)
- func (b *Buffer) WriteUvarint32(field Number, v uint32)
- func (b *Buffer) WriteUvarint64(field Number, v uint64)
- func (b *Buffer) WriteUvarint8(field Number, v uint8)
- func (b *Buffer) WriteVarint16(field Number, v int16)
- func (b *Buffer) WriteVarint32(field Number, v int32)
- func (b *Buffer) WriteVarint64(field Number, v int64)
- func (b *Buffer) WriteVarint8(field Number, v int8)
- func (b *Buffer) WriteVarintFloat32(field Number, v float32)
- func (b *Buffer) WriteVarintFloat64(field Number, v float64)
- func (b *Buffer) WriteZigzag32Float32(field Number, v float32)
- func (b *Buffer) WriteZigzag32Float64(field Number, v float64)
- func (b *Buffer) WriteZigzag32Int16(field Number, v int16)
- func (b *Buffer) WriteZigzag32Int32(field Number, v int32)
- func (b *Buffer) WriteZigzag32Int64(field Number, v int64)
- func (b *Buffer) WriteZigzag32Int8(field Number, v int8)
- func (b *Buffer) WriteZigzag32Uint16(field Number, v uint16)
- func (b *Buffer) WriteZigzag32Uint32(field Number, v uint32)
- func (b *Buffer) WriteZigzag32Uint64(field Number, v uint64)
- func (b *Buffer) WriteZigzag32Uint8(field Number, v uint8)
- func (b *Buffer) WriteZigzag64Float32(field Number, v float32)
- func (b *Buffer) WriteZigzag64Float64(field Number, v float64)
- func (b *Buffer) WriteZigzag64Int16(field Number, v int16)
- func (b *Buffer) WriteZigzag64Int32(field Number, v int32)
- func (b *Buffer) WriteZigzag64Int64(field Number, v int64)
- func (b *Buffer) WriteZigzag64Int8(field Number, v int8)
- func (b *Buffer) WriteZigzag64Uint16(field Number, v uint16)
- func (b *Buffer) WriteZigzag64Uint32(field Number, v uint32)
- func (b *Buffer) WriteZigzag64Uint64(field Number, v uint64)
- func (b *Buffer) WriteZigzag64Uint8(field Number, v uint8)
- type Number
- type Type
Constants ¶
const ( WireVarint = 0 WireFixed32 = 5 WireFixed64 = 1 WireBytes = 2 WireStartGroup = 3 WireEndGroup = 4 )
Variables ¶
Functions ¶
func AppendBytes ¶
AppendBytes appends v to b as a length-prefixed bytes value.
func AppendFixed32 ¶
AppendFixed32 appends v to b as a little-endian uint32.
func AppendFixed64 ¶
AppendFixed64 appends v to b as a little-endian uint64.
func AppendGroup ¶
AppendGroup appends v to b as group value, with a trailing end group marker. The value v must not contain the end marker.
func AppendString ¶
AppendString appends v to b as a length-prefixed bytes value.
func AppendVarint ¶
AppendVarint appends v to b as a varint-encoded uint64.
func ConsumeBytes ¶
ConsumeBytes parses b as a length-prefixed bytes value, reporting its length. This returns a negative length upon an error (see ParseError).
func ConsumeField ¶
ConsumeField parses an entire field record (both tag and value) and returns the field number, the wire type, and the total length. This returns a negative length upon an error (see ParseError).
The total length includes the tag header and the end group marker (if the field is a group).
func ConsumeFieldValue ¶
ConsumeFieldValue parses a field value and returns its length. This assumes that the field Number and wire Type have already been parsed. This returns a negative length upon an error (see ParseError).
When parsing a group, the length includes the end group marker and the end group is verified to match the starting field number.
func ConsumeFixed32 ¶
ConsumeFixed32 parses b as a little-endian uint32, reporting its length. This returns a negative length upon an error (see ParseError).
func ConsumeFixed64 ¶
ConsumeFixed64 parses b as a little-endian uint64, reporting its length. This returns a negative length upon an error (see ParseError).
func ConsumeGroup ¶
ConsumeGroup parses b as a group value until the trailing end group marker, and verifies that the end marker matches the provided num. The value v does not contain the end marker, while the length does contain the end marker. This returns a negative length upon an error (see ParseError).
func ConsumeString ¶
ConsumeString parses b as a length-prefixed bytes value, reporting its length. This returns a negative length upon an error (see ParseError).
func ConsumeTag ¶
ConsumeTag parses b as a varint-encoded tag, reporting its length. This returns a negative length upon an error (see ParseError).
func ConsumeVarint ¶
ConsumeVarint parses b as a varint-encoded uint64, reporting its length. This returns a negative length upon an error (see ParseError).
func DecodeBool ¶
DecodeBool decodes a uint64 as a bool.
Input: { 0, 1, 2, …} Output: {false, true, true, …}
func DecodeTag ¶
DecodeTag decodes the field Number and wire Type from its unified form. The Number is -1 if the decoded field number overflows int32. Other than overflow, this does not check for field number validity.
func DecodeVarint ¶
DecodeVarint parses a varint encoded integer from b, returning the integer value and the length of the varint. It returns (0, 0) if there is a parse error.
func DecodeZigZag ¶
DecodeZigZag decodes a zig-zag-encoded uint64 as an int64.
Input: {…, 5, 3, 1, 0, 2, 4, 6, …} Output: {…, -3, -2, -1, 0, +1, +2, +3, …}
func EncodeVarint ¶
EncodeVarint returns the varint encoded bytes of v.
func EncodeZigZag ¶
EncodeZigZag encodes an int64 as a zig-zag-encoded uint64.
Input: {…, -3, -2, -1, 0, +1, +2, +3, …} Output: {…, 5, 3, 1, 0, 2, 4, 6, …}
func ParseError ¶
ParseError converts an error code into an error value. This returns nil if n is a non-negative number.
func SizeBytes ¶
SizeBytes returns the encoded size of a length-prefixed bytes value, given only the length.
func SizeFixed32 ¶
func SizeFixed32() int
SizeFixed32 returns the encoded size of a fixed32; which is always 4.
func SizeFixed64 ¶
func SizeFixed64() int
SizeFixed64 returns the encoded size of a fixed64; which is always 8.
func SizeVarint ¶
SizeVarint returns the encoded size of a varint. The size is guaranteed to be within 1 and 10, inclusive.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a buffer for encoding and decoding the protobuf wire format. It may be reused between invocations to reduce memory usage.
func NewBuffer ¶
NewBuffer allocates a new Buffer initialized with buf, where the contents of buf are considered the unread portion of the buffer.
func (*Buffer) DecodeFixed32 ¶
DecodeFixed32 consumes a 32-bit little-endian integer from the buffer.
func (*Buffer) DecodeFixed64 ¶
DecodeFixed64 consumes a 64-bit little-endian integer from the buffer.
func (*Buffer) DecodeRawBytes ¶
DecodeRawBytes consumes a length-prefixed raw bytes from the buffer. If alloc is specified, it returns a copy the raw bytes rather than a sub-slice of the buffer.
func (*Buffer) DecodeStringBytes ¶
DecodeStringBytes consumes a length-prefixed raw bytes from the buffer. It does not validate whether the raw bytes contain valid UTF-8.
func (*Buffer) DecodeVarint ¶
DecodeVarint consumes an encoded unsigned varint from the buffer.
func (*Buffer) DecodeZigzag32 ¶
DecodeZigzag32 consumes an encoded 32-bit zig-zag varint from the buffer.
func (*Buffer) DecodeZigzag64 ¶
DecodeZigzag64 consumes an encoded 64-bit zig-zag varint from the buffer.
func (*Buffer) EncodeFixed32 ¶
EncodeFixed32 appends a 32-bit little-endian integer to the buffer.
func (*Buffer) EncodeFixed64 ¶
EncodeFixed64 appends a 64-bit little-endian integer to the buffer.
func (*Buffer) EncodeRawBytes ¶
EncodeRawBytes appends a length-prefixed raw bytes to the buffer.
func (*Buffer) EncodeStringBytes ¶
EncodeStringBytes appends a length-prefixed raw bytes to the buffer. It does not validate whether v contains valid UTF-8.
func (*Buffer) EncodeTag ¶
EncodeTag encodes num and typ as a varint-encoded tag and appends it to b.
func (*Buffer) EncodeVarint ¶
EncodeVarint appends an unsigned varint encoding to the buffer.
func (*Buffer) EncodeZigzag32 ¶
EncodeZigzag32 appends a 32-bit zig-zag varint encoding to the buffer.
func (*Buffer) EncodeZigzag64 ¶
EncodeZigzag64 appends a 64-bit zig-zag varint encoding to the buffer.
func (*Buffer) ReadFloat32 ¶
ReadFloat32 reads next float32 value.
func (*Buffer) ReadFloat32ZigZag ¶
ReadFloat32ZigZag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadFloat64 ¶
ReadFloat64 reads next float64 value
func (*Buffer) ReadFloat64ZigZag ¶
ReadFloat64ZigZag reads next zigzag encoded number preferring 64-bits
func (*Buffer) ReadInt16ZigZag ¶
ReadInt16ZigZag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadInt32Zigzag ¶
ReadInt32Zigzag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadInt64ZigZag ¶
ReadInt64ZigZag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadUint16ZigZag ¶
ReadUint16ZigZag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadUint32 ¶
ReadUint32 reads next encoded number preferring 32-bits
func (*Buffer) ReadUint32ZigZag ¶
ReadUint32ZigZag reads next zigzag encoded number preferring 32-bits
func (*Buffer) ReadUint64 ¶
ReadUint64 reads next encoded number preferring 64-bits
func (*Buffer) ReadUint64ZigZag ¶
ReadUint64ZigZag reads next zigzag encoded number preferring 64-bits
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset clears the internal buffer of all written and unread data.
func (*Buffer) SetBuf ¶
SetBuf sets buf as the internal buffer, where the contents of buf are considered the unread portion of the buffer.
func (*Buffer) SetDeterministic ¶
SetDeterministic specifies whether to use deterministic serialization.
Deterministic serialization guarantees that for a given binary, equal messages will always be serialized to the same bytes. This implies:
- Repeated serialization of a message will return the same bytes.
- Different processes of the same binary (which may be executing on different machines) will serialize equal messages to the same bytes.
Note that the deterministic serialization is NOT canonical across languages. It is not guaranteed to remain stable over time. It is unstable across different builds with schema changes due to unknown fields. Users who need canonical serialization (e.g., persistent storage in a canonical form, fingerprinting, etc.) should define their own canonicalization specification and implement their own serializer rather than relying on this API.
If deterministic serialization is requested, map entries will be sorted by keys in lexographical order. This is an implementation detail and subject to change.
func (*Buffer) WriteFixed32Float32 ¶
func (*Buffer) WriteFixed32Float64 ¶
func (*Buffer) WriteFixed32Int16 ¶
func (*Buffer) WriteFixed32Int32 ¶
func (*Buffer) WriteFixed32Int64 ¶
func (*Buffer) WriteFixed32Int8 ¶
func (*Buffer) WriteFixed32Uint16 ¶
func (*Buffer) WriteFixed32Uint32 ¶
func (*Buffer) WriteFixed32Uint64 ¶
func (*Buffer) WriteFixed32Uint8 ¶
func (*Buffer) WriteFixed64Float32 ¶
func (*Buffer) WriteFixed64Float64 ¶
func (*Buffer) WriteFixed64Int16 ¶
func (*Buffer) WriteFixed64Int32 ¶
func (*Buffer) WriteFixed64Int64 ¶
func (*Buffer) WriteFixed64Int8 ¶
func (*Buffer) WriteFixed64Uint16 ¶
func (*Buffer) WriteFixed64Uint32 ¶
func (*Buffer) WriteFixed64Uint64 ¶
func (*Buffer) WriteFixed64Uint8 ¶
func (*Buffer) WriteHeader ¶
func (*Buffer) WriteString ¶
func (*Buffer) WriteUvarint16 ¶
func (*Buffer) WriteUvarint32 ¶
func (*Buffer) WriteUvarint64 ¶
func (*Buffer) WriteUvarint8 ¶
func (*Buffer) WriteVarint16 ¶
func (*Buffer) WriteVarint32 ¶
func (*Buffer) WriteVarint64 ¶
func (*Buffer) WriteVarint8 ¶
func (*Buffer) WriteVarintFloat32 ¶
func (*Buffer) WriteVarintFloat64 ¶
func (*Buffer) WriteZigzag32Float32 ¶
func (*Buffer) WriteZigzag32Float64 ¶
func (*Buffer) WriteZigzag32Int16 ¶
func (*Buffer) WriteZigzag32Int32 ¶
func (*Buffer) WriteZigzag32Int64 ¶
func (*Buffer) WriteZigzag32Int8 ¶
func (*Buffer) WriteZigzag32Uint16 ¶
func (*Buffer) WriteZigzag32Uint32 ¶
func (*Buffer) WriteZigzag32Uint64 ¶
func (*Buffer) WriteZigzag32Uint8 ¶
func (*Buffer) WriteZigzag64Float32 ¶
func (*Buffer) WriteZigzag64Float64 ¶
func (*Buffer) WriteZigzag64Int16 ¶
func (*Buffer) WriteZigzag64Int32 ¶
func (*Buffer) WriteZigzag64Int64 ¶
func (*Buffer) WriteZigzag64Int8 ¶
func (*Buffer) WriteZigzag64Uint16 ¶
func (*Buffer) WriteZigzag64Uint32 ¶
func (*Buffer) WriteZigzag64Uint64 ¶
func (*Buffer) WriteZigzag64Uint8 ¶
type Number ¶
type Number int32
Number represents the field number.