codec

package
v0.45.7-reap.sdk.v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 13 Imported by: 148

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(cdc JSONCodec, toPrint proto.Message) ([]byte, error)

MarshalYAML marshals toPrint using JSONCodec 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) Marshal

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

Marshal implements BinaryMarshaler.Marshal 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 Marshal 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 JSONCodec.MarshalJSON method, it marshals to JSON using legacy amino codec.

func (*AminoCodec) MarshalLengthPrefixed

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

MarshalLengthPrefixed implements BinaryMarshaler.MarshalLengthPrefixed method.

func (*AminoCodec) MustMarshal

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

MustMarshal implements BinaryMarshaler.MustMarshal method.

func (*AminoCodec) MustMarshalJSON

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

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

func (*AminoCodec) MustMarshalLengthPrefixed

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

MustMarshalLengthPrefixed implements BinaryMarshaler.MustMarshalLengthPrefixed method.

func (*AminoCodec) MustUnmarshal

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

MustUnmarshal implements BinaryMarshaler.MustUnmarshal method.

func (*AminoCodec) MustUnmarshalJSON

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

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

func (*AminoCodec) MustUnmarshalLengthPrefixed

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

MustUnmarshalLengthPrefixed implements BinaryMarshaler.MustUnmarshalLengthPrefixed method.

func (*AminoCodec) Unmarshal

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

Unmarshal implements BinaryMarshaler.Unmarshal 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 Unmarshal 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 JSONCodec.UnmarshalJSON method, it unmarshals from JSON using legacy amino codec.

func (*AminoCodec) UnmarshalLengthPrefixed

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

UnmarshalLengthPrefixed implements BinaryMarshaler.UnmarshalLengthPrefixed method.

type AminoMarshaler

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

AminoMarshaler defines an interface a type must implement to serialize itself for Amino codec.

type BinaryCodec

type BinaryCodec interface {
	// Marshal returns binary encoding of v.
	Marshal(o ProtoMarshaler) ([]byte, error)
	// MustMarshal calls Marshal and panics if error is returned.
	MustMarshal(o ProtoMarshaler) []byte

	// MarshalLengthPrefixed returns binary encoding of v with bytes length prefix.
	MarshalLengthPrefixed(o ProtoMarshaler) ([]byte, error)
	// MustMarshalLengthPrefixed calls MarshalLengthPrefixed and panics if
	// error is returned.
	MustMarshalLengthPrefixed(o ProtoMarshaler) []byte

	// Unmarshal parses the data encoded with Marshal method and stores the result
	// in the value pointed to by v.
	Unmarshal(bz []byte, ptr ProtoMarshaler) error
	// MustUnmarshal calls Unmarshal and panics if error is returned.
	MustUnmarshal(bz []byte, ptr ProtoMarshaler)

	// Unmarshal parses the data encoded with UnmarshalLengthPrefixed method and stores
	// the result in the value pointed to by v.
	UnmarshalLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
	// MustUnmarshalLengthPrefixed calls UnmarshalLengthPrefixed and panics if error
	// is returned.
	MustUnmarshalLengthPrefixed(bz []byte, ptr ProtoMarshaler)

	// MarshalInterface is a helper method which will wrap `i` into `Any` for correct
	// binary interface (de)serialization.
	MarshalInterface(i proto.Message) ([]byte, error)
	// UnmarshalInterface is a helper method which will parse binary enoded data
	// into `Any` and unpack any into the `ptr`. It fails if the target interface type
	// is not registered in codec, or is not compatible with the serialized data
	UnmarshalInterface(bz []byte, ptr interface{}) error

	types.AnyUnpacker
}

type Codec

type Codec interface {
	BinaryCodec
	JSONCodec
}

Codec defines a functionality for serializing other objects. Users can defin a custom Protobuf-based serialization. Note, Amino can still be used without any dependency on Protobuf. SDK provides to Codec implementations:

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

type JSONCodec

type JSONCodec interface {
	// MarshalJSON returns JSON encoding of v.
	MarshalJSON(o proto.Message) ([]byte, error)
	// MustMarshalJSON calls MarshalJSON and panics if error is returned.
	MustMarshalJSON(o proto.Message) []byte
	// MarshalInterfaceJSON is a helper method which will wrap `i` into `Any` for correct
	// JSON interface (de)serialization.
	MarshalInterfaceJSON(i proto.Message) ([]byte, error)
	// UnmarshalInterfaceJSON is a helper method which will parse JSON enoded data
	// into `Any` and unpack any into the `ptr`. It fails if the target interface type
	// is not registered in codec, or is not compatible with the serialized data
	UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error

	// UnmarshalJSON parses the data encoded with MarshalJSON method and stores the result
	// in the value pointed to by v.
	UnmarshalJSON(bz []byte, ptr proto.Message) error
	// MustUnmarshalJSON calls Unmarshal and panics if error is returned.
	MustUnmarshalJSON(bz []byte, ptr proto.Message)
}

type LegacyAmino

type LegacyAmino struct {
	Amino *amino.Codec
}

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

func NewLegacyAmino

func NewLegacyAmino() *LegacyAmino

func (*LegacyAmino) Marshal

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

func (*LegacyAmino) MarshalJSON

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

MarshalJSON implements codec.Codec interface

func (*LegacyAmino) MarshalJSONIndent

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

func (*LegacyAmino) MarshalLengthPrefixed

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

func (*LegacyAmino) MustMarshal

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

func (*LegacyAmino) MustMarshalJSON

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

func (*LegacyAmino) MustMarshalLengthPrefixed

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

func (*LegacyAmino) MustUnmarshal

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

func (*LegacyAmino) MustUnmarshalJSON

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

func (*LegacyAmino) MustUnmarshalLengthPrefixed

func (cdc *LegacyAmino) MustUnmarshalLengthPrefixed(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) Unmarshal

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

func (*LegacyAmino) UnmarshalJSON

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

UnmarshalJSON implements codec.Codec interface

func (*LegacyAmino) UnmarshalLengthPrefixed

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

func (*LegacyAmino) UnpackAny

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

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

InterfaceRegistry returns InterfaceRegistry

func (*ProtoCodec) Marshal

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

Marshal implements BinaryMarshaler.Marshal method. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.MarshalInterface

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 Marshal 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 JSONCodec.MarshalJSON method, it marshals to JSON using proto codec. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.MarshalInterfaceJSON

func (*ProtoCodec) MarshalLengthPrefixed

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

MarshalLengthPrefixed implements BinaryMarshaler.MarshalLengthPrefixed method.

func (*ProtoCodec) MustMarshal

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

MustMarshal implements BinaryMarshaler.MustMarshal method. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.MarshalInterface

func (*ProtoCodec) MustMarshalJSON

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

MustMarshalJSON implements JSONCodec.MustMarshalJSON method, it executes MarshalJSON except it panics upon failure. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.MarshalInterfaceJSON

func (*ProtoCodec) MustMarshalLengthPrefixed

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

MustMarshalLengthPrefixed implements BinaryMarshaler.MustMarshalLengthPrefixed method.

func (*ProtoCodec) MustUnmarshal

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

MustUnmarshal implements BinaryMarshaler.MustUnmarshal method. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.UnmarshalInterface

func (*ProtoCodec) MustUnmarshalJSON

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

MustUnmarshalJSON implements JSONCodec.MustUnmarshalJSON method, it executes UnmarshalJSON except it panics upon failure. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.UnmarshalInterfaceJSON

func (*ProtoCodec) MustUnmarshalLengthPrefixed

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

MustUnmarshalLengthPrefixed implements BinaryMarshaler.MustUnmarshalLengthPrefixed method.

func (*ProtoCodec) Unmarshal

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

Unmarshal implements BinaryMarshaler.Unmarshal method. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.UnmarshalInterface

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 Unmarshal 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 JSONCodec.UnmarshalJSON method, it unmarshals from JSON using proto codec. NOTE: this function must be used with a concrete type which implements proto.Message. For interface please use the codec.UnmarshalInterfaceJSON

func (*ProtoCodec) UnmarshalLengthPrefixed

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

UnmarshalLengthPrefixed implements BinaryMarshaler.UnmarshalLengthPrefixed method.

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 {
	Codec
	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 to serialize itself as a 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:
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:

Jump to

Keyboard shortcuts

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