Initial import

This commit is contained in:
2025-10-10 10:05:13 +02:00
parent 3effc1597b
commit b96b6e7f8f
164 changed files with 5473 additions and 0 deletions

61
storage/kv.go Normal file
View File

@@ -0,0 +1,61 @@
package storage
import (
"encoding/json"
"git.maze.io/maze/conduit/storage/codec"
)
// KV implements a key-value store.
type KV interface {
// Has checks if the key is present.
Has(key string) bool
// Get a value by key.
Get(key string) (value []byte, ok bool)
}
// WritableKV can store key-value items.
type WritableKV interface {
KV
// Close the key-value storage.
Close() error
// DeleteKey removes a key.
Delete(key string) error
// Set a value by key.
Set(key string, value []byte) error
}
type EncodedKV interface {
Has(key string) bool
Get(key string, value any) (ok bool, err error)
}
type EncodedWritableKV interface {
EncodedKV
Close() error
Delete(key string) error
Set(key string, value []byte) error
}
type encodedKV struct {
kv KV
encode func(any) ([]byte, error)
decode func([]byte, any) error
}
func (kv encodedKV) Has(key)
func NewEncodedKV(kv KV, codec codec.Codec) EncodedKV {
return &encodedKV{
kv: kv,
encode: json.Marshal,
decode: json.Unmarshal,
}
}