/
bool.go
144 lines (129 loc) · 3.75 KB
/
bool.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package basicnode
import (
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/node/mixins"
)
var (
_ ipld.Node = plainBool(false)
_ ipld.NodePrototype = Prototype__Bool{}
_ ipld.NodeBuilder = &plainBool__Builder{}
_ ipld.NodeAssembler = &plainBool__Assembler{}
)
func NewBool(value bool) ipld.Node {
v := plainBool(value)
return &v
}
// plainBool is a simple boxed boolean that complies with ipld.Node.
type plainBool bool
// -- Node interface methods -->
func (plainBool) Kind() ipld.Kind {
return ipld.Kind_Bool
}
func (plainBool) LookupByString(string) (ipld.Node, error) {
return mixins.Bool{TypeName: "bool"}.LookupByString("")
}
func (plainBool) LookupByNode(key ipld.Node) (ipld.Node, error) {
return mixins.Bool{TypeName: "bool"}.LookupByNode(nil)
}
func (plainBool) LookupByIndex(idx int64) (ipld.Node, error) {
return mixins.Bool{TypeName: "bool"}.LookupByIndex(0)
}
func (plainBool) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
return mixins.Bool{TypeName: "bool"}.LookupBySegment(seg)
}
func (plainBool) MapIterator() ipld.MapIterator {
return nil
}
func (plainBool) ListIterator() ipld.ListIterator {
return nil
}
func (plainBool) Length() int64 {
return -1
}
func (plainBool) IsAbsent() bool {
return false
}
func (plainBool) IsNull() bool {
return false
}
func (n plainBool) AsBool() (bool, error) {
return bool(n), nil
}
func (plainBool) AsInt() (int64, error) {
return mixins.Bool{TypeName: "bool"}.AsInt()
}
func (plainBool) AsFloat() (float64, error) {
return mixins.Bool{TypeName: "bool"}.AsFloat()
}
func (plainBool) AsString() (string, error) {
return mixins.Bool{TypeName: "bool"}.AsString()
}
func (plainBool) AsBytes() ([]byte, error) {
return mixins.Bool{TypeName: "bool"}.AsBytes()
}
func (plainBool) AsLink() (ipld.Link, error) {
return mixins.Bool{TypeName: "bool"}.AsLink()
}
func (plainBool) Prototype() ipld.NodePrototype {
return Prototype__Bool{}
}
// -- NodePrototype -->
type Prototype__Bool struct{}
func (Prototype__Bool) NewBuilder() ipld.NodeBuilder {
var w plainBool
return &plainBool__Builder{plainBool__Assembler{w: &w}}
}
// -- NodeBuilder -->
type plainBool__Builder struct {
plainBool__Assembler
}
func (nb *plainBool__Builder) Build() ipld.Node {
return nb.w
}
func (nb *plainBool__Builder) Reset() {
var w plainBool
*nb = plainBool__Builder{plainBool__Assembler{w: &w}}
}
// -- NodeAssembler -->
type plainBool__Assembler struct {
w *plainBool
}
func (plainBool__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) {
return mixins.BoolAssembler{TypeName: "bool"}.BeginMap(0)
}
func (plainBool__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) {
return mixins.BoolAssembler{TypeName: "bool"}.BeginList(0)
}
func (plainBool__Assembler) AssignNull() error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignNull()
}
func (na *plainBool__Assembler) AssignBool(v bool) error {
*na.w = plainBool(v)
return nil
}
func (plainBool__Assembler) AssignInt(int64) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignInt(0)
}
func (plainBool__Assembler) AssignFloat(float64) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignFloat(0)
}
func (plainBool__Assembler) AssignString(string) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignString("")
}
func (plainBool__Assembler) AssignBytes([]byte) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignBytes(nil)
}
func (plainBool__Assembler) AssignLink(ipld.Link) error {
return mixins.BoolAssembler{TypeName: "bool"}.AssignLink(nil)
}
func (na *plainBool__Assembler) AssignNode(v ipld.Node) error {
if v2, err := v.AsBool(); err != nil {
return err
} else {
*na.w = plainBool(v2)
return nil
}
}
func (plainBool__Assembler) Prototype() ipld.NodePrototype {
return Prototype__Bool{}
}