diff options
author | David Symonds <dsymonds@golang.org> | 2015-01-28 17:07:47 +1100 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2015-01-28 17:07:47 +1100 |
commit | a11b6342f0e28eab4059c0cabbad38cef38b9b6e (patch) | |
tree | 0537d16745932e07202568182fa9327c7b617c16 | |
parent | 7f07925444bb51fa4cf9dfe6f7661876f8852275 (diff) | |
download | protobuf-a11b6342f0e28eab4059c0cabbad38cef38b9b6e.tar.gz |
Permit omission of a colon before a message-typed map value.
-rw-r--r-- | proto/decode.go | 4 | ||||
-rw-r--r-- | proto/text_parser.go | 2 | ||||
-rw-r--r-- | proto/text_parser_test.go | 2 | ||||
-rw-r--r-- | protoc-gen-go/generator/generator.go | 10 |
4 files changed, 6 insertions, 12 deletions
diff --git a/proto/decode.go b/proto/decode.go index 88622c3..129792e 100644 --- a/proto/decode.go +++ b/proto/decode.go @@ -518,9 +518,7 @@ func (o *Buffer) dec_string(p *Properties, base structPointer) error { if err != nil { return err } - sp := new(string) - *sp = s - *structPointer_String(base, p.field) = sp + *structPointer_String(base, p.field) = &s return nil } diff --git a/proto/text_parser.go b/proto/text_parser.go index ddd9579..d1caeff 100644 --- a/proto/text_parser.go +++ b/proto/text_parser.go @@ -570,7 +570,7 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) error { if err := p.consumeToken("value"); err != nil { return err } - if err := p.consumeToken(":"); err != nil { + if err := p.checkForColon(props.mvalprop, dst.Type().Elem()); err != nil { return err } if err := p.readAny(val, props.mvalprop); err != nil { diff --git a/proto/text_parser_test.go b/proto/text_parser_test.go index e5ee8b9..1360e8e 100644 --- a/proto/text_parser_test.go +++ b/proto/text_parser_test.go @@ -463,6 +463,7 @@ func TestMapParsing(t *testing.T) { m := new(MessageWithMap) const in = `name_mapping:<key:1234 value:"Feist"> name_mapping:<key:1 value:"Beatles">` + `msg_mapping:<key:-4 value:<f: 2.0>>` + + `msg_mapping<key:-2 value<f: 4.0>>` + // no colon after "value" `byte_mapping:<key:true value:"so be it">` want := &MessageWithMap{ NameMapping: map[int32]string{ @@ -471,6 +472,7 @@ func TestMapParsing(t *testing.T) { }, MsgMapping: map[int64]*FloatingPoint{ -4: {F: Float64(2.0)}, + -2: {F: Float64(4.0)}, }, ByteMapping: map[bool][]byte{ true: []byte("so be it"), diff --git a/protoc-gen-go/generator/generator.go b/protoc-gen-go/generator/generator.go index 8b02ba5..952ad56 100644 --- a/protoc-gen-go/generator/generator.go +++ b/protoc-gen-go/generator/generator.go @@ -102,12 +102,6 @@ func fileIsProto3(file *descriptor.FileDescriptorProto) bool { func (c *common) proto3() bool { return fileIsProto3(c.file) } -func fileUsesMaps(file *descriptor.FileDescriptorProto) bool { - return true -} - -func (c *common) usesMaps() bool { return fileUsesMaps(c.file) } - // Descriptor represents a protocol buffer message. type Descriptor struct { common @@ -1018,7 +1012,7 @@ func (g *Generator) generate(file *FileDescriptor) { } for _, desc := range g.file.desc { // Don't generate virtual messages for maps. - if desc.GetOptions().GetMapEntry() && desc.usesMaps() { + if desc.GetOptions().GetMapEntry() { continue } g.generateMessage(desc) @@ -1530,7 +1524,7 @@ func (g *Generator) generateMessage(message *Descriptor) { if *field.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE { desc := g.ObjectNamed(field.GetTypeName()) - if d, ok := desc.(*Descriptor); ok && d.GetOptions().GetMapEntry() && d.usesMaps() { + if d, ok := desc.(*Descriptor); ok && d.GetOptions().GetMapEntry() { // Figure out the Go types and tags for the key and value types. keyField, valField := d.Field[0], d.Field[1] keyType, keyWire := g.GoType(d, keyField) |