protobuf: google.golang.org/protobuf/internal/encoding/messageset Index | Files

package messageset

import "google.golang.org/protobuf/internal/encoding/messageset"

Package messageset encodes and decodes the obsolete MessageSet wire format.

Index

Package Files

messageset.go

Constants

const (
    FieldItem    = protowire.Number(1)
    FieldTypeID  = protowire.Number(2)
    FieldMessage = protowire.Number(3)
)

The MessageSet wire format is equivalent to a message defiend as follows, where each Item defines an extension field with a field number of 'type_id' and content of 'message'. MessageSet extensions must be non-repeated message fields.

message MessageSet {
	repeated group Item = 1 {
		required int32 type_id = 2;
		required string message = 3;
	}
}
const ExtensionName = "message_set_extension"

ExtensionName is the field name for extensions of MessageSet.

A valid MessageSet extension must be of the form:

message MyMessage {
	extend proto2.bridge.MessageSet {
		optional MyMessage message_set_extension = 1234;
	}
	...
}

func AppendFieldEnd Uses

func AppendFieldEnd(b []byte) []byte

AppendFieldEnd appends the trailing end group marker for a MessageSet item field.

func AppendFieldStart Uses

func AppendFieldStart(b []byte, num protowire.Number) []byte

AppendFieldStart appends the start of a MessageSet item field containing an extension with the given number. The caller must add the message subfield (including the tag).

func AppendUnknown Uses

func AppendUnknown(b, unknown []byte) ([]byte, error)

AppendUnknown appends unknown fields to b in MessageSet format.

For historic reasons, unresolved items in a MessageSet are stored in a message's unknown fields section in non-MessageSet format. That is, an unknown item with typeID T and value V appears in the unknown fields as a field with number T and value V.

This function converts the unknown fields back into MessageSet form.

func ConsumeFieldValue Uses

func ConsumeFieldValue(b []byte, wantLen bool) (typeid protowire.Number, message []byte, n int, err error)

ConsumeFieldValue parses b as a MessageSet item field value until and including the trailing end group marker. It assumes the start group tag has already been parsed. It returns the contents of the type_id and message subfields and the total item length.

If wantLen is true, the returned message value includes the length prefix.

func IsMessageSet Uses

func IsMessageSet(md pref.MessageDescriptor) bool

IsMessageSet returns whether the message uses the MessageSet wire format.

func IsMessageSetExtension Uses

func IsMessageSetExtension(fd pref.FieldDescriptor) bool

IsMessageSetExtension reports this field properly extends a MessageSet.

func SizeField Uses

func SizeField(num protowire.Number) int

SizeField returns the size of a MessageSet item field containing an extension with the given field number, not counting the contents of the message subfield.

func SizeUnknown Uses

func SizeUnknown(unknown []byte) (size int)

SizeUnknown returns the size of an unknown fields section in MessageSet format.

See AppendUnknown.

func Unmarshal Uses

func Unmarshal(b []byte, wantLen bool, fn func(typeID protowire.Number, value []byte) error) error

Unmarshal parses a MessageSet.

It calls fn with the type ID and value of each item in the MessageSet. Unknown fields are discarded.

If wantLen is true, the item values include the varint length prefix. This is ugly, but simplifies the fast-path decoder in internal/impl.

Package messageset imports 4 packages (graph) and is imported by 9 packages. Updated 2020-08-08. Refresh now. Tools for package owners.