mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-01 03:29:12 -05:00
Add ValueStore interface.
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
package tree
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/dolthub/dolt/go/store/val"
|
||||
"sync"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/prolly/message"
|
||||
@@ -32,6 +34,8 @@ const (
|
||||
|
||||
// NodeStore reads and writes prolly tree Nodes.
|
||||
type NodeStore interface {
|
||||
val.ValueStore
|
||||
|
||||
// Read reads a prolly tree Node from the store.
|
||||
Read(ctx context.Context, ref hash.Hash) (Node, error)
|
||||
|
||||
@@ -204,3 +208,14 @@ func (ns nodeStore) Format() *types.NomsBinFormat {
|
||||
func (ns nodeStore) PurgeCaches() {
|
||||
ns.cache.purge()
|
||||
}
|
||||
|
||||
func (ns nodeStore) ReadBytes(ctx context.Context, h hash.Hash) ([]byte, error) {
|
||||
return NewByteArray(h, ns).ToBytes(ctx)
|
||||
}
|
||||
|
||||
func (ns nodeStore) WriteBytes(ctx context.Context, b []byte) (hash.Hash, error) {
|
||||
_, h, err := SerializeBytesToAddr(ctx, ns, bytes.NewReader(b), len(b))
|
||||
return h, err
|
||||
}
|
||||
|
||||
var _ val.ValueStore = nodeStore{}
|
||||
|
||||
@@ -272,6 +272,14 @@ type nodeStoreValidator struct {
|
||||
bbp *sync.Pool
|
||||
}
|
||||
|
||||
func (v nodeStoreValidator) ReadBytes(ctx context.Context, h hash.Hash) ([]byte, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (v nodeStoreValidator) WriteBytes(ctx context.Context, val []byte) (hash.Hash, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (v nodeStoreValidator) Read(ctx context.Context, ref hash.Hash) (Node, error) {
|
||||
nd, err := v.ns.Read(ctx, ref)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2025 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package val
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
|
||||
type ValueStore interface {
|
||||
ReadBytes(ctx context.Context, h hash.Hash) ([]byte, error)
|
||||
WriteBytes(ctx context.Context, val []byte) (hash.Hash, error)
|
||||
}
|
||||
Reference in New Issue
Block a user