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 hybrid_codec.go json.go proto_codec.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(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 Uses

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

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON Uses

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

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

func RegisterEvidences Uses

func RegisterEvidences(cdc *Codec)

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 {
    *Codec
}

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

func NewAminoCodec Uses

func NewAminoCodec(codec *Codec) *AminoCodec

func (*AminoCodec) MarshalBinaryBare Uses

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

func (*AminoCodec) MarshalBinaryLengthPrefixed Uses

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

func (*AminoCodec) MustMarshalBinaryBare Uses

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

func (*AminoCodec) MustMarshalBinaryLengthPrefixed Uses

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

func (*AminoCodec) MustUnmarshalBinaryBare Uses

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

func (*AminoCodec) MustUnmarshalBinaryLengthPrefixed Uses

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

func (*AminoCodec) UnmarshalBinaryBare Uses

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

func (*AminoCodec) UnmarshalBinaryLengthPrefixed Uses

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

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 Codec Uses

type Codec struct {
    Amino *amino.Codec
}

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

func New Uses

func New() *Codec

func (*Codec) MarshalBinaryBare Uses

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

func (*Codec) MarshalBinaryLengthPrefixed Uses

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

func (*Codec) MarshalJSON Uses

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

func (*Codec) MarshalJSONIndent Uses

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

func (*Codec) MustMarshalBinaryBare Uses

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

func (*Codec) MustMarshalBinaryLengthPrefixed Uses

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

func (*Codec) MustMarshalJSON Uses

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

func (*Codec) MustUnmarshalBinaryBare Uses

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

func (*Codec) MustUnmarshalBinaryLengthPrefixed Uses

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

func (*Codec) MustUnmarshalJSON Uses

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

func (*Codec) PrintTypes Uses

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

func (*Codec) RegisterConcrete Uses

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

func (*Codec) RegisterInterface Uses

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

func (*Codec) Seal Uses

func (cdc *Codec) Seal()

func (*Codec) UnmarshalBinaryBare Uses

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

func (*Codec) UnmarshalBinaryLengthPrefixed Uses

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

func (*Codec) UnmarshalJSON Uses

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

func (*Codec) UnpackAny Uses

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

type HybridCodec Uses

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 Uses

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

func (*HybridCodec) MarshalBinaryLengthPrefixed Uses

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

func (*HybridCodec) MarshalJSON Uses

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

func (*HybridCodec) MustMarshalBinaryBare Uses

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

func (*HybridCodec) MustMarshalBinaryLengthPrefixed Uses

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

func (*HybridCodec) MustMarshalJSON Uses

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

func (*HybridCodec) MustUnmarshalBinaryBare Uses

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

func (*HybridCodec) MustUnmarshalBinaryLengthPrefixed Uses

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

func (*HybridCodec) MustUnmarshalJSON Uses

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

func (*HybridCodec) UnmarshalBinaryBare Uses

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

func (*HybridCodec) UnmarshalBinaryLengthPrefixed Uses

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

func (*HybridCodec) UnmarshalJSON Uses

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

func (*HybridCodec) UnpackAny Uses

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

type JSONMarshaler Uses

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

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

func NewHybridCodec Uses

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

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(anyUnpacker types.AnyUnpacker) *ProtoCodec

func (*ProtoCodec) MarshalBinaryBare Uses

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

func (*ProtoCodec) MarshalBinaryLengthPrefixed Uses

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

func (*ProtoCodec) MarshalJSON Uses

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

func (*ProtoCodec) MustMarshalBinaryBare Uses

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

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed Uses

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

func (*ProtoCodec) MustMarshalJSON Uses

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

func (*ProtoCodec) MustUnmarshalBinaryBare Uses

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

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed Uses

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

func (*ProtoCodec) MustUnmarshalJSON Uses

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

func (*ProtoCodec) UnmarshalBinaryBare Uses

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

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed Uses

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

func (*ProtoCodec) UnmarshalJSON Uses

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

func (*ProtoCodec) UnpackAny Uses

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

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 12 packages (graph) and is imported by 630 packages. Updated 2020-08-04. Refresh now. Tools for package owners.