-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
87 lines (73 loc) · 2.02 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
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 := "data"
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnBytes("Bytes"))
ts.Accumulate(schema.SpawnList("BlockSizes", "Int", false))
/*
type UnixTime struct {
seconds Int
fractionalNanoseconds Int
}
*/
ts.Accumulate(schema.SpawnStruct("UnixTime",
[]schema.StructField{
schema.SpawnStructField("Seconds", "Int", false, false),
schema.SpawnStructField("FractionalNanoseconds", "Int", true, false),
},
schema.SpawnStructRepresentationMap(nil),
))
/*
type UnixFSData struct {
dataType Int
data optional Bytes
filesize optional Int;
blocksizes [Int]
hashType optional Int
fanout optional Int
mode optional Int
mtime optional UnixTime
} representation map
*/
ts.Accumulate(schema.SpawnStruct("UnixFSData",
[]schema.StructField{
schema.SpawnStructField("DataType", "Int", false, false),
schema.SpawnStructField("Data", "Bytes", true, false),
schema.SpawnStructField("FileSize", "Int", true, false),
schema.SpawnStructField("BlockSizes", "BlockSizes", false, false),
schema.SpawnStructField("HashType", "Int", true, false),
schema.SpawnStructField("Fanout", "Int", true, false),
schema.SpawnStructField("Mode", "Int", true, false),
schema.SpawnStructField("Mtime", "UnixTime", true, false),
},
schema.SpawnStructRepresentationMap(nil),
))
/*
type UnixFSMetadata struct {
mimeType optional String
} representation map
*/
ts.Accumulate(schema.SpawnStruct("UnixFSMetadata",
[]schema.StructField{
schema.SpawnStructField("MimeType", "String", 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)
}