codec

package
v0.0.0-...-4955b9a Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UpgradeHeight                    int64 = math.MaxInt64
	NotProtoCompatibleInterfaceError       = errors.New("the interface passed for encoding does not implement proto marshaller")
)

Functions

func MarshalAny

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

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

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

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON

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

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

func RegisterEvidences

func RegisterEvidences(legacy *LegacyAmino, _ *ProtoCodec)

func UnmarshalAny

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)

Types

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)

	types.AnyUnpacker
}

type Codec

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

func NewCodec

func NewCodec(anyUnpacker types.AnyUnpacker) *Codec

func (*Codec) AminoCodec

func (cdc *Codec) AminoCodec() *LegacyAmino

func (*Codec) DisableUpgradeOverride

func (cdc *Codec) DisableUpgradeOverride()

func (*Codec) IsAfterUpgrade

func (cdc *Codec) IsAfterUpgrade(height int64) bool

func (*Codec) LegacyMarshalBinaryBare

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

func (*Codec) LegacyMarshalBinaryLengthPrefixed

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

func (*Codec) LegacyUnmarshalBinaryBare

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

func (*Codec) LegacyUnmarshalBinaryLengthPrefixed

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

func (*Codec) MarshalBinaryBare

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

func (*Codec) MarshalBinaryLengthPrefixed

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

func (*Codec) MarshalJSON

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

func (*Codec) MarshalJSONIndent

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

func (*Codec) MustMarshalJSON

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

func (*Codec) MustUnmarshalJSON

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

func (*Codec) ProtoCodec

func (cdc *Codec) ProtoCodec() *ProtoCodec

func (*Codec) ProtoMarshalBinaryBare

func (cdc *Codec) ProtoMarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*Codec) ProtoMarshalBinaryLengthPrefixed

func (cdc *Codec) ProtoMarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*Codec) ProtoUnmarshalBinaryBare

func (cdc *Codec) ProtoUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*Codec) ProtoUnmarshalBinaryLengthPrefixed

func (cdc *Codec) ProtoUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*Codec) RegisterImplementation

func (cdc *Codec) RegisterImplementation(iface interface{}, impls ...proto.Message)

func (*Codec) RegisterInterface

func (cdc *Codec) RegisterInterface(name string, iface interface{}, impls ...proto.Message)

func (*Codec) RegisterStructure

func (cdc *Codec) RegisterStructure(o interface{}, name string)

func (*Codec) SetUpgradeOverride

func (cdc *Codec) SetUpgradeOverride(b bool)

func (*Codec) UnmarshalBinaryBare

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

func (*Codec) UnmarshalBinaryLengthPrefixed

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

func (*Codec) UnmarshalJSON

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

type JSONMarshaler

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

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

type LegacyAmino

type LegacyAmino struct {
	Amino *amino.Codec
}

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

func NewLegacyAminoCodec

func NewLegacyAminoCodec() *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)

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

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

func (*ProtoCodec) MarshalBinaryBare

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

func (*ProtoCodec) MarshalBinaryLengthPrefixed

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

func (*ProtoCodec) MarshalJSON

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

func (*ProtoCodec) MustMarshalBinaryBare

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

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed

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

func (*ProtoCodec) MustMarshalJSON

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

func (*ProtoCodec) MustUnmarshalBinaryBare

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

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed

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

func (*ProtoCodec) MustUnmarshalJSON

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

func (*ProtoCodec) Register

func (pc *ProtoCodec) Register(protoName string, iface interface{}, impls ...proto.Message)

func (*ProtoCodec) RegisterImplementation

func (pc *ProtoCodec) RegisterImplementation(iface interface{}, impls ...proto.Message)

func (*ProtoCodec) UnmarshalBinaryBare

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

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed

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

func (*ProtoCodec) UnmarshalJSON

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

func (*ProtoCodec) UnpackAny

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

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.UnmarshalObject([]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.UnmarshalObject([]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