-
Notifications
You must be signed in to change notification settings - Fork 196
Closed
Description
Hello there. I've been integrating my C++ project into golang. I'm unable to generate decoder and unmarshaler because the project uses one-byte keys in msgpack to shorten the payload.
type ValueSegment struct {
Offset int `msg:"\x0b"`
...
}
According to spec, strings such as "\x0b" are allowed as keys.
tools/imports fails to format the generated code because it contains illegal characters which should have been escaped. The fix is trivial.
--- a/src/github.com/tinylib/msgp/gen/decode.go
+++ b/src/github.com/tinylib/msgp/gen/decode.go
@@ -102,7 +102,7 @@ func (d *decodeGen) structAsMap(s *Struct) {
d.p.print("\nswitch msgp.UnsafeString(field) {")
for i := range s.Fields {
d.ctx.PushString(s.Fields[i].FieldName)
- d.p.printf("\ncase \"%s\":", s.Fields[i].FieldTag)
+ d.p.printf("\ncase %q:", s.Fields[i].FieldTag)
next(d, s.Fields[i].FieldElem)
d.ctx.Pop()
if !d.p.ok() {
--- a/src/github.com/tinylib/msgp/gen/unmarshal.go
+++ b/src/github.com/tinylib/msgp/gen/unmarshal.go
@@ -105,7 +105,7 @@ func (u *unmarshalGen) mapstruct(s *Struct) {
if !u.p.ok() {
return
}
- u.p.printf("\ncase \"%s\":", s.Fields[i].FieldTag)
+ u.p.printf("\ncase %q:", s.Fields[i].FieldTag)
u.ctx.PushString(s.Fields[i].FieldName)
next(u, s.Fields[i].FieldElem)
u.ctx.Pop()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels