-
Notifications
You must be signed in to change notification settings - Fork 4
/
schema.go
48 lines (43 loc) · 998 Bytes
/
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
package hamt
import (
_ "embed"
"fmt"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
"github.com/multiformats/go-multicodec"
)
var (
//go:embed schema.ipldsch
schemaBytes []byte
HashMapNodePrototype schema.TypedPrototype
HashMapRootPrototype schema.TypedPrototype
)
type (
HashMapRoot struct {
HashAlg multicodec.Code
BucketSize int
Hamt HashMapNode
}
HashMapNode struct {
Map []byte
Data []Element
}
Element struct {
HashMapNode *ipld.Link
Bucket *Bucket
}
Bucket []BucketEntry
BucketEntry struct {
Key []byte
Value ipld.Node
}
)
func init() {
ts, err := ipld.LoadSchemaBytes(schemaBytes)
if err != nil {
panic(fmt.Errorf("failed to load schema: %w", err))
}
HashMapRootPrototype = bindnode.Prototype((*HashMapRoot)(nil), ts.TypeByName("HashMapRoot"))
HashMapNodePrototype = bindnode.Prototype((*HashMapNode)(nil), ts.TypeByName("HashMapNode"))
}