gen.go 1.43 KB
Newer Older
1
//go:build ignore
Rod Vagg's avatar
Rod Vagg committed
2 3
// +build ignore

Rod Vagg's avatar
Rod Vagg committed
4 5
package main

6
// based on https://gitlab.dms3.io/ld/go-ld-prime-proto/blob/master/gen/main.go
Rod Vagg's avatar
Rod Vagg committed
7 8

import (
Rod Vagg's avatar
Rod Vagg committed
9 10
	"fmt"
	"os"
Rod Vagg's avatar
Rod Vagg committed
11

12 13
	"gitlab.dms3.io/ld/go-ld-prime/schema"
	gengo "gitlab.dms3.io/ld/go-ld-prime/schema/gen/go"
Rod Vagg's avatar
Rod Vagg committed
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
)

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),
	))

Rod Vagg's avatar
Rod Vagg committed
61 62 63 64 65 66
	if errs := ts.ValidateGraph(); errs != nil {
		for _, err := range errs {
			fmt.Printf("- %s\n", err)
		}
		os.Exit(1)
	}
Rod Vagg's avatar
Rod Vagg committed
67

Rod Vagg's avatar
Rod Vagg committed
68
	gengo.Generate(".", pkgName, ts, adjCfg)
Rod Vagg's avatar
Rod Vagg committed
69
}