genKindStringReprString.go 3.05 KB
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1
package gengo
Eric Myhre's avatar
Eric Myhre committed
2 3 4 5 6 7

import (
	"io"
)

func (gk generateKindString) EmitNodeType(w io.Writer) {
Eric Myhre's avatar
Eric Myhre committed
8
	doTemplate(`
9
		var _ ipld.Node = {{ .Type.Name }}{}
Eric Myhre's avatar
Eric Myhre committed
10

11
		type {{ .Type.Name }} struct{ x string }
12

Eric Myhre's avatar
Eric Myhre committed
13
	`, w, gk)
Eric Myhre's avatar
Eric Myhre committed
14 15 16
}

func (gk generateKindString) EmitNodeMethodReprKind(w io.Writer) {
Eric Myhre's avatar
Eric Myhre committed
17
	doTemplate(`
18
		func ({{ .Type.Name }}) ReprKind() ipld.ReprKind {
Eric Myhre's avatar
Eric Myhre committed
19 20
			return ipld.ReprKind_String
		}
Eric Myhre's avatar
Eric Myhre committed
21
	`, w, gk)
Eric Myhre's avatar
Eric Myhre committed
22
}
23 24 25 26

// FUTURE: consider breaking the nodebuilder methods down like the node methods are; a lot of the "nope" variants could be reused.
func (gk generateKindString) EmitNodeMethodNodeBuilder(w io.Writer) {
	doTemplate(`
27 28
		func ({{ .Type.Name }}) NodeBuilder() ipld.NodeBuilder {
			return {{ .Type.Name }}__NodeBuilder{}
29 30
		}

31
		type {{ .Type.Name }}__NodeBuilder struct{}
32

33
		func (nb {{ .Type.Name }}__NodeBuilder) CreateMap() (ipld.MapBuilder, error) {
34 35
			return nil, ipld.ErrWrongKind{MethodName: "CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
		}
36
		func (nb {{ .Type.Name }}__NodeBuilder) AmendMap() (ipld.MapBuilder, error) {
37 38
			return nil, ipld.ErrWrongKind{MethodName: "AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
		}
39
		func (nb {{ .Type.Name }}__NodeBuilder) CreateList() (ipld.ListBuilder, error) {
40 41
			return nil, ipld.ErrWrongKind{MethodName: "CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
		}
42
		func (nb {{ .Type.Name }}__NodeBuilder) AmendList() (ipld.ListBuilder, error) {
43 44
			return nil, ipld.ErrWrongKind{MethodName: "AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
		}
45
		func (nb {{ .Type.Name }}__NodeBuilder) CreateNull() (ipld.Node, error) {
46 47
			return nil, ipld.ErrWrongKind{MethodName: "CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_String}
		}
48
		func (nb {{ .Type.Name }}__NodeBuilder) CreateBool(v bool) (ipld.Node, error) {
49 50
			return nil, ipld.ErrWrongKind{MethodName: "CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_String}
		}
51
		func (nb {{ .Type.Name }}__NodeBuilder) CreateInt(v int) (ipld.Node, error) {
52 53
			return nil, ipld.ErrWrongKind{MethodName: "CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_String}
		}
54
		func (nb {{ .Type.Name }}__NodeBuilder) CreateFloat(v float64) (ipld.Node, error) {
55 56
			return nil, ipld.ErrWrongKind{MethodName: "CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_String}
		}
57 58
		func (nb {{ .Type.Name }}__NodeBuilder) CreateString(v string) (ipld.Node, error) {
			return {{ .Type.Name }}{v}, nil
59
		}
60
		func (nb {{ .Type.Name }}__NodeBuilder) CreateBytes(v []byte) (ipld.Node, error) {
61 62
			return nil, ipld.ErrWrongKind{MethodName: "CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_String}
		}
63
		func (nb {{ .Type.Name }}__NodeBuilder) CreateLink(v ipld.Link) (ipld.Node, error) {
64 65 66 67
			return nil, ipld.ErrWrongKind{MethodName: "CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_String}
		}
	`, w, gk)
}