com

package module
v0.0.0-...-ea7d12c Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 3 Imported by: 37

README

Commons for simple and streaming mus Golang serializers

Defines common constants, constraints, errors and validator interface.

Documentation

Index

Constants

View Source
const (
	Num64RawSize = 8
	Num32RawSize = 4
	Num16RawSize = 2
	Num8RawSize  = 1
)

These constants define the number of bytes required for all uint, int, float types in Raw encoding.

View Source
const (
	Uint64MaxVarintLen = 10
	Uint32MaxVarintLen = 5
	Uint16MaxVarintLen = 3
	Uint8MaxVarintLen  = 1
)

These constants define the maximum number of bytes used by Varint encoding for all uint types.

View Source
const (
	Uint64MaxLastByte byte = 1
	Uint32MaxLastByte byte = 15
	Uint16MaxLastByte byte = 3
	Uint8MaxLastByte  byte = 255
)

These constants define the maximum last byte in Varint encoding for all uint types.

Variables

View Source
var ErrNegativeLength = errors.New("negative length")

ErrNegativeLength happens on Unmarshal when some data was encoded with length and value, and length is negative.

View Source
var ErrOverflow = errors.New("overflow")

ErrOverflow happens on Unmarshal when bytes number limit of the type was exceeded.

View Source
var ErrUnknownDTM = errors.New("unknown DTM")

ErrUnknownDTM happens when there is no such DTM in Registry.

View Source
var ErrUnsupportedIntSize = errors.New("unsupported IntSize")

ErrUnsupportedIntSize happens on init, if system int size is not supported.

View Source
var ErrWrongFormat = errors.New("wrong format")

ErrWrongFormat happends on Unmarshal when an incorrect format is encountered.

View Source
var ErrWrongTypeVersion = errors.New("wrong TypeVersion")

ErrWrongTypeVersion happens when the type version from Registry dosn't hold a specific type.

Functions

func UintMaxLastByte

func UintMaxLastByte() byte

UintMaxLastByte returns the maximum last byte in Varint encoding for uint type.

func UintMaxVarintLen

func UintMaxVarintLen() int

UintMaxVarintLen returns the maximum number of bytes used by Varint encoding for uint type.

Types

type DTM

type DTM int

DTM represents a data type metadata.

type Integer16

type Integer16 interface {
	~uint16 | ~int16
}

Integer64 is a constraint that permits any 16-bit integer type.

type Integer32

type Integer32 interface {
	~uint | ~uint32 | ~int | ~int32
}

Integer64 is a constraint that permits any 32-bit integer type.

type Integer64

type Integer64 interface {
	~uint | ~uint64 | ~int | ~int64
}

Integer64 is a constraint that permits any 64-bit integer type.

type Integer8

type Integer8 interface {
	~uint8 | ~int8
}

Integer64 is a constraint that permits any 8-bit integer type.

type MigrateCurrent

type MigrateCurrent[V, T any] func(v V) (t T, err error)

MigrateCurrent migrates the current data version to the old one.

type MigrateOld

type MigrateOld[T, V any] func(t T) (v V, err error)

MigrateOld migrates the old data version to the current one.

type Num32

type Num32 interface {
	~float32 | Integer32
}

Num32 is a constraint that permits any 32-bit integer or float type.

type Num64

type Num64 interface {
	~float64 | Integer64
}

Num64 is a constraint that permits any 64-bit integer or float type.

type PtrFlag

type PtrFlag byte

PtrFlag defines the metadata used to encode pointers.

const (
	NotNil PtrFlag = iota
	Nil
	Mapping
)

These constants determine the values of PtrFlag.

type PtrMap

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

PtrMap helps to implement pointer mapping.

func NewPtrMap

func NewPtrMap() *PtrMap

NewPtrMap creates a new PtrMap.

func (*PtrMap) Get

func (m *PtrMap) Get(ptr unsafe.Pointer) (key int, pst bool)

func (*PtrMap) Put

func (m *PtrMap) Put(ptr unsafe.Pointer) (key int)

type Registry

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

Registry contains all supported type versions.

func NewRegistry

func NewRegistry(versions []TypeVersion) Registry

Creates a new Registry.

func (Registry) Get

func (r Registry) Get(dtm DTM) (tv TypeVersion, err error)

Get returns the type version by DTM.

Returns ErrUnknownDTM if specified DTM is not in Registry.

type ReversePtrMap

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

ReversePtrMap helps to implement pointer mapping.

func NewReversePtrMap

func NewReversePtrMap() ReversePtrMap

NewReversePtrMap creates a new ReversePtrMap.

func (ReversePtrMap) Get

func (mp ReversePtrMap) Get(key int) (ptr unsafe.Pointer, pst bool)

func (ReversePtrMap) Put

func (mp ReversePtrMap) Put(key int, ptr unsafe.Pointer)

type TypeVersion

type TypeVersion any

TypeVersion defines a type version for Registry.

type Validator

type Validator[T any] interface {
	Validate(t T) error
}

Validator is the interface that wraps Validate method.

Validate performs data validation.

type ValidatorFn

type ValidatorFn[T any] func(t T) (err error)

ValidatorFn is a functional implementation of the Validator interface.

func (ValidatorFn[T]) Validate

func (fn ValidatorFn[T]) Validate(t T) (err error)

Jump to

Keyboard shortcuts

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