diff --git a/src/google/protobuf/editions/codegen_tests/proto2_proto3_enum.proto b/src/google/protobuf/editions/codegen_tests/proto2_proto3_enum.proto index d9527ffdc9..9ffb861382 100644 --- a/src/google/protobuf/editions/codegen_tests/proto2_proto3_enum.proto +++ b/src/google/protobuf/editions/codegen_tests/proto2_proto3_enum.proto @@ -13,8 +13,6 @@ import "google/protobuf/editions/codegen_tests/proto3_enum.proto"; message Proto2ImportedEnumMessage { optional protobuf_editions_test.proto3.Proto3Enum enum_field = 1; - // clang-format off - // TODO Transforms don't support multi-line fields yet. - optional protobuf_editions_test.proto3.Proto3Enum enum_field_default = 2 [default = BAZ]; - // clang-format on + optional protobuf_editions_test.proto3.Proto3Enum enum_field_default = 2 + [default = BAZ]; } diff --git a/src/google/protobuf/editions/golden/editions_transform_proto2.proto b/src/google/protobuf/editions/golden/editions_transform_proto2.proto index 193b7e06d3..275a1eea56 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto2.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto2.proto @@ -6,50 +6,68 @@ // https://developers.google.com/open-source/licenses/bsd edition = "2023"; -import "google/protobuf/cpp_features.proto"; -option features.enum_type = CLOSED; -option features.repeated_field_encoding = EXPANDED; -option features.utf8_validation = UNVERIFIED; -option features.json_format = LEGACY_BEST_EFFORT; -option features.(pb.cpp).legacy_closed_enum = true; // This file contains various edge cases we've collected from migrating real // protos in order to lock down the transformations. -// LINT: ALLOW_GROUPS +// LINT:ALLOW_GROUPS package protobuf_editions_test; +import "google/protobuf/cpp_features.proto"; + +option features.enum_type = CLOSED; +option features.repeated_field_encoding = EXPANDED; +option features.utf8_validation = UNVERIFIED; +option features.json_format = LEGACY_BEST_EFFORT; +option features.(pb.cpp).legacy_closed_enum = true; option java_multiple_files = true; option cc_enable_arenas = true; -message EmptyMessage {} -message EmptyMessage2 {} +message EmptyMessage { +} + +message EmptyMessage2 { +} -service EmptyService {} +service EmptyService { +} service BasicService { - rpc BasicMethod(EmptyMessage) returns (EmptyMessage) {} + rpc BasicMethod(EmptyMessage) returns (EmptyMessage); } // clang-format off -message UnformattedMessage{ - int32 a=1 ; - message Foo { int32 a = 1; } - Foo foo = 2 [features.message_encoding = DELIMITED]; - string string_piece_with_zero = 3 [ctype=STRING_PIECE, default="ab\000c"]; - float long_float_name_wrapped = 4; +message UnformattedMessage { + int32 a = 1; + + message Foo { + int32 a = 1; + } + + Foo foo = 2 [ + features.message_encoding = DELIMITED + ]; + string string_piece_with_zero = 3 [ + ctype = STRING_PIECE, + default = "ab\000c" + ]; + + float long_float_name_wrapped = 4; } + // clang-format on message ParentMessage { message ExtendedMessage { - extensions 536860000 to 536869999 [declaration = { - number: 536860000 - full_name: ".protobuf_editions_test.extension" - type: ".protobuf_editions_test.EmptyMessage" - }]; + extensions 536860000 to 536869999 [ + declaration = { + number: 536860000, + full_name: ".protobuf_editions_test.extension", + type: ".protobuf_editions_test.EmptyMessage" + } + ]; } } @@ -59,26 +77,42 @@ extend ParentMessage.ExtendedMessage { message TestMessage { string string_field = 1; - map string_map_field = 7; - repeated int32 int_field = 8; - repeated int32 int_field_packed = 9 [features.repeated_field_encoding = PACKED]; - repeated int32 int_field_unpacked = 10; + repeated int32 int_field_packed = 9 [ + features.repeated_field_encoding = PACKED + ]; - repeated int32 options_strip_beginning = 4 [ /* inline comment*/ debug_redact = true, deprecated = false ]; - repeated int32 options_strip_middle = 5 [debug_redact = true, deprecated = false]; - repeated int32 options_strip_end = 6 [debug_redact = true, deprecated = false]; + repeated int32 int_field_unpacked = 10; + repeated int32 options_strip_beginning = 4 [ + /* inline comment */ + debug_redact = true, + deprecated = false + ]; + + repeated int32 options_strip_middle = 5 [ + debug_redact = true, + deprecated = false + ]; + + repeated int32 options_strip_end = 6 [ + debug_redact = true, + deprecated = false + ]; message OptionalGroup { int32 a = 17; } - OptionalGroup optionalgroup = 16 [features.message_encoding = DELIMITED]; + + OptionalGroup optionalgroup = 16 [ + features.message_encoding = DELIMITED + ]; } enum TestEnum { - FOO = 1; // Non-zero default + FOO = 1; // Non-zero default + BAR = 2; BAZ = 3; - NEG = -1; // Intentionally negative. + NEG = -1; // Intentionally negative. } diff --git a/src/google/protobuf/editions/golden/editions_transform_proto2_lite.proto b/src/google/protobuf/editions/golden/editions_transform_proto2_lite.proto index df5a49d01c..b46e5ab7d0 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto2_lite.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto2_lite.proto @@ -6,21 +6,20 @@ // https://developers.google.com/open-source/licenses/bsd edition = "2023"; + +package protobuf_editions_test; + import "google/protobuf/cpp_features.proto"; + option features.enum_type = CLOSED; option features.repeated_field_encoding = EXPANDED; option features.utf8_validation = UNVERIFIED; option features.json_format = LEGACY_BEST_EFFORT; option features.(pb.cpp).legacy_closed_enum = true; - -package protobuf_editions_test; - option optimize_for = LITE_RUNTIME; message TestMessageLite { string string_field = 1; - map string_map_field = 4; - int32 int_field = 5; } diff --git a/src/google/protobuf/editions/golden/editions_transform_proto2_utf8_disabled.proto b/src/google/protobuf/editions/golden/editions_transform_proto2_utf8_disabled.proto index 810810390e..44fd0533de 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto2_utf8_disabled.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto2_utf8_disabled.proto @@ -6,20 +6,19 @@ // https://developers.google.com/open-source/licenses/bsd edition = "2023"; + +package protobuf_editions_test; + import "google/protobuf/cpp_features.proto"; + option features.enum_type = CLOSED; option features.repeated_field_encoding = EXPANDED; option features.utf8_validation = UNVERIFIED; option features.json_format = LEGACY_BEST_EFFORT; option features.(pb.cpp).legacy_closed_enum = true; -package protobuf_editions_test; - - message TestMessageUtf8Disabled { string string_field = 1; - map string_map_field = 4; - int32 int_field = 5; } diff --git a/src/google/protobuf/editions/golden/editions_transform_proto3.proto b/src/google/protobuf/editions/golden/editions_transform_proto3.proto index 454f7d1504..82826f6dc3 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto3.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto3.proto @@ -6,16 +6,17 @@ // https://developers.google.com/open-source/licenses/bsd edition = "2023"; -option features.field_presence = IMPLICIT; package protobuf_editions_test; +option features.field_presence = IMPLICIT; + message TestMessageProto3 { string string_field = 1; - map string_map_field = 4; - repeated int32 int_field = 7; repeated int32 int_field_packed = 8; - repeated int32 int_field_unpacked = 9 [features.repeated_field_encoding = EXPANDED]; + repeated int32 int_field_unpacked = 9 [ + features.repeated_field_encoding = EXPANDED + ]; } diff --git a/src/google/protobuf/editions/golden/editions_transform_proto3_utf8_disabled.proto b/src/google/protobuf/editions/golden/editions_transform_proto3_utf8_disabled.proto index 26ba294f08..acb8081e1a 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto3_utf8_disabled.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto3_utf8_disabled.proto @@ -6,15 +6,13 @@ // https://developers.google.com/open-source/licenses/bsd edition = "2023"; -option features.field_presence = IMPLICIT; package protobuf_editions_test; +option features.field_presence = IMPLICIT; message TestMessageProto3 { string string_field = 1; - map string_map_field = 4; - repeated int32 int_field = 7; } diff --git a/src/google/protobuf/editions/golden/test_messages_proto2.proto b/src/google/protobuf/editions/golden/test_messages_proto2.proto index c6d936cdeb..d30b8748f2 100644 --- a/src/google/protobuf/editions/golden/test_messages_proto2.proto +++ b/src/google/protobuf/editions/golden/test_messages_proto2.proto @@ -8,26 +8,25 @@ // Test schema for proto2 messages. This test schema is used by: // // - conformance tests -// -// LINT: ALLOW_GROUPS +// LINT:ALLOW_GROUPS edition = "2023"; + +package protobuf_test_messages.proto2; + import "google/protobuf/cpp_features.proto"; + option features.enum_type = CLOSED; option features.repeated_field_encoding = EXPANDED; option features.utf8_validation = UNVERIFIED; option features.json_format = LEGACY_BEST_EFFORT; option features.(pb.cpp).legacy_closed_enum = true; - -package protobuf_test_messages.proto2; - option java_package = "com.google.protobuf_test_messages.proto2"; option objc_class_prefix = "Proto2"; // This is the default, but we specify it here explicitly. option optimize_for = SPEED; - option cc_enable_arenas = true; // This proto includes every type of field in both singular and repeated @@ -47,7 +46,7 @@ message TestAllTypesProto2 { FOO = 0; BAR = 1; BAZ = 2; - NEG = -1; // Intentionally negative. + NEG = -1; // Intentionally negative. } // Singular @@ -66,15 +65,17 @@ message TestAllTypesProto2 { bool optional_bool = 13; string optional_string = 14; bytes optional_bytes = 15; - NestedMessage optional_nested_message = 18; ForeignMessageProto2 optional_foreign_message = 19; - NestedEnum optional_nested_enum = 21; ForeignEnumProto2 optional_foreign_enum = 22; + string optional_string_piece = 24 [ + ctype = STRING_PIECE + ]; - string optional_string_piece = 24 [ctype = STRING_PIECE]; - string optional_cord = 25 [ctype = CORD]; + string optional_cord = 25 [ + ctype = CORD + ]; TestAllTypesProto2 recursive_message = 27; @@ -94,31 +95,74 @@ message TestAllTypesProto2 { repeated bool repeated_bool = 43; repeated string repeated_string = 44; repeated bytes repeated_bytes = 45; - repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessageProto2 repeated_foreign_message = 49; - repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnumProto2 repeated_foreign_enum = 52; + repeated string repeated_string_piece = 54 [ + ctype = STRING_PIECE + ]; - repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; - repeated string repeated_cord = 55 [ctype = CORD]; + repeated string repeated_cord = 55 [ + ctype = CORD + ]; // Packed - repeated int32 packed_int32 = 75 [features.repeated_field_encoding = PACKED]; - repeated int64 packed_int64 = 76 [features.repeated_field_encoding = PACKED]; - repeated uint32 packed_uint32 = 77 [features.repeated_field_encoding = PACKED]; - repeated uint64 packed_uint64 = 78 [features.repeated_field_encoding = PACKED]; - repeated sint32 packed_sint32 = 79 [features.repeated_field_encoding = PACKED]; - repeated sint64 packed_sint64 = 80 [features.repeated_field_encoding = PACKED]; - repeated fixed32 packed_fixed32 = 81 [features.repeated_field_encoding = PACKED]; - repeated fixed64 packed_fixed64 = 82 [features.repeated_field_encoding = PACKED]; - repeated sfixed32 packed_sfixed32 = 83 [features.repeated_field_encoding = PACKED]; - repeated sfixed64 packed_sfixed64 = 84 [features.repeated_field_encoding = PACKED]; - repeated float packed_float = 85 [features.repeated_field_encoding = PACKED]; - repeated double packed_double = 86 [features.repeated_field_encoding = PACKED]; - repeated bool packed_bool = 87 [features.repeated_field_encoding = PACKED]; - repeated NestedEnum packed_nested_enum = 88 [features.repeated_field_encoding = PACKED]; + repeated int32 packed_int32 = 75 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int64 packed_int64 = 76 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint32 packed_uint32 = 77 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint64 packed_uint64 = 78 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint32 packed_sint32 = 79 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint64 packed_sint64 = 80 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed32 packed_fixed32 = 81 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed64 packed_fixed64 = 82 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed32 packed_sfixed32 = 83 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed64 packed_sfixed64 = 84 [ + features.repeated_field_encoding = PACKED + ]; + + repeated float packed_float = 85 [ + features.repeated_field_encoding = PACKED + ]; + + repeated double packed_double = 86 [ + features.repeated_field_encoding = PACKED + ]; + + repeated bool packed_bool = 87 [ + features.repeated_field_encoding = PACKED + ]; + + repeated NestedEnum packed_nested_enum = 88 [ + features.repeated_field_encoding = PACKED + ]; // Unpacked repeated int32 unpacked_int32 = 89; @@ -177,24 +221,71 @@ message TestAllTypesProto2 { int32 group_int32 = 202; uint32 group_uint32 = 203; } - Data data = 201 [features.message_encoding = DELIMITED]; + + Data data = 201 [ + features.message_encoding = DELIMITED + ]; // default values - int32 default_int32 = 241 [default = -123456789]; - int64 default_int64 = 242 [default = -9123456789123456789]; - uint32 default_uint32 = 243 [default = 2123456789]; - uint64 default_uint64 = 244 [default = 10123456789123456789]; - sint32 default_sint32 = 245 [default = -123456789]; - sint64 default_sint64 = 246 [default = -9123456789123456789]; - fixed32 default_fixed32 = 247 [default = 2123456789]; - fixed64 default_fixed64 = 248 [default = 10123456789123456789]; - sfixed32 default_sfixed32 = 249 [default = -123456789]; - sfixed64 default_sfixed64 = 250 [default = -9123456789123456789]; - float default_float = 251 [default = 9e9]; - double default_double = 252 [default = 7e22]; - bool default_bool = 253 [default = true]; - string default_string = 254 [default = "Rosebud"]; - bytes default_bytes = 255 [default = "joshua"]; + int32 default_int32 = 241 [ + default = -123456789 + ]; + + int64 default_int64 = 242 [ + default = -9123456789123456789 + ]; + + uint32 default_uint32 = 243 [ + default = 2123456789 + ]; + + uint64 default_uint64 = 244 [ + default = 10123456789123456789 + ]; + + sint32 default_sint32 = 245 [ + default = -123456789 + ]; + + sint64 default_sint64 = 246 [ + default = -9123456789123456789 + ]; + + fixed32 default_fixed32 = 247 [ + default = 2123456789 + ]; + + fixed64 default_fixed64 = 248 [ + default = 10123456789123456789 + ]; + + sfixed32 default_sfixed32 = 249 [ + default = -123456789 + ]; + + sfixed64 default_sfixed64 = 250 [ + default = -9123456789123456789 + ]; + + float default_float = 251 [ + default = 9.0E9 + ]; + + double default_double = 252 [ + default = 7.0E22 + ]; + + bool default_bool = 253 [ + default = true + ]; + + string default_string = 254 [ + default = "Rosebud" + ]; + + bytes default_bytes = 255 [ + default = "joshua" + ]; // Test field-name-to-JSON-name convention. // (protobuf says names can be any valid C/C++ identifier.) @@ -231,6 +322,7 @@ message TestAllTypesProto2 { extend MessageSetCorrect { MessageSetCorrectExtension1 message_set_extension = 1547769; } + string str = 25; } @@ -238,6 +330,7 @@ message TestAllTypesProto2 { extend MessageSetCorrect { MessageSetCorrectExtension2 message_set_extension = 4135312; } + int32 i = 9; } } @@ -260,15 +353,21 @@ message UnknownToTestAllTypes { int32 optional_int32 = 1001; string optional_string = 1002; ForeignMessageProto2 nested_message = 1003; + message OptionalGroup { int32 a = 1; } - OptionalGroup optionalgroup = 1004 [features.message_encoding = DELIMITED]; + + OptionalGroup optionalgroup = 1004 [ + features.message_encoding = DELIMITED + ]; + bool optional_bool = 1006; repeated int32 repeated_int32 = 1011; } -message NullHypothesisProto2 {} +message NullHypothesisProto2 { +} message EnumOnlyProto2 { enum Bool { @@ -289,8 +388,14 @@ message ProtoWithKeywords { message TestAllRequiredTypesProto2 { message NestedMessage { - int32 a = 1 [features.field_presence = LEGACY_REQUIRED]; - TestAllRequiredTypesProto2 corecursive = 2 [features.field_presence = LEGACY_REQUIRED]; + int32 a = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; + + TestAllRequiredTypesProto2 corecursive = 2 [ + features.field_presence = LEGACY_REQUIRED + ]; + TestAllRequiredTypesProto2 optional_corecursive = 3; } @@ -298,36 +403,100 @@ message TestAllRequiredTypesProto2 { FOO = 0; BAR = 1; BAZ = 2; - NEG = -1; // Intentionally negative. + NEG = -1; // Intentionally negative. } // Singular - int32 required_int32 = 1 [features.field_presence = LEGACY_REQUIRED]; - int64 required_int64 = 2 [features.field_presence = LEGACY_REQUIRED]; - uint32 required_uint32 = 3 [features.field_presence = LEGACY_REQUIRED]; - uint64 required_uint64 = 4 [features.field_presence = LEGACY_REQUIRED]; - sint32 required_sint32 = 5 [features.field_presence = LEGACY_REQUIRED]; - sint64 required_sint64 = 6 [features.field_presence = LEGACY_REQUIRED]; - fixed32 required_fixed32 = 7 [features.field_presence = LEGACY_REQUIRED]; - fixed64 required_fixed64 = 8 [features.field_presence = LEGACY_REQUIRED]; - sfixed32 required_sfixed32 = 9 [features.field_presence = LEGACY_REQUIRED]; - sfixed64 required_sfixed64 = 10 [features.field_presence = LEGACY_REQUIRED]; - float required_float = 11 [features.field_presence = LEGACY_REQUIRED]; - double required_double = 12 [features.field_presence = LEGACY_REQUIRED]; - bool required_bool = 13 [features.field_presence = LEGACY_REQUIRED]; - string required_string = 14 [features.field_presence = LEGACY_REQUIRED]; - bytes required_bytes = 15 [features.field_presence = LEGACY_REQUIRED]; - - NestedMessage required_nested_message = 18 [features.field_presence = LEGACY_REQUIRED]; - ForeignMessageProto2 required_foreign_message = 19 [features.field_presence = LEGACY_REQUIRED]; - - NestedEnum required_nested_enum = 21 [features.field_presence = LEGACY_REQUIRED]; - ForeignEnumProto2 required_foreign_enum = 22 [features.field_presence = LEGACY_REQUIRED]; - - string required_string_piece = 24 [ctype = STRING_PIECE, features.field_presence = LEGACY_REQUIRED]; - string required_cord = 25 [ctype = CORD, features.field_presence = LEGACY_REQUIRED]; - - TestAllRequiredTypesProto2 recursive_message = 27 [features.field_presence = LEGACY_REQUIRED]; + int32 required_int32 = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; + + int64 required_int64 = 2 [ + features.field_presence = LEGACY_REQUIRED + ]; + + uint32 required_uint32 = 3 [ + features.field_presence = LEGACY_REQUIRED + ]; + + uint64 required_uint64 = 4 [ + features.field_presence = LEGACY_REQUIRED + ]; + + sint32 required_sint32 = 5 [ + features.field_presence = LEGACY_REQUIRED + ]; + + sint64 required_sint64 = 6 [ + features.field_presence = LEGACY_REQUIRED + ]; + + fixed32 required_fixed32 = 7 [ + features.field_presence = LEGACY_REQUIRED + ]; + + fixed64 required_fixed64 = 8 [ + features.field_presence = LEGACY_REQUIRED + ]; + + sfixed32 required_sfixed32 = 9 [ + features.field_presence = LEGACY_REQUIRED + ]; + + sfixed64 required_sfixed64 = 10 [ + features.field_presence = LEGACY_REQUIRED + ]; + + float required_float = 11 [ + features.field_presence = LEGACY_REQUIRED + ]; + + double required_double = 12 [ + features.field_presence = LEGACY_REQUIRED + ]; + + bool required_bool = 13 [ + features.field_presence = LEGACY_REQUIRED + ]; + + string required_string = 14 [ + features.field_presence = LEGACY_REQUIRED + ]; + + bytes required_bytes = 15 [ + features.field_presence = LEGACY_REQUIRED + ]; + + NestedMessage required_nested_message = 18 [ + features.field_presence = LEGACY_REQUIRED + ]; + + ForeignMessageProto2 required_foreign_message = 19 [ + features.field_presence = LEGACY_REQUIRED + ]; + + NestedEnum required_nested_enum = 21 [ + features.field_presence = LEGACY_REQUIRED + ]; + + ForeignEnumProto2 required_foreign_enum = 22 [ + features.field_presence = LEGACY_REQUIRED + ]; + + string required_string_piece = 24 [ + features.field_presence = LEGACY_REQUIRED, + ctype = STRING_PIECE + ]; + + string required_cord = 25 [ + features.field_presence = LEGACY_REQUIRED, + ctype = CORD + ]; + + TestAllRequiredTypesProto2 recursive_message = 27 [ + features.field_presence = LEGACY_REQUIRED + ]; + TestAllRequiredTypesProto2 optional_recursive_message = 28; // extensions @@ -335,27 +504,95 @@ message TestAllRequiredTypesProto2 { // groups message Data { - int32 group_int32 = 202 [features.field_presence = LEGACY_REQUIRED]; - uint32 group_uint32 = 203 [features.field_presence = LEGACY_REQUIRED]; + int32 group_int32 = 202 [ + features.field_presence = LEGACY_REQUIRED + ]; + + uint32 group_uint32 = 203 [ + features.field_presence = LEGACY_REQUIRED + ]; } - Data data = 201 [features.message_encoding = DELIMITED, features.field_presence = LEGACY_REQUIRED]; + + Data data = 201 [ + features.field_presence = LEGACY_REQUIRED, + features.message_encoding = DELIMITED + ]; // default values - int32 default_int32 = 241 [default = -123456789, features.field_presence = LEGACY_REQUIRED]; - int64 default_int64 = 242 [default = -9123456789123456789, features.field_presence = LEGACY_REQUIRED]; - uint32 default_uint32 = 243 [default = 2123456789, features.field_presence = LEGACY_REQUIRED]; - uint64 default_uint64 = 244 [default = 10123456789123456789, features.field_presence = LEGACY_REQUIRED]; - sint32 default_sint32 = 245 [default = -123456789, features.field_presence = LEGACY_REQUIRED]; - sint64 default_sint64 = 246 [default = -9123456789123456789, features.field_presence = LEGACY_REQUIRED]; - fixed32 default_fixed32 = 247 [default = 2123456789, features.field_presence = LEGACY_REQUIRED]; - fixed64 default_fixed64 = 248 [default = 10123456789123456789, features.field_presence = LEGACY_REQUIRED]; - sfixed32 default_sfixed32 = 249 [default = -123456789, features.field_presence = LEGACY_REQUIRED]; - sfixed64 default_sfixed64 = 250 [default = -9123456789123456789, features.field_presence = LEGACY_REQUIRED]; - float default_float = 251 [default = 9e9, features.field_presence = LEGACY_REQUIRED]; - double default_double = 252 [default = 7e22, features.field_presence = LEGACY_REQUIRED]; - bool default_bool = 253 [default = true, features.field_presence = LEGACY_REQUIRED]; - string default_string = 254 [default = "Rosebud", features.field_presence = LEGACY_REQUIRED]; - bytes default_bytes = 255 [default = "joshua", features.field_presence = LEGACY_REQUIRED]; + int32 default_int32 = 241 [ + features.field_presence = LEGACY_REQUIRED, + default = -123456789 + ]; + + int64 default_int64 = 242 [ + features.field_presence = LEGACY_REQUIRED, + default = -9123456789123456789 + ]; + + uint32 default_uint32 = 243 [ + features.field_presence = LEGACY_REQUIRED, + default = 2123456789 + ]; + + uint64 default_uint64 = 244 [ + features.field_presence = LEGACY_REQUIRED, + default = 10123456789123456789 + ]; + + sint32 default_sint32 = 245 [ + features.field_presence = LEGACY_REQUIRED, + default = -123456789 + ]; + + sint64 default_sint64 = 246 [ + features.field_presence = LEGACY_REQUIRED, + default = -9123456789123456789 + ]; + + fixed32 default_fixed32 = 247 [ + features.field_presence = LEGACY_REQUIRED, + default = 2123456789 + ]; + + fixed64 default_fixed64 = 248 [ + features.field_presence = LEGACY_REQUIRED, + default = 10123456789123456789 + ]; + + sfixed32 default_sfixed32 = 249 [ + features.field_presence = LEGACY_REQUIRED, + default = -123456789 + ]; + + sfixed64 default_sfixed64 = 250 [ + features.field_presence = LEGACY_REQUIRED, + default = -9123456789123456789 + ]; + + float default_float = 251 [ + features.field_presence = LEGACY_REQUIRED, + default = 9.0E9 + ]; + + double default_double = 252 [ + features.field_presence = LEGACY_REQUIRED, + default = 7.0E22 + ]; + + bool default_bool = 253 [ + features.field_presence = LEGACY_REQUIRED, + default = true + ]; + + string default_string = 254 [ + features.field_presence = LEGACY_REQUIRED, + default = "Rosebud" + ]; + + bytes default_bytes = 255 [ + features.field_presence = LEGACY_REQUIRED, + default = "joshua" + ]; // Reserved for unknown fields test. reserved 1000 to 9999; @@ -371,13 +608,19 @@ message TestAllRequiredTypesProto2 { extend MessageSetCorrect { MessageSetCorrectExtension1 message_set_extension = 1547769; } - string str = 25 [features.field_presence = LEGACY_REQUIRED]; + + string str = 25 [ + features.field_presence = LEGACY_REQUIRED + ]; } message MessageSetCorrectExtension2 { extend MessageSetCorrect { MessageSetCorrectExtension2 message_set_extension = 4135312; } - int32 i = 9 [features.field_presence = LEGACY_REQUIRED]; + + int32 i = 9 [ + features.field_presence = LEGACY_REQUIRED + ]; } } diff --git a/src/google/protobuf/editions/golden/test_messages_proto3.proto b/src/google/protobuf/editions/golden/test_messages_proto3.proto index a5a5fd478e..be9ca144e4 100644 --- a/src/google/protobuf/editions/golden/test_messages_proto3.proto +++ b/src/google/protobuf/editions/golden/test_messages_proto3.proto @@ -10,19 +10,11 @@ // - benchmarks // - fuzz tests // - conformance tests -// edition = "2023"; -option features.field_presence = IMPLICIT; package protobuf_test_messages.proto3; -option java_package = "com.google.protobuf_test_messages.proto3"; -option objc_class_prefix = "Proto3"; - -// This is the default, but we specify it here explicitly. -option optimize_for = SPEED; - import "google/protobuf/any.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/field_mask.proto"; @@ -30,6 +22,12 @@ import "google/protobuf/struct.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/wrappers.proto"; +option features.field_presence = IMPLICIT; +option java_package = "com.google.protobuf_test_messages.proto3"; +option objc_class_prefix = "Proto3"; + +// This is the default, but we specify it here explicitly. +option optimize_for = SPEED; option cc_enable_arenas = true; // This proto includes every type of field in both singular and repeated @@ -49,7 +47,7 @@ message TestAllTypesProto3 { FOO = 0; BAR = 1; BAZ = 2; - NEG = -1; // Intentionally negative. + NEG = -1; // Intentionally negative. } enum AliasedEnum { @@ -79,16 +77,18 @@ message TestAllTypesProto3 { bool optional_bool = 13; string optional_string = 14; bytes optional_bytes = 15; - NestedMessage optional_nested_message = 18; ForeignMessage optional_foreign_message = 19; - NestedEnum optional_nested_enum = 21; ForeignEnum optional_foreign_enum = 22; AliasedEnum optional_aliased_enum = 23; + string optional_string_piece = 24 [ + ctype = STRING_PIECE + ]; - string optional_string_piece = 24 [ctype = STRING_PIECE]; - string optional_cord = 25 [ctype = CORD]; + string optional_cord = 25 [ + ctype = CORD + ]; TestAllTypesProto3 recursive_message = 27; @@ -108,15 +108,17 @@ message TestAllTypesProto3 { repeated bool repeated_bool = 43; repeated string repeated_string = 44; repeated bytes repeated_bytes = 45; - repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessage repeated_foreign_message = 49; - repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnum repeated_foreign_enum = 52; + repeated string repeated_string_piece = 54 [ + ctype = STRING_PIECE + ]; - repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; - repeated string repeated_cord = 55 [ctype = CORD]; + repeated string repeated_cord = 55 [ + ctype = CORD + ]; // Packed repeated int32 packed_int32 = 75; @@ -135,20 +137,61 @@ message TestAllTypesProto3 { repeated NestedEnum packed_nested_enum = 88; // Unpacked - repeated int32 unpacked_int32 = 89 [features.repeated_field_encoding = EXPANDED]; - repeated int64 unpacked_int64 = 90 [features.repeated_field_encoding = EXPANDED]; - repeated uint32 unpacked_uint32 = 91 [features.repeated_field_encoding = EXPANDED]; - repeated uint64 unpacked_uint64 = 92 [features.repeated_field_encoding = EXPANDED]; - repeated sint32 unpacked_sint32 = 93 [features.repeated_field_encoding = EXPANDED]; - repeated sint64 unpacked_sint64 = 94 [features.repeated_field_encoding = EXPANDED]; - repeated fixed32 unpacked_fixed32 = 95 [features.repeated_field_encoding = EXPANDED]; - repeated fixed64 unpacked_fixed64 = 96 [features.repeated_field_encoding = EXPANDED]; - repeated sfixed32 unpacked_sfixed32 = 97 [features.repeated_field_encoding = EXPANDED]; - repeated sfixed64 unpacked_sfixed64 = 98 [features.repeated_field_encoding = EXPANDED]; - repeated float unpacked_float = 99 [features.repeated_field_encoding = EXPANDED]; - repeated double unpacked_double = 100 [features.repeated_field_encoding = EXPANDED]; - repeated bool unpacked_bool = 101 [features.repeated_field_encoding = EXPANDED]; - repeated NestedEnum unpacked_nested_enum = 102 [features.repeated_field_encoding = EXPANDED]; + repeated int32 unpacked_int32 = 89 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated int64 unpacked_int64 = 90 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated uint32 unpacked_uint32 = 91 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated uint64 unpacked_uint64 = 92 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated sint32 unpacked_sint32 = 93 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated sint64 unpacked_sint64 = 94 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated fixed32 unpacked_fixed32 = 95 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated fixed64 unpacked_fixed64 = 96 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated sfixed32 unpacked_sfixed32 = 97 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated sfixed64 unpacked_sfixed64 = 98 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated float unpacked_float = 99 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated double unpacked_double = 100 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated bool unpacked_bool = 101 [ + features.repeated_field_encoding = EXPANDED + ]; + + repeated NestedEnum unpacked_nested_enum = 102 [ + features.repeated_field_encoding = EXPANDED + ]; // Map map map_int32_int32 = 56; @@ -194,7 +237,6 @@ message TestAllTypesProto3 { google.protobuf.DoubleValue optional_double_wrapper = 207; google.protobuf.StringValue optional_string_wrapper = 208; google.protobuf.BytesValue optional_bytes_wrapper = 209; - repeated google.protobuf.BoolValue repeated_bool_wrapper = 211; repeated google.protobuf.Int32Value repeated_int32_wrapper = 212; repeated google.protobuf.Int64Value repeated_int64_wrapper = 213; @@ -204,7 +246,6 @@ message TestAllTypesProto3 { repeated google.protobuf.DoubleValue repeated_double_wrapper = 217; repeated google.protobuf.StringValue repeated_string_wrapper = 218; repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219; - google.protobuf.Duration optional_duration = 301; google.protobuf.Timestamp optional_timestamp = 302; google.protobuf.FieldMask optional_field_mask = 303; @@ -212,7 +253,6 @@ message TestAllTypesProto3 { google.protobuf.Any optional_any = 305; google.protobuf.Value optional_value = 306; google.protobuf.NullValue optional_null_value = 307; - repeated google.protobuf.Duration repeated_duration = 311; repeated google.protobuf.Timestamp repeated_timestamp = 312; repeated google.protobuf.FieldMask repeated_fieldmask = 313; @@ -256,7 +296,8 @@ enum ForeignEnum { FOREIGN_BAZ = 2; } -message NullHypothesisProto3 {} +message NullHypothesisProto3 { +} message EnumOnlyProto3 { enum Bool { diff --git a/src/google/protobuf/editions/transform.awk b/src/google/protobuf/editions/transform.awk deleted file mode 100644 index 945ac98c1d..0000000000 --- a/src/google/protobuf/editions/transform.awk +++ /dev/null @@ -1,187 +0,0 @@ -# Protocol Buffers - Google's data interchange format -# Copyright 2023 Google Inc. All rights reserved. -# https://developers.google.com/protocol-buffers/ -# -# 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. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# 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. - -noop = 0 - -function join(array, len, sep) -{ - if(len== 0) { - return "" - } - result = array[1] - for (i = 2; i <= len; i++) - result = result sep array[i] - return result -} - -function strip_option(option, options_list) -{ - # First try to strip out matching commas - sub("\\<" option "\\s*,", "", options_list) - sub(",\\s*" option "\\>", "", options_list) - # Fallback to just stripping the option - sub(option, "", options_list) - return options_list -} - -function transform_field(field) -{ - if (!match(field, /\w+\s*=\s*[0-9-]+/)) { - return field - } - if (match(field, /(.*[0-9])\s*\[(.*)\];(.*)/, arr)) { - field_def = arr[1] - existing_options = arr[2] - field_comments = arr[3] - } else { - match(field, /(.*);(.*)/, arr) - field_def = arr[1] - field_comments = arr[2] - existing_options = 0 - } - num_options = 0 - - if(syntax == 2) { - sub(/\/, "features.repeated_field_encoding = PACKED", existing_options) - existing_options = strip_option("packed = false", existing_options) - if (match(field_def, /^\s*required\>/)) { - sub(/\/, "features.repeated_field_encoding = EXPANDED", existing_options) - existing_options = strip_option("packed = true", existing_options) - if (match($0, /\/)) { - sub(/\ 0) { - ret = field_def " [" existing_options ", " join(options, num_options, ",") "];" field_comments - } else if (existing_options) { - ret = field_def " [" existing_options "];" field_comments - } else if(num_options > 0) { - ret = field_def " [" join(options, num_options, ",") "];" field_comments - } else { - ret = field_def ";" field_comments - } - delete options - return ret -} - -# Skip comments -/^\s*\/\// { - print $0 - next -} - -/syntax = "proto2"/ { - print "edition = \"2023\";" - print "import \"third_party/protobuf/cpp_features.proto\";" - print "option features.enum_type = CLOSED;" - print "option features.repeated_field_encoding = EXPANDED;" - print "option features.utf8_validation = UNVERIFIED;" - print "option features.json_format = LEGACY_BEST_EFFORT;" - print "option features.(pb.cpp).legacy_closed_enum = true;" - syntax = 2 - next -} - -/syntax = "proto3"/ { - print "edition = \"2023\";" - print "option features.field_presence = IMPLICIT;" - syntax = 3 - next -} - -# Group handling. -/\/)) { - match($0, /(\s*)(\w*)\s*group\s*(\w*)\s*=\s*([0-9]*)\s*{(\s*[^}]*}?)/, arr) - if (arr[0, "length"] == 0) { - print("[ERROR] Invalid group match: ", $0) - exit - } - current_group_whitespace = arr[1] - current_group_presence = arr[2] - current_group_name = arr[3] - current_group_number = arr[4] - current_group_extra = transform_field(arr[5]) - - print current_group_whitespace "message", current_group_name, "{" current_group_extra - } else if (match($0, /}/)) { - print $0 - } - if (match($0, /}/)) { - $0 = current_group_whitespace current_group_presence " " current_group_name " " tolower(current_group_name) " = " current_group_number " [features.message_encoding = DELIMITED];" - } else if (match($0, /\/)) { - next - } -} - -# Skip declarations we don't transform. -/^\s*(message|enum|oneof|extend|service)\s+(\w|\.)*\s*{/ { - noop = 1 -} -/^\s*rpc\s+\w*\s*\(/ { - noop = 1 -} -/^\s*(}|\/\/|$)/ { - noop = 1 -} -/^\s*(extensions|package|reserved|import) .*;/ { - noop = 1 -} -/^\s*option\s+[a-zA-Z0-9._()]*\s*=.*;/ { - noop = 1 -} -/\s*extensions.* \[/, /\]/ { - noop = 1 -} -noop { - print $0 - next -} - -/./, /;/ { - if (buffered_field != "") { - sub(/\s+/, " ", $0) - } - buffered_field = (buffered_field $0) - if (!match($0, /;/)) { - next - } - print(transform_field(buffered_field)) - buffered_field = "" -}