Skip to content

Commit

Permalink
GoString plugin: generate values instead of pointers when a field is …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
pjgjordaan authored and jmarais committed Oct 11, 2019
1 parent 627c0c9 commit 8142193
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ regenerate:
make -C test/issue503 regenerate
make -C test/issue530 regenerate
make -C test/issue617 regenerate
make -C test/issue630 regenerate

make gofmt

Expand Down
4 changes: 2 additions & 2 deletions plugin/gostring/gostring.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
} else {
goTyp, _ := p.GoType(message, field)
goTyp = strings.Replace(goTyp, "[]", "", 1)
p.P("vs := make([]*", goTyp, ", len(this.", fieldname, "))")
p.P("vs := make([]", goTyp, ", len(this.", fieldname, "))")
p.P("for i := range vs {")
p.In()
p.P("vs[i] = &this.", fieldname, "[i]")
p.P("vs[i] = this.", fieldname, "[i]")
p.Out()
p.P("}")
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", vs) + ",\n")`)
Expand Down
16 changes: 8 additions & 8 deletions test/combos/both/thetest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/combos/marshaler/thetest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/combos/unmarshaler/thetest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/issue630/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Protocol Buffers for Go with Gadgets
#
# Copyright (c) 2013, The GoGo Authors. All rights reserved.
# http://github.com/gogo/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

regenerate:
(protoc --proto_path=../../protobuf/:../../../../../:. --gogo_out=. issue630.proto)
Loading

0 comments on commit 8142193

Please sign in to comment.