states

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeScalar

func DecodeScalar[T any](b []byte) (T, error)

DecodeScalar unmarshals bytes into a ProtoScalar value using the appropriate protobuf wrapper.

func EncodeScalar

func EncodeScalar[T any](v T) ([]byte, error)

EncodeScalar marshals a ProtoScalar value into bytes using protobuf wrappers.

Types

type MapCodec added in v0.0.4

type MapCodec[K comparable, V any] interface {
	EncodeKey(key K) ([]byte, error)
	DecodeKey(b []byte) (K, error)
	EncodeValue(value V) ([]byte, error)
	DecodeValue(b []byte) (V, error)
}

type MapState

type MapState[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMapState

func NewMapState[K comparable, V any](name string, codec MapCodec[K, V]) *MapState[K, V]

NewMapState creates a new MapState, applying any provided options.

func (*MapState[K, V]) All

func (s *MapState[K, V]) All() iter.Seq2[K, V]

func (*MapState[K, V]) Delete

func (s *MapState[K, V]) Delete(key K)

func (*MapState[K, V]) Get

func (s *MapState[K, V]) Get(key K) (V, bool)

func (*MapState[K, V]) Load

func (s *MapState[K, V]) Load(entries []internal.StateEntry) error

func (*MapState[K, V]) Mutations

func (s *MapState[K, V]) Mutations() ([]internal.StateMutation, error)

func (*MapState[K, V]) Name

func (s *MapState[K, V]) Name() string

Name returns the state's name

func (*MapState[K, V]) Set

func (s *MapState[K, V]) Set(key K, value V)

func (*MapState[K, V]) Size

func (s *MapState[K, V]) Size() int

Size returns the current number of items in the map state.

type ProtoScalar

type ProtoScalar interface {
	~int | ~int32 | ~int64 |
		~uint | ~uint32 | ~uint64 |
		~float32 | ~float64 |
		~string |
		~bool |
		time.Time
}

ProtoScalar represents the go types that can be wrapped by protobuf. The EncodeScaler and DecodeScaler functions use permissive `any` types so that they can work with the caller's types. They will have runtime errors if the types don't match ProtoScalar.

type ScalarValueCodec

type ScalarValueCodec[T ProtoScalar] struct{}

ScalarValueCodec is a codec for simple scalar values using protobuf serialization

func (ScalarValueCodec[T]) Decode

func (c ScalarValueCodec[T]) Decode(b []byte) (T, error)

func (ScalarValueCodec[T]) Encode

func (c ScalarValueCodec[T]) Encode(value T) ([]byte, error)

type StateSpec

type StateSpec[T any] struct {
	ID        string
	Query     internal.QueryType
	Load      func([]internal.StateEntry) (*T, error)
	Mutations func(*T) ([]internal.StateMutation, error)
}

func (*StateSpec[T]) StateFor

func (s *StateSpec[T]) StateFor(subject *internal.Subject) *T

type ValueCodec

type ValueCodec[T any] interface {
	Encode(T) ([]byte, error)
	Decode([]byte) (T, error)
}

type ValueState

type ValueState[T any] struct {
	// contains filtered or unexported fields
}

func NewValueState

func NewValueState[T any](name string, codec ValueCodec[T]) *ValueState[T]

func (*ValueState[T]) Drop

func (s *ValueState[T]) Drop()

func (*ValueState[T]) Load

func (s *ValueState[T]) Load(entries []internal.StateEntry) error

func (*ValueState[T]) Mutations

func (s *ValueState[T]) Mutations() ([]internal.StateMutation, error)

func (*ValueState[T]) Name

func (s *ValueState[T]) Name() string

func (*ValueState[T]) Set

func (s *ValueState[T]) Set(value T)

func (*ValueState[T]) Value

func (s *ValueState[T]) Value() T

type ValueUpdate

type ValueUpdate[V any] struct {
	IsDelete bool
	Value    V
}

Jump to

Keyboard shortcuts

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