-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ignored tag directives on unnamed fields
Example: ``` type S struct { ABool bool `msg:",omitempty"` } ``` ... would ignore the omitempty, since all tags were replaced, resulting in output like: ``` // MarshalMsg implements msgp.Marshaler func (z S) MarshalMsg(b []byte) (o []byte, err error) { o = msgp.Require(b, z.Msgsize()) // map header, size 1 // string "ABool" o = append(o, 0x81, 0xa5, 0x41, 0x42, 0x6f, 0x6f, 0x6c) o = msgp.AppendBool(o, z.ABool) return } ``` Keep remaining tags when filling out the field name. Code after: ``` // MarshalMsg implements msgp.Marshaler func (z S) MarshalMsg(b []byte) (o []byte, err error) { o = msgp.Require(b, z.Msgsize()) // check for omitted fields zb0001Len := uint32(1) var zb0001Mask uint8 /* 1 bits */ _ = zb0001Mask if z.ABool == false { zb0001Len-- zb0001Mask |= 0x1 } // variable map header, size zb0001Len o = append(o, 0x80|uint8(zb0001Len)) if zb0001Len == 0 { return } if (zb0001Mask & 0x1) == 0 { // if not omitted // string "ABool" o = append(o, 0xa5, 0x41, 0x42, 0x6f, 0x6f, 0x6c) o = msgp.AppendBool(o, z.ABool) } return } ``` Regression test added.
- Loading branch information
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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