protoconv

package
v1.7.0-dev-20191011 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 7 Imported by: 30

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 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{}) (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