jsonpb

package
v9.4.36+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: Apache-2.0, BSD-3-Clause Imports: 12 Imported by: 16

Documentation

Overview

Package jsonpb provides marshaling and unmarshaling between protocol buffers and JSON. It follows the specification 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 buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSimpleStringEnum

func RegisterSimpleStringEnum(typeName string, typePrefix string, valueMap map[string]int32)

RegisterSimpleStringEnum registers a simple string value map.

func SimpleStringEnumValueMap

func SimpleStringEnumValueMap(typeName string) map[string]int32

SimpleStringEnumValueMap gets a simple string value map.

func Unmarshal

func Unmarshal(r io.Reader, pb proto.Message) 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.

func UnmarshalString

func UnmarshalString(str string, pb proto.Message) error

UnmarshalString will populate the fields of a protocol buffer based on a JSON string. This function is lenient and will decode any options permutations of the related Marshaler.

Types

type Marshaler

type Marshaler struct {
	// Whether to render enum values as integers, as opposed to string values.
	EnumsAsInts bool
	// Whether to render enum values as simple strings, as opposed to string values.
	EnumsAsSimpleStrings bool

	// 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.
	Indent string
}

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

func (*Marshaler) Marshal

func (m *Marshaler) Marshal(out io.Writer, pb proto.Message) error

Marshal marshals a protocol buffer into JSON.

func (*Marshaler) MarshalToString

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

MarshalToString converts a protocol buffer object to JSON string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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