Skip to content

Commit

Permalink
proto: remove Proto3UnknownFields flag (protocolbuffers#497)
Browse files Browse the repository at this point in the history
This flag was necessary inside Google for the transition to having
proto3 preserve unknown fields by default.
Outside of Google, this is unnecessary since the dev branch is
the transition.
  • Loading branch information
dsnet authored Jan 27, 2018
1 parent 3525335 commit b409cc5
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 61 deletions.
10 changes: 5 additions & 5 deletions _conformance/conformance.pb.go

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

10 changes: 5 additions & 5 deletions _conformance/conformance_proto/conformance.pb.go

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

10 changes: 5 additions & 5 deletions jsonpb/jsonpb_test_proto/more_test_objects.pb.go

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

6 changes: 0 additions & 6 deletions proto/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,6 @@ import (
"sync"
)

// Proto3UnknownFields enables whether unknown fields are preserved when
// unmarshaling proto3 messages. By default, this is disabled.
// This variable should only be set at init time.
// This variable is temporary and will go away soon. Do not rely on it.
var Proto3UnknownFields = false

var errInvalidUTF8 = errors.New("proto: invalid UTF-8 string")

// Message is implemented by generated protocol buffer messages.
Expand Down
10 changes: 5 additions & 5 deletions proto/proto3_proto/proto3.pb.go

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

10 changes: 2 additions & 8 deletions proto/proto3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,7 @@ func TestUnknownFieldPreservation(t *testing.T) {
t.Fatalf("proto.Unmarshal: %v", err)
}

if proto.Proto3UnknownFields {
if !bytes.Equal(m.XXX_unrecognized, []byte(b2)) {
t.Fatalf("mismatching unknown fields:\ngot %q\nwant %q", m.XXX_unrecognized, b2)
}
} else {
if len(m.XXX_unrecognized) > 0 {
t.Fatalf("unexpected unknown fields: got %q", m.XXX_unrecognized)
}
if !bytes.Equal(m.XXX_unrecognized, []byte(b2)) {
t.Fatalf("mismatching unknown fields:\ngot %q\nwant %q", m.XXX_unrecognized, b2)
}
}
5 changes: 0 additions & 5 deletions proto/table_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ func (u *unmarshalInfo) computeUnmarshalInfo() {
for i := 0; i < n; i++ {
f := t.Field(i)
if f.Name == "XXX_unrecognized" {
isProto3 := f.Tag.Get("protobuf_unrecognized") == "proto3"
if isProto3 && !Proto3UnknownFields {
continue // Explicit disabling of unknown fields in proto3
}

// The byte slice used to hold unrecognized input is special.
if f.Type != reflect.TypeOf(([]byte)(nil)) {
panic("bad type for XXX_unrecognized field: " + f.Type.Name())
Expand Down
7 changes: 1 addition & 6 deletions protoc-gen-go/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1978,12 +1978,7 @@ func (g *Generator) generateMessage(message *Descriptor) {
}
g.P(g.Pkg["proto"], ".XXX_InternalExtensions `", messageset, "json:\"-\"`")
}
if message.proto3() {
// TODO: Remove this when proto3 always preserves unknown fields.
g.P("XXX_unrecognized\t[]byte `protobuf_unrecognized:\"proto3\" json:\"-\"`")
} else {
g.P("XXX_unrecognized\t[]byte `json:\"-\"`")
}
g.P("XXX_unrecognized\t[]byte `json:\"-\"`")
g.P("XXX_sizecache\tint32 `json:\"-\"`")
g.Out()
g.P("}")
Expand Down
2 changes: 1 addition & 1 deletion ptypes/any/any.pb.go

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

2 changes: 1 addition & 1 deletion ptypes/duration/duration.pb.go

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

2 changes: 1 addition & 1 deletion ptypes/empty/empty.pb.go

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

6 changes: 3 additions & 3 deletions ptypes/struct/struct.pb.go

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

2 changes: 1 addition & 1 deletion ptypes/timestamp/timestamp.pb.go

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

18 changes: 9 additions & 9 deletions ptypes/wrappers/wrappers.pb.go

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

0 comments on commit b409cc5

Please sign in to comment.