jsonpb

package
v0.0.0-...-3d67040 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: ISC Imports: 8 Imported by: 0

README

jsonpb

Build Status ISC License GoDoc

Package jsonpb provides an API for marshaling protobuf objects to JSON and back. There is a golang library to perform these operations, however it converts all byte arrays to base64 strings instead of hex which is typically used by Bitcoin Cash. It also doesn't know to convert little endian byte arrays to big endian.

Thus this package is a wrapper around the original jsonpb package that handles marshaling and unmarshaling to the format expected in Bitcoin Cash.

Installation and Updating

$ go get -u github.com/gcash/bchutil/jsonpb

License

Package jsonpb is licensed under the copyfree ISC License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type Marshaler

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

	// Whether to render fields with zero values.
	EmitDefaults 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

	// Whether to use the original (.proto) name for fields.
	OrigName bool
}

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

The original jsonpb marshaler will marshal bytes as base64 strings. For Bitcoin we obviously prefer hex strings. This marshaler will also convert all 32 byte litte endian arrays to big endian hex strings.

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.

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