codec

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalAny added in v1.0.0

func MarshalAny(m Marshaler, x interface{}) ([]byte, error)

MarshalAny is a convenience function for packing the provided value in an Any and then proto marshaling it to bytes

func MarshalIndentFromJSON added in v1.0.0

func MarshalIndentFromJSON(bz []byte) ([]byte, error)

MarshalIndentFromJSON returns indented JSON-encoded bytes from already encoded JSON bytes. The output encoding will adhere to the original input's encoding (e.g. Proto3).

func MarshalJSONIndent

func MarshalJSONIndent(m JSONMarshaler, obj interface{}) ([]byte, error)

MarshalJSONIndent provides a utility for indented JSON encoding of an object via an Amino codec. It returns an error if it cannot serialize or indent as JSON.

func MustMarshalJSONIndent added in v1.0.0

func MustMarshalJSONIndent(m JSONMarshaler, obj interface{}) []byte

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON added in v1.0.0

func ProtoMarshalJSON(msg proto.Message) ([]byte, error)

ProtoMarshalJSON provides an auxiliary function to return Proto3 JSON encoded bytes of a message.

func ProtoMarshalJSONIndent added in v1.0.0

func ProtoMarshalJSONIndent(msg proto.Message) ([]byte, error)

ProtoMarshalJSONIndent provides an auxiliary function to return Proto3 indented JSON encoded bytes of a message.

func RegisterCrypto

func RegisterCrypto(cdc *Codec)

RegisterCrypto registers all crypto dependency types with the provided Amino codec.

func RegisterEvidences added in v1.0.0

func RegisterEvidences(cdc *Codec)

RegisterEvidences registers Tendermint evidence types with the provided Amino codec.

func UnmarshalAny added in v1.0.0

func UnmarshalAny(m Marshaler, iface interface{}, bz []byte) error

UnmarshalAny is a convenience function for proto unmarshaling an Any from bz and then unpacking it to the interface pointer passed in as iface using the provided AnyUnpacker or returning an error

Ex:

var x MyInterface
err := UnmarshalAny(unpacker, &x, bz)

Types

type AminoCodec added in v1.0.0

type AminoCodec struct {
	// contains filtered or unexported fields
}

AminoCodec defines a codec that utilizes Amino for both binary and JSON encoding.

func (*AminoCodec) MarshalBinaryBare added in v1.0.0

func (ac *AminoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*AminoCodec) MarshalBinaryLengthPrefixed added in v1.0.0

func (ac *AminoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*AminoCodec) MarshalJSON added in v1.0.0

func (ac *AminoCodec) MarshalJSON(o interface{}) ([]byte, error)

func (*AminoCodec) MustMarshalBinaryBare added in v1.0.0

func (ac *AminoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte

func (*AminoCodec) MustMarshalBinaryLengthPrefixed added in v1.0.0

func (ac *AminoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

func (*AminoCodec) MustMarshalJSON added in v1.0.0

func (ac *AminoCodec) MustMarshalJSON(o interface{}) []byte

func (*AminoCodec) MustUnmarshalBinaryBare added in v1.0.0

func (ac *AminoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

func (*AminoCodec) MustUnmarshalBinaryLengthPrefixed added in v1.0.0

func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

func (*AminoCodec) MustUnmarshalJSON added in v1.0.0

func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*AminoCodec) UnmarshalBinaryBare added in v1.0.0

func (ac *AminoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*AminoCodec) UnmarshalBinaryLengthPrefixed added in v1.0.0

func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*AminoCodec) UnmarshalJSON added in v1.0.0

func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error

func (*AminoCodec) UnpackAny added in v1.0.0

func (*AminoCodec) UnpackAny(*types.Any, interface{}) error

type Codec

type Codec = amino.Codec

Codec defines a type alias for an Amino codec.

var Cdc *Codec

Cdc defines a global generic sealed Amino codec to be used throughout sdk. It has all Tendermint crypto and evidence types registered.

TODO: Consider removing this global.

func New

func New() *Codec

type HybridCodec added in v1.0.0

type HybridCodec struct {
	// contains filtered or unexported fields
}

HybridCodec defines a codec that utilizes Protobuf for binary encoding and Amino for JSON encoding.

func (*HybridCodec) MarshalBinaryBare added in v1.0.0

func (hc *HybridCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*HybridCodec) MarshalBinaryLengthPrefixed added in v1.0.0

func (hc *HybridCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*HybridCodec) MarshalJSON added in v1.0.0

func (hc *HybridCodec) MarshalJSON(o interface{}) ([]byte, error)

func (*HybridCodec) MustMarshalBinaryBare added in v1.0.0

func (hc *HybridCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte

func (*HybridCodec) MustMarshalBinaryLengthPrefixed added in v1.0.0

func (hc *HybridCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

func (*HybridCodec) MustMarshalJSON added in v1.0.0

func (hc *HybridCodec) MustMarshalJSON(o interface{}) []byte

func (*HybridCodec) MustUnmarshalBinaryBare added in v1.0.0

func (hc *HybridCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

func (*HybridCodec) MustUnmarshalBinaryLengthPrefixed added in v1.0.0

func (hc *HybridCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

func (*HybridCodec) MustUnmarshalJSON added in v1.0.0

func (hc *HybridCodec) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*HybridCodec) UnmarshalBinaryBare added in v1.0.0

func (hc *HybridCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*HybridCodec) UnmarshalBinaryLengthPrefixed added in v1.0.0

func (hc *HybridCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*HybridCodec) UnmarshalJSON added in v1.0.0

func (hc *HybridCodec) UnmarshalJSON(bz []byte, ptr interface{}) error

func (*HybridCodec) UnpackAny added in v1.0.0

func (hc *HybridCodec) UnpackAny(any *types.Any, iface interface{}) error

type JSONMarshaler added in v1.0.0

type JSONMarshaler interface {
	MarshalJSON(o interface{}) ([]byte, error)
	MustMarshalJSON(o interface{}) []byte

	UnmarshalJSON(bz []byte, ptr interface{}) error
	MustUnmarshalJSON(bz []byte, ptr interface{})
}

type Marshaler added in v1.0.0

type Marshaler interface {
	MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)
	MustMarshalBinaryBare(o ProtoMarshaler) []byte

	MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)
	MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

	UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error
	MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

	UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
	MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

	JSONMarshaler
	types.AnyUnpacker
}

Marshaler defines the interface module codecs must implement in order to support backwards compatibility with Amino while allowing custom Protobuf-based serialization. Note, Amino can still be used without any dependency on Protobuf. There are three typical implementations that fulfill this contract:

1. AminoCodec: Provides full Amino serialization compatibility. 2. ProtoCodec: Provides full Protobuf serialization compatibility. 3. HybridCodec: Provides Protobuf serialization for binary encoding and Amino for JSON encoding.

func NewAminoCodec added in v1.0.0

func NewAminoCodec(amino *Codec) Marshaler

func NewHybridCodec added in v1.0.0

func NewHybridCodec(amino *Codec, unpacker types.AnyUnpacker) Marshaler

func NewProtoCodec added in v1.0.0

func NewProtoCodec(anyUnpacker types.AnyUnpacker) Marshaler

type ProtoCodec added in v1.0.0

type ProtoCodec struct {
	// contains filtered or unexported fields
}

ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON encoding.

func (*ProtoCodec) MarshalBinaryBare added in v1.0.0

func (pc *ProtoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*ProtoCodec) MarshalBinaryLengthPrefixed added in v1.0.0

func (pc *ProtoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*ProtoCodec) MarshalJSON added in v1.0.0

func (pc *ProtoCodec) MarshalJSON(o interface{}) ([]byte, error)

func (*ProtoCodec) MustMarshalBinaryBare added in v1.0.0

func (pc *ProtoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed added in v1.0.0

func (pc *ProtoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

func (*ProtoCodec) MustMarshalJSON added in v1.0.0

func (pc *ProtoCodec) MustMarshalJSON(o interface{}) []byte

func (*ProtoCodec) MustUnmarshalBinaryBare added in v1.0.0

func (pc *ProtoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed added in v1.0.0

func (pc *ProtoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

func (*ProtoCodec) MustUnmarshalJSON added in v1.0.0

func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*ProtoCodec) UnmarshalBinaryBare added in v1.0.0

func (pc *ProtoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed added in v1.0.0

func (pc *ProtoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*ProtoCodec) UnmarshalJSON added in v1.0.0

func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error

func (*ProtoCodec) UnpackAny added in v1.0.0

func (pc *ProtoCodec) UnpackAny(any *types.Any, iface interface{}) error

type ProtoMarshaler added in v1.0.0

type ProtoMarshaler interface {
	proto.Message // for JSON serialization

	Marshal() ([]byte, error)
	MarshalTo(data []byte) (n int, err error)
	MarshalToSizedBuffer(dAtA []byte) (int, error)
	Size() int
	Unmarshal(data []byte) error
}

ProtoMarshaler defines an interface a type must implement as protocol buffer defined message.

Directories

Path Synopsis
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection

Jump to

Keyboard shortcuts

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