proto

package
v2.0.0-...-d24bc72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInitialized

func IsInitialized(m Message) error

IsInitialized returns an error if any required fields in m are not set.

func Marshal

func Marshal(m Message) ([]byte, error)

Marshal returns the wire-format encoding of m.

func Size

func Size(m Message) int

Size returns the size in bytes of the wire-format encoding of m.

func Unmarshal

func Unmarshal(b []byte, m Message) error

Unmarshal parses the wire-format message in b and places the result in m.

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)

func (UnmarshalOptions) Unmarshal

func (o UnmarshalOptions) Unmarshal(b []byte, m Message) error

Unmarshal parses the wire-format message in b and places the result in m.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL