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.
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 ¶
MessageToStruct converts a proto message to a Protoable struct.
Click to show internal directories.
Click to hide internal directories.