protowire package - google.golang.org/protobuf/encoding/protowire - Go Packages (original) (raw)

Package protowire parses and formats the raw wire encoding. See https://protobuf.dev/programming-guides/encoding.

For marshaling and unmarshaling entire protobuf messages, use the google.golang.org/protobuf/proto package instead.

This section is empty.

This section is empty.

AppendBytes appends v to b as a length-prefixed bytes value.

AppendFixed32 appends v to b as a little-endian uint32.

AppendFixed64 appends v to b as a little-endian uint64.

AppendGroup appends v to b as group value, with a trailing end group marker. The value v must not contain the end marker.

AppendString appends v to b as a length-prefixed bytes value.

AppendTag encodes num and typ as a varint-encoded tag and appends it to b.

AppendVarint appends v to b as a varint-encoded uint64.

ConsumeBytes parses b as a length-prefixed bytes value, reporting its length. This returns a negative length upon an error (see ParseError).

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(num Number, typ Type, b []byte) (n int)

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.

ConsumeFixed32 parses b as a little-endian uint32, reporting its length. This returns a negative length upon an error (see ParseError).

ConsumeFixed64 parses b as a little-endian uint64, reporting its length. This returns a negative length upon an error (see ParseError).

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

ConsumeString parses b as a length-prefixed bytes value, reporting its length. This returns a negative length upon an error (see ParseError).

ConsumeTag parses b as a varint-encoded tag, reporting its length. This returns a negative length upon an error (see ParseError).

ConsumeVarint parses b as a varint-encoded uint64, reporting its length. This returns a negative length upon an error (see ParseError).

DecodeBool decodes a uint64 as a bool.

Input: { 0, 1, 2, …} Output: {false, true, true, …}

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.

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, …}

EncodeBool encodes a bool as a uint64.

Input: {false, true} Output: { 0, 1}

EncodeTag encodes the field Number and wire Type into its unified form.

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, …}

ParseError converts an error code into an error value. This returns nil if n is a non-negative number.

SizeBytes returns the encoded size of a length-prefixed bytes value, given only the length.

SizeFixed32 returns the encoded size of a fixed32; which is always 4.

SizeFixed64 returns the encoded size of a fixed64; which is always 8.

SizeGroup returns the encoded size of a group, given only the length.

func SizeTag(num Number) int

SizeVarint returns the encoded size of a varint. The size is guaranteed to be within 1 and 10, inclusive.

Number represents the field number.

const ( MinValidNumber Number = 1 FirstReservedNumber Number = 19000 LastReservedNumber Number = 19999 MaxValidNumber Number = 1<<29 - 1 DefaultRecursionLimit = 10000 )

func (n Number) IsValid() bool

IsValid reports whether the field number is semantically valid.

Type represents the wire type.

const ( VarintType Type = 0 Fixed32Type Type = 5 Fixed64Type Type = 1 BytesType Type = 2 StartGroupType Type = 3 EndGroupType Type = 4 )