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.
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 ¶ added in v0.9.6
type FromProtoContext struct {
// contains filtered or unexported fields
}
FromProtoContext stores internal state for conversion from proto
func (*FromProtoContext) GetReferencedObject ¶ added in v0.9.6
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 ¶ added in v0.9.6
type ToProtoContext struct {
// contains filtered or unexported fields
}
ToProtoContext stores internal state for conversion to proto
func (*ToProtoContext) GetReferenceID ¶ added in v0.9.6
func (ctx *ToProtoContext) GetReferenceID(value interface{}, nilValue interface{}) (id int64, isNew bool)
GetReferenceID returns unique identifier for the given object. nilValue is the default-initialized instance which will be mapped to ID 0.