cosmos-sdk: github.com/cosmos/cosmos-sdk/codec Index | Files | Directories

package codec

import "github.com/cosmos/cosmos-sdk/codec"

Index

Package Files

amino.go amino_codec.go any.go codec.go json.go proto_codec.go yaml.go

func MarshalAny Uses

func MarshalAny(m BinaryMarshaler, 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 MarshalJSONIndent Uses

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 Uses

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 Uses

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

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON Uses

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 Uses

func RegisterEvidences(cdc *LegacyAmino)

RegisterEvidences registers Tendermint evidence types with the provided Amino codec.

func UnmarshalAny Uses

func UnmarshalAny(m BinaryMarshaler, 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)

type AminoCodec Uses

type AminoCodec struct {
    *LegacyAmino
}

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

func NewAminoCodec Uses

func NewAminoCodec(codec *LegacyAmino) *AminoCodec

NewAminoCodec returns a reference to a new AminoCodec

func (*AminoCodec) MarshalBinaryBare Uses

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

MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.

func (*AminoCodec) MarshalBinaryLengthPrefixed Uses

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

MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.

func (*AminoCodec) MarshalJSON Uses

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 Uses

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

MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.

func (*AminoCodec) MustMarshalBinaryLengthPrefixed Uses

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

MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.

func (*AminoCodec) MustMarshalJSON Uses

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

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

func (*AminoCodec) MustUnmarshalBinaryBare Uses

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

MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.

func (*AminoCodec) MustUnmarshalBinaryLengthPrefixed Uses

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

MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.

func (*AminoCodec) MustUnmarshalJSON Uses

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 Uses

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

UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.

func (*AminoCodec) UnmarshalBinaryLengthPrefixed Uses

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

UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.

func (*AminoCodec) UnmarshalJSON Uses

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 Uses

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 Uses

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)

    types.AnyUnpacker
}

type JSONMarshaler Uses

type JSONMarshaler interface {
    MarshalJSON(o proto.Message) ([]byte, error)
    MustMarshalJSON(o proto.Message) []byte

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

type LegacyAmino Uses

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 Uses

func NewLegacyAmino() *LegacyAmino

func (*LegacyAmino) MarshalBinaryBare Uses

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

func (*LegacyAmino) MarshalBinaryLengthPrefixed Uses

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

func (*LegacyAmino) MarshalJSON Uses

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

MarshalJSON implements codec.Marshaler interface

func (*LegacyAmino) MarshalJSONIndent Uses

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

func (*LegacyAmino) MustMarshalBinaryBare Uses

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

func (*LegacyAmino) MustMarshalBinaryLengthPrefixed Uses

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

func (*LegacyAmino) MustMarshalJSON Uses

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

func (*LegacyAmino) MustUnmarshalBinaryBare Uses

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

func (*LegacyAmino) MustUnmarshalBinaryLengthPrefixed Uses

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

func (*LegacyAmino) MustUnmarshalJSON Uses

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

func (*LegacyAmino) PrintTypes Uses

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

func (*LegacyAmino) RegisterConcrete Uses

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

func (*LegacyAmino) RegisterInterface Uses

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

func (*LegacyAmino) Seal Uses

func (cdc *LegacyAmino) Seal()

func (*LegacyAmino) UnmarshalBinaryBare Uses

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

func (*LegacyAmino) UnmarshalBinaryLengthPrefixed Uses

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

func (*LegacyAmino) UnmarshalJSON Uses

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

UnmarshalJSON implements codec.Marshaler interface

func (*LegacyAmino) UnpackAny Uses

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

type Marshaler Uses

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 Uses

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

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

func NewProtoCodec Uses

func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec

NewProtoCodec returns a reference to a new ProtoCodec

func (*ProtoCodec) InterfaceRegistry Uses

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

func (*ProtoCodec) MarshalBinaryBare Uses

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

MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.

func (*ProtoCodec) MarshalBinaryLengthPrefixed Uses

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

MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MarshalJSON Uses

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

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

func (*ProtoCodec) MustMarshalBinaryBare Uses

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

MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed Uses

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

MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustMarshalJSON Uses

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

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

func (*ProtoCodec) MustUnmarshalBinaryBare Uses

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

MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed Uses

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

MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustUnmarshalJSON Uses

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 Uses

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

UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed Uses

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

UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) UnmarshalJSON Uses

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 Uses

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 Uses

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

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

type ProtoMarshaler Uses

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

PathSynopsis
legacyPackage legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
typesPackage 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
unknownprotounknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:

Package codec imports 13 packages (graph) and is imported by 842 packages. Updated 2020-11-14. Refresh now. Tools for package owners.