reflectcodec

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: BSD-3-Clause Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// SliceLenTagName that specifies the length of a slice.
	SliceLenTagName = "len"

	// TagValue is the value the tag must have to be serialized.
	TagValue = "true"
)
View Source
const (
	// DefaultTagName that enables serialization.
	DefaultTagName = "serialize"
)

Variables

View Source
var (
	ErrMaxMarshalSliceLimitExceeded = errors.New("maximum marshal slice limit exceeded")
)

Functions

func New

func New(typer TypeCodec, tagNames []string, maxSliceLen uint32) codec.Codec

New returns a new, concurrency-safe codec

Types

type FieldDesc

type FieldDesc struct {
	Index       int
	MaxSliceLen uint32
}

type StructFielder

type StructFielder interface {
	// Returns the fields that have been marked as serializable in [t], which is
	// a struct type. Additionally, returns the custom maximum length slice that
	// may be serialized into the field, if any.
	// Returns an error if a field has tag "[tagName]: [TagValue]" but the field
	// is un-exported.
	// GetSerializedField(Foo) --> [1,5,8] means Foo.Field(1), Foo.Field(5),
	// Foo.Field(8) are to be serialized/deserialized.
	GetSerializedFields(t reflect.Type) ([]FieldDesc, error)
}

StructFielder handles discovery of serializable fields in a struct.

func NewStructFielder

func NewStructFielder(tagNames []string, maxSliceLen uint32) StructFielder

type TypeCodec

type TypeCodec interface {
	// UnpackPrefix unpacks the prefix of an interface from the given packer.
	// The prefix specifies the concrete type that the interface should be
	// deserialized into. This function returns a new instance of that concrete
	// type. The concrete type must implement the given type.
	UnpackPrefix(*wrappers.Packer, reflect.Type) (reflect.Value, error)

	// PackPrefix packs the prefix for the given type into the given packer.
	// This identifies the bytes that follow, which are the byte representation
	// of an interface, as having the given concrete type.
	// When deserializing the bytes, the prefix specifies which concrete type
	// to deserialize into.
	PackPrefix(*wrappers.Packer, reflect.Type) error
}

Jump to

Keyboard shortcuts

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