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: 13 Imported by: 7

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 NewStorable

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

NewStorable creates a new storable model instance.

func NewStorableReference

func NewStorableReference[OuterModelType any, OuterModelPtrType model.ReferencePtrType[OuterModelType, SourceIDType, TargetIDType], SourceIDType, TargetIDType any](sourceID SourceIDType, targetID TargetIDType) (newInstance *OuterModelType)

NewStorableReference creates a new storable reference model instance.

func NewStorableReferenceWithMetadata

func NewStorableReferenceWithMetadata[OuterModelType any, OuterModelPtrType model.ReferenceWithMetadataPtrType[OuterModelType, SourceIDType, TargetIDType, InnerModelType], SourceIDType, TargetIDType, InnerModelType any](sourceID SourceIDType, targetID TargetIDType, model *InnerModelType) (newInstance *OuterModelType)

NewStorableReferenceWithMetadata creates a new storable reference model instance.

Types

type Storable

type Storable[IDType, OuterModelType any, OuterModelPtrType model.PtrType[OuterModelType, InnerModelType], InnerModelType any] struct {
	M InnerModelType

	*syncutils.RWMutexFake
	*objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Storable is the base type for all storable models. It should be embedded in a wrapper type. It provides locking and serialization primitives. Types that implement interfaces need to override the serialization logic so that the correct interface can be inferred.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Bytes

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Bytes() (bytes []byte, err error)

Bytes serializes a model to a byte slice.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Decode

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Decode(b []byte) (int, error)

Decode deserializes the model from a byte slice.

func (Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Encode

func (s Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Encode() ([]byte, error)

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

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) FromBytes(bytes []byte) (consumedBytes int, err error)

FromBytes deserializes a model from a byte slice.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) FromObjectStorage

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) FromObjectStorage(key, data []byte) (err error)

FromObjectStorage deserializes a model from the object storage.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ID

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ID() (id IDType)

ID returns the ID of the model.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) IDFromBytes

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) IDFromBytes(bytes []byte) (err error)

IDFromBytes deserializes an ID from a byte slice.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ImportStorable

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ImportStorable(other *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType])

ImportModel imports the model of the other storable.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Init

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) Init()

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

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) InnerModel() *InnerModelType

InnerModel returns the inner Model that holds the data.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) InvalidateBytesCache

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) InvalidateBytesCache()

InvalidateBytesCache invalidates the bytes cache.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) New

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) New(innerModelType *InnerModelType, cacheBytes ...bool)

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

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ObjectStorageKey

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ObjectStorageKey() (key []byte)

ObjectStorageKey returns the bytes, that are used as a key to store the object in the k/v store.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ObjectStorageValue

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) ObjectStorageValue() (value []byte)

ObjectStorageValue returns the bytes, that are stored in the value part of the k/v store.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) SetID

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) SetID(id IDType)

SetID sets the ID of the model.

func (*Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) String

func (s *Storable[IDType, OuterModelType, OuterModelPtrType, InnerModelType]) String() string

String returns a string representation of the model.

type StorableReference

type StorableReference[OuterModelType any, OuterModelPtrType model.ReferencePtrType[OuterModelType, SourceIDType, TargetIDType], SourceIDType, TargetIDType any] struct {
	*objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

StorableReference is the base type for all storable reference models. It should be embedded in a wrapper type. It provides locking and serialization primitives.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Bytes

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Bytes() (bytes []byte, err error)

Bytes serializes a storable reference model to a byte slice.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Decode

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Decode(b []byte) (int, error)

Decode deserializes the model from a byte slice.

func (StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Encode

func (s StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Encode() ([]byte, error)

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

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) FromBytes

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) FromBytes(bytes []byte) (consumedBytes int, err error)

FromBytes deserializes a storable reference model from a byte slice.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) FromObjectStorage

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) FromObjectStorage(key, _ []byte) (err error)

FromObjectStorage deserializes a model from the object storage.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Init

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) Init()

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

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) KeyPartitions

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) KeyPartitions() []int

KeyPartitions returns a slice of the key partitions that are used to store the object in the k/v store.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) New

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) New(sourceID SourceIDType, targetID TargetIDType)

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

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) ObjectStorageKey

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) ObjectStorageKey() (key []byte)

ObjectStorageKey returns the bytes, that are used as a key to store the object in the k/v store.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) ObjectStorageValue

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) ObjectStorageValue() (value []byte)

ObjectStorageValue returns the bytes, that are stored in the value part of the k/v store.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) SourceID

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) SourceID() SourceIDType

SourceID returns the SourceID of the storable reference model.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) String

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) String() string

String returns a string representation of the model.

func (*StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) TargetID

func (s *StorableReference[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType]) TargetID() TargetIDType

TargetID returns the TargetID of the storable reference model.

type StorableReferenceWithMetadata

type StorableReferenceWithMetadata[OuterModelType any, OuterModelPtrType model.ReferenceWithMetadataPtrType[OuterModelType, SourceIDType, TargetIDType, InnerModelType], SourceIDType, TargetIDType, InnerModelType any] struct {
	M InnerModelType

	*syncutils.RWMutexFake
	*objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

StorableReferenceWithMetadata is the base type for all storable reference models. It should be embedded in a wrapper type. It provides locking and serialization primitives.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Bytes

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Bytes() (bytes []byte, err error)

Bytes serializes a storable reference model to a byte slice.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Decode

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Decode(b []byte) (int, error)

Decode deserializes the model from a byte slice.

func (StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Encode

func (s StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Encode() ([]byte, error)

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

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) FromBytes

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) FromBytes(bytes []byte) (consumedBytes int, err error)

FromBytes deserializes a storable reference model from a byte slice.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) FromObjectStorage

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) FromObjectStorage(key, value []byte) (err error)

FromObjectStorage deserializes a model from the object storage.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Init

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) Init()

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

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) InnerModel

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) InnerModel() *InnerModelType

InnerModel returns the inner Model that holds the data.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) KeyPartitions

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) KeyPartitions() []int

KeyPartitions returns a slice of the key partitions that are used to store the object in the k/v store.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) New

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) New(sourceID SourceIDType, targetID TargetIDType, model *InnerModelType)

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

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) ObjectStorageKey

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) ObjectStorageKey() (key []byte)

ObjectStorageKey returns the bytes, that are used as a key to store the object in the k/v store.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) ObjectStorageValue

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) ObjectStorageValue() (value []byte)

ObjectStorageValue returns the bytes, that are stored in the value part of the k/v store.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) SourceID

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) SourceID() SourceIDType

SourceID returns the SourceID of the storable reference model.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) String

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) String() string

String returns a string representation of the model.

func (*StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) TargetID

func (s *StorableReferenceWithMetadata[OuterModelType, OuterModelPtrType, SourceIDType, TargetIDType, InnerModelType]) TargetID() TargetIDType

TargetID returns the TargetID of the storable reference model.

Jump to

Keyboard shortcuts

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