anyutil

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 10

Documentation

Overview

Package any is a helper library to be used as a replacement for some of the official "google.golang.org/protobuf/types/known/anypb"'s functions which prepend the "type.googleapis.com" prefix in type URLs.

In the Cosmos SDK, an Any's TypeURL starts with a `/` character, e.g. "/cosmos.bank.v1beta1.MsgSend". However, if we pack this MsgSend into an anypb.Any using the offical anypb package's helper functions, we get a TypeURL which is "type.googleapis.com/cosmos.bank.v1beta1.MsgSend".

Therefore, the following 3 functions/methods cannot be used within the Cosmos context: - anypb.New - anypb.MarshalFrom - anypb.Any#MarshalFrom as all of them append the unwanted prefix.

This package exposes the `New` and `MarshalFrom` helper functions, which do not prepend any prefix to type URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalFrom

func MarshalFrom(dst *anypb.Any, src proto.Message, opts proto.MarshalOptions) error

MarshalFrom marshals src into dst as the underlying message using the provided marshal options.

If no options are specified, call dst.MarshalFrom instead.

func New

func New(src proto.Message) (*anypb.Any, error)

New marshals src into a new Any instance.

func Unpack

func Unpack(any *anypb.Any, fileResolver protodesc.Resolver, typeResolver protoregistry.MessageTypeResolver) (proto.Message, error)

Unpack unpacks the message inside an any, first using the provided typeResolver (defaults to protoregistry.GlobalTypes), and if that fails, then using the provided fileResolver (defaults to protoregistry.GlobalFiles) with dynamicpb.

Types

This section is empty.

Jump to

Keyboard shortcuts

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