-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen.go
68 lines (55 loc) · 1.41 KB
/
gen.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build ignore
package main
// based on https://github.com/ipld/go-ipld-prime-proto/blob/master/gen/main.go
import (
"fmt"
"os"
"github.com/ipld/go-ipld-prime/schema"
gengo "github.com/ipld/go-ipld-prime/schema/gen/go"
)
func main() {
ts := schema.TypeSystem{}
ts.Init()
adjCfg := &gengo.AdjunctCfg{}
pkgName := "dagpb"
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnLink("Link"))
ts.Accumulate(schema.SpawnBytes("Bytes"))
/*
type PBLink struct {
Hash Link
Name optional String
Tsize optional Int
}
*/
ts.Accumulate(schema.SpawnStruct("PBLink",
[]schema.StructField{
schema.SpawnStructField("Hash", "Link", false, false),
schema.SpawnStructField("Name", "String", true, false),
schema.SpawnStructField("Tsize", "Int", true, false),
},
schema.SpawnStructRepresentationMap(nil),
))
ts.Accumulate(schema.SpawnList("PBLinks", "PBLink", false))
/*
type PBNode struct {
Links [PBLink]
Data optional Bytes
}
*/
ts.Accumulate(schema.SpawnStruct("PBNode",
[]schema.StructField{
schema.SpawnStructField("Links", "PBLinks", false, false),
schema.SpawnStructField("Data", "Bytes", true, false),
},
schema.SpawnStructRepresentationMap(nil),
))
if errs := ts.ValidateGraph(); errs != nil {
for _, err := range errs {
fmt.Printf("- %s\n", err)
}
os.Exit(1)
}
gengo.Generate(".", pkgName, ts, adjCfg)
}