types

package
v1.0.0-playground Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

Functions

func UnpackInterfaces

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

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

Types

type AminoJSONPacker

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

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

type AminoJSONUnpacker

type AminoJSONUnpacker struct {
	Cdc *amino.Codec
}

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

func (AminoJSONUnpacker) UnpackAny

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

type AminoPacker

type AminoPacker struct {
	Cdc *amino.Codec
}

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

func (AminoPacker) UnpackAny

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

type AminoUnpacker

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

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

type Any

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

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

func NewPopulatedAny(r randyAny, easy bool) *Any

func (*Any) ClearCachedValue

func (any *Any) ClearCachedValue()

ClearCachedValue clears the cached value from the Any

func (*Any) Compare

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

func (*Any) Descriptor

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

func (*Any) Equal

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

func (*Any) GetCachedValue

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

GetCachedValue returns the cached value from the Any if present

func (*Any) GetTypeUrl

func (m *Any) GetTypeUrl() string

func (*Any) GetValue

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

func (*Any) GoString

func (this *Any) GoString() string

func (*Any) Marshal

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

func (Any) MarshalAmino

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

func (Any) MarshalJSON

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

func (*Any) MarshalTo

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

func (*Any) MarshalToSizedBuffer

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

func (*Any) Pack

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

func (*Any) ProtoMessage()

func (*Any) Reset

func (m *Any) Reset()

func (*Any) Size

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

func (*Any) String

func (this *Any) String() string

func (*Any) Unmarshal

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

func (*Any) UnmarshalAmino

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

func (*Any) UnmarshalJSON

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

func (*Any) XXX_DiscardUnknown

func (m *Any) XXX_DiscardUnknown()

func (*Any) XXX_Marshal

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

func (*Any) XXX_Merge

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

func (*Any) XXX_MessageName

func (*Any) XXX_MessageName() string

func (*Any) XXX_Size

func (m *Any) XXX_Size() int

func (*Any) XXX_Unmarshal

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

func (*Any) XXX_WellKnownType

func (*Any) XXX_WellKnownType() string

type AnyUnpacker

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

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_sdk.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

func NewInterfaceRegistry() InterfaceRegistry

NewInterfaceRegistry returns a new InterfaceRegistry

type UnpackInterfacesMessage

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

Jump to

Keyboard shortcuts

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