registry

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 8 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindnodeRegistry

type BindnodeRegistry map[reflect.Type]prototypeData

BindnodeRegistry holds TypedPrototype and bindnode options for Go types and will use that data for conversion operations.

func NewRegistry

func NewRegistry() BindnodeRegistry

NewRegistry creates a new BindnodeRegistry

func (BindnodeRegistry) IsRegistered

func (br BindnodeRegistry) IsRegistered(ptrType interface{}) bool

IsRegistered can be used to determine if the type has already been registered within this registry. Using RegisterType on an already registered type will cause a panic, so where this may be the case, IsRegistered can be used to check.

func (BindnodeRegistry) RegisterType

func (br BindnodeRegistry) RegisterType(ptrType interface{}, schema string, typeName string, options ...bindnode.Option) (err error)

RegisterType registers ptrType with schema such that it can be wrapped and unwrapped without needing the schema, Type, or TypedPrototype. Typically the typeName will match the Go type name, but it can be whatever is defined in the schema for the type being registered. Registering the same type twice on this registry will cause an error. This call may also error if the schema is invalid or the type doesn't match the schema. Additionally, panics from within bindnode's initial prototype checks will be captured and returned as errors from this function.

func (BindnodeRegistry) TypeFromBytes

func (br BindnodeRegistry) TypeFromBytes(byts []byte, ptrValue interface{}, decoder codec.Decoder) (interface{}, error)

TypeFromBytes deserializes bytes using the given codec from its bytes and instantiates the Go type that's provided as a pointer via the ptrValue argument.

func (BindnodeRegistry) TypeFromNode

func (br BindnodeRegistry) TypeFromNode(node datamodel.Node, ptrValue interface{}) (interface{}, error)

TypeFromNode converts an datamodel.Node into an appropriate Go type that's provided as a pointer via the ptrValue argument.

func (BindnodeRegistry) TypeFromReader

func (br BindnodeRegistry) TypeFromReader(r io.Reader, ptrValue interface{}, decoder codec.Decoder) (interface{}, error)

TypeFromReader deserializes bytes using the given codec from a Reader and instantiates the Go type that's provided as a pointer via the ptrValue argument.

func (BindnodeRegistry) TypeToBytes

func (br BindnodeRegistry) TypeToBytes(ptrValue interface{}, encoder codec.Encoder) ([]byte, error)

TypeToBytes is a utility method that serializes a Go type that's provided as a pointer via the ptrValue argument through the given codec and returns the bytes.

func (BindnodeRegistry) TypeToNode

func (br BindnodeRegistry) TypeToNode(ptrValue interface{}) schema.TypedNode

TypeToNode converts a Go type that's provided as a pointer via the ptrValue argument to an schema.TypedNode.

func (BindnodeRegistry) TypeToWriter

func (br BindnodeRegistry) TypeToWriter(ptrValue interface{}, w io.Writer, encoder codec.Encoder) error

TypeToWriter is a utility method that serializes a Go type that's provided as a pointer via the ptrValue argument through the given codec to a Writer.

Jump to

Keyboard shortcuts

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