metadata

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package metadata converts anypb.Any proto to a Protoable struct and vice versa.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrProtoNotPresent indicates that unmarshalling failed because the proto type
	// in `anypb.Any` is not present in the binary.
	ErrProtoNotPresent = errors.New("the proto type is not present/imported")
	// ErrProtoNotRegistered indicates that no struct conversion is registered
	// for the proto -> struct direction.
	ErrProtoNotRegistered = errors.New("the proto that we're trying to decode is not registered")
	// ErrStructNotRegistered indicates that no proto conversion is registered for
	// the struct -> proto direction
	ErrStructNotRegistered = errors.New("the struct that we're trying to encode is not registered")
)

Functions

func Register

func Register[ProtoType proto.Message, StructType Protoable](
	toStruct func(ProtoType) StructType,
	toProto func(StructType) ProtoType,
)

Register registers a metadata type for conversion between proto and struct. It panics if the type is already registered.

func RegisterNil

func RegisterNil[StructType Protoable]()

RegisterNil registers a metadata type that intentionally cannot be converted to proto. Conversion will silently "fail" and output nil.

func StructToProto

func StructToProto(meta Protoable) (*anypb.Any, error)

StructToProto converts a Protoable struct to an anypb.Any proto.

Types

type Protoable

type Protoable interface {
	// IsProtoable is a marker method to ensure that only intended types serve as metadata.
	IsProtoable()
}

Protoable is the interface that all metadata types must implement. This is used in the plugger linter to ensure that only intended types serve as metadata, and that they are registered for conversion between proto and struct.

func MessageToStruct

func MessageToStruct(msg proto.Message) (Protoable, error)

MessageToStruct converts a proto message to a Protoable struct.

func ProtoToStruct

func ProtoToStruct(anyMsg *anypb.Any) (Protoable, error)

ProtoToStruct converts an anypb.Any proto to a Protoable struct.

Jump to

Keyboard shortcuts

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