state

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package state holds data and it's state

Index

Constants

This section is empty.

Variables

View Source
var (
	StateUpdaterPoolGet = func() *StateUpdater {
		return stateUpdaterPool.Get().(*StateUpdater)
	}
	StateUpdaterPoolPut = func(stu *StateUpdater) {
		stu.Lock()
		defer stu.Unlock()

		stu.State = nil
		stu.opcache = nil
		stu.orig = nil
		stu.height = base.NilHeight
		stu.operations = nil

		stateUpdaterPool.Put(stu)
	}
)
View Source
var (
	StateV0Type = hint.Type("stete")
	StateV0Hint = hint.NewHint(StateV0Type, "v0.0.1")
)
View Source
var (
	FixedTreeNodeType   = hint.Type("state-fixedtree-node")
	FixedTreeNodeHint   = hint.NewHint(FixedTreeNodeType, "v0.0.1")
	FixedTreeNodeHinter = FixedTreeNode{
		BaseFixedTreeNode: tree.BaseFixedTreeNode{BaseHinter: hint.NewBaseHinter(FixedTreeNodeHint)},
	}
)
View Source
var (
	BytesValueType   = hint.Type("state-bytes-value")
	BytesValueHint   = hint.NewHint(BytesValueType, "v0.0.1")
	BytesValueHinter = BytesValue{BaseHinter: hint.NewBaseHinter(BytesValueHint)}
)
View Source
var (
	DurationValueType   = hint.Type("state-duration-value")
	DurationValueHint   = hint.NewHint(DurationValueType, "v0.0.1")
	DurationValueHinter = DurationValue{BaseHinter: hint.NewBaseHinter(DurationValueHint)}
)
View Source
var (
	HintedValueType   = hint.Type("state-hinted-value")
	HintedValueHint   = hint.NewHint(HintedValueType, "v0.0.1")
	HintedValueHinter = HintedValue{BaseHinter: hint.NewBaseHinter(HintedValueHint)}
)
View Source
var (
	NumberValueType   = hint.Type("state-number-value")
	NumberValueHint   = hint.NewHint(NumberValueType, "v0.0.1")
	NumberValueHinter = NumberValue{BaseHinter: hint.NewBaseHinter(NumberValueHint)}
)
View Source
var (
	SliceValueType   = hint.Type("state-slice-value")
	SliceValueHint   = hint.NewHint(SliceValueType, "v0.0.1")
	SliceValueHinter = SliceValue{BaseHinter: hint.NewBaseHinter(SliceValueHint)}
)
View Source
var (
	StringValueType   = hint.Type("state-string-value")
	StringValueHint   = hint.NewHint(StringValueType, "v0.0.1")
	StringValueHinter = StringValue{BaseHinter: hint.NewBaseHinter(StringValueHint)}
)

Functions

func IsValidKey

func IsValidKey(s string) error

Types

type BytesValue

type BytesValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBytesValue

func NewBytesValue(v interface{}) (BytesValue, error)

func (BytesValue) Equal

func (bv BytesValue) Equal(v Value) bool

func (BytesValue) Hash

func (bv BytesValue) Hash() valuehash.Hash

func (BytesValue) Interface

func (bv BytesValue) Interface() interface{}

func (BytesValue) IsValid

func (bv BytesValue) IsValid([]byte) error

func (BytesValue) MarshalBSON

func (bv BytesValue) MarshalBSON() ([]byte, error)

func (BytesValue) MarshalJSON

func (bv BytesValue) MarshalJSON() ([]byte, error)

func (BytesValue) Set

func (bv BytesValue) Set(v interface{}) (Value, error)

func (*BytesValue) UnpackBSON

func (bv *BytesValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*BytesValue) UnpackJSON

func (bv *BytesValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type BytesValueUnpackerBSON

type BytesValueUnpackerBSON struct {
	H valuehash.Bytes `bson:"hash"`
	V []byte          `bson:"value"`
}

type DurationValue

type DurationValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewDurationValue

func NewDurationValue(d time.Duration) (DurationValue, error)

func (DurationValue) Equal

func (dv DurationValue) Equal(v Value) bool

func (DurationValue) Hash

func (dv DurationValue) Hash() valuehash.Hash

func (DurationValue) Interface

func (dv DurationValue) Interface() interface{}

func (DurationValue) IsValid

func (dv DurationValue) IsValid([]byte) error

func (DurationValue) MarshalBSON

func (dv DurationValue) MarshalBSON() ([]byte, error)

func (DurationValue) MarshalJSON

func (dv DurationValue) MarshalJSON() ([]byte, error)

func (DurationValue) Set

func (dv DurationValue) Set(v interface{}) (Value, error)

func (*DurationValue) UnpackBSON

func (dv *DurationValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*DurationValue) UnpackJSON

func (dv *DurationValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type DurationValueUnpackerBSON

type DurationValueUnpackerBSON struct {
	H valuehash.Bytes `bson:"hash"`
	V int64           `bson:"value"`
}

type FixedTreeNode

type FixedTreeNode struct {
	tree.BaseFixedTreeNode
}

func NewFixedTreeNode

func NewFixedTreeNode(index uint64, key []byte) FixedTreeNode

func (*FixedTreeNode) UnmarshalBSON

func (no *FixedTreeNode) UnmarshalBSON(b []byte) error

func (*FixedTreeNode) UnmarshalJSON

func (no *FixedTreeNode) UnmarshalJSON(b []byte) error

type HintedValue

type HintedValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewHintedValue

func NewHintedValue(v hint.Hinter) (HintedValue, error)

func (HintedValue) Equal

func (hv HintedValue) Equal(v Value) bool

func (HintedValue) Hash

func (hv HintedValue) Hash() valuehash.Hash

func (HintedValue) Interface

func (hv HintedValue) Interface() interface{}

func (HintedValue) IsValid

func (hv HintedValue) IsValid([]byte) error

func (HintedValue) MarshalBSON

func (hv HintedValue) MarshalBSON() ([]byte, error)

func (HintedValue) MarshalJSON

func (hv HintedValue) MarshalJSON() ([]byte, error)

func (HintedValue) Set

func (hv HintedValue) Set(v interface{}) (Value, error)

func (*HintedValue) UnpackBSON

func (hv *HintedValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*HintedValue) UnpackJSON

func (hv *HintedValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type HintedValueUnpackerBSON

type HintedValueUnpackerBSON struct {
	V bson.Raw `bson:"value"`
}

type NumberValue

type NumberValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewNumberValue

func NewNumberValue(v interface{}) (NumberValue, error)

func (NumberValue) Equal

func (nv NumberValue) Equal(v Value) bool

func (NumberValue) Hash

func (nv NumberValue) Hash() valuehash.Hash

func (NumberValue) Interface

func (nv NumberValue) Interface() interface{}

func (NumberValue) IsValid

func (nv NumberValue) IsValid([]byte) error

func (NumberValue) MarshalBSON

func (nv NumberValue) MarshalBSON() ([]byte, error)

func (NumberValue) MarshalJSON

func (nv NumberValue) MarshalJSON() ([]byte, error)

func (NumberValue) Set

func (nv NumberValue) Set(v interface{}) (Value, error)

func (NumberValue) Type

func (nv NumberValue) Type() reflect.Kind

func (*NumberValue) UnpackBSON

func (nv *NumberValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*NumberValue) UnpackJSON

func (nv *NumberValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type NumberValueBSONUnpacker

type NumberValueBSONUnpacker struct {
	H valuehash.Bytes `bson:"hash"`
	V []byte          `bson:"value"`
	T reflect.Kind    `bson:"type"`
}

type NumberValueJSONPacker

type NumberValueJSONPacker struct {
	jsonenc.HintedHead
	H valuehash.Hash `json:"hash"`
	V []byte         `json:"value"`
	T reflect.Kind   `json:"type"`
}

type NumberValueJSONUnpacker

type NumberValueJSONUnpacker struct {
	H valuehash.Bytes `json:"hash"`
	V []byte          `json:"value"`
	T reflect.Kind    `json:"type"`
}

type PreProcessor

type PreProcessor interface {
	PreProcess(
		getState func(key string) (State, bool, error),
		setState func(valuehash.Hash, ...State) error,
	) (Processor, error)
}

type Processor

type Processor interface {
	Process(
		getState func(key string) (State, bool, error),
		setState func(valuehash.Hash, ...State) error,
	) error
}

type SliceValue

type SliceValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

SliceValue only supports the interface{} implements hint.Hinter and valuehash.Hasher().

func NewSliceValue

func NewSliceValue(v interface{}) (SliceValue, error)

func (SliceValue) Equal

func (sv SliceValue) Equal(v Value) bool

func (SliceValue) Hash

func (sv SliceValue) Hash() valuehash.Hash

func (SliceValue) Interface

func (sv SliceValue) Interface() interface{}

func (SliceValue) IsValid

func (sv SliceValue) IsValid([]byte) error

func (SliceValue) MarshalBSON

func (sv SliceValue) MarshalBSON() ([]byte, error)

func (SliceValue) MarshalJSON

func (sv SliceValue) MarshalJSON() ([]byte, error)

func (SliceValue) Set

func (sv SliceValue) Set(v interface{}) (Value, error)

func (*SliceValue) UnpackBSON

func (sv *SliceValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*SliceValue) UnpackJSON

func (sv *SliceValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type State

type State interface {
	isvalid.IsValider
	hint.Hinter
	valuehash.Hasher
	Key() string
	Value() Value
	SetValue(Value) (State, error)
	SetHash(valuehash.Hash) (State, error)
	Height() base.Height
	SetHeight(base.Height) State
	PreviousHeight() base.Height
	SetPreviousHeight(base.Height) (State, error)
	Operations() []valuehash.Hash
	SetOperation([]valuehash.Hash) State
	GenerateHash() valuehash.Hash
	Merge(State) (State, error)
	Clear() State
}

type StateUpdater

type StateUpdater struct {
	sync.RWMutex
	State
	// contains filtered or unexported fields
}

func NewStateUpdater

func NewStateUpdater(st State) *StateUpdater

func (*StateUpdater) AddOperation

func (stu *StateUpdater) AddOperation(op valuehash.Hash) error

func (*StateUpdater) GetState

func (stu *StateUpdater) GetState() State

func (*StateUpdater) Merge

func (stu *StateUpdater) Merge(source State) error

func (*StateUpdater) Operations

func (stu *StateUpdater) Operations() []valuehash.Hash

func (*StateUpdater) Reset

func (stu *StateUpdater) Reset() error

func (*StateUpdater) SetHash

func (stu *StateUpdater) SetHash(h valuehash.Hash) error

func (*StateUpdater) SetHeight

func (stu *StateUpdater) SetHeight(h base.Height) *StateUpdater

func (*StateUpdater) SetValue

func (stu *StateUpdater) SetValue(value Value) error

type StateV0

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

func NewStateV0

func NewStateV0(key string, value Value, height base.Height) (StateV0, error)

func (StateV0) BSONM

func (st StateV0) BSONM() bson.M

func (StateV0) Clear

func (st StateV0) Clear() State

func (StateV0) GenerateHash

func (st StateV0) GenerateHash() valuehash.Hash

func (StateV0) Hash

func (st StateV0) Hash() valuehash.Hash

func (StateV0) Height

func (st StateV0) Height() base.Height

func (StateV0) Hint

func (StateV0) Hint() hint.Hint

func (StateV0) IsValid

func (st StateV0) IsValid([]byte) error

func (StateV0) Key

func (st StateV0) Key() string

func (StateV0) MarshalBSON

func (st StateV0) MarshalBSON() ([]byte, error)

func (StateV0) MarshalJSON

func (st StateV0) MarshalJSON() ([]byte, error)

func (StateV0) Merge

func (st StateV0) Merge(source State) (State, error)

func (StateV0) Operations

func (st StateV0) Operations() []valuehash.Hash

func (StateV0) PackerJSON

func (st StateV0) PackerJSON() StateV0PackerJSON

func (StateV0) PreviousHeight

func (st StateV0) PreviousHeight() base.Height

func (StateV0) SetHash

func (st StateV0) SetHash(h valuehash.Hash) (State, error)

func (StateV0) SetHeight

func (st StateV0) SetHeight(h base.Height) State

func (StateV0) SetOperation

func (st StateV0) SetOperation(ops []valuehash.Hash) State

func (StateV0) SetPreviousHeight

func (st StateV0) SetPreviousHeight(h base.Height) (State, error)

func (StateV0) SetValue

func (st StateV0) SetValue(value Value) (State, error)

func (*StateV0) UnpackBSON

func (st *StateV0) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*StateV0) UnpackJSON

func (st *StateV0) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

func (StateV0) Value

func (st StateV0) Value() Value

type StateV0PackerJSON

type StateV0PackerJSON struct {
	jsonenc.HintedHead
	H   valuehash.Hash   `json:"hash"`
	K   string           `json:"key"`
	V   Value            `json:"value"`
	PH  base.Height      `json:"previous_height"`
	HT  base.Height      `json:"height"`
	OPS []valuehash.Hash `json:"operations"`
}

type StateV0UnpackerBSON

type StateV0UnpackerBSON struct {
	H   valuehash.Bytes   `bson:"hash"`
	K   string            `bson:"key"`
	V   bson.Raw          `bson:"value"`
	PH  base.Height       `bson:"previous_height"`
	HT  base.Height       `bson:"height"`
	OPS []valuehash.Bytes `bson:"operations"`
}

type StateV0UnpackerJSON

type StateV0UnpackerJSON struct {
	H   valuehash.Bytes   `json:"hash"`
	K   string            `json:"key"`
	V   json.RawMessage   `json:"value"`
	PH  base.Height       `json:"previous_height"`
	HT  base.Height       `json:"height"`
	OPS []valuehash.Bytes `json:"operations"`
}

type StringValue

type StringValue struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewStringValue

func NewStringValue(v interface{}) (StringValue, error)

func (StringValue) Equal

func (sv StringValue) Equal(v Value) bool

func (StringValue) Hash

func (sv StringValue) Hash() valuehash.Hash

func (StringValue) Interface

func (sv StringValue) Interface() interface{}

func (StringValue) IsValid

func (sv StringValue) IsValid([]byte) error

func (StringValue) MarshalBSON

func (sv StringValue) MarshalBSON() ([]byte, error)

func (StringValue) MarshalJSON

func (sv StringValue) MarshalJSON() ([]byte, error)

func (StringValue) Set

func (sv StringValue) Set(v interface{}) (Value, error)

func (*StringValue) UnpackBSON

func (sv *StringValue) UnpackBSON(b []byte, enc *bsonenc.Encoder) error

func (*StringValue) UnpackJSON

func (sv *StringValue) UnpackJSON(b []byte, enc *jsonenc.Encoder) error

type StringValueUnpackerBSON

type StringValueUnpackerBSON struct {
	H valuehash.Bytes `bson:"hash"`
	V string          `bson:"value"`
}

type Value

type Value interface {
	hint.Hinter
	valuehash.Hasher
	isvalid.IsValider
	Equal(Value) bool
	Interface() interface{}
	Set(interface{}) (Value, error)
}

Jump to

Keyboard shortcuts

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