Documentation ¶
Overview ¶
Package jsonpb marshals and unmarshals protocol buffer messages as JSON format. It follows the guide at https://developers.google.com/protocol-buffers/docs/proto3#json.
This package produces a different output than the standard "encoding/json" package, which does not operate correctly on protocol buffer messages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MarshalOptions ¶
type MarshalOptions struct { pragma.NoUnkeyedLiterals // AllowPartial allows messages that have missing required fields to marshal // without returning an error. If AllowPartial is false (the default), // Marshal will return error if there are any missing required fields. AllowPartial bool // If Indent is a non-empty string, it causes entries for an Array or Object // to be preceded by the indent and trailed by a newline. Indent can only be // composed of space or tab characters. Indent string // Resolver is the registry used for type lookups when marshaling // google.protobuf.Any messages. If Resolver is not set, marshaling will // default to using protoregistry.GlobalTypes. Resolver *protoregistry.Types // contains filtered or unexported fields }
MarshalOptions is a configurable JSON format marshaler.
type UnmarshalOptions ¶
type UnmarshalOptions struct { pragma.NoUnkeyedLiterals // AllowPartial accepts input for messages that will result in missing // required fields. If AllowPartial is false (the default), Unmarshal will // return error if there are any missing required fields. AllowPartial bool // Resolver is the registry used for type lookups when unmarshaling extensions // and processing Any. If Resolver is not set, unmarshaling will default to // using protoregistry.GlobalTypes. Resolver *protoregistry.Types // contains filtered or unexported fields }
UnmarshalOptions is a configurable JSON format parser.
func (UnmarshalOptions) Unmarshal ¶
func (o UnmarshalOptions) Unmarshal(m proto.Message, b []byte) error
Unmarshal reads the given []byte and populates the given proto.Message using options in UnmarshalOptions object. It will clear the message first before setting the fields. If it returns an error, the given message may be partially set.