forked from glycerine/greenpack
/
templateZid.go
101 lines (94 loc) · 2.95 KB
/
templateZid.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
package gen
// -fast zid-using versions of decode/unmarshal
// We treat empty fields as if they were Nil on the wire.
var templateDecodeMsgZid = `
// -- templateDecodeMsgZid starts here--
var totalEncodedFields_ uint32
totalEncodedFields_, err = dc.ReadMapHeader()
if err != nil {
return
}
encodedFieldsLeft_ := totalEncodedFields_
missingFieldsLeft_ := maxFields_ - totalEncodedFields_
var nextMiss_ int = -1
var found_ [maxFields_]bool
var curField_ int
doneWithStruct_:
// First fill all the encoded fields, then
// treat the remaining, missing fields, as Nil.
for encodedFieldsLeft_ > 0 || missingFieldsLeft_ > 0 {
//fmt.Printf("encodedFieldsLeft: %%v, missingFieldsLeft: %%v, found: '%%v', fields: '%%#v'\n", encodedFieldsLeft_, missingFieldsLeft_, msgp.ShowFound(found_[:]), decodeMsgFieldOrder_)
if encodedFieldsLeft_ > 0 {
encodedFieldsLeft_--
curField_, err = dc.ReadInt()
if err != nil {
return
}
} else {
//missing fields need handling
if nextMiss_ < 0 {
// tell the reader to only give us Nils
// until further notice.
dc.PushAlwaysNil()
nextMiss_ = 0
}
for nextMiss_ < maxFields_ && (found_[nextMiss_] || decodeMsgFieldSkip_[nextMiss_]) {
nextMiss_++
}
if nextMiss_ == maxFields_ {
// filled all the empty fields!
break doneWithStruct_
}
missingFieldsLeft_--
curField_ = nextMiss_
}
//fmt.Printf("switching on curField: '%%v'\n", curField_)
switch curField_ {
// -- templateDecodeMsgZid ends here --
`
var templateUnmarshalMsgZid = `
// -- templateUnmarshalMsgZid starts here--
var totalEncodedFields_ uint32
if !nbs.AlwaysNil {
totalEncodedFields_, bts, err = nbs.ReadMapHeaderBytes(bts)
if err != nil {
return
}
}
encodedFieldsLeft_ := totalEncodedFields_
missingFieldsLeft_ := maxFields_ - totalEncodedFields_
var nextMiss_ int = -1
var found_ [maxFields_]bool
var curField_ int
doneWithStruct_:
// First fill all the encoded fields, then
// treat the remaining, missing fields, as Nil.
for encodedFieldsLeft_ > 0 || missingFieldsLeft_ > 0 {
//fmt.Printf("encodedFieldsLeft: %%v, missingFieldsLeft: %%v, found: '%%v', fields: '%%#v'\n", encodedFieldsLeft_, missingFieldsLeft_, msgp.ShowFound(found_[:]), unmarshalMsgFieldOrder_)
if encodedFieldsLeft_ > 0 {
encodedFieldsLeft_--
curField_, bts, err = nbs.ReadIntBytes(bts)
if err != nil {
return
}
} else {
//missing fields need handling
if nextMiss_ < 0 {
// set bts to contain just mnil (0xc0)
bts = nbs.PushAlwaysNil(bts)
nextMiss_ = 0
}
for nextMiss_ < maxFields_ && (found_[nextMiss_] || unmarshalMsgFieldSkip_[nextMiss_]) {
nextMiss_++
}
if nextMiss_ == maxFields_ {
// filled all the empty fields!
break doneWithStruct_
}
missingFieldsLeft_--
curField_ = nextMiss_
}
//fmt.Printf("switching on curField: '%%v'\n", curField_)
switch curField_ {
// -- templateUnmarshalMsgZid ends here --
`