-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extensions #666
Support extensions #666
Changes from 2 commits
d2d1553
4f9f909
eb9a200
97b9729
c1d5b71
5fd6e96
ac0b669
9c99c21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
# proto2 extensions are not implemented | ||
# WARNING, test=Recommended.Proto2.JsonInput.FieldNameExtension.Validator: Expected JSON payload but got type 1. request=json_payload: "{\n \"[protobuf_test_messages.proto2.extension_int32]\": 1\n }" requested_output_format: JSON message_type: "protobuf_test_messages.proto2.TestAllTypesProto2" test_category: JSON_TEST, response=parse_error: "Error: cannot decode message protobuf_test_messages.proto2.TestAllTypesProto2 from JSON: key \"[protobuf_test_messages.proto2.extension_int32]\" is unknown" | ||
Recommended.Proto2.JsonInput.FieldNameExtension.Validator | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2021-2024 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto2"; | ||
package proto2ext; | ||
|
||
import "extra/example.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
|
||
// The message we're going to extend | ||
message Proto2Extendee { | ||
optional int32 own_field = 1; | ||
extensions 1000 to 9999; | ||
} | ||
|
||
// An enumeration used in extensions | ||
enum Proto2ExtEnum { | ||
PROTO2_EXT_ENUM_YES = 1; | ||
PROTO2_EXT_ENUM_NO = 2; | ||
} | ||
|
||
// A message used in extensions | ||
message Proto2ExtMessage { | ||
optional string string_field = 1; | ||
} | ||
|
||
// Testing all kinds of extensions. | ||
// Required fields, maps, oneof are not allowed in extensions. | ||
extend Proto2Extendee { | ||
|
||
optional uint32 uint32_ext = 1001; | ||
optional uint32 uint32_ext_with_default = 1002 [default = 999]; | ||
|
||
optional string string_ext = 2001; | ||
optional string string_ext_with_default = 2002 [default = "hello \" */ "]; | ||
|
||
optional uint64 uint64_ext = 3001; | ||
optional uint64 uint64_ext_js_string = 3002 [jstype = JS_STRING]; | ||
|
||
optional bytes bytes_ext = 4001; | ||
optional bytes bytes_ext_with_default = 4002 [default = "\0x\\x\"x\'A\101\x41\x41\u0041\U00000041\b\f\n\r\t\v"]; | ||
|
||
optional Proto2ExtEnum enum_ext = 5001; | ||
optional Proto2ExtEnum enum_ext_with_default = 5002 [default = PROTO2_EXT_ENUM_NO]; | ||
|
||
optional Proto2ExtMessage message_ext = 6001; | ||
optional docs.User message_ext_proto3 = 6002; | ||
|
||
repeated Proto2ExtMessage repeated_message_ext = 7001; | ||
repeated Proto2ExtEnum repeated_enum_ext = 7005; | ||
repeated string repeated_string_ext = 7002; | ||
repeated uint32 packed_uint32_ext = 7003 [packed = true]; | ||
repeated uint32 unpacked_uint32_ext = 7004; // unpacked by default in proto2 | ||
|
||
optional google.protobuf.UInt32Value wrapper_ext = 8001; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since groups are now ostensibly supported, let's also add a group extension, to make sure they work, too. (Maybe a repeated group extension, too?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 added in 97b9729. |
||
|
||
// A container for nested extensions | ||
message Proto2ExtContainer { | ||
extend Proto2Extendee { | ||
optional uint32 uint32_ext = 9001; | ||
} | ||
message Child { | ||
extend Proto2Extendee { | ||
optional uint32 uint32_ext = 9010; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021-2024 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
package proto3ext; | ||
|
||
import "google/protobuf/descriptor.proto"; | ||
import "extra/example.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
|
||
// In proto3, we can only extend options. | ||
extend google.protobuf.FileOptions { | ||
uint32 uint32_ext = 1001; | ||
optional uint32 optional_uint32_ext = 1002; | ||
repeated uint32 packed_uint32_ext = 7003; | ||
repeated uint32 unpacked_uint32_ext = 7004 [packed = false]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing 100% of the protobuf v25.2 conformance tests now.