Documentation ¶
Index ¶
- Variables
- func CompareHash(u, v [32]byte) int
- func CompareTxid(u, v *url.TxID) int
- func CompareUrl(u, v *url.URL) int
- func ParseString(s string) (string, error)
- func Struct[T any, PT ptrBinaryValue[T]]() encodableValue[PT]
- func Union[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) encodableValue[T]
- func UnionFactory[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) func() encodableValue[T]
- func Wrapped[T any](funcs *wrapperFuncs[T]) encodableValue[T]
- func WrappedFactory[T any](funcs *wrapperFuncs[T]) func() encodableValue[T]
- type Counted
- func (c *Counted[T]) Commit() error
- func (c *Counted[T]) Count() (int, error)
- func (c *Counted[T]) Get(i int) (T, error)
- func (c *Counted[T]) GetAll() ([]T, error)
- func (c *Counted[T]) IsDirty() bool
- func (c *Counted[T]) Last() (int, T, error)
- func (c *Counted[T]) Put(v T) error
- func (c *Counted[T]) Resolve(key Key) (Record, Key, error)
- type Key
- type KvStore
- type List
- type Record
- type RecordPtr
- type Set
- type Store
- type Value
- func (v *Value[T]) Commit() error
- func (v *Value[T]) Get() (u T, err error)
- func (v *Value[T]) GetAs(target interface{}) error
- func (v *Value[T]) GetValue() (encoding.BinaryValue, error)
- func (v *Value[T]) IsDirty() bool
- func (v *Value[T]) Key(i int) interface{}
- func (v *Value[T]) LoadBytes(data []byte) error
- func (v *Value[T]) LoadValue(value ValueReader, put bool) error
- func (v *Value[T]) Put(u T) error
- func (v *Value[T]) Resolve(key Key) (Record, Key, error)
- type ValueMarshaller
- type ValueReader
- type ValueUnmarshaller
- type ValueWriter
Constants ¶
This section is empty.
Variables ¶
var BytesWrapper = &wrapperFuncs[[]byte]{ copy: func(v []byte) []byte { u := make([]byte, len(v)); copy(u, v); return u }, marshal: oldMarshal(encoding.BytesMarshalBinary), unmarshal: encoding.BytesUnmarshalBinary, }
BytesWrapper defines un/marshalling functions for byte slice fields.
var HashWrapper = &wrapperFuncs[[32]byte]{ copy: copyValue[[32]byte], marshal: oldMarshalPtr(encoding.ChainMarshalBinary), unmarshal: encoding.ChainUnmarshalBinary, }
HashWrapper defines un/marshalling functions for hash fields.
var StringWrapper = &wrapperFuncs[string]{ copy: copyValue[string], marshal: oldMarshal(encoding.StringMarshalBinary), unmarshal: encoding.StringUnmarshalBinary, }
StringWrapper defines un/marshalling functions for string fields.
var TxidWrapper = &wrapperFuncs[*url.TxID]{ copy: copyRef[*url.TxID], marshal: marshalAsString[*url.TxID], unmarshal: unmarshalFromString(url.ParseTxID), }
TxidWrapper defines un/marshalling functions for txid fields.
var UintWrapper = &wrapperFuncs[uint64]{ copy: copyValue[uint64], marshal: oldMarshal(encoding.UvarintMarshalBinary), unmarshal: encoding.UvarintUnmarshalBinary, }
UintWrapper defines un/marshalling functions for uint fields.
var UrlWrapper = &wrapperFuncs[*url.URL]{ copy: copyRef[*url.URL], marshal: marshalAsString[*url.URL], unmarshal: unmarshalFromString(url.Parse), }
UrlWrapper defines un/marshalling functions for url fields.
Functions ¶
func CompareHash ¶
func CompareTxid ¶
func CompareUrl ¶
func ParseString ¶
func Struct ¶
func Struct[T any, PT ptrBinaryValue[T]]() encodableValue[PT]
Struct returns an encodable value for the given encodable struct-type.
func Union ¶
func Union[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) encodableValue[T]
Union returns an encodable value for the given encodable union type.
func UnionFactory ¶
func UnionFactory[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) func() encodableValue[T]
UnionFactory curries Union.
func Wrapped ¶
func Wrapped[T any](funcs *wrapperFuncs[T]) encodableValue[T]
Wrapped returns an encodable value for the given type using the given wrapper functions.
func WrappedFactory ¶
func WrappedFactory[T any](funcs *wrapperFuncs[T]) func() encodableValue[T]
WrappedFactory curries Wrapped.
Types ¶
type Counted ¶
type Counted[T any] struct { // contains filtered or unexported fields }
Counted records an insertion-ordered list of values as separate records plus a record for the count.
func NewCounted ¶
func NewCounted[T any](logger log.Logger, store Store, key Key, namefmt string, new func() encodableValue[T]) *Counted[T]
NewCounted returns a new Counted using the given encodable value type.
type Key ¶
type Key []interface{}
A Key is the key for a record.
func (Key) MarshalJSON ¶
MarshalJSON is implemented so keys are formatted nicely by zerolog.
type KvStore ¶
type KvStore struct {
Store storage.KeyValueTxn
}
KvStore is a Store that reads/writes from/to a key-value store.
type List ¶
List records an unordered list of values as a single record.
type Record ¶
type Record interface { // Resolve resolves the record or a child record. Resolve(key Key) (Record, Key, error) // IsDirty returns true if the record has been modified. IsDirty() bool // Commit writes any modifications to the store. Commit() error }
A Record is a component of a data model.
type Set ¶
Set records an ordered list of values as a single record.
func NewSet ¶
func NewSet[T any](logger log.Logger, store Store, key Key, namefmt string, encoder encodableValue[T], cmp func(u, v T) int) *Set[T]
NewSet returns a new Set using the given encoder and comparison.
type Store ¶
type Store interface { // GetValue loads the value from the underlying store and writes it. Byte // stores call LoadBytes(data) and value stores call LoadValue(v, false). GetValue(key Key, value ValueWriter) error // PutValue gets the value from the reader and stores it. A byte store // marshals the value and stores the bytes. A value store finds the // appropriate value and calls LoadValue(v, true). PutValue(key Key, value ValueReader) error }
A Store loads and stores values.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
Value records a value.
func NewValue ¶
func NewValue[T any](logger log.Logger, store Store, key Key, namefmt string, allowMissing bool, value encodableValue[T]) *Value[T]
NewValue returns a new Value using the given encodable value.
func (*Value[T]) GetAs ¶
GetAs loads the value, coerces it to the target type, and assigns it to the target. The target must be a non-nil pointer to T.
func (*Value[T]) GetValue ¶
func (v *Value[T]) GetValue() (encoding.BinaryValue, error)
GetValue loads the value.
type ValueMarshaller ¶
type ValueReader ¶
type ValueReader interface { // GetValue returns the value. GetValue() (encoding.BinaryValue, error) }
A ValueReader holds a readable value.
type ValueUnmarshaller ¶
type ValueWriter ¶
type ValueWriter interface { // LoadValue stores the value of the reader into the receiver. LoadValue(value ValueReader, put bool) error // LoadBytes unmarshals a value from bytes into the receiver. LoadBytes(data []byte) error }
A ValueWriter holds a writable value.