Created
April 17, 2018 08:02
-
-
Save dholm/a1b8821e1c1b4dfc1caaf67aa4c2c43a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gpbug | |
//go:generate greenpack -io=false -marshal=true -no-structnames-onwire -omit-clue | |
type I1 uint64 | |
type Str string | |
type Struct1 struct { | |
M1 I1 `zid:"0"` | |
M2 Str `zid:"1"` | |
} | |
type Struct2 struct { | |
M1 Struct1 `zid:"0"` | |
M2 []byte `zid:"1"` | |
M3 string `zid:"2"` | |
M4 string `zid:"3"` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- greenpack-bug_gen.go.1 2018-04-17 10:01:50.525620178 +0200 | |
+++ greenpack-bug_gen.go 2018-04-17 10:01:50.545620245 +0200 | |
@@ -278,7 +278,7 @@ | |
return 4 | |
} | |
var fieldsInUse uint32 = 4 | |
- isempty[0] = false | |
+ isempty[0] = false // struct values are never empty | |
if isempty[0] { | |
fieldsInUse-- | |
} | |
@@ -314,10 +314,24 @@ | |
if !empty[0] { | |
// string "M1" | |
o = append(o, 0xa2, 0x4d, 0x31) | |
- o, err = z.M1.MarshalMsg(o) // not is.iface, gen/marshal.go:243 | |
- if err != nil { | |
- return | |
+ | |
+ // honor the omitempty tags | |
+ var empty [2]bool | |
+ fieldsInUse := z.M1.fieldsNotEmpty(empty[:]) | |
+ o = msgp.AppendMapHeader(o, fieldsInUse) | |
+ | |
+ if !empty[0] { | |
+ // string "M1" | |
+ o = append(o, 0xa2, 0x4d, 0x31) | |
+ o = msgp.AppendUint64(o, uint64(z.M1.M1)) | |
+ } | |
+ | |
+ if !empty[1] { | |
+ // string "M2" | |
+ o = append(o, 0xa2, 0x4d, 0x32) | |
+ o = msgp.AppendString(o, string(z.M1.M2)) | |
} | |
+ | |
} | |
if !empty[1] { | |
@@ -408,10 +422,89 @@ | |
case "M1": | |
found6zgensym_1452b2c984fe1b1a_7[0] = true | |
- bts, err = z.M1.UnmarshalMsg(bts) | |
- if err != nil { | |
- return | |
+ const maxFields8zgensym_1452b2c984fe1b1a_9 = 2 | |
+ | |
+ // -- templateUnmarshalMsg starts here-- | |
+ var totalEncodedFields8zgensym_1452b2c984fe1b1a_9 uint32 | |
+ if !nbs.AlwaysNil { | |
+ totalEncodedFields8zgensym_1452b2c984fe1b1a_9, bts, err = nbs.ReadMapHeaderBytes(bts) | |
+ if err != nil { | |
+ return | |
+ } | |
+ } | |
+ encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 := totalEncodedFields8zgensym_1452b2c984fe1b1a_9 | |
+ missingFieldsLeft8zgensym_1452b2c984fe1b1a_9 := maxFields8zgensym_1452b2c984fe1b1a_9 - totalEncodedFields8zgensym_1452b2c984fe1b1a_9 | |
+ | |
+ var nextMiss8zgensym_1452b2c984fe1b1a_9 int32 = -1 | |
+ var found8zgensym_1452b2c984fe1b1a_9 [maxFields8zgensym_1452b2c984fe1b1a_9]bool | |
+ var curField8zgensym_1452b2c984fe1b1a_9 string | |
+ | |
+ doneWithStruct8zgensym_1452b2c984fe1b1a_9: | |
+ // First fill all the encoded fields, then | |
+ // treat the remaining, missing fields, as Nil. | |
+ for encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 || missingFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 { | |
+ //fmt.Printf("encodedFieldsLeft: %v, missingFieldsLeft: %v, found: '%v', fields: '%#v'\n", encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9, missingFieldsLeft8zgensym_1452b2c984fe1b1a_9, msgp.ShowFound(found8zgensym_1452b2c984fe1b1a_9[:]), unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9) | |
+ if encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9 > 0 { | |
+ encodedFieldsLeft8zgensym_1452b2c984fe1b1a_9-- | |
+ field, bts, err = nbs.ReadMapKeyZC(bts) | |
+ if err != nil { | |
+ return | |
+ } | |
+ curField8zgensym_1452b2c984fe1b1a_9 = msgp.UnsafeString(field) | |
+ } else { | |
+ //missing fields need handling | |
+ if nextMiss8zgensym_1452b2c984fe1b1a_9 < 0 { | |
+ // set bts to contain just mnil (0xc0) | |
+ bts = nbs.PushAlwaysNil(bts) | |
+ nextMiss8zgensym_1452b2c984fe1b1a_9 = 0 | |
+ } | |
+ for nextMiss8zgensym_1452b2c984fe1b1a_9 < maxFields8zgensym_1452b2c984fe1b1a_9 && (found8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9] || unmarshalMsgFieldSkip8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9]) { | |
+ nextMiss8zgensym_1452b2c984fe1b1a_9++ | |
+ } | |
+ if nextMiss8zgensym_1452b2c984fe1b1a_9 == maxFields8zgensym_1452b2c984fe1b1a_9 { | |
+ // filled all the empty fields! | |
+ break doneWithStruct8zgensym_1452b2c984fe1b1a_9 | |
+ } | |
+ missingFieldsLeft8zgensym_1452b2c984fe1b1a_9-- | |
+ curField8zgensym_1452b2c984fe1b1a_9 = unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9[nextMiss8zgensym_1452b2c984fe1b1a_9] | |
+ } | |
+ //fmt.Printf("switching on curField: '%v'\n", curField8zgensym_1452b2c984fe1b1a_9) | |
+ switch curField8zgensym_1452b2c984fe1b1a_9 { | |
+ // -- templateUnmarshalMsg ends here -- | |
+ | |
+ case "M1": | |
+ found8zgensym_1452b2c984fe1b1a_9[0] = true | |
+ { | |
+ var zgensym_1452b2c984fe1b1a_10 uint64 | |
+ zgensym_1452b2c984fe1b1a_10, bts, err = nbs.ReadUint64Bytes(bts) | |
+ | |
+ if err != nil { | |
+ return | |
+ } | |
+ z.M1.M1 = I1(zgensym_1452b2c984fe1b1a_10) | |
+ } | |
+ case "M2": | |
+ found8zgensym_1452b2c984fe1b1a_9[1] = true | |
+ { | |
+ var zgensym_1452b2c984fe1b1a_11 string | |
+ zgensym_1452b2c984fe1b1a_11, bts, err = nbs.ReadStringBytes(bts) | |
+ | |
+ if err != nil { | |
+ return | |
+ } | |
+ z.M1.M2 = Str(zgensym_1452b2c984fe1b1a_11) | |
+ } | |
+ default: | |
+ bts, err = msgp.Skip(bts) | |
+ if err != nil { | |
+ return | |
+ } | |
+ } | |
+ } | |
+ if nextMiss8zgensym_1452b2c984fe1b1a_9 != -1 { | |
+ bts = nbs.PopAlwaysNil() | |
} | |
+ | |
case "M2": | |
found6zgensym_1452b2c984fe1b1a_7[1] = true | |
if nbs.AlwaysNil || msgp.IsNil(bts) { | |
@@ -470,8 +563,13 @@ | |
var unmarshalMsgFieldSkip6zgensym_1452b2c984fe1b1a_7 = []bool{false, false, false, false} | |
+// fields of Struct1 | |
+var unmarshalMsgFieldOrder8zgensym_1452b2c984fe1b1a_9 = []string{"M1", "M2"} | |
+ | |
+var unmarshalMsgFieldSkip8zgensym_1452b2c984fe1b1a_9 = []bool{false, false} | |
+ | |
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message | |
func (z *Struct2) Msgsize() (s int) { | |
- s = 1 + 3 + z.M1.Msgsize() + 3 + msgp.BytesPrefixSize + len(z.M2) + 3 + msgp.StringPrefixSize + len(z.M3) + 3 + msgp.StringPrefixSize + len(z.M4) | |
+ s = 1 + 3 + 1 + 3 + msgp.Uint64Size + 3 + msgp.StringPrefixSize + len(string(z.M1.M2)) + 3 + msgp.BytesPrefixSize + len(z.M2) + 3 + msgp.StringPrefixSize + len(z.M3) + 3 + msgp.StringPrefixSize + len(z.M4) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment