1067 Commits

Author SHA1 Message Date
Koichi Shiraishi
fc44d00d5a proto: use reflect.Ptr for backward compatibility
reflect.Pointer introduced on go1.18. Support 1.17 and earlier.

Change-Id: I62dcdb580a7976068e86df432bc44ee21c2cda81
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/412354
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-06-17 06:55:02 +00:00
Mitko Asenov
380c339ec1 proto: short-circuit Equal when inputs are identical
I added benchmarks (measured on Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz) that show the difference:

name                                  old time/op  new time/op  delta
EqualWithSmallEmpty-12                 241ns ± 6%   242ns ± 6%     ~     (p=0.796 n=10+10)
EqualWithIdenticalPtrEmpty-12          241ns ± 3%     7ns ± 4%  -97.19%  (p=0.000 n=10+10)
EqualWithLargeEmpty-12                2.68µs ± 3%  2.59µs ± 3%   -3.27%  (p=0.000 n=10+10)
EqualWithDeeplyNestedEqual-12         73.9µs ± 3%  71.8µs ± 1%   -2.91%   (p=0.000 n=10+9)
EqualWithDeeplyNestedDifferent-12     20.0µs ± 5%  19.4µs ± 5%   -3.06%  (p=0.029 n=10+10)
EqualWithDeeplyNestedIdenticalPtr-12  73.9µs ± 4%   0.0µs ± 2%  -99.99%  (p=0.000 n=10+10)

Change-Id: I1b83fa477d6432eafd355b322f507cf90b9a6751
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/411377
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
2022-06-15 11:39:31 +00:00
Koichi Shiraishi
784c482554 all: remove shorthand import aliases
Change-Id: I62ec79419354a2c65ac69e4bcc1cc864a6a40a1a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/407934
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-05-24 20:05:50 +00:00
Koichi Shiraishi
e62d8edb75 all: remove duplicate imports
protoreflect (as pref) and protoiface (as piface) are imported
duplicates in some files.
Respect package name, remove unnecessary aliased import statements.

Change-Id: Ie9897f17a50d19a462035964e366af72afed0e4d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/405694
Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-05-23 17:24:26 +00:00
Kir Kolyshkin
11ec34fe79 gha-ci: update github actions to latest versions
Update
 - actions/setup-go from v2 to v3;
 - actions/checkout from v2 to v3;
 - actions/cache from v2 to v3.0.2.

Tested at https://github.com/kolyshkin/protobuf-go/runs/6480937412

Change-Id: Ibeda7c83b1dfaf69dff1dab358b977958a48e51d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406846
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2022-05-23 16:51:27 +00:00
Kir Kolyshkin
147729ae80 gha-ci: bump Go version, nits
1. Switch from Go 1.16 to Go 1.x (which should now resolve to Go 1.18.1).

2. Add a comment explaining that the above version is not the actual Go
   version used for testing.

3. Drop -mod=vendor as this is the unconditional default since Go 1.16
   (unless GO111MODULES overrides this).

4. While at it, fix the options order in go test command, putting options
   before the file name.

Tested at https://github.com/kolyshkin/protobuf-go/actions/runs/2342081396

Change-Id: Icc9aa47ddc0d04abb69b48fcb6b021e3e8a98df3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406954
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-23 06:49:14 +00:00
Kir Kolyshkin
4790de629c all: update to latest staticcheck
The staticcheck version being used (2020.1.4) can no longer
work with latest Go, spitting out errors like this one:

> could not load export data: cannot import
> "unicode" (unknown iexport format version 2), export data is newer
> version - update tool (compile)

Update to latest version, 2022.1.2, to fix this.

Change-Id: I745482561a46baebc70931443008b95bec2fa377
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406842
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-19 15:39:12 +00:00
Damien Neil
f8e9eb526f internal/encoding/text: fix -0 comparisons in tests
Correctly distinguish between 0 and -0 in tests.

Change-Id: I41f6702a903ca0cf9edf9e95be812a3a29930978
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406917
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-19 09:42:31 +00:00
Kir Kolyshkin
bf9455640d all: fix typos
Brought to you by codespell v2.1.0, using the command

	codespell -S .cache,vendor -L ot,ba,fo,unparseable -w

Note that the misspelled "unparseable" comes from the
github.com/protocolbuffers/protobuf, where it is explicitly ignored
(see [1] and some explanation at [2]), so we ignore it here, too.

[1] https://github.com/protocolbuffers/protobuf/pull/7752
[2] https://github.com/protocolbuffers/protobuf/pull/7751#discussion_r460170422

Change-Id: Ie1ca705db4f11df8ec8b22fdc22b6a6ee667ae5b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406845
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-19 09:32:38 +00:00
Kir Kolyshkin
06eea5e15f internal/impl: CompressGZIP: simplify
This simplifies the code and fixes the following linter warning
reported by staticcheck:

        internal/impl/legacy_export.go:84:51: uint16(blockSize) ^ 0x0000 always equals uint16(blockSize) (SA4016)

Similar code:
 https://cs.opensource.google/go/go/+/master:src/compress/flate/huffman_bit_writer.go;l=413-414;drc=19309779ac5e2f5a2fd3cbb34421dafb2855ac21

Change-Id: Id099b0de635f668d44f57bacd89b564337560254
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406841
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2022-05-18 18:09:39 +00:00
Kir Kolyshkin
4db09f5dd7 all: add/bump tested Go versions
Add 1.18.1.

Bump 1.16.0 -> 1.16.15, 1.17.3 -> 1.17.10.

Change-Id: Ic19b47004484970b404e4eb8b2d02955410f65af
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406839
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-17 22:28:33 +00:00
Kir Kolyshkin
563f06fbeb internal/encoding/text/decode: limit errId length
Avoid very long errors returned by limiting the length of what errId
returns to 32 bytes (the value is chosen so that the error will not
be too long yet useful).

Append ellipsis to the returned value to denote that it was truncated.

Change-Id: I232d5192a2d9ad675daa0be0fe0c8518489c2953
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406694
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-17 20:42:32 +00:00
Kir Kolyshkin
a0482351ba internal/encoding/text/decode: stop using regexp
This eliminates the last user of the regexp package, which should save
about 130K from the resulting stripped binary importing this package
(unless, of course, regexp is brought in directly of via another
dependency).

Added some new cases to TestDecoder to test the new function.

Benchmark (not included) shows the following results, comparing to
old implementation using regexp.Find:

name     old time/op    new time/op    delta
ErrId-4    1.93µs ± 1%    0.21µs ± 1%   -89.20%  (p=0.002 n=6+6)

name     old alloc/op   new alloc/op   delta
ErrId-4      128B ± 0%        0B       -100.00%  (p=0.002 n=6+6)

name     old allocs/op  new allocs/op  delta
ErrId-4      13.0 ± 0%       0.0       -100.00%  (p=0.002 n=6+6)

Change-Id: I5569a47580f41cc60f92c444e8d43bb3f26faa4e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/402774
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-16 20:59:57 +00:00
Joe Tsai
8a7ba0762c reflect/protoreflect: improve documentation for message types
There are a number of message types, which can be confusing.
Expand the documentation. In particular, use Go's reflection model
as an analogy, which helps users if they are at least familiar
with how Go reflection works. After all, protobuf reflection
was modeled after Go reflection to a large degree.

Change-Id: I388ae41c792905145ccc86dc938b901a2b79f408
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/399654
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-04-12 06:05:53 +00:00
Lasse Folger
d77bd4b022 release.bash: replace aliased git commands with non-aliased equivalents
Change-Id: Ie9a9fd1d4cefc28c8fb5429a975ac50436e29d70
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/394454
Reviewed-by: Chressie Himpel <chressie@google.com>
Reviewed-by: Florian Zenker <floriank@google.com>
2022-03-22 12:18:24 +00:00
Lasse Folger
4c88e077ec all: start v1.28.0-devel
Change-Id: Ie9bd9f62312ff3f50787abd60067956b2911c59a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/391415
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-22 07:56:25 +00:00
Lasse Folger
32051b4f86 all: release v1.28.0
Change-Id: Ied1d78a3cc0d417fbbd1d10d30730173af3e20d4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/391414
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.28.0
2022-03-22 07:56:23 +00:00
Lasse Folger
3992ea83a2 all: implement depth limit for unmarshaling
+ This change introduce a default and configurable depth limit for
  proto.Unmarshal. If a message is nested deeper than the limit,
  unmarshaling will fail. There are two ways to nest messages. Either by
  having fields which are message types itself or by using groups.
+ The default limit is 10,000 for now. This might change in the future
  to align it with other language implementation (C++ and Java use 100
  as limit).
+ If pure groups (groups that don't contain message fields) are nested
  deeper than the default limit the unmarshaling fails with:
  proto: cannot parse invalid wire-format data
+ Note: the configured limit does not apply to pure groups.
+ This change is introduced to improve security and robustness. Because
  unmarshaling is implemented using recursion it can lead to stack overflows
  for certain inputs. The introduced limit protects against this.
+ A secondary motivation for this limit is the alignment with other
  languages. Protocol buffers are a language interoperability mechanism
  and thus either all implementations should accept the input or all
  implementation should reject the input.

Change-Id: I14bdb44d06e4bd1aa90d6336c2cf6446003b2037
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/385854
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
2022-02-17 17:07:31 +00:00
Damien Neil
e5db2960ed all: update supported versions
Go 1.9 and 1.10 produce binaries that don't run on the most recent version
of macOS. Drop these versions from the tested set.

Update minor revision where a newer one is available:
  1.15.9 -> 1.15.15
  1.16.1 -> 1.16.10

Add 1.17.3.

Bump go.mod version to go1.11.

Fixes golang/protobuf#1394.

Change-Id: I7850b86819d356891917d2987f080d3e7dbd7cc5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/370055
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Florian Zenker <floriank@google.com>
2022-01-04 22:58:13 +00:00
Damien Neil
3a9e1dc314 all: gofmt all
Change-Id: I1d42c8d784440a0b7e40b4f0b8da54be0fb338a6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/370054
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Florian Zenker <floriank@google.com>
2022-01-04 22:57:54 +00:00
Emmanuel T Odeke
26e8bcb3c7 all: remove unnecessary string([]byte) conversion in fmt.Sprintf with %s
Change-Id: I64aab811cbcbfa410817894f1cd1d83f88f27bf6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/365874
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-11-29 18:55:28 +00:00
Joe Tsai
5aec41b480 testing/protocmp: add Message.Unwrap
The Unwrap method returns the original concrete message value.
In theory this allows users to mutate the original message when the
cmp documentation says that all options should be mutation free.
If users want to disregard this documented restriction, they can
already do so in a number of different ways.

Updates #1347

Change-Id: I65225681ab5dbce0763a140fd02666a4ab542a04
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/340489
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-08-06 18:43:50 +00:00
Damien Neil
05be61fde3 reflect/protoreflect: add more docs on Value aliasing
Fixes golang/protobuf#1346

Change-Id: I9deb36e1c5e4f28c1c7e99ca64260c7a86af4ea1
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/339569
Trust: Damien Neil <dneil@google.com>
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <joetsai@digital-static.net>
2021-08-05 18:00:43 +00:00
Joe Tsai
b03064a95c all: start v1.27.1-devel
Change-Id: Ifaeb330729a8d6f7fc403926db50d50e127859e9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/331290
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-28 18:25:47 +00:00
Joe Tsai
b92717ecb6 all: release v1.27.1
Change-Id: I9acc84df59805ba789ef42ee2dc43e14ce56818b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/331289
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.27.1
2021-06-28 18:25:36 +00:00
Joe Tsai
177d70e4ab README.md: mention protopath and protorange packages
Change-Id: I33045b4356642d433d88112cf0c6e6210dace58e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/331229
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-27 06:10:47 +00:00
Joe Tsai
aa432c0868 cmd/protoc-gen-go: fix generation of enum defaults
Previously, this call strconv.FormatInt with base 32,
when the intention is to call it with base 10.

Change-Id: I31cdd2415b3a80936cdcdeb5612a486204404ecb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/331149
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-27 06:07:42 +00:00
Joe Tsai
49b6f723d3 all: start v1.27.0-devel
Change-Id: I7f2f94ed40c71582838fe6ffcb103b9e98a49d1c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/330871
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-25 18:50:12 +00:00
Joe Tsai
3f51f05e40 all: release v1.27.0
Change-Id: Id3587f2020fa58a41574e5f2669c9e50568f06e2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/330870
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.27.0
2021-06-25 18:49:55 +00:00
Joe Tsai
dc57387746 release.bash: make work on Linux
Most releases of Linux use the GNU version of sed, while
most releases of macOS use the BSD version of sed.

For the -i flag, BSD always expects an argument,
while GNU expects an optional argument in a different format.

See https://www.freebsd.org/cgi/man.cgi?query=sed&sektion=&n=1
See https://www.gnu.org/software/sed/manual/html_node/Command_002dLine-Options.html#Command_002dLine-Options

Change-Id: Id0f472553c8583d427524f59b36c376d6bc28786
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/330869
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-06-25 08:33:33 +00:00
Damien Neil
21e33cc910 reflect/protoregistry: restore conflicting file names check
There are inconsistencies between implementations on what happens when
a single program contains generated code for multiple files with the
same source path. At least one canonical implementation (C++) will fail
at link time. Others print warnings. Some silently resolve the registry
conflict in favor of one file or the other. The protobuf maintainers
agree, however, that the desired behavior is for this condition to be an
error.

Updates golang/protobuf#1122

Change-Id: I716708f16ef90210bdfceb0888691e47783df172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/322729
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-06-02 01:04:00 +00:00
Damien Neil
426f20bc78 release.bash: make work on macOS
macOS's sed always considers the parameter following -i to be an
extension, so "-i -e" means "edit in place saving backup with a -e
extension".

macOS's sed does not support \s in regexps.

Change-Id: Ic9b57baa5fc88fff2251c640d11ed417a7257f13
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/322449
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-25 06:48:41 +00:00
Damien Neil
febffdd88e reflect/protoregistry: permit conflicting file names
Remove the requirement that all registered files have unique names.

Files.FindFileByPath now returns an error if multiple files match
the path. Files.RangeFiles iterates over all files, including ones with
the same name.

Unlike descriptor names, file names are not part of any of the wire
encodings. Conflicts in file names only affect file lookups by path,
which is an uncommon operation.

The Files.RegisterFile documentation already states (inaccurately),
"It is permitted for multiple files to have the same file path."
This change brings the behavior of RegisterFile in line with the
documentation.

Fixes golang/protobuf#1122

Change-Id: I2750e35736fd34def23fa6ab6d6a829095a65a26
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321531
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-25 00:53:49 +00:00
Joe Tsai
4c193d18ec compiler/protogen: relax rules for valid import paths
The path "sub.example.com" is a valid Go import path and
should not be rejected. Relax the check to require at least one
dot or slash. Either way, it still prevents the situation where
a user erroneously treats this option as just the package name.

Change-Id: I3df811e1eae61c9d2a0b81c001a27cc7c08c3838
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/316949
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-05-24 23:00:18 +00:00
Joe Tsai
acaef6adb7 cmd/protoc-gen-go: avoid referencing remote enum values by name
The Go generator has historically always prefixed an enum value
with the name of the enum type, when it was unnecessary to do so.

For example:
	enum Status {
		STATUS_FAILED = 0;
		STATUS_PASSED = 1;
	}
would be generated as:
	type Status int32
	const (
		Status_STATUS_FAILED Status = 0
		Status_STATUS_PASSED Status = 1
	)

It is common for the enum values to be manually prefixed by the
enum type since protobuf enums use C++ namespace rules where
enum types and enum values are in the same namespace scope.
Thus, having the Go generator add a prefix is redundant.
See https://github.com/golang/protobuf/issues/513.

Some custom Go generators like protoc-gen-gogo allow removing
the prefix with the gogoproto.goproto_enum_prefix feature.
However, this leads to interoperability issues between
protoc-gen-go and protoc-gen-gogo, where the enum value names
cannot be accurately inferred.

Avoid this problem by just hard-coding the enum value number
for values declared in other packages. This provides benefits
in interoperability at the small cost of enum values possibly
being stale if their value were ever changed in a remote package.
However, this would only occur with use of proto2 enums and
default values, which seems to be an exceptionally rare situation.

Before:
	Default_MyMessage_MyField = remotepb.FooEnum_FOO_ENUM
After:
	Default_MyMessage_MyField = remotepb.FooEnum(4) // remotepb.FooEnum_FOO_ENUM

Before:
	func (x *MyMessage) GetField() remotepb.FooEnum {
		...
		return remotepb.FooEnum_FOO_ZERO
	}
After:
	func (x *MyMessage) GetField() remotepb.FooEnum {
		...
		return remotepb.FooEnum(0) // always 0 for proto3 and often 0 for proto2
	}

Change-Id: I3a06cd553f2eaf6124666f6c36c196d500d35718
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/319649
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-05-24 22:21:56 +00:00
Damien Neil
50a85913fb all: build Windows protoc-gen-go as a .exe in a zip
Add a .exe suffix to the protoc-gen-go Windows binary.
Use zip instead of tar for the Windows release archive.

Fixes golang/protobuf#1323

Change-Id: If42fa6dfd8b5496148310fa2a3359161f1124229
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321530
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-20 19:40:23 +00:00
Damien Neil
24d799b3c1 internal/impl: support typed nil source for Merge of aberrant messages
When merging aberrant messages with legacy Marshal and Unmarshal
methods, check for a typed nil source before calling Marshal.

Add an aberrant message with Marshal/Unmarshal methods to
internal/testprotos/nullable and use it to test the internal/impl
support for these methods.

Fixes golang/protobuf#1324

Change-Id: Ib6ce85b30b46e3392a226ca6abe411932a371f02
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321529
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-20 18:23:20 +00:00
sryoya
0e358a402f reflect/protorange: fix typo of func name in comment
Change-Id: I80ffc34e29757e0cbdccdd530404fa215cfaf75f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/317989
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
2021-05-07 17:05:00 +00:00
Joe Tsai
c30776bb3b encoding/prototext: fix skipping of unknown fields
Inside decoder.skipValue we should not be calling skipValue again
since we had already read the value earlier. The only possible
composite type in the context of a list is another message,
which is already handled in the case above.

Change-Id: If40da2d369e0a64a64ba9b961377331231158fe2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/317430
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Herbie Ong <herbie@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2021-05-06 20:07:56 +00:00
Joe Tsai
fb30439f55 testing/protopack: add Message.UnmarshalAbductive
The protobuf wire format is insufficiently self-decribing such that
it is impossible to know whether for sure whether an unknown bytes value
is a sub-message or not. However, protopack is primarily used for debugging
where a best-effort guess is still very useful.

The Message.UnmarshalAbductive unmarshals an unknown bytes value as a message
if it is syntactically well-formed. Otherwise, it is left as is.

Change-Id: I5e2b4b995e2b5eb60942a242558bf4cea1da9891
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/309669
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-04-14 20:38:42 +00:00
Aliaksandr Mianzhynski
fc9592f7ac cmd/protoc-gen-go: add protoc suffix
Change-Id: Ib09bd3cbd15088d534de34b08d01a4d7a4880c0a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/306209
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Damien Neil <dneil@google.com>
2021-04-08 23:03:09 +00:00
Joe Tsai
e4fcb9f7e7 reflect: add protopath and protorange packages
The protopath package provides a means to programmatically represent
a sequence of protobuf reflection operations.
The protorange package traverses through a message and
calls a user-provided function as it iterates.

This feature sets the groundwork for the often requested feature
of being able to exclude certain fields when merging or serializing.

package protopath
    type Path []Step
    type Step struct{ ... }
        func Root(protoreflect.MessageDescriptor) Step
        func FieldAccess(protoreflect.FieldDescriptor) Step
        func UnknownAccess() Step
        func ListIndex(int) Step
        func MapIndex(protoreflect.MapKey) Step
        func AnyExpand(protoreflect.MessageDescriptor) Step
        func (Step) Kind() StepKind
        func (Step) FieldDescriptor() protoreflect.FieldDescriptor
        func (Step) MessageDescriptor() protoreflect.MessageDescriptor
        func (Step) ListIndex() int
        func (Step) MapIndex() protoreflect.MapKey
        func (Step) String() string
    type StepKind int
        const RootStep StepKind
        const FieldAccessStep StepKind
        const UnknownAccessStep StepKind
        const ListIndexStep StepKind
        const MapIndexStep StepKind
        const AnyExpandStep StepKind
    type Values struct {
        Path   Path
        Values []protoreflect.Value
    }
    func (Values) Index(int) (out struct{ ... })
    func (Values) Len() int
    func (Values) String() string

package protorange
    var Break error
    var Terminate error
    func Range(protoreflect.Message, func(protopath.Values) error) error
    type Options struct {
        Stable bool
        Resolver interface { ... }
    }
    func (Options) Range(m protoreflect.Message, push, pop func(protopath.Values) error) error

Change-Id: I29cbd5142fe169d78367d54a95d37801888b64f4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/236540
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-04-01 23:09:19 +00:00
Joe Tsai
31610fd913 cmd/protoc-gen-go: remove generation of the ExtensionRangeArray method
The ExtensionRangeArray was a pseudo-internal API that was used by
the protobuf runtime implementation to know what the extension ranges are.
For some time now, the runtime implementation does not make use of this.

According to all the latest modules known by the module proxy,
no code depends directly on this method being present.

In the extremely rare case where some user code is depending on this method,
the user can place a .go file next to the generated .pb.go file that
injects this method.

Change-Id: Iae40a9a33b8c9b5a243d48db14f25b05ca24e3dc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/305574
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-29 20:25:28 +00:00
Joe Tsai
f821cae922 all: start v1.26.0-devel
Change-Id: I544bd53c41794d5da2d381d3b182293a465f3c4b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302753
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-18 00:28:12 +00:00
Joe Tsai
f2d1f6cbe1 all: release v1.26.0
Change-Id: I15ecd5b768516fd2382cfbc8b337ad3d8817deab
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302752
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.26.0
2021-03-18 00:27:53 +00:00
Joe Tsai
41ef85a559 all: add weak dependency on github.com/golang/protobuf
Add back the weak dependency on github.com/golang/protobuf.

Change-Id: I2e6fabbe2cac3b694fb56a86bb3aa85cc8615b42
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262684
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-18 00:24:57 +00:00
Joe Tsai
bdf6e19f23 all: start v1.26.0-rc.1.devel
Change-Id: I46da1bbedc2a0e53de1b02b07c5d6b76a18e1894
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302751
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-17 22:45:59 +00:00
Joe Tsai
1c57cacb03 all: release v1.26.0-rc.1
Change-Id: I849df1819bf980fea006516beba4a551696e3811
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302750
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.26.0-rc.1
2021-03-17 22:45:34 +00:00
Joe Tsai
b7197c14de all: remove weak dependency on github.com/golang/protobuf
Temporarily remove the dependency on github.com/golang/protobuf
and add it back in a subsequent CL. This allows us to break some of
the infinite cycles of old versions in the go.sum file.

Change-Id: Ifb5c2c160713d47a43ba2bcedc18ebe2ce33dcea
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262683
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-17 21:55:02 +00:00
Joe Tsai
e471641887 cmd/protoc-gen-go: support --help flag
When someone has no idea what a binary does, it is convention to
pass the "--help" flag. When done, we should point the user
to the devsite documentation on protoc with protoc-gen-go.

Change-Id: I36289a1ae025b9e12521b34362370aba5235a44b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302330
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 20:24:12 +00:00