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 MsgTypeURL(msg proto.Message) string
- func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error
- type AminoJSONPacker
- type AminoJSONUnpacker
- type AminoPacker
- type AminoUnpacker
- type Any
- type AnyUnpacker
- type InterfaceRegistry
- type InterfaceRegistryOptions
- type ProtoJSONPacker
- type UnpackInterfacesMessage
Constants ¶
This section is empty.
Variables ¶
var NewAnyWithValue = gogoproto.NewAnyWithCacheWithValue
NewAnyWithValue is an alias for gogoproto.NewAnyWithCacheWithValue. This function creates a new Any instance containing the provided value, with caching mechanisms to improve performance.
var UnsafePackAny = gogoproto.UnsafePackAnyWithCache
UnsafePackAny is an alias for gogoproto.UnsafePackAnyWithCache. This function packs a given message into an Any type without performing safety checks.
Functions ¶
func MsgTypeURL ¶
MsgTypeURL returns the TypeURL of a `sdk.Msg`.
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 = gogoproto.AminoJSONPacker
AminoJSONPacker is an alias for gogoproto.AminoJSONPacker. It allows for packing data into a JSON format using Amino encoding rules.
type AminoJSONUnpacker ¶
type AminoJSONUnpacker = gogoproto.AminoJSONUnpacker
AminoJSONUnpacker is an alias for gogoproto.AminoJSONUnpacker. It provides the ability to unpack JSON data encoded with Amino encoding rules.
type AminoPacker ¶
type AminoPacker = gogoproto.AminoPacker
AminoPacker is an alias for gogoproto.AminoPacker. It provides functionality for packing and unpacking data using the Amino encoding.
type AminoUnpacker ¶
type AminoUnpacker = gogoproto.AminoUnpacker
AminoUnpacker is an alias for gogoproto.AminoUnpacker. It is used for unpacking Amino-encoded data into Go types.
type Any ¶
Any is an alias for gogoproto.Any. It represents a protocol buffer message that can contain any arbitrary data. This is used for encoding and decoding unknown or dynamic content in a type-safe manner.
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 registry.InterfaceRegistrar // 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 // EnsureRegistered ensures there is a registered interface for the given concrete type. EnsureRegistered(iface interface{}) error protodesc.Resolver // RangeFiles iterates over all registered files and calls f on each one. This // implements the part of protoregistry.Files that is needed for reflecting over // the entire FileDescriptorSet. RangeFiles(f func(protoreflect.FileDescriptor) bool) SigningContext() *signing.Context // contains filtered or unexported methods }
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
func NewInterfaceRegistryWithOptions ¶
func NewInterfaceRegistryWithOptions(options InterfaceRegistryOptions) (InterfaceRegistry, error)
NewInterfaceRegistryWithOptions returns a new InterfaceRegistry with the given options.
type InterfaceRegistryOptions ¶
type InterfaceRegistryOptions struct { // ProtoFiles is the set of files to use for the registry. It is required. ProtoFiles signing.ProtoFileResolver // SigningOptions are the signing options to use for the registry. SigningOptions signing.Options }
InterfaceRegistryOptions are options for creating a new InterfaceRegistry.
type ProtoJSONPacker ¶
type ProtoJSONPacker = gogoproto.ProtoJSONPacker
ProtoJSONPacker is an alias for gogoproto.ProtoJSONPacker. This is used for packing protocol buffer messages into a JSON format.
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