jsonpb

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 15 Imported by: 67

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyResolver

type AnyResolver interface {
	Resolve(typeURL string) (proto.Message, error)
}

AnyResolver takes a type URL, present in an Any message, and resolves it into an instance of the associated message.

type IMarshaler deprecated

type IMarshaler interface {
	MarshalJSONPB(*Marshaler) ([]byte, error)
}

IMarshaler is implemented by protobuf messages that customize the way they are marshaled to JSON. Messages that implement this should also implement JSONPBUnmarshaler so that the custom format can be parsed.

The JSON marshaling must follow the proto to JSON specification:

https://developers.google.com/protocol-buffers/docs/proto3#json

Deprecated: Custom types should implement protobuf reflection instead.

type Marshaler

type Marshaler struct {
	// OrigName specifies whether to use the original protobuf name for fields.
	OrigName bool

	// EnumsAsInts specifies whether to render enum values as integers,
	// as opposed to string values.
	EnumsAsInts bool

	// EmitDefaults specifies whether to render fields with zero values.
	EmitDefaults bool

	// Indent controls whether the output is compact or not.
	// If empty, the output is compact JSON. Otherwise, every JSON object
	// entry and JSON array value will be on its own line.
	// Each line will be preceded by repeated copies of Indent, where the
	// number of copies is the current indentation depth.
	Indent string

	// AnyResolver is used to resolve the google.protobuf.Any well-known type.
	// If unset, the global registry is used by default.
	AnyResolver AnyResolver
}

Marshaler is a configurable object for marshaling protocol buffer messages to the specified JSON representation.

func (*Marshaler) Marshal

func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error

Marshal serializes a protobuf message as JSON into w.

func (*Marshaler) MarshalToString

func (jm *Marshaler) MarshalToString(m proto.Message) (string, error)

MarshalToString serializes a protobuf message as JSON in string form.

Jump to

Keyboard shortcuts

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