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

package types

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

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

Index

Package Files

any.go any.pb.go compat.go doc.go interface_registry.go

Variables

var (
    ErrInvalidLengthAny        = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowAny          = fmt.Errorf("proto: integer overflow")
    ErrUnexpectedEndOfGroupAny = fmt.Errorf("proto: unexpected end of group")
)
var Debug = true

func UnpackInterfaces Uses

func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error

UnpackInterfaces is a convenience function that calls UnpackInterfaces on x if x implements UnpackInterfacesMessage

type AminoJSONPacker Uses

type AminoJSONPacker struct {
    Cdc *amino.Codec
}

AminoUnpacker is an AnyUnpacker provided for backwards compatibility with amino for the JSON un-marshaling phase

func (AminoJSONPacker) UnpackAny Uses

func (a AminoJSONPacker) UnpackAny(any *Any, _ interface{}) error

type AminoJSONUnpacker Uses

type AminoJSONUnpacker struct {
    Cdc *amino.Codec
}

AminoUnpacker is an AnyUnpacker provided for backwards compatibility with amino for the JSON marshaling phase

func (AminoJSONUnpacker) UnpackAny Uses

func (a AminoJSONUnpacker) UnpackAny(any *Any, iface interface{}) error

type AminoPacker Uses

type AminoPacker struct {
    Cdc *amino.Codec
}

AminoUnpacker is an AnyUnpacker provided for backwards compatibility with amino for the binary marshaling phase

func (AminoPacker) UnpackAny Uses

func (a AminoPacker) UnpackAny(any *Any, _ interface{}) error

type AminoUnpacker Uses

type AminoUnpacker struct {
    Cdc *amino.Codec
}

AminoUnpacker is an AnyUnpacker provided for backwards compatibility with amino for the binary un-marshaling phase

func (AminoUnpacker) UnpackAny Uses

func (a AminoUnpacker) UnpackAny(any *Any, iface interface{}) error

type Any Uses

type Any struct {

    // nolint
    TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
    // Must be a valid serialized protocol buffer of the above specified type.
    Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`

    // nolint
    XXX_NoUnkeyedLiteral struct{} `json:"-"`

    // nolint
    XXX_unrecognized []byte `json:"-"`

    // nolint
    XXX_sizecache int32 `json:"-"`
    // contains filtered or unexported fields
}

func NewAnyWithValue Uses

func NewAnyWithValue(value proto.Message) (*Any, error)

NewAnyWithValue constructs a new Any packed with the value provided or returns an error if that value couldn't be packed. This also caches the packed value so that it can be retrieved from GetCachedValue without unmarshaling

func NewPopulatedAny Uses

func NewPopulatedAny(r randyAny, easy bool) *Any

func UnsafePackAny Uses

func UnsafePackAny(x interface{}) *Any

UnsafePackAny packs the value x in the Any and instead of returning the error in the case of a packing failure, keeps the cached value. This should only be used in situations where compatibility is needed with amino. Amino-only values can safely be packed using this method when they will only be marshaled with amino and not protobuf.

func (*Any) ClearCachedValue Uses

func (any *Any) ClearCachedValue()

ClearCachedValue clears the cached value from the Any

func (*Any) Compare Uses

func (this *Any) Compare(that interface{}) int

func (*Any) Descriptor Uses

func (*Any) Descriptor() ([]byte, []int)

func (*Any) Equal Uses

func (this *Any) Equal(that interface{}) bool

func (*Any) GetCachedValue Uses

func (any *Any) GetCachedValue() interface{}

GetCachedValue returns the cached value from the Any if present

func (*Any) GetTypeUrl Uses

func (m *Any) GetTypeUrl() string

func (*Any) GetValue Uses

func (m *Any) GetValue() []byte

func (*Any) GoString Uses

func (this *Any) GoString() string

func (*Any) Marshal Uses

func (m *Any) Marshal() (dAtA []byte, err error)

func (Any) MarshalAmino Uses

func (any Any) MarshalAmino() ([]byte, error)

func (Any) MarshalJSON Uses

func (any Any) MarshalJSON() ([]byte, error)

func (*Any) MarshalTo Uses

func (m *Any) MarshalTo(dAtA []byte) (int, error)

func (*Any) MarshalToSizedBuffer Uses

func (m *Any) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Any) Pack Uses

func (any *Any) Pack(x proto.Message) error

Pack packs the value x in the Any or returns an error. This also caches the packed value so that it can be retrieved from GetCachedValue without unmarshaling

func (*Any) ProtoMessage Uses

func (*Any) ProtoMessage()

func (*Any) Reset Uses

func (m *Any) Reset()

func (*Any) Size Uses

func (m *Any) Size() (n int)

func (*Any) String Uses

func (this *Any) String() string

func (*Any) Unmarshal Uses

func (m *Any) Unmarshal(dAtA []byte) error

func (*Any) UnmarshalAmino Uses

func (any *Any) UnmarshalAmino(bz []byte) error

func (*Any) UnmarshalJSON Uses

func (any *Any) UnmarshalJSON(bz []byte) error

func (*Any) XXX_DiscardUnknown Uses

func (m *Any) XXX_DiscardUnknown()

func (*Any) XXX_Marshal Uses

func (m *Any) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Any) XXX_Merge Uses

func (m *Any) XXX_Merge(src proto.Message)

func (*Any) XXX_MessageName Uses

func (*Any) XXX_MessageName() string

func (*Any) XXX_Size Uses

func (m *Any) XXX_Size() int

func (*Any) XXX_Unmarshal Uses

func (m *Any) XXX_Unmarshal(b []byte) error

func (*Any) XXX_WellKnownType Uses

func (*Any) XXX_WellKnownType() string

type AnyUnpacker Uses

type AnyUnpacker interface {
    // UnpackAny unpacks the value in any to the interface pointer passed in as
    // iface. Note that the type in any must have been registered in the
    // underlying whitelist registry as a concrete type for that interface
    // Ex:
    //    var msg sdk.Msg
    //    err := cdc.UnpackAny(any, &msg)
    //    ...
    UnpackAny(any *Any, iface interface{}) error
}

AnyUnpacker is an interface which allows safely unpacking types packed in Any's against a whitelist of registered types

type InterfaceRegistry Uses

type InterfaceRegistry interface {
    AnyUnpacker

    // RegisterInterface associates protoName as the public name for the
    // interface passed in as iface. This is to be used primarily to create
    // a public facing registry of interface implementations for clients.
    // protoName should be a well-chosen public facing name that remains stable.
    // RegisterInterface takes an optional list of impls to be registered
    // as implementations of iface.
    //
    // Ex:
    //   registry.RegisterInterface("cosmos.v1beta1.Msg", (*sdk.Msg)(nil))
    RegisterInterface(protoName string, iface interface{}, impls ...proto.Message)

    // RegisterImplementations registers impls as concrete implementations of
    // the interface iface.
    //
    // Ex:
    //  registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{})
    RegisterImplementations(iface interface{}, impls ...proto.Message)
}

InterfaceRegistry provides a mechanism for registering interfaces and implementations that can be safely unpacked from Any

func NewInterfaceRegistry Uses

func NewInterfaceRegistry() InterfaceRegistry

NewInterfaceRegistry returns a new InterfaceRegistry

type ProtoJSONPacker Uses

type ProtoJSONPacker struct {
    JSONPBMarshaler *jsonpb.Marshaler
}

ProtoJSONPacker is an AnyUnpacker provided for compatibility with jsonpb

func (ProtoJSONPacker) UnpackAny Uses

func (a ProtoJSONPacker) UnpackAny(any *Any, _ interface{}) error

type UnpackInterfacesMessage Uses

type UnpackInterfacesMessage interface {
    // UnpackInterfaces is implemented in order to unpack values packed within
    // Any's using the AnyUnpacker. It should generally be implemented as
    // follows:
    //   func (s *MyStruct) UnpackInterfaces(unpacker AnyUnpacker) error {
    //		var x AnInterface
    //		// where X is an Any field on MyStruct
    //		err := unpacker.UnpackAny(s.X, &x)
    //		if err != nil {
    //			return nil
    //		}
    //		// where Y is a field on MyStruct that implements UnpackInterfacesMessage itself
    //		err = s.Y.UnpackInterfaces(unpacker)
    //		if err != nil {
    //			return nil
    //		}
    //		return nil
    //	 }
    UnpackInterfaces(unpacker AnyUnpacker) error
}

UnpackInterfacesMessage is meant to extend protobuf types (which implement proto.Message) to support a post-deserialization phase which unpacks types packed within Any's using the whitelist provided by AnyUnpacker

Package types imports 12 packages (graph) and is imported by 46 packages. Updated 2020-08-12. Refresh now. Tools for package owners.