jsonpb

package
v1.2.115 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 4 Imported by: 2

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. Deprecated: use protojson.Marshal instead.

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. Deprecated: use protojson.MarshalIndent instead.

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. Deprecated: use protojson.Unmarshal instead.

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. Deprecated: use protojson.Marshaler instead.

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). Deprecated: use protojson.WithMarshalResolver instead.

func WithMarshalEmitDefaults

func WithMarshalEmitDefaults(emitDefaults bool) MarshalerOption

Whether to render fields with zero values. Deprecated: use protojson.WithMarshalEmitUnpopulated instead.

func WithMarshalEnumsAsInts

func WithMarshalEnumsAsInts(enumsAsInts bool) MarshalerOption

Whether to render enum values as integers, as opposed to string values. Deprecated: use protojson.WithMarshalUseEnumNumbers instead.

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. Deprecated: use protojson.WithMarshalIndent instead.

func WithMarshalOrigName

func WithMarshalOrigName(origName bool) MarshalerOption

Whether to use the original (.proto) name for fields. Deprecated: use protojson.WithMarshalUseProtoNames instead.

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. Deprecated: use protojson.Unmarshaler instead.

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 deprecated

func WithUnmarshalAllowUnknownFields(allowUnknownFields bool) UnmarshalerOption

Deprecated: use protojson.WithUnmarshalDiscardUnknown instead.

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). Deprecated: use protojson.WithUnmarshalResolver instead.

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