Skip to content

Commit 8142193

Browse files
pjgjordaanjmarais
authored andcommitted
GoString plugin: generate values instead of pointers when a field is repeated and non-nullable. (#631)
* GoString plugin: generate values instead of pointers when a field is repeated and non-nullable. * Added additional test for repeated, nullable fields. Regenerated pbs.
1 parent 627c0c9 commit 8142193

10 files changed

Lines changed: 383 additions & 34 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ regenerate:
137137
make -C test/issue503 regenerate
138138
make -C test/issue530 regenerate
139139
make -C test/issue617 regenerate
140+
make -C test/issue630 regenerate
140141

141142
make gofmt
142143

plugin/gostring/gostring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
238238
} else {
239239
goTyp, _ := p.GoType(message, field)
240240
goTyp = strings.Replace(goTyp, "[]", "", 1)
241-
p.P("vs := make([]*", goTyp, ", len(this.", fieldname, "))")
241+
p.P("vs := make([]", goTyp, ", len(this.", fieldname, "))")
242242
p.P("for i := range vs {")
243243
p.In()
244-
p.P("vs[i] = &this.", fieldname, "[i]")
244+
p.P("vs[i] = this.", fieldname, "[i]")
245245
p.Out()
246246
p.P("}")
247247
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", vs) + ",\n")`)

test/combos/both/thetest.pb.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/combos/marshaler/thetest.pb.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/combos/unmarshaler/thetest.pb.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/issue630/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Protocol Buffers for Go with Gadgets
2+
#
3+
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
4+
# http://github.com/gogo/protobuf
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are
8+
# met:
9+
#
10+
# * Redistributions of source code must retain the above copyright
11+
# notice, this list of conditions and the following disclaimer.
12+
# * Redistributions in binary form must reproduce the above
13+
# copyright notice, this list of conditions and the following disclaimer
14+
# in the documentation and/or other materials provided with the
15+
# distribution.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
regenerate:
30+
(protoc --proto_path=../../protobuf/:../../../../../:. --gogo_out=. issue630.proto)

0 commit comments

Comments
 (0)