Documentation ¶
Index ¶
- Variables
- func CompareHash(u, v [32]byte) int
- func CompareTxid(u, v *url.TxID) int
- func CompareUint(u, v uint64) int
- func CompareUrl(u, v *url.URL) int
- func MapKeyBytes(v []byte) [32]byte
- func MapKeyUrl(v *url.URL) [32]byte
- 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 ChainHead
- type Counted
- type Key
- type KvStore
- type List
- type Record
- type Set
- type Store
- type TerminalRecord
- type Value
- type ValueMarshaller
- type ValueReader
- type ValueUnmarshaller
- type ValueWriter
- type WalkFunc
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.MarshalBytes), unmarshal: encoding.UnmarshalBytes, }
BytesWrapper defines un/marshalling functions for byte slice fields.
var ErrNotEnoughData = errors.BadRequest.With("not enough data")
var ErrOverflow = errors.BadRequest.With("overflow")
var HashWrapper = &wrapperFuncs[[32]byte]{ copy: copyValue[[32]byte], marshal: oldMarshalPtr(encoding.MarshalHash), unmarshal: encoding.UnmarshalHash, }
HashWrapper defines un/marshalling functions for hash fields.
var StringWrapper = &wrapperFuncs[string]{ copy: copyValue[string], marshal: oldMarshal(encoding.MarshalString), unmarshal: encoding.UnmarshalString, }
StringWrapper defines un/marshalling functions for string fields.
var TxidWrapper = &wrapperFuncs[*url.TxID]{ copy: copyValue[*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.MarshalUint), unmarshal: encoding.UnmarshalUint, }
UintWrapper defines un/marshalling functions for uint fields.
var UrlWrapper = &wrapperFuncs[*url.URL]{ copy: copyValue[*url.URL], marshal: marshalAsString[*url.URL], unmarshal: unmarshalFromString(url.Parse), }
UrlWrapper defines un/marshalling functions for url fields.
Functions ¶
func CompareHash ¶
func CompareTxid ¶
func CompareUint ¶ added in v1.1.0
func CompareUrl ¶
func MapKeyBytes ¶
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 ChainHead ¶ added in v1.1.0
type ChainHead struct { Count int64 `json:"count,omitempty" form:"count" query:"count" validate:"required"` Pending [][]byte `json:"pending,omitempty" form:"pending" query:"pending" validate:"required"` HashList [][]byte `json:"hashList,omitempty" form:"hashList" query:"hashList" validate:"required"` }
func (*ChainHead) CopyAsInterface ¶ added in v1.1.0
func (v *ChainHead) CopyAsInterface() interface{}
func (*ChainHead) MarshalJSON ¶ added in v1.1.0
func (*ChainHead) UnmarshalJSON ¶ added in v1.1.0
type Counted ¶
type Counted[T any] interface { Record Get(int) (T, error) Put(T) error Count() (int, error) GetAll() ([]T, error) Last() (int, T, error) Overwrite([]T) error }
Counted records an insertion-ordered list of values as separate records plus a record for the count.
type KvStore ¶
type KvStore struct {
Store storage.KeyValueTxn
}
KvStore is a Store that reads/writes from/to a key-value store.
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 // WalkChanges walks the record and calls the function for any changed // values. WalkChanges(fn WalkFunc) error }
A Record is a component of a data model.
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 TerminalRecord ¶ added in v1.1.0
type TerminalRecord interface { Record ValueReader Key() Key }
type ValueMarshaller ¶
type ValueReader ¶
type ValueReader interface { // GetValue returns the value. GetValue() (value encoding.BinaryValue, version int, err 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, put bool) error }
A ValueWriter holds a writable value.
type WalkFunc ¶ added in v1.1.0
type WalkFunc func(TerminalRecord) error