jsonpb

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: 16 Imported by: 0

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

func Marshal

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

Marshal writes the given proto.Message in JSON format using default options.

func Unmarshal

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

Unmarshal reads the given []byte into the given proto.Message.

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.

func (MarshalOptions) Marshal

func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error)

Marshal marshals the given proto.Message in the JSON format using options in MarshalOptions.

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.

Jump to

Keyboard shortcuts

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