pbjson

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 1

README

pbjson

Go Report Card

pbjson is a wrapper around the protobuf jsonpb package that offers the same API as the stdlib encoding/json package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(msg Message, opts ...EncoderOption) ([]byte, error)

func MarshalToString

func MarshalToString(msg Message, opts ...EncoderOption) (string, error)

func Unmarshal

func Unmarshal(b []byte, msg Message, opts ...DecoderOption) error

Unmarshal unmarshals a byte array into a proto message.

func UnmarshalString

func UnmarshalString(str string, msg Message, opts ...DecoderOption) error

UnmarshalString unmarshals a string into a proto message.

Types

type Decoder

type Decoder struct {
	jsonpb.Unmarshaler
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader, opts ...DecoderOption) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(msg Message) error

type DecoderOption

type DecoderOption func(*decoderOptions)

func AllowUnknownFields

func AllowUnknownFields(b bool) DecoderOption

type Encoder

type Encoder struct {
	jsonpb.Marshaler
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(w io.Writer, opts ...EncoderOption) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(msg Message) error

type EncoderOption

type EncoderOption func(*encoderOptions)

func WithDefaults

func WithDefaults(enable bool) EncoderOption

WithDefaults ensures all fields are emitted, even when they have the default value (the "zero" value).

func WithIndent

func WithIndent(indent string) EncoderOption

func WithIndentDepth

func WithIndentDepth(indentDepth int) EncoderOption

type Message

type Message proto.Message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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