model

package
v0.0.0-...-15a9106 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0, BSD-2-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrParseBytesFailed is returned if information can not be parsed from a sequence of bytes.
	ErrParseBytesFailed = errors.New("failed to parse bytes")
)

Functions

func NewImmutable

func NewImmutable[OuterModelType any, OuterModelPtrType PtrType[OuterModelType, InnerModelType], InnerModelType any](model *InnerModelType, cacheBytes ...bool) (newInstance *OuterModelType)

NewImmutable creates a new immutable model instance.

func NewMutable

func NewMutable[OuterModelType any, OuterModelPtrType PtrType[OuterModelType, InnerModelType], InnerModelType any](model *InnerModelType, cacheBytes ...bool) (newInstance *OuterModelType)

NewMutable creates a new mutable model instance.

Types

type Immutable

type Immutable[OuterModelType any, OuterModelPtrType PtrType[OuterModelType, InnerModelType], InnerModelType any] struct {
	M InnerModelType
	// contains filtered or unexported fields
}

Immutable is the base type for all immutable models. It should be embedded in a wrapper type. It provides serialization primitives.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Bytes

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Bytes() (bytes []byte, err error)

Bytes serializes a model to a byte slice.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Decode

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Decode(b []byte) (int, error)

Decode deserializes the model from a byte slice.

func (Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Encode

func (i Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Encode() ([]byte, error)

Encode serializes the "content of the model" to a byte slice.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes(bytes []byte) (consumedBytes int, err error)

FromBytes deserializes a model from a byte slice.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Init

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) Init()

Init initializes the model after it has been restored from it's serialized version.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel() *InnerModelType

InnerModel returns the inner Model that holds the data.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) New

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) New(innerModelType *InnerModelType, cacheBytes ...bool)

New initializes the model with the necessary values when being manually created through a constructor.

func (*Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) String

func (i *Immutable[OuterModelType, OuterModelPtrType, InnerModelType]) String() string

String returns a string representation of the model.

type Mutable

type Mutable[OuterModelType any, OuterModelPtrType PtrType[OuterModelType, InnerModelType], InnerModelType any] struct {
	M InnerModelType

	*sync.RWMutex
	// contains filtered or unexported fields
}

Mutable is the base type for simple mutable models. It should be embedded in a wrapper type. It provides serialization and locking primitives.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Bytes

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Bytes() (bytes []byte, err error)

Bytes serializes a model to a byte slice.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Decode

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Decode(b []byte) (int, error)

Decode deserializes the model from a byte slice.

func (Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Encode

func (m Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Encode() ([]byte, error)

Encode serializes the "content of the model" to a byte slice.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes(bytes []byte) (consumedBytes int, err error)

FromBytes deserializes a model from a byte slice.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Init

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) Init()

Init initializes the model after it has been restored from it's serialized version.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel() *InnerModelType

InnerModel returns the inner Model that holds the data.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) InvalidateBytesCache

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) InvalidateBytesCache()

InvalidateBytesCache invalidates the bytes cache.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) New

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) New(innerModelType *InnerModelType, cacheBytes ...bool)

New initializes the model with the necessary values when being manually created through a constructor.

func (*Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) String

func (m *Mutable[OuterModelType, OuterModelPtrType, InnerModelType]) String() string

String returns a string representation of the model.

type PtrType

type PtrType[OuterModelType any, InnerModelType any] interface {
	*OuterModelType

	New(innerModelType *InnerModelType, cacheBytes ...bool)
	Init()
	InnerModel() *InnerModelType
}

PtrType is a type constraint that ensures that all the required methods are available.

type ReferencePtrType

type ReferencePtrType[OuterModelType, SourceIDType, TargetIDType any] interface {
	*OuterModelType

	New(SourceIDType, TargetIDType)
	Init()
	SourceID() SourceIDType
	TargetID() TargetIDType
}

ReferencePtrType is a type constraint that ensures that all the required methods are available.

type ReferenceWithMetadataPtrType

type ReferenceWithMetadataPtrType[OuterModelType, SourceIDType, TargetIDType, InnerModelType any] interface {
	*OuterModelType

	New(SourceIDType, TargetIDType, *InnerModelType)
	Init()
	SourceID() SourceIDType
	TargetID() TargetIDType
	InnerModel() *InnerModelType
}

ReferenceWithMetadataPtrType is a type constraint that ensures that all the required methods are available.

Jump to

Keyboard shortcuts

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