-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
50 lines (41 loc) · 1.24 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cas
import (
"bytes"
"context"
"io"
"github.com/hemantthanna/cas/schema"
"github.com/hemantthanna/cas/storage"
"github.com/hemantthanna/cas/types"
)
var (
typeDirEnt = schema.MustTypeOf(&schema.DirEntry{})
typeSizedRef = schema.MustTypeOf(&types.SizedRef{})
)
type SchemaIterator = storage.SchemaIterator
func (s *Storage) StoreSchema(ctx context.Context, o schema.Object) (SizedRef, error) {
buf := new(bytes.Buffer)
if err := schema.Encode(buf, o); err != nil {
return SizedRef{}, err
}
exp := types.BytesRef(buf.Bytes())
return s.StoreBlob(ctx, buf, &StoreConfig{
Expect: SizedRef{Ref: exp, Size: uint64(buf.Len())},
})
}
func (s *Storage) FetchSchema(ctx context.Context, ref types.Ref) (io.ReadCloser, uint64, error) {
return s.index.FetchSchema(ctx, ref)
}
func (s *Storage) DecodeSchema(ctx context.Context, ref types.Ref) (schema.Object, error) {
rc, _, err := s.index.FetchSchema(ctx, ref)
if err != nil {
return nil, err
}
defer rc.Close()
return schema.Decode(rc)
}
func (s *Storage) IterateSchema(ctx context.Context, typs ...string) SchemaIterator {
return s.index.IterateSchema(ctx, typs...)
}
func (s *Storage) ReindexSchema(ctx context.Context, force bool) error {
return s.index.ReindexSchema(ctx, force)
}