typeurl

package module
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 193

README

typeurl

PkgGoDev Build Status codecov Go Report Card

A Go package for managing the registration, marshaling, and unmarshaling of encoded types.

This package helps when types are sent over a ttrpc/GRPC API and marshaled as a protobuf Any

Project details

typeurl is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.

Optional

By default, support for gogoproto is available along side the standard Google protobuf types. You can choose to leave gogo support out by using the !no_gogo build tag.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func Is

func Is(any Any, v interface{}) bool

Is returns true if the type of the Any is the same as v.

func MarshalAnyToProto added in v2.2.0

func MarshalAnyToProto(from interface{}) (*anypb.Any, error)

MarshalAnyToProto converts an arbitrary interface to google.golang.org/protobuf/types/known/anypb.Any.

func MarshalProto added in v2.2.0

func MarshalProto(from Any) *anypb.Any

MarshalProto converts typeurl.Any to google.golang.org/protobuf/types/known/anypb.Any.

func Register

func Register(v interface{}, args ...string)

Register a type with a base URL for JSON marshaling. When the MarshalAny and UnmarshalAny functions are called they will treat the Any type value as JSON. To use protocol buffers for handling the Any value the proto.Register function should be used instead of this function.

func TypeURL

func TypeURL(v interface{}) (string, error)

TypeURL returns the type url for a registered type.

func UnmarshalAny

func UnmarshalAny(any Any) (interface{}, error)

UnmarshalAny unmarshals the any type into a concrete type.

func UnmarshalByTypeURL

func UnmarshalByTypeURL(typeURL string, value []byte) (interface{}, error)

UnmarshalByTypeURL unmarshals the given type and value to into a concrete type.

func UnmarshalTo

func UnmarshalTo(any Any, out interface{}) error

UnmarshalTo unmarshals the any type into a concrete type passed in the out argument. It is identical to UnmarshalAny, but lets clients provide a destination type through the out argument.

func UnmarshalToByTypeURL

func UnmarshalToByTypeURL(typeURL string, value []byte, out interface{}) error

UnmarshalToByTypeURL unmarshals the given type and value into a concrete type passed in the out argument. It is identical to UnmarshalByTypeURL, but lets clients provide a destination type through the out argument.

Types

type Any

type Any interface {
	// GetTypeUrl returns a URL/resource name that uniquely identifies
	// the type of the serialized protocol buffer message.
	GetTypeUrl() string

	// GetValue returns a valid serialized protocol buffer of the type that
	// GetTypeUrl() indicates.
	GetValue() []byte
}

Any contains an arbitrary protcol buffer message along with its type.

While there is google.golang.org/protobuf/types/known/anypb.Any, we'd like to have our own to hide the underlying protocol buffer implementations from containerd clients.

https://developers.google.com/protocol-buffers/docs/proto3#any

func MarshalAny

func MarshalAny(v interface{}) (Any, error)

MarshalAny marshals the value v into an any with the correct TypeUrl. If the provided object is already a proto.Any message, then it will be returned verbatim. If it is of type proto.Message, it will be marshaled as a protocol buffer. Otherwise, the object will be marshaled to json.

Jump to

Keyboard shortcuts

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