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 ¶
- Variables
- func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error
- type AminoJSONPacker
- type AminoJSONUnpacker
- type AminoPacker
- type AminoUnpacker
- type Any
- func (any *Any) ClearCachedValue()
- func (this *Any) Compare(that interface{}) int
- func (*Any) Descriptor() ([]byte, []int)
- func (this *Any) Equal(that interface{}) bool
- func (any *Any) GetCachedValue() interface{}
- func (m *Any) GetTypeUrl() string
- func (m *Any) GetValue() []byte
- func (this *Any) GoString() string
- func (m *Any) Marshal() (dAtA []byte, err error)
- func (any Any) MarshalAmino() ([]byte, error)
- func (any *Any) MarshalJSON() ([]byte, error)
- func (m *Any) MarshalTo(dAtA []byte) (int, error)
- func (m *Any) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (any *Any) Pack(x proto.Message) error
- func (*Any) ProtoMessage()
- func (m *Any) Reset()
- func (m *Any) Size() (n int)
- func (this *Any) String() string
- func (m *Any) Unmarshal(dAtA []byte) error
- func (any *Any) UnmarshalAmino(bz []byte) error
- func (any *Any) UnmarshalJSON(bz []byte) error
- func (m *Any) XXX_DiscardUnknown()
- func (m *Any) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Any) XXX_Merge(src proto.Message)
- func (*Any) XXX_MessageName() string
- func (m *Any) XXX_Size() int
- func (m *Any) XXX_Unmarshal(b []byte) error
- func (*Any) XXX_WellKnownType() string
- type AnyUnpacker
- type InterfaceRegistry
- type IntoAny
- type ProtoJSONPacker
- type UnpackInterfacesMessage
Constants ¶
This section is empty.
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 UnsafePackAny ¶
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 ¶
func (any *Any) ClearCachedValue()
ClearCachedValue clears the cached value from the Any
func (*Any) Descriptor ¶
func (*Any) GetCachedValue ¶
func (any *Any) GetCachedValue() interface{}
GetCachedValue returns the cached value from the Any if present
func (*Any) GetTypeUrl ¶
func (Any) MarshalAmino ¶
func (*Any) MarshalJSON ¶
func (*Any) Pack ¶
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) UnmarshalAmino ¶
func (*Any) UnmarshalJSON ¶
func (*Any) XXX_DiscardUnknown ¶
func (m *Any) XXX_DiscardUnknown()
func (*Any) XXX_MessageName ¶
func (*Any) XXX_Unmarshal ¶
func (*Any) XXX_WellKnownType ¶
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 jsonpb.AnyResolver // 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) // ListAllInterfaces list the type URLs of all registered interfaces. ListAllInterfaces() []string // ListImplementations lists the valid type URLs for the given interface name that can be used // for the provided interface type URL. ListImplementations(ifaceTypeURL string) []string }
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 IntoAny ¶
type IntoAny interface {
AsAny() *Any
}
IntoAny represents a type that can be wrapped into an Any.
type ProtoJSONPacker ¶
ProtoJSONPacker is an AnyUnpacker provided for compatibility with jsonpb
func (ProtoJSONPacker) UnpackAny ¶
func (a ProtoJSONPacker) UnpackAny(any *Any, _ interface{}) error
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 AnyInterface // // 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