jsonpb

package
v0.0.0-...-cf28ba7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(pb proto.Message, options ...MarshalerOption) ([]byte, error)

Marshal returns the JSON encoding of v.

func MarshalIndent

func MarshalIndent(pb proto.Message, prefix, indent string, options ...MarshalerOption) ([]byte, error)

MarshalIndent is like Marshal but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.

func Unmarshal

func Unmarshal(data []byte, pb proto.Message, options ...UnmarshalerOption) error

Unmarshal unmarshals a JSON object stream into a protocol buffer. This function is lenient and will decode any options permutations of the related Marshaler.

Types

type EmptyMarshalerOption

type EmptyMarshalerOption struct{}

EmptyMarshalerOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyUnmarshalerOption

type EmptyUnmarshalerOption struct{}

EmptyUnmarshalerOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Marshaler

type Marshaler struct {
	jsonpb.Marshaler
}

Marshaler is a configurable object for converting between protocol buffer objects and a JSON representation for them.

func (*Marshaler) ApplyOptions

func (o *Marshaler) ApplyOptions(options ...MarshalerOption) *Marshaler

type MarshalerOption

type MarshalerOption interface {
	// contains filtered or unexported methods
}

A MarshalerOption sets options.

func WithMarshalAnyResolver

func WithMarshalAnyResolver(anyResolver jsonpb.AnyResolver) MarshalerOption

A custom URL resolver to use when marshaling Any messages to JSON. If unset, the default resolution strategy is to extract the fully-qualified type name from the type URL and pass that to proto.MessageType(string).

func WithMarshalEmitDefaults

func WithMarshalEmitDefaults(emitDefaults bool) MarshalerOption

Whether to render fields with zero values.

func WithMarshalEnumsAsInts

func WithMarshalEnumsAsInts(enumsAsInts bool) MarshalerOption

Whether to render enum values as integers, as opposed to string values.

func WithMarshalIndent

func WithMarshalIndent(indent string) MarshalerOption

A string to indent each level by. The presence of this field will also cause a space to appear between the field separator and value, and for newlines to be appear between fields and array elements.

func WithMarshalOrigName

func WithMarshalOrigName(origName bool) MarshalerOption

Whether to use the original (.proto) name for fields.

type MarshalerOptionFunc

type MarshalerOptionFunc func(*Marshaler)

MarshalerOptionFunc wraps a function that modifies Marshaler into an implementation of the MarshalerOption interface.

type Unmarshaler

type Unmarshaler struct {
	jsonpb.Unmarshaler
}

Unmarshaler is a configurable object for converting from a JSON representation to a protocol buffer object.

func (*Unmarshaler) ApplyOptions

func (o *Unmarshaler) ApplyOptions(options ...UnmarshalerOption) *Unmarshaler

type UnmarshalerOption

type UnmarshalerOption interface {
	// contains filtered or unexported methods
}

A UnmarshalerOption sets options.

func WithUnmarshalAllowUnknownFields

func WithUnmarshalAllowUnknownFields(allowUnknownFields bool) UnmarshalerOption

func WithUnmarshalAnyResolver

func WithUnmarshalAnyResolver(anyResolver jsonpb.AnyResolver) UnmarshalerOption

A custom URL resolver to use when marshaling Any messages to JSON. If unset, the default resolution strategy is to extract the fully-qualified type name from the type URL and pass that to proto.MessageType(string).

type UnmarshalerOptionFunc

type UnmarshalerOptionFunc func(*Unmarshaler)

UnmarshalerOptionFunc wraps a function that modifies Unmarshaler into an implementation of the UnmarshalerOption interface.

Jump to

Keyboard shortcuts

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