typemapper

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TypeMapper

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

TypeMapper is used to map between registered IDs and components and translates between server and client components, Note: Unexported members are supported, however embedded members will not be populated if also unexported.

func NewMapper

func NewMapper(components map[uint]any) TypeMapper

NewMapper initializes a type mapper. This is responsible for serialization/deserialization.

func (*TypeMapper) Deserialize

func (db *TypeMapper) Deserialize(data []byte) (any, error)

Deserialize a component by decoding its ID, and then the actual struct.

func (*TypeMapper) Lookup

func (db *TypeMapper) Lookup(id uint) reflect.Type

Lookup finds the Type based on a component ID.

func (*TypeMapper) LookupId

func (db *TypeMapper) LookupId(componentType reflect.Type) uint

LookupId finds the component ID from a Type.

func (*TypeMapper) Register

func (db *TypeMapper) Register(id uint, component any) error

Register registers a mapping based on ID and an instance of the type.

func (*TypeMapper) RegisterType

func (db *TypeMapper) RegisterType(id uint, componentType reflect.Type) error

RegisterType registers a mapping based on ID and reflect.Type.

func (*TypeMapper) Serialize

func (db *TypeMapper) Serialize(component any) ([]byte, error)

Serialize a component to bytes that can be networked.

Jump to

Keyboard shortcuts

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