Involved Source Filescheckinit.godecode.godecode_gen.go
Package proto provides functions operating on protocol buffer messages.
For documentation on protocol buffers in general, see:
https://developers.google.com/protocol-buffers
For a tutorial on using protocol buffers with Go, see:
https://developers.google.com/protocol-buffers/docs/gotutorial
For a guide to generated Go protocol buffer code, see:
https://developers.google.com/protocol-buffers/docs/reference/go-generated
Binary serialization
This package contains functions to convert to and from the wire format,
an efficient binary serialization of protocol buffers.
• Size reports the size of a message in the wire format.
• Marshal converts a message to the wire format.
The MarshalOptions type provides more control over wire marshaling.
• Unmarshal converts a message from the wire format.
The UnmarshalOptions type provides more control over wire unmarshaling.
Basic message operations
• Clone makes a deep copy of a message.
• Merge merges the content of a message into another.
• Equal compares two messages. For more control over comparisons
and detailed reporting of differences, see package
"google.golang.org/protobuf/testing/protocmp".
• Reset clears the content of a message.
• CheckInitialized reports whether all required fields in a message are set.
Optional scalar constructors
The API for some generated messages represents optional scalar fields
as pointers to a value. For example, an optional string field has the
Go type *string.
• Bool, Int32, Int64, Uint32, Uint64, Float32, Float64, and String
take a value and return a pointer to a new instance of it,
to simplify construction of optional field values.
Generated enum types usually have an Enum method which performs the
same operation.
Optional scalar fields are only supported in proto2.
Extension accessors
• HasExtension, GetExtension, SetExtension, and ClearExtension
access extension field values in a protocol buffer message.
Extension fields are only supported in proto2.
Related packages
• Package "google.golang.org/protobuf/encoding/protojson" converts messages to
and from JSON.
• Package "google.golang.org/protobuf/encoding/prototext" converts messages to
and from the text format.
• Package "google.golang.org/protobuf/reflect/protoreflect" provides a
reflection interface for protocol buffer data types.
• Package "google.golang.org/protobuf/testing/protocmp" provides features
to compare protocol buffer messages with the "github.com/google/go-cmp/cmp"
package.
• Package "google.golang.org/protobuf/types/dynamicpb" provides a dynamic
message type, suitable for working with messages where the protocol buffer
type is only known at runtime.
This module contains additional packages for more specialized use cases.
Consult the individual package documentation for details.
encode.goencode_gen.goequal.goextension.gomerge.gomessageset.goproto.goproto_methods.goreset.gosize.gosize_gen.gowrappers.go
Package-Level Type Names (total 4, in which 3 are exported)
/* sort exporteds by: | */
MarshalOptions configures the marshaler.
Example usage:
b, err := MarshalOptions{Deterministic: true}.Marshal(m)
AllowPartial allows messages that have missing required fields to marshal
without returning an error. If AllowPartial is false (the default),
Marshal will return an error if there are any missing required fields.
Deterministic controls whether the same message will always be
serialized to the same bytes within the same binary.
Setting this option guarantees that repeated serialization of
the same message will return the same bytes, and that different
processes of the same binary (which may be executing on different
machines) will serialize equal messages to the same bytes.
It has no effect on the resulting size of the encoded message compared
to a non-deterministic marshal.
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.) must 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.
NoUnkeyedLiteralspragma.NoUnkeyedLiterals
UseCachedSize indicates that the result of a previous Size call
may be reused.
Setting this option asserts that:
1. Size has previously been called on this message with identical
options (except for UseCachedSize itself).
2. The message and all its submessages have not changed in any
way since the Size call.
If either of these invariants is violated,
the results are undefined and may include panics or corrupted output.
Implementations MAY take this option into account to provide
better performance, but there is no guarantee that they will do so.
There is absolutely no guarantee that Size followed by Marshal with
UseCachedSize set will perform equivalently to Marshal alone.
Marshal returns the wire-format encoding of m.
MarshalAppend appends the wire-format encoding of m to b,
returning the result.
MarshalState returns the wire-format encoding of a message.
This method permits fine-grained control over the marshaler.
Most users should use Marshal instead.
Size returns the size in bytes of the wire-format encoding of m.
marshal is a centralized function that all marshal operations go through.
For profiling purposes, avoid changing the name of this function or
introducing other code paths for marshal that do not go through this.
( T) marshalField(b []byte, fd protoreflect.FieldDescriptor, value protoreflect.Value) ([]byte, error)( T) marshalList(b []byte, fd protoreflect.FieldDescriptor, list protoreflect.List) ([]byte, error)( T) marshalMap(b []byte, fd protoreflect.FieldDescriptor, mapv protoreflect.Map) ([]byte, error)( T) marshalMessage(b []byte, m protoreflect.Message) ([]byte, error)( T) marshalMessageSet(b []byte, m protoreflect.Message) ([]byte, error)( T) marshalMessageSetField(b []byte, fd protoreflect.FieldDescriptor, value protoreflect.Value) ([]byte, error)( T) marshalMessageSlow(b []byte, m protoreflect.Message) ([]byte, error)( T) marshalSingular(b []byte, fd protoreflect.FieldDescriptor, v protoreflect.Value) ([]byte, error)
size is a centralized function that all size operations go through.
For profiling purposes, avoid changing the name of this function or
introducing other code paths for size that do not go through this.
( T) sizeField(fd protoreflect.FieldDescriptor, value protoreflect.Value) (size int)( T) sizeList(num protowire.Number, fd protoreflect.FieldDescriptor, list protoreflect.List) (size int)( T) sizeMap(num protowire.Number, fd protoreflect.FieldDescriptor, mapv protoreflect.Map) (size int)( T) sizeMessageSet(m protoreflect.Message) (size int)( T) sizeMessageSlow(m protoreflect.Message) (size int)( T) sizeSingular(num protowire.Number, kind protoreflect.Kind, v protoreflect.Value) int
func google.golang.org/protobuf/types/known/anypb.MarshalFrom(dst *anypb.Any, src Message, opts MarshalOptions) error
Message is the top-level interface that all messages must implement.
It provides access to a reflective view of a message.
Any implementation of this interface may be used with all functions in the
protobuf module that accept a Message, except where otherwise specified.
This is the v2 interface definition for protobuf messages.
The v1 interface definition is "github.com/golang/protobuf/proto".Message.
To convert a v1 message to a v2 message,
use "github.com/golang/protobuf/proto".MessageV2.
To convert a v2 message to a v1 message,
use "github.com/golang/protobuf/proto".MessageV1.
UnmarshalOptions configures the unmarshaler.
Example usage:
err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
AllowPartial accepts input for messages that will result in missing
required fields. If AllowPartial is false (the default), Unmarshal will
return an error if there are any missing required fields.
If DiscardUnknown is set, unknown fields are ignored.
Merge merges the input into the destination message.
The default behavior is to always reset the message before unmarshaling,
unless Merge is specified.
NoUnkeyedLiteralspragma.NoUnkeyedLiterals
Resolver is used for looking up types when unmarshaling extension fields.
If nil, this defaults to using protoregistry.GlobalTypes.
Unmarshal parses the wire-format message in b and places the result in m.
The provided message must be mutable (e.g., a non-nil pointer to a message).
UnmarshalState parses a wire-format message and places the result in m.
This method permits fine-grained control over the unmarshaler.
Most users should use Unmarshal instead.
unmarshal is a centralized function that all unmarshal operations go through.
For profiling purposes, avoid changing the name of this function or
introducing other code paths for unmarshal that do not go through this.
( T) unmarshalList(b []byte, wtyp protowire.Type, list protoreflect.List, fd protoreflect.FieldDescriptor) (n int, err error)( T) unmarshalMap(b []byte, wtyp protowire.Type, mapv protoreflect.Map, fd protoreflect.FieldDescriptor) (n int, err error)( T) unmarshalMessage(b []byte, m protoreflect.Message) error( T) unmarshalMessageSet(b []byte, m protoreflect.Message) error( T) unmarshalMessageSetField(m protoreflect.Message, num protowire.Number, v []byte) error( T) unmarshalMessageSlow(b []byte, m protoreflect.Message) error
unmarshalScalar decodes a value of the given kind.
Message values are decoded into a []byte which aliases the input data.
( T) unmarshalSingular(b []byte, wtyp protowire.Type, m protoreflect.Message, fd protoreflect.FieldDescriptor) (n int, err error)
func google.golang.org/protobuf/types/known/anypb.UnmarshalNew(src *anypb.Any, opts UnmarshalOptions) (dst Message, err error)
func google.golang.org/protobuf/types/known/anypb.UnmarshalTo(src *anypb.Any, dst Message, opts UnmarshalOptions) error
Package-Level Functions (total 37, in which 22 are exported)
Bool stores v in a new bool value and returns a pointer to it.
CheckInitialized returns an error if any required fields in m are not set.
ClearExtension clears an extension field such that subsequent
HasExtension calls return false.
It panics if m is invalid or if xt does not extend m.
Clone returns a deep copy of m.
If the top-level message is invalid, it returns an invalid message as well.
Equal reports whether two messages are equal.
If two messages marshal to the same bytes under deterministic serialization,
then Equal is guaranteed to report true.
Two messages are equal if they belong to the same message descriptor,
have the same set of populated known and extension field values,
and the same set of unknown fields values. If either of the top-level
messages are invalid, then Equal reports true only if both are invalid.
Scalar values are compared with the equivalent of the == operator in Go,
except bytes values which are compared using bytes.Equal and
floating point values which specially treat NaNs as equal.
Message values are compared by recursively calling Equal.
Lists are equal if each element value is also equal.
Maps are equal if they have the same set of keys, where the pair of values
for each key is also equal.
Float32 stores v in a new float32 value and returns a pointer to it.
Float64 stores v in a new float64 value and returns a pointer to it.
GetExtension retrieves the value for an extension field.
If the field is unpopulated, it returns the default value for
scalars and an immutable, empty value for lists or messages.
It panics if xt does not extend m.
HasExtension reports whether an extension field is populated.
It returns false if m is invalid or if xt does not extend m.
Int32 stores v in a new int32 value and returns a pointer to it.
Int64 stores v in a new int64 value and returns a pointer to it.
Marshal returns the wire-format encoding of m.
Merge merges src into dst, which must be a message with the same descriptor.
Populated scalar fields in src are copied to dst, while populated
singular messages in src are merged into dst by recursively calling Merge.
The elements of every list field in src is appended to the corresponded
list fields in dst. The entries of every map field in src is copied into
the corresponding map field in dst, possibly replacing existing entries.
The unknown fields of src are appended to the unknown fields of dst.
It is semantically equivalent to unmarshaling the encoded form of src
into dst with the UnmarshalOptions.Merge option specified.
MessageName returns the full name of m.
If m is nil, it returns an empty string.
RangeExtensions iterates over every populated extension field in m in an
undefined order, calling f for each extension type and value encountered.
It returns immediately if f returns false.
While iterating, mutating operations may only be performed
on the current extension field.
Reset clears every field in the message.
The resulting message shares no observable memory with its previous state
other than the memory for the message itself.
SetExtension stores the value of an extension field.
It panics if m is invalid, xt does not extend m, or if type of v
is invalid for the specified extension field.
Size returns the size in bytes of the wire-format encoding of m.
String stores v in a new string value and returns a pointer to it.
Uint32 stores v in a new uint32 value and returns a pointer to it.
Uint64 stores v in a new uint64 value and returns a pointer to it.
Unmarshal parses the wire-format message in b and places the result in m.
The provided message must be mutable (e.g., a non-nil pointer to a message).
emptyBytesForMessage returns a nil buffer if and only if m is invalid,
otherwise it returns a non-nil empty buffer.
This is to assist the edge-case where user-code does the following:
m1.OptionalBytes, _ = proto.Marshal(m2)
where they expect the proto2 "optional_bytes" field to be populated
if any only if m2 is a valid message.
equalField compares two fields.
equalList compares two lists.
equalMap compares two maps.
equalMessage compares two messages.
equalUnknown compares unknown fields by direct comparison on the raw bytes
of each individual field number.
growcap scales up the capacity of a slice.
Given a slice with a current capacity of oldcap and a desired
capacity of wantcap, growcap returns a new capacity >= wantcap.
The algorithm is mostly identical to the one used by append as of Go 1.14.
Package-Level Variables (total 5, in which 1 are exported)
Error matches all errors produced by packages in the protobuf module.
That is, errors.Is(err, Error) reports whether an error is produced
by this module.
We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
errUnknown is used internally to indicate fields which should be added
to the unknown field set of a message. It is never returned from an exported
function.
When encoding length-prefixed fields, we speculatively set aside some number of bytes
for the length, encode the data, and then encode the length (shifting the data if necessary
to make room).
The pages are generated with Goldsv0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.