codec

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSONIndent

func MarshalJSONIndent(cdc *LegacyAmino, 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 MarshalYAML

func MarshalYAML(jsonMarshaler JSONMarshaler, toPrint proto.Message) ([]byte, error)

MarshalYAML marshals toPrint using jsonMarshaler to leverage specialized MarshalJSON methods (usually related to serialize data with protobuf or amin depending on a configuration). This involves additional roundtrip through JSON.

func MustMarshalJSONIndent

func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON

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

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

func RegisterEvidences

func RegisterEvidences(cdc *LegacyAmino)

RegisterEvidences registers Tendermint evidence types with the provided Amino codec.

Types

type AminoCodec

type AminoCodec struct {
	*LegacyAmino
}

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

func NewAminoCodec

func NewAminoCodec(codec *LegacyAmino) *AminoCodec

NewAminoCodec returns a reference to a new AminoCodec

func (*AminoCodec) MarshalBinaryBare

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

MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.

func (*AminoCodec) MarshalBinaryLengthPrefixed

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

MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.

func (*AminoCodec) MarshalInterface

func (ac *AminoCodec) MarshalInterface(i proto.Message) ([]byte, error)

MarshalInterface is a convenience function for amino marshaling interfaces. The `i` must be an interface. NOTE: to marshal a concrete type, you should use MarshalBinaryBare instead

func (*AminoCodec) MarshalInterfaceJSON

func (ac *AminoCodec) MarshalInterfaceJSON(i proto.Message) ([]byte, error)

MarshalInterfaceJSON is a convenience function for amino marshaling interfaces. The `i` must be an interface. NOTE: to marshal a concrete type, you should use MarshalJSON instead

func (*AminoCodec) MarshalJSON

func (ac *AminoCodec) MarshalJSON(o proto.Message) ([]byte, error)

MarshalJSON implements JSONMarshaler.MarshalJSON method, it marshals to JSON using legacy amino codec.

func (*AminoCodec) MustMarshalBinaryBare

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

MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.

func (*AminoCodec) MustMarshalBinaryLengthPrefixed

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

MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.

func (*AminoCodec) MustMarshalJSON

func (ac *AminoCodec) MustMarshalJSON(o proto.Message) []byte

MustMarshalJSON implements JSONMarshaler.MustMarshalJSON method, it executes MarshalJSON except it panics upon failure.

func (*AminoCodec) MustUnmarshalBinaryBare

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

MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.

func (*AminoCodec) MustUnmarshalBinaryLengthPrefixed

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

MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.

func (*AminoCodec) MustUnmarshalJSON

func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message)

MustUnmarshalJSON implements JSONMarshaler.MustUnmarshalJSON method, it executes UnmarshalJSON except it panics upon failure.

func (*AminoCodec) UnmarshalBinaryBare

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

UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.

func (*AminoCodec) UnmarshalBinaryLengthPrefixed

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

UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.

func (*AminoCodec) UnmarshalInterface

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

UnmarshalInterface is a convenience function for amino unmarshaling interfaces. `ptr` must be a pointer to an interface. NOTE: to unmarshal a concrete type, you should use UnmarshalBinaryBare instead

Example:

var x MyInterface
err := cdc.UnmarshalInterface(bz, &x)

func (*AminoCodec) UnmarshalInterfaceJSON

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

UnmarshalInterfaceJSON is a convenience function for amino unmarshaling interfaces. `ptr` must be a pointer to an interface. NOTE: to unmarshal a concrete type, you should use UnmarshalJSON instead

Example:

var x MyInterface
err := cdc.UnmarshalInterfaceJSON(bz, &x)

func (*AminoCodec) UnmarshalJSON

func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error

UnmarshalJSON implements JSONMarshaler.UnmarshalJSON method, it unmarshals from JSON using legacy amino codec.

type AminoMarshaler

type AminoMarshaler interface {
	MarshalAmino() ([]byte, error)
	UnmarshalAmino([]byte) error
	MarshalAminoJSON() ([]byte, error)
	UnmarshalAminoJSON([]byte) error
}

AminoMarshaler defines an interface where Amino marshalling can be overridden by custom marshalling.

type BinaryMarshaler

type BinaryMarshaler 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)

	MarshalInterface(i proto.Message) ([]byte, error)
	UnmarshalInterface(bz []byte, ptr interface{}) error

	types.AnyUnpacker
}

type JSONMarshaler

type JSONMarshaler interface {
	MarshalJSON(o proto.Message) ([]byte, error)
	MustMarshalJSON(o proto.Message) []byte
	MarshalInterfaceJSON(i proto.Message) ([]byte, error)
	UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error

	UnmarshalJSON(bz []byte, ptr proto.Message) error
	MustUnmarshalJSON(bz []byte, ptr proto.Message)
}

type LegacyAmino

type LegacyAmino struct {
	Amino *amino.Codec
}

deprecated: LegacyAmino defines a wrapper for an Amino codec that properly handles protobuf types with Any's

func NewLegacyAmino

func NewLegacyAmino() *LegacyAmino

func (*LegacyAmino) MarshalBinaryBare

func (cdc *LegacyAmino) MarshalBinaryBare(o interface{}) ([]byte, error)

func (*LegacyAmino) MarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error)

func (*LegacyAmino) MarshalJSON

func (cdc *LegacyAmino) MarshalJSON(o interface{}) ([]byte, error)

MarshalJSON implements codec.Marshaler interface

func (*LegacyAmino) MarshalJSONIndent

func (cdc *LegacyAmino) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error)

func (*LegacyAmino) MustMarshalBinaryBare

func (cdc *LegacyAmino) MustMarshalBinaryBare(o interface{}) []byte

func (*LegacyAmino) MustMarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MustMarshalBinaryLengthPrefixed(o interface{}) []byte

func (*LegacyAmino) MustMarshalJSON

func (cdc *LegacyAmino) MustMarshalJSON(o interface{}) []byte

func (*LegacyAmino) MustUnmarshalBinaryBare

func (cdc *LegacyAmino) MustUnmarshalBinaryBare(bz []byte, ptr interface{})

func (*LegacyAmino) MustUnmarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{})

func (*LegacyAmino) MustUnmarshalJSON

func (cdc *LegacyAmino) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*LegacyAmino) PrintTypes

func (cdc *LegacyAmino) PrintTypes(out io.Writer) error

func (*LegacyAmino) RegisterConcrete

func (cdc *LegacyAmino) RegisterConcrete(o interface{}, name string, copts *amino.ConcreteOptions)

func (*LegacyAmino) RegisterInterface

func (cdc *LegacyAmino) RegisterInterface(ptr interface{}, iopts *amino.InterfaceOptions)

func (*LegacyAmino) Seal

func (cdc *LegacyAmino) Seal()

func (*LegacyAmino) UnmarshalBinaryBare

func (cdc *LegacyAmino) UnmarshalBinaryBare(bz []byte, ptr interface{}) error

func (*LegacyAmino) UnmarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error

func (*LegacyAmino) UnmarshalJSON

func (cdc *LegacyAmino) UnmarshalJSON(bz []byte, ptr interface{}) error

UnmarshalJSON implements codec.Marshaler interface

func (*LegacyAmino) UnpackAny

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

type Marshaler

type Marshaler interface {
	BinaryMarshaler
	JSONMarshaler
}

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 two typical implementations that fulfill this contract:

1. AminoCodec: Provides full Amino serialization compatibility. 2. ProtoCodec: Provides full Protobuf serialization compatibility.

type ProtoCodec

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

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

func NewProtoCodec

func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec

NewProtoCodec returns a reference to a new ProtoCodec

func (*ProtoCodec) InterfaceRegistry

func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry

func (*ProtoCodec) MarshalBinaryBare

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

MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.

func (*ProtoCodec) MarshalBinaryLengthPrefixed

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

MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MarshalInterface

func (pc *ProtoCodec) MarshalInterface(i proto.Message) ([]byte, error)

MarshalInterface is a convenience function for proto marshalling interfaces. It packs the provided value, which must be an interface, in an Any and then marshals it to bytes. NOTE: to marshal a concrete type, you should use MarshalBinaryBare instead

func (*ProtoCodec) MarshalInterfaceJSON

func (pc *ProtoCodec) MarshalInterfaceJSON(x proto.Message) ([]byte, error)

MarshalInterfaceJSON is a convenience function for proto marshalling interfaces. It packs the provided value in an Any and then marshals it to bytes. NOTE: to marshal a concrete type, you should use MarshalJSON instead

func (*ProtoCodec) MarshalJSON

func (pc *ProtoCodec) MarshalJSON(o proto.Message) ([]byte, error)

MarshalJSON implements JSONMarshaler.MarshalJSON method, it marshals to JSON using proto codec.

func (*ProtoCodec) MustMarshalBinaryBare

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

MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed

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

MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustMarshalJSON

func (pc *ProtoCodec) MustMarshalJSON(o proto.Message) []byte

MustMarshalJSON implements JSONMarshaler.MustMarshalJSON method, it executes MarshalJSON except it panics upon failure.

func (*ProtoCodec) MustUnmarshalBinaryBare

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

MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed

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

MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustUnmarshalJSON

func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message)

MustUnmarshalJSON implements JSONMarshaler.MustUnmarshalJSON method, it executes UnmarshalJSON except it panics upon failure.

func (*ProtoCodec) UnmarshalBinaryBare

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

UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed

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

UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) UnmarshalInterface

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

UnmarshalInterface is a convenience function for proto unmarshaling interfaces. It unmarshals an Any from bz bytes and then unpacks it to the `ptr`, which must be a pointer to a non empty interface with registered implementations. NOTE: to unmarshal a concrete type, you should use UnmarshalBinaryBare instead

Example:

var x MyInterface
err := cdc.UnmarshalInterface(bz, &x)

func (*ProtoCodec) UnmarshalInterfaceJSON

func (pc *ProtoCodec) UnmarshalInterfaceJSON(bz []byte, iface interface{}) error

UnmarshalInterfaceJSON is a convenience function for proto unmarshaling interfaces. It unmarshals an Any from bz bytes and then unpacks it to the `iface`, which must be a pointer to a non empty interface, implementing proto.Message with registered implementations. NOTE: to unmarshal a concrete type, you should use UnmarshalJSON instead

Example:

var x MyInterface  // must implement proto.Message
err := cdc.UnmarshalInterfaceJSON(&x, bz)

func (*ProtoCodec) UnmarshalJSON

func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error

UnmarshalJSON implements JSONMarshaler.UnmarshalJSON method, it unmarshals from JSON using proto codec.

func (*ProtoCodec) UnpackAny

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

UnpackAny implements AnyUnpacker.UnpackAny method, it unpacks the value in any to the interface pointer passed in as iface.

type ProtoCodecMarshaler

type ProtoCodecMarshaler interface {
	Marshaler
	InterfaceRegistry() types.InterfaceRegistry
}

ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both binary and JSON encoding.

type ProtoMarshaler

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 legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
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
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report: a) Unknown fields in the stream -- this is indicative of mismatched services, perhaps a malicious actor b) Mismatched wire types for a field -- this is indicative of mismatched services Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil { // Handle the error.
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report: a) Unknown fields in the stream -- this is indicative of mismatched services, perhaps a malicious actor b) Mismatched wire types for a field -- this is indicative of mismatched services Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil { // Handle the error.

Jump to

Keyboard shortcuts

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