-
Notifications
You must be signed in to change notification settings - Fork 1
/
NestedArray_json.go
79 lines (77 loc) · 2.04 KB
/
NestedArray_json.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
package value_tests
import jsoniter "github.com/json-iterator/tinygo"
type NestedArray_json struct {
}
func (json NestedArray_json) Type() interface{} {
var val NestedArray
return val
}
func (json NestedArray_json) Unmarshal(iter *jsoniter.Iterator, out interface{}) {
NestedArray_json_unmarshal(iter, out.(*NestedArray))
}
func (json NestedArray_json) Marshal(stream *jsoniter.Stream, val interface{}) {
NestedArray_json_marshal(stream, val.(NestedArray))
}
func NestedArray_json_unmarshal(iter *jsoniter.Iterator, out *NestedArray) {
i := 0
val := *out
more := iter.ReadArrayHead()
for more {
if i == len(val) {
val = append(val, make(NestedArray, 4)...)
}
NestedArray_array1_json_unmarshal(iter, &val[i])
i++
more = iter.ReadArrayMore()
}
if i == 0 {
*out = NestedArray{}
} else {
*out = val[:i]
}
}
func NestedArray_json_unmarshal_field(iter *jsoniter.Iterator, field string, out *NestedArray) bool {
if field == "NestedArray" {
NestedArray_json_unmarshal(iter, out)
return true
}
return false
}
func NestedArray_array1_json_unmarshal (iter *jsoniter.Iterator, out *[2]float64) {
i := 0
val := *out
more := iter.ReadArrayHead()
for more {
if i < 2 {
iter.ReadFloat64(&val[i])
} else {
iter.Skip()
}
i++
more = iter.ReadArrayMore()
}
}
func NestedArray_json_marshal(stream *jsoniter.Stream, val NestedArray) {
if len(val) == 0 {
stream.WriteEmptyArray()
} else {
stream.WriteArrayHead()
for i, elem := range val {
if i != 0 { stream.WriteMore() }
NestedArray_array2_json_marshal(stream, elem)
}
stream.WriteArrayTail()
}
}
func NestedArray_json_marshal_field(stream *jsoniter.Stream, val NestedArray) {
stream.WriteObjectField("NestedArray")
NestedArray_json_marshal(stream, val)
stream.WriteMore()
}
func NestedArray_array2_json_marshal (stream *jsoniter.Stream, val [2]float64) {
stream.WriteArrayHead()
stream.WriteFloat64(val[0])
stream.WriteMore()
stream.WriteFloat64(val[1])
stream.WriteArrayTail()
}