nicejsonpb

package module
v0.0.0-...-c7e7769 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Nice Golang Protobuf JSONPB

Travis Build Apache 2.0 License

The jsonpb implementation of golang/protobuf has very bad error handling, making it hard to return human-understandable errors.

This is a fork of the Unmarshal functionality of jsonpb with fixes for error handling:

  • Errors are are now prefixed with a "stack" path of fields that are returned in
  • Poor "cannot deserialize into `json.RawMessage" errors now use proper types
  • Unknown fields now return a helpful message listing known fields :)

Relevant upstream Issue: https://github.com/golang/protobuf/issues/266

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldError

func FieldError(fieldName string, err error) error

FieldError wraps a given error providing a message call stack.

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 UnmarshalNext

func UnmarshalNext(dec *json.Decoder, pb proto.Message) error

UnmarshalNext unmarshals the next protocol buffer from a JSON object stream. 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 Unmarshaler

type Unmarshaler struct {
	// Whether to allow messages to contain unknown fields, as opposed to
	// failing to unmarshal.
	AllowUnknownFields bool
}

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

func (*Unmarshaler) Unmarshal

func (u *Unmarshaler) 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 (*Unmarshaler) UnmarshalNext

func (u *Unmarshaler) UnmarshalNext(dec *json.Decoder, pb proto.Message) error

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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