golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.64k stars 1.58k forks source link

Support for optional fields #1595

Closed wim07101993 closed 3 months ago

wim07101993 commented 4 months ago

When declaring a field as optional the protoc-gen-go compiler exits with the error: protos/test.proto: This file contains proto3 optional fields, but --experimental_allow_proto3_optional was not set.

Is this still experimental? It was added in v1.22.0 almost 4 years ago.

command: protoc --go_out "generated" protos/test.proto

proto file:

syntax = "proto3";

package option_test;

option go_package = "grpc_test";

message OptionMessage {
  optional int32 value = 1;
}
$ protoc --version
libprotoc 3.12.4
$ protoc-gen-go --version
protoc-gen-go v1.28.1
neild commented 4 months ago

That error message is printed by protoc, not the Go code generator.

I believe the most recent version of protoc is 25.3: https://github.com/protocolbuffers/protobuf/releases

wim07101993 commented 3 months ago

Indeed, the version I had came from the Ubuntu package manager but hasn't been updated since 2020... The latest releases from github seem to work.