Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInitialized ¶
IsInitialized returns an error if any required fields in m are not set.
Types ¶
type MarshalOptions ¶
type MarshalOptions struct { // 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. AllowPartial bool // 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. // // 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. Deterministic bool // 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 broken, the results are undefined // but may include panics or invalid 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. UseCachedSize bool pragma.NoUnkeyedLiterals }
MarshalOptions configures the marshaler.
Example usage:
b, err := MarshalOptions{Deterministic: true}.Marshal(m)
func (MarshalOptions) Marshal ¶
func (o MarshalOptions) Marshal(m Message) ([]byte, error)
Marshal returns the wire-format encoding of m.
func (MarshalOptions) MarshalAppend ¶
func (o MarshalOptions) MarshalAppend(b []byte, m Message) ([]byte, error)
MarshalAppend appends the wire-format encoding of m to b, returning the result.
func (MarshalOptions) Size ¶
func (o MarshalOptions) Size(m Message) int
Size returns the size in bytes of the wire-format encoding of m.
type Message ¶
type Message = protoreflect.ProtoMessage
Message is the top-level interface that all messages must implement.
type UnmarshalOptions ¶
type UnmarshalOptions struct { // 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. AllowPartial bool // If DiscardUnknown is set, unknown fields are ignored. DiscardUnknown bool pragma.NoUnkeyedLiterals }
UnmarshalOptions configures the unmarshaler.
Example usage:
err := UnmarshalOptions{DiscardUnknown: true}.Unmarshal(b, m)
Click to show internal directories.
Click to hide internal directories.