protoconv

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package protoconv provides a mechanism to register functions to convert objects to and from proto messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(toProto, toObject interface{})

Register registers the converters toProto and toObject. toProto must be a function with the signature:

func(context.Context, O) (P, error)

toObject must be a function with the signature:

func(context.Context, P) (O, error)

Where P is the proto message type and O is the object type.

func ToObject

func ToObject(ctx context.Context, msg proto.Message) (interface{}, error)

ToObject converts obj to a proto message using the converter registered with Register.

func ToProto

func ToProto(ctx context.Context, obj interface{}) (proto.Message, error)

ToProto converts obj to a proto message using the converter registered with Register.

Types

type ErrNoConverterRegistered

type ErrNoConverterRegistered struct {
	Object interface{}
}

ErrNoConverterRegistered is the error returned from ToProto or ToObject when the object's type is not registered for conversion.

func (ErrNoConverterRegistered) Error

func (e ErrNoConverterRegistered) Error() string

type FromProtoContext

type FromProtoContext struct {
	// contains filtered or unexported fields
}

FromProtoContext stores internal state for conversion from proto

func (*FromProtoContext) GetReferencedObject

func (ctx *FromProtoContext) GetReferencedObject(id int64, nilValue interface{}, getValue func() (newValue interface{}, initValue func())) interface{}

GetReferencedObject returns referenceable object with the given ID. nilValue is the default-initialized instance to return for ID 0. getValue is callback function which be called if we see the ID for first time (returned as value+constructor, since that is needed to support cycles).

type ToProtoContext

type ToProtoContext struct {
	// contains filtered or unexported fields
}

ToProtoContext stores internal state for conversion to proto

func (*ToProtoContext) GetReferenceID

func (ctx *ToProtoContext) GetReferenceID(value interface{}) (id int64, isNew bool)

GetReferenceID returns unique identifier for the given object.

Jump to

Keyboard shortcuts

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