From 4c923285a32ebcb53ce2ba03144e50d4dbedaf7b Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 17 Sep 2024 18:35:19 -0700 Subject: [PATCH] Fix packed reflection handling bug in edition 2023. This is a very narrow edge case where touching a packed extension via generated APIs first, and then doing so reflectively will trigger a DCHECK. Otherwise, reflective APIs will work but not use packed encoding for the extension. This was likely a pre-existing bug dating back to proto3, where it would only be visible on custom options (the only extensions allowed in proto3). To help qualify this and uncover similar issues, unittest.proto was migrated to editions. This turned up some other minor issues in DebugString and python. PiperOrigin-RevId: 675785611 --- compatibility/BUILD.bazel | 6 - .../com/google/protobuf/DescriptorsTest.java | 125 +- python/descriptor.c | 6 + .../protobuf/internal/descriptor_test.py | 7 +- .../google/protobuf/internal/message_test.py | 22 +- .../protobuf/internal/reflection_test.py | 4 +- python/google/protobuf/pyext/descriptor.cc | 5 + .../protobuf/compiler/cpp/file_unittest.cc | 2 + src/google/protobuf/descriptor.cc | 12 +- src/google/protobuf/descriptor_unittest.cc | 53 + .../protobuf/dynamic_message_unittest.cc | 23 + src/google/protobuf/extension_set_unittest.cc | 3 + .../protobuf/generated_message_reflection.cc | 3 +- .../generated_message_reflection_unittest.cc | 43 + src/google/protobuf/test_util.inc | 38 + src/google/protobuf/unittest.proto | 2316 +++++++++++------ 16 files changed, 1822 insertions(+), 846 deletions(-) diff --git a/compatibility/BUILD.bazel b/compatibility/BUILD.bazel index e4d96c41d8d23..82c8b919cb53a 100644 --- a/compatibility/BUILD.bazel +++ b/compatibility/BUILD.bazel @@ -33,12 +33,6 @@ java_runtime_conformance( gencode_version = "main", ) -# Generates a build_test named "conformance_v3.25.0" -java_runtime_conformance( - name = "java_conformance_v3.25.0", - gencode_version = "3.25.0", -) - # Breaking change detection for well-known types and descriptor.proto. buf_breaking_test( name = "any_proto_breaking", diff --git a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 09cab291e7170..903e1158d548d 100644 --- a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -19,6 +19,7 @@ import com.google.protobuf.DescriptorProtos.FeatureSetDefaults; import com.google.protobuf.DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault; import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; +import com.google.protobuf.DescriptorProtos.FieldOptions; import com.google.protobuf.DescriptorProtos.FileDescriptorProto; import com.google.protobuf.DescriptorProtos.FileOptions; import com.google.protobuf.DescriptorProtos.MethodDescriptorProto; @@ -53,7 +54,6 @@ import protobuf_unittest.UnittestProto.TestReservedFields; import protobuf_unittest.UnittestProto.TestService; import protobuf_unittest.UnittestRetention; -import proto3_unittest.UnittestProto3; import protobuf_unittest.UnittestProto3Extensions.Proto3FileExtensions; import java.util.Collections; import java.util.List; @@ -1256,32 +1256,106 @@ public void testLegacyGroupTransform() { } @Test - public void testLegacyInferRequired() { - FieldDescriptor field = UnittestProto.TestRequired.getDescriptor().findFieldByName("a"); + public void testLegacyInferRequired() throws Exception { + FileDescriptor file = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setSyntax("proto2") + .addMessageType( + DescriptorProto.newBuilder() + .setName("Foo") + .addField( + FieldDescriptorProto.newBuilder() + .setName("a") + .setNumber(1) + .setType(FieldDescriptorProto.Type.TYPE_INT32) + .setLabel(FieldDescriptorProto.Label.LABEL_REQUIRED) + .build()) + .build()) + .build(), + new FileDescriptor[0]); + FieldDescriptor field = file.findMessageTypeByName("Foo").findFieldByName("a"); assertThat(field.features.getFieldPresence()) .isEqualTo(DescriptorProtos.FeatureSet.FieldPresence.LEGACY_REQUIRED); } @Test - public void testLegacyInferGroup() { - FieldDescriptor field = - UnittestProto.TestAllTypes.getDescriptor().findFieldByName("optionalgroup"); + public void testLegacyInferGroup() throws Exception { + FileDescriptor file = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setSyntax("proto2") + .addMessageType( + DescriptorProto.newBuilder() + .setName("Foo") + .addNestedType( + DescriptorProto.newBuilder().setName("OptionalGroup").build()) + .addField( + FieldDescriptorProto.newBuilder() + .setName("optionalgroup") + .setNumber(1) + .setType(FieldDescriptorProto.Type.TYPE_GROUP) + .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) + .setTypeName("Foo.OptionalGroup") + .build()) + .build()) + .build(), + new FileDescriptor[0]); + FieldDescriptor field = file.findMessageTypeByName("Foo").findFieldByName("optionalgroup"); assertThat(field.features.getMessageEncoding()) .isEqualTo(DescriptorProtos.FeatureSet.MessageEncoding.DELIMITED); } @Test - public void testLegacyInferProto2Packed() { - FieldDescriptor field = - UnittestProto.TestPackedTypes.getDescriptor().findFieldByName("packed_int32"); + public void testLegacyInferProto2Packed() throws Exception { + FileDescriptor file = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setSyntax("proto2") + .addMessageType( + DescriptorProto.newBuilder() + .setName("Foo") + .addField( + FieldDescriptorProto.newBuilder() + .setName("a") + .setNumber(1) + .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED) + .setType(FieldDescriptorProto.Type.TYPE_INT32) + .setOptions(FieldOptions.newBuilder().setPacked(true).build()) + .build()) + .build()) + .build(), + new FileDescriptor[0]); + FieldDescriptor field = file.findMessageTypeByName("Foo").findFieldByName("a"); assertThat(field.features.getRepeatedFieldEncoding()) .isEqualTo(DescriptorProtos.FeatureSet.RepeatedFieldEncoding.PACKED); } @Test - public void testLegacyInferProto3Expanded() { - FieldDescriptor field = - UnittestProto3.TestUnpackedTypes.getDescriptor().findFieldByName("repeated_int32"); + public void testLegacyInferProto3Expanded() throws Exception { + FileDescriptor file = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setSyntax("proto3") + .addMessageType( + DescriptorProto.newBuilder() + .setName("Foo") + .addField( + FieldDescriptorProto.newBuilder() + .setName("a") + .setNumber(1) + .setType(FieldDescriptorProto.Type.TYPE_INT32) + .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED) + .setOptions(FieldOptions.newBuilder().setPacked(false).build()) + .build()) + .build()) + .build(), + new FileDescriptor[0]); + FieldDescriptor field = file.findMessageTypeByName("Foo").findFieldByName("a"); assertThat(field.features.getRepeatedFieldEncoding()) .isEqualTo(DescriptorProtos.FeatureSet.RepeatedFieldEncoding.EXPANDED); } @@ -1302,9 +1376,16 @@ public void testLegacyInferProto2Utf8Validation() throws Exception { } @Test - public void testProto2Defaults() { - FieldDescriptor proto2Field = TestAllTypes.getDescriptor().findFieldByName("optional_int32"); - DescriptorProtos.FeatureSet features = proto2Field.features; + public void testProto2Defaults() throws Exception { + FileDescriptor proto2File = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setPackage("protobuf_unittest") + .setSyntax("proto2") + .build(), + new FileDescriptor[0]); + DescriptorProtos.FeatureSet features = proto2File.features; assertThat(features.getFieldPresence()) .isEqualTo(DescriptorProtos.FeatureSet.FieldPresence.EXPLICIT); assertThat(features.getEnumType()).isEqualTo(DescriptorProtos.FeatureSet.EnumType.CLOSED); @@ -1323,10 +1404,16 @@ public void testProto2Defaults() { } @Test - public void testProto3Defaults() { - FieldDescriptor proto3Field = - UnittestProto3.TestAllTypes.getDescriptor().findFieldByName("optional_int32"); - DescriptorProtos.FeatureSet features = proto3Field.features; + public void testProto3Defaults() throws Exception { + FileDescriptor proto3File = + FileDescriptor.buildFrom( + FileDescriptorProto.newBuilder() + .setName("some/filename/some.proto") + .setPackage("proto3_unittest") + .setSyntax("proto3") + .build(), + new FileDescriptor[0]); + DescriptorProtos.FeatureSet features = proto3File.features; assertThat(features.getFieldPresence()) .isEqualTo(DescriptorProtos.FeatureSet.FieldPresence.IMPLICIT); assertThat(features.getEnumType()).isEqualTo(DescriptorProtos.FeatureSet.EnumType.OPEN); diff --git a/python/descriptor.c b/python/descriptor.c index 7e121c40433ec..ebd384e929a3e 100644 --- a/python/descriptor.c +++ b/python/descriptor.c @@ -1062,6 +1062,11 @@ static PyObject* PyUpb_FieldDescriptor_GetIsExtension( return PyBool_FromLong(upb_FieldDef_IsExtension(self->def)); } +static PyObject* PyUpb_FieldDescriptor_GetIsPacked(PyUpb_DescriptorBase* self, + void* closure) { + return PyBool_FromLong(upb_FieldDef_IsPacked(self->def)); +} + static PyObject* PyUpb_FieldDescriptor_GetNumber(PyUpb_DescriptorBase* self, void* closure) { return PyLong_FromLong(upb_FieldDef_Number(self->def)); @@ -1164,6 +1169,7 @@ static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = { "Default Value"}, {"has_default_value", (getter)PyUpb_FieldDescriptor_HasDefaultValue}, {"is_extension", (getter)PyUpb_FieldDescriptor_GetIsExtension, NULL, "ID"}, + {"is_packed", (getter)PyUpb_FieldDescriptor_GetIsPacked, NULL, "Is Packed"}, // TODO //{ "id", (getter)GetID, NULL, "ID"}, {"message_type", (getter)PyUpb_FieldDescriptor_GetMessageType, NULL, diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 02361195a620a..9ca3c8c2fe860 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -18,17 +18,18 @@ from google.protobuf import symbol_database from google.protobuf import text_format from google.protobuf.internal import api_implementation +from google.protobuf.internal import test_proto2_pb2 from google.protobuf.internal import test_util from google.protobuf.internal import testing_refleaks from google.protobuf.internal import _parameterized -from google.protobuf import unittest_legacy_features_pb2 from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_features_pb2 from google.protobuf import unittest_import_pb2 +from google.protobuf import unittest_legacy_features_pb2 from google.protobuf import unittest_pb2 -from google.protobuf import unittest_proto3_pb2 from google.protobuf import unittest_proto3_extensions_pb2 +from google.protobuf import unittest_proto3_pb2 TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII = """ @@ -1325,7 +1326,7 @@ def testLegacyInferProto3Expanded(self): ) def testProto2Defaults(self): - features = unittest_pb2.TestAllTypes.DESCRIPTOR.fields_by_name[ + features = test_proto2_pb2.TestProto2.DESCRIPTOR.fields_by_name[ 'optional_int32' ]._GetFeatures() fs = descriptor_pb2.FeatureSet diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 2326ed9687fd0..2a723eabb0c49 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -1408,18 +1408,20 @@ def testDel(self): del msg.repeated_nested_message def testAssignInvalidEnum(self): - """Assigning an invalid enum number is not allowed in proto2.""" + """Assigning an invalid enum number is not allowed for closed enums.""" m = unittest_pb2.TestAllTypes() - # Proto2 can not assign unknown enum. - with self.assertRaises(ValueError) as _: - m.optional_nested_enum = 1234567 - self.assertRaises(ValueError, m.repeated_nested_enum.append, 1234567) - # Assignment is a different code path than append for the C++ impl. - m.repeated_nested_enum.append(2) - m.repeated_nested_enum[0] = 2 - with self.assertRaises(ValueError): - m.repeated_nested_enum[0] = 123456 + # TODO Enable these once upb's behavior is made conformant. + if api_implementation.Type() != 'upb': + # Can not assign unknown enum to closed enums. + with self.assertRaises(ValueError) as _: + m.optional_nested_enum = 1234567 + self.assertRaises(ValueError, m.repeated_nested_enum.append, 1234567) + # Assignment is a different code path than append for the C++ impl. + m.repeated_nested_enum.append(2) + m.repeated_nested_enum[0] = 2 + with self.assertRaises(ValueError): + m.repeated_nested_enum[0] = 123456 # Unknown enum value can be parsed but is ignored. m2 = unittest_proto3_arena_pb2.TestAllTypes() diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 40726440342ba..db8eaa1b44caa 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -3261,13 +3261,13 @@ def testPackedOptions(self): proto.optional_int32 = 1 proto.optional_double = 3.0 for field_descriptor, _ in proto.ListFields(): - self.assertEqual(False, field_descriptor.GetOptions().packed) + self.assertEqual(False, field_descriptor.is_packed) proto = unittest_pb2.TestPackedTypes() proto.packed_int32.append(1) proto.packed_double.append(3.0) for field_descriptor, _ in proto.ListFields(): - self.assertEqual(True, field_descriptor.GetOptions().packed) + self.assertEqual(True, field_descriptor.is_packed) self.assertEqual(descriptor.FieldDescriptor.LABEL_REPEATED, field_descriptor.label) diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 323a8d3ad19c1..c4b9f5e2dda5a 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -853,6 +853,10 @@ static PyObject* IsExtension(PyBaseDescriptor *self, void *closure) { return PyBool_FromLong(_GetDescriptor(self)->is_extension()); } +static PyObject* IsPacked(PyBaseDescriptor* self, void* closure) { + return PyBool_FromLong(_GetDescriptor(self)->is_packed()); +} + static PyObject* HasDefaultValue(PyBaseDescriptor *self, void *closure) { return PyBool_FromLong(_GetDescriptor(self)->has_default_value()); } @@ -1050,6 +1054,7 @@ static PyGetSetDef Getters[] = { {"default_value", (getter)GetDefaultValue, nullptr, "Default Value"}, {"has_default_value", (getter)HasDefaultValue}, {"is_extension", (getter)IsExtension, nullptr, "ID"}, + {"is_packed", (getter)IsPacked, nullptr, "Is Packed"}, {"id", (getter)GetID, nullptr, "ID"}, {"_cdescriptor", (getter)GetCDescriptor, nullptr, "HAACK REMOVE ME"}, diff --git a/src/google/protobuf/compiler/cpp/file_unittest.cc b/src/google/protobuf/compiler/cpp/file_unittest.cc index e667736538d42..f7cec1d2d9ba0 100644 --- a/src/google/protobuf/compiler/cpp/file_unittest.cc +++ b/src/google/protobuf/compiler/cpp/file_unittest.cc @@ -48,6 +48,7 @@ TEST(FileTest, TopologicallyOrderedDescriptors) { "TestUnpackedTypes", "TestUnpackedExtensions", "TestReservedFields", + "TestRequiredOpenEnum", "TestRequiredOneof.NestedMessage", "TestRequiredNoMaskMulti", "TestRequiredEnumNoMask", @@ -111,6 +112,7 @@ TEST(FileTest, TopologicallyOrderedDescriptors) { "RedactedFields.MapUnredactedStringEntry", "RedactedFields.MapRedactedStringEntry", "OptionalGroup_extension", + "OpenEnumMessage", "OneString", "OneBytes", "MoreString", diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index d3c604e0963fe..4ef1eeeadfb65 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -3599,8 +3599,10 @@ void Descriptor::DebugString(int depth, std::string* contents, if (reserved_name_count() > 0) { absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_name_count(); i++) { - absl::SubstituteAndAppend(contents, "\"$0\", ", - absl::CEscape(reserved_name(i))); + absl::SubstituteAndAppend( + contents, + file()->edition() < Edition::EDITION_2023 ? "\"$0\", " : "$0, ", + absl::CEscape(reserved_name(i))); } contents->replace(contents->size() - 2, 2, ";\n"); } @@ -3819,8 +3821,10 @@ void EnumDescriptor::DebugString( if (reserved_name_count() > 0) { absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_name_count(); i++) { - absl::SubstituteAndAppend(contents, "\"$0\", ", - absl::CEscape(reserved_name(i))); + absl::SubstituteAndAppend( + contents, + file()->edition() < Edition::EDITION_2023 ? "\"$0\", " : "$0, ", + absl::CEscape(reserved_name(i))); } contents->replace(contents->size() - 2, 2, ";\n"); } diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 30d15ddee5ffd..f2e9aee5347a8 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -4500,6 +4500,28 @@ TEST_F(ValidationErrorTest, ReservedFieldsDebugString) { file->DebugString()); } +TEST_F(ValidationErrorTest, ReservedFieldsDebugString2023) { + const FileDescriptor* file = BuildFile(R"pb( + syntax: "editions" + edition: EDITION_2023 + name: "foo.proto" + message_type { + name: "Foo" + reserved_name: "foo" + reserved_name: "bar" + reserved_range { start: 5 end: 6 } + reserved_range { start: 10 end: 20 } + })pb"); + + ASSERT_EQ( + "edition = \"2023\";\n\n" + "message Foo {\n" + " reserved 5, 10 to 19;\n" + " reserved foo, bar;\n" + "}\n\n", + file->DebugString()); +} + TEST_F(ValidationErrorTest, DebugStringReservedRangeMax) { const FileDescriptor* file = BuildFile(absl::Substitute( "name: \"foo.proto\" " @@ -4686,6 +4708,37 @@ TEST_F(ValidationErrorTest, EnumReservedFieldsDebugString) { file->DebugString()); } +TEST_F(ValidationErrorTest, EnumReservedFieldsDebugString2023) { + const FileDescriptor* file = BuildFile(R"pb( + syntax: "editions" + edition: EDITION_2023 + name: "foo.proto" + enum_type { + name: "Foo" + value { name: "FOO" number: 3 } + options { features { enum_type: CLOSED } } + reserved_name: "foo" + reserved_name: "bar" + reserved_range { start: -6 end: -6 } + reserved_range { start: -5 end: -4 } + reserved_range { start: -1 end: 1 } + reserved_range { start: 5 end: 5 } + reserved_range { start: 10 end: 19 } + })pb"); + + ASSERT_EQ( + "edition = \"2023\";\n\n" + "enum Foo {\n" + " option features = {\n" + " enum_type: CLOSED\n" + " };\n" + " FOO = 3;\n" + " reserved -6, -5 to -4, -1 to 1, 5, 10 to 19;\n" + " reserved foo, bar;\n" + "}\n\n", + file->DebugString()); +} + TEST_F(ValidationErrorTest, InvalidDefaults) { BuildFileWithErrors( "name: \"foo.proto\" " diff --git a/src/google/protobuf/dynamic_message_unittest.cc b/src/google/protobuf/dynamic_message_unittest.cc index 323a3a2e46d3a..135610307ee97 100644 --- a/src/google/protobuf/dynamic_message_unittest.cc +++ b/src/google/protobuf/dynamic_message_unittest.cc @@ -77,6 +77,8 @@ class DynamicMessageTest : public ::testing::TestWithParam { const Message* prototype_; const Descriptor* extensions_descriptor_; const Message* extensions_prototype_; + const Descriptor* packed_extensions_descriptor_; + const Message* packed_extensions_prototype_; const Descriptor* packed_descriptor_; const Message* packed_prototype_; const Descriptor* oneof_descriptor_; @@ -98,6 +100,12 @@ class DynamicMessageTest : public ::testing::TestWithParam { ASSERT_TRUE(extensions_descriptor_ != nullptr); extensions_prototype_ = factory_.GetPrototype(extensions_descriptor_); + packed_extensions_descriptor_ = + pool_.FindMessageTypeByName("protobuf_unittest.TestPackedExtensions"); + ASSERT_TRUE(packed_extensions_descriptor_ != nullptr); + packed_extensions_prototype_ = + factory_.GetPrototype(packed_extensions_descriptor_); + packed_descriptor_ = pool_.FindMessageTypeByName("protobuf_unittest.TestPackedTypes"); ASSERT_TRUE(packed_descriptor_ != nullptr); @@ -162,6 +170,21 @@ TEST_P(DynamicMessageTest, Extensions) { } } +TEST_P(DynamicMessageTest, PackedExtensions) { + // Check that extensions work. + Arena arena; + Message* message = + packed_extensions_prototype_->New(GetParam() ? &arena : nullptr); + TestUtil::ReflectionTester reflection_tester(packed_extensions_descriptor_); + + reflection_tester.SetPackedFieldsViaReflection(message); + reflection_tester.ExpectPackedFieldsSetViaReflection(*message); + + if (!GetParam()) { + delete message; + } +} + TEST_P(DynamicMessageTest, PackedFields) { // Check that packed fields work properly. Arena arena; diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 3e125a1b62353..d6107ee7159a5 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -1193,6 +1193,9 @@ TEST(ExtensionSetTest, DynamicExtensions) { // Test adding a dynamic extension to a compiled-in message object. FileDescriptorProto dynamic_proto; + unittest::TestDynamicExtensions::descriptor()->file()->CopyHeadingTo( + &dynamic_proto); + dynamic_proto.clear_dependency(); dynamic_proto.set_name("dynamic_extensions_test.proto"); dynamic_proto.add_dependency( unittest::TestAllExtensions::descriptor()->file()->name()); diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index f61ceb30562e0..31e66c826821e 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -1768,8 +1768,7 @@ void Reflection::ListFields(const Message& message, USAGE_MUTABLE_CHECK_ALL(Add##TYPENAME, REPEATED, CPPTYPE); \ if (field->is_extension()) { \ MutableExtensionSet(message)->Add##TYPENAME( \ - field->number(), field->type(), field->options().packed(), value, \ - field); \ + field->number(), field->type(), field->is_packed(), value, field); \ } else { \ AddField(message, field, value); \ } \ diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index 61f82efae0510..d13e79ddba231 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -360,6 +360,19 @@ TEST_P(GeneratedMessageReflectionSwapTest, Extensions) { TestUtil::ExpectAllExtensionsSet(rhs); } +TEST_P(GeneratedMessageReflectionSwapTest, PackedExtensions) { + unittest::TestPackedExtensions lhs; + unittest::TestPackedExtensions rhs; + + TestUtil::SetPackedExtensions(&lhs); + + Swap(lhs.GetReflection(), &lhs, &rhs); + + EXPECT_EQ(lhs.SerializeAsString(), ""); + + TestUtil::ExpectPackedExtensionsSet(rhs); +} + TEST_P(GeneratedMessageReflectionSwapTest, Unknown) { unittest::TestEmptyMessage lhs, rhs; @@ -695,6 +708,18 @@ TEST(GeneratedMessageReflectionTest, RemoveLastExtensions) { TestUtil::ExpectLastRepeatedExtensionsRemoved(message); } +TEST(GeneratedMessageReflectionTest, RemoveLastPackedExtensions) { + unittest::TestPackedExtensions message; + TestUtil::ReflectionTester reflection_tester( + unittest::TestPackedExtensions::descriptor()); + + TestUtil::SetPackedExtensions(&message); + + reflection_tester.RemoveLastRepeatedsViaReflection(&message); + + TestUtil::ExpectLastRepeatedExtensionsRemoved(message); +} + TEST(GeneratedMessageReflectionTest, ReleaseLast) { unittest::TestAllTypes message; const Descriptor* descriptor = message.GetDescriptor(); @@ -795,6 +820,24 @@ TEST(GeneratedMessageReflectionTest, Extensions) { TestUtil::ExpectRepeatedExtensionsModified(message); } +TEST(GeneratedMessageReflectionTest, PackedExtensions) { + // Set every extension to a unique value then go back and check all those + // values. + unittest::TestPackedExtensions message; + + // First set the extensions via the generated API (see b/366468123). + TestUtil::SetPackedExtensions(&message); + TestUtil::ExpectPackedExtensionsSet(message); + message.Clear(); + + TestUtil::ReflectionTester reflection_tester( + unittest::TestPackedExtensions::descriptor()); + + reflection_tester.SetPackedFieldsViaReflection(&message); + TestUtil::ExpectPackedExtensionsSet(message); + reflection_tester.ExpectPackedFieldsSetViaReflection(message); +} + TEST(GeneratedMessageReflectionTest, FindExtensionTypeByNumber) { const Reflection* reflection = unittest::TestAllExtensions::default_instance().GetReflection(); diff --git a/src/google/protobuf/test_util.inc b/src/google/protobuf/test_util.inc index 3b99b77e81aed..a98674bbebbf3 100644 --- a/src/google/protobuf/test_util.inc +++ b/src/google/protobuf/test_util.inc @@ -76,6 +76,8 @@ inline void ExpectOneofClear(const UNITTEST::TestOneof2& message); inline void ExpectLastRepeatedsRemoved(const UNITTEST::TestAllTypes& message); inline void ExpectLastRepeatedExtensionsRemoved( const UNITTEST::TestAllExtensions& message); +inline void ExpectLastRepeatedExtensionsRemoved( + const UNITTEST::TestPackedExtensions& message); inline void ExpectLastRepeatedsReleased(const UNITTEST::TestAllTypes& message); inline void ExpectLastRepeatedExtensionsReleased( const UNITTEST::TestAllExtensions& message); @@ -2073,6 +2075,42 @@ inline void TestUtil::ExpectLastRepeatedExtensionsRemoved( EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0)); } +inline void TestUtil::ExpectLastRepeatedExtensionsRemoved( + const UNITTEST::TestPackedExtensions& message) { + // Test that one element was removed. + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_int32_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_int64_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_uint32_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_uint64_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_sint32_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_sint64_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_fixed32_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_fixed64_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_sfixed32_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_sfixed64_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_float_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_double_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_bool_extension)); + ASSERT_EQ(1, message.ExtensionSize(UNITTEST::packed_enum_extension)); + + // Test that the remaining element is the correct one. + EXPECT_EQ(601, message.GetExtension(UNITTEST::packed_int32_extension, 0)); + EXPECT_EQ(602, message.GetExtension(UNITTEST::packed_int64_extension, 0)); + EXPECT_EQ(603, message.GetExtension(UNITTEST::packed_uint32_extension, 0)); + EXPECT_EQ(604, message.GetExtension(UNITTEST::packed_uint64_extension, 0)); + EXPECT_EQ(605, message.GetExtension(UNITTEST::packed_sint32_extension, 0)); + EXPECT_EQ(606, message.GetExtension(UNITTEST::packed_sint64_extension, 0)); + EXPECT_EQ(607, message.GetExtension(UNITTEST::packed_fixed32_extension, 0)); + EXPECT_EQ(608, message.GetExtension(UNITTEST::packed_fixed64_extension, 0)); + EXPECT_EQ(609, message.GetExtension(UNITTEST::packed_sfixed32_extension, 0)); + EXPECT_EQ(610, message.GetExtension(UNITTEST::packed_sfixed64_extension, 0)); + EXPECT_EQ(611, message.GetExtension(UNITTEST::packed_float_extension, 0)); + EXPECT_EQ(612, message.GetExtension(UNITTEST::packed_double_extension, 0)); + EXPECT_TRUE(message.GetExtension(UNITTEST::packed_bool_extension, 0)); + EXPECT_EQ(UNITTEST::FOREIGN_BAR, + message.GetExtension(UNITTEST::packed_enum_extension, 0)); +} + inline void TestUtil::ExpectLastRepeatedsReleased( const UNITTEST::TestAllTypes& message) { ASSERT_EQ(1, message.repeatedgroup_size()); diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index 6e97be2f37b1f..3d23298e4265a 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -13,27 +13,32 @@ // // LINT: ALLOW_GROUPS, LEGACY_NAMES -syntax = "proto2"; - -// Some generic_services option(s) added automatically. -// See: http://go/proto2-generic-services-default -option cc_generic_services = true; // auto-added -option java_generic_services = true; // auto-added -option py_generic_services = true; // auto-added -option cc_enable_arenas = true; - -import "google/protobuf/unittest_import.proto"; +edition = "2023"; // We don't put this in a package within proto2 because we need to make sure // that the generated code doesn't depend on being in the proto2 namespace. // In test_util.h we do "using namespace unittest = protobuf_unittest". package protobuf_unittest; +import "google/protobuf/unittest_import.proto"; + +option features = { + enum_type: CLOSED + repeated_field_encoding: EXPANDED + utf8_validation: NONE +}; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + // Protos optimized for SPEED use a strict superset of the generated code // of equivalent ones optimized for CODE_SIZE, so we should optimize all our // tests for speed unless explicitly testing code size optimization. option optimize_for = SPEED; - option java_outer_classname = "UnittestProto"; // This proto includes every type of field in both singular and repeated @@ -43,113 +48,190 @@ message TestAllTypes { // The field name "b" fails to compile in proto1 because it conflicts with // a local variable named "b" in one of the generated methods. Doh. // This file needs to compile in proto1 to test backwards-compatibility. - optional int32 bb = 1; + int32 bb = 1; } enum NestedEnum { FOO = 1; BAR = 2; BAZ = 3; - NEG = -1; // Intentionally negative. + NEG = -1; // Intentionally negative. } // Singular - optional int32 optional_int32 = 1; - optional int64 optional_int64 = 2; - optional uint32 optional_uint32 = 3; - optional uint64 optional_uint64 = 4; - optional sint32 optional_sint32 = 5; - optional sint64 optional_sint64 = 6; - optional fixed32 optional_fixed32 = 7; - optional fixed64 optional_fixed64 = 8; - optional sfixed32 optional_sfixed32 = 9; - optional sfixed64 optional_sfixed64 = 10; - optional float optional_float = 11; - optional double optional_double = 12; - optional bool optional_bool = 13; - optional string optional_string = 14; - optional bytes optional_bytes = 15; - - optional group OptionalGroup = 16 { - optional int32 a = 17; + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; + sfixed64 optional_sfixed64 = 10; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; + + message OptionalGroup { + int32 a = 17; } - optional NestedMessage optional_nested_message = 18; - optional ForeignMessage optional_foreign_message = 19; - optional protobuf_unittest_import.ImportMessage optional_import_message = 20; + OptionalGroup optionalgroup = 16 [ + features.message_encoding = DELIMITED + ]; - optional NestedEnum optional_nested_enum = 21; - optional ForeignEnum optional_foreign_enum = 22; - optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; + NestedMessage optional_nested_message = 18; + ForeignMessage optional_foreign_message = 19; + protobuf_unittest_import.ImportMessage optional_import_message = 20; + NestedEnum optional_nested_enum = 21; + ForeignEnum optional_foreign_enum = 22; + protobuf_unittest_import.ImportEnum optional_import_enum = 23; + string optional_string_piece = 24 [ + ctype = STRING_PIECE + ]; - optional string optional_string_piece = 24 [ctype=STRING_PIECE]; - optional string optional_cord = 25 [ctype=CORD]; + string optional_cord = 25 [ + ctype = CORD + ]; // Defined in unittest_import_public.proto - optional protobuf_unittest_import.PublicImportMessage - optional_public_import_message = 26; + protobuf_unittest_import.PublicImportMessage optional_public_import_message = 26; + NestedMessage optional_lazy_message = 27 [ + lazy = true + ]; - optional NestedMessage optional_lazy_message = 27 [lazy=true]; - optional NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy=true]; + NestedMessage optional_unverified_lazy_message = 28 [ + unverified_lazy = true + ]; // Repeated - repeated int32 repeated_int32 = 31; - repeated int64 repeated_int64 = 32; - repeated uint32 repeated_uint32 = 33; - repeated uint64 repeated_uint64 = 34; - repeated sint32 repeated_sint32 = 35; - repeated sint64 repeated_sint64 = 36; - repeated fixed32 repeated_fixed32 = 37; - repeated fixed64 repeated_fixed64 = 38; + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; repeated sfixed32 repeated_sfixed32 = 39; repeated sfixed64 repeated_sfixed64 = 40; - repeated float repeated_float = 41; - repeated double repeated_double = 42; - repeated bool repeated_bool = 43; - repeated string repeated_string = 44; - repeated bytes repeated_bytes = 45; - - repeated group RepeatedGroup = 46 { - optional int32 a = 47; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + message RepeatedGroup { + int32 a = 47; } - repeated NestedMessage repeated_nested_message = 48; - repeated ForeignMessage repeated_foreign_message = 49; - repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; + repeated RepeatedGroup repeatedgroup = 46 [ + features.message_encoding = DELIMITED + ]; - repeated NestedEnum repeated_nested_enum = 51; - repeated ForeignEnum repeated_foreign_enum = 52; - repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; + repeated NestedMessage repeated_nested_message = 48; + repeated ForeignMessage repeated_foreign_message = 49; + repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; + repeated NestedEnum repeated_nested_enum = 51; + repeated ForeignEnum repeated_foreign_enum = 52; + repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; + 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 + ]; - repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; + repeated NestedMessage repeated_lazy_message = 57 [ + lazy = true + ]; // Singular with defaults - optional int32 default_int32 = 61 [default = 41 ]; - optional int64 default_int64 = 62 [default = 42 ]; - optional uint32 default_uint32 = 63 [default = 43 ]; - optional uint64 default_uint64 = 64 [default = 44 ]; - optional sint32 default_sint32 = 65 [default = -45 ]; - optional sint64 default_sint64 = 66 [default = 46 ]; - optional fixed32 default_fixed32 = 67 [default = 47 ]; - optional fixed64 default_fixed64 = 68 [default = 48 ]; - optional sfixed32 default_sfixed32 = 69 [default = 49 ]; - optional sfixed64 default_sfixed64 = 70 [default = -50 ]; - optional float default_float = 71 [default = 51.5 ]; - optional double default_double = 72 [default = 52e3 ]; - optional bool default_bool = 73 [default = true ]; - optional string default_string = 74 [default = "hello"]; - optional bytes default_bytes = 75 [default = "world"]; - - optional NestedEnum default_nested_enum = 81 [default = BAR ]; - optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; - optional protobuf_unittest_import.ImportEnum - default_import_enum = 83 [default = IMPORT_BAR]; - - optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; - optional string default_cord = 85 [ctype=CORD,default="123"]; + int32 default_int32 = 61 [ + default = 41 + ]; + + int64 default_int64 = 62 [ + default = 42 + ]; + + uint32 default_uint32 = 63 [ + default = 43 + ]; + + uint64 default_uint64 = 64 [ + default = 44 + ]; + + sint32 default_sint32 = 65 [ + default = -45 + ]; + + sint64 default_sint64 = 66 [ + default = 46 + ]; + + fixed32 default_fixed32 = 67 [ + default = 47 + ]; + + fixed64 default_fixed64 = 68 [ + default = 48 + ]; + + sfixed32 default_sfixed32 = 69 [ + default = 49 + ]; + + sfixed64 default_sfixed64 = 70 [ + default = -50 + ]; + + float default_float = 71 [ + default = 51.5 + ]; + + double default_double = 72 [ + default = 5.2e4 + ]; + + bool default_bool = 73 [ + default = true + ]; + + string default_string = 74 [ + default = "hello" + ]; + + bytes default_bytes = 75 [ + default = "world" + ]; + + NestedEnum default_nested_enum = 81 [ + default = BAR + ]; + + ForeignEnum default_foreign_enum = 82 [ + default = FOREIGN_BAR + ]; + + protobuf_unittest_import.ImportEnum default_import_enum = 83 [ + default = IMPORT_BAR + ]; + + string default_string_piece = 84 [ + ctype = STRING_PIECE, + default = "abc" + ]; + + string default_cord = 85 [ + ctype = CORD, + default = "123" + ]; // For oneof test oneof oneof_field { @@ -157,29 +239,54 @@ message TestAllTypes { NestedMessage oneof_nested_message = 112; string oneof_string = 113; bytes oneof_bytes = 114; - string oneof_cord = 115 [ctype=CORD]; - string oneof_string_piece = 116 [ctype=STRING_PIECE]; - NestedMessage oneof_lazy_nested_message = 117 [lazy=true]; + string oneof_cord = 115 [ + ctype = CORD + ]; + + string oneof_string_piece = 116 [ + ctype = STRING_PIECE + ]; + + NestedMessage oneof_lazy_nested_message = 117 [ + lazy = true + ]; } } // This proto includes a recursively nested message. message NestedTestAllTypes { - optional NestedTestAllTypes child = 1; - optional TestAllTypes payload = 2; + NestedTestAllTypes child = 1; + TestAllTypes payload = 2; repeated NestedTestAllTypes repeated_child = 3; - optional NestedTestAllTypes lazy_child = 4 [lazy=true]; - optional TestAllTypes eager_child = 5 [lazy=false]; + NestedTestAllTypes lazy_child = 4 [ + lazy = true + ]; + + TestAllTypes eager_child = 5 [ + lazy = false + ]; } message TestDeprecatedFields { - optional int32 deprecated_int32 = 1 [deprecated=true]; - repeated string deprecated_repeated_string = 4 [deprecated=true]; - optional TestAllTypes.NestedMessage deprecated_message = 3 [deprecated=true]; + int32 deprecated_int32 = 1 [ + deprecated = true + ]; + + repeated string deprecated_repeated_string = 4 [ + deprecated = true + ]; + + TestAllTypes.NestedMessage deprecated_message = 3 [ + deprecated = true + ]; + oneof oneof_fields { - int32 deprecated_int32_in_oneof = 2 [deprecated=true]; + int32 deprecated_int32_in_oneof = 2 [ + deprecated = true + ]; } - optional TestDeprecatedFields nested = 5; + + TestDeprecatedFields nested = 5; } message TestDeprecatedMessage { @@ -189,20 +296,21 @@ message TestDeprecatedMessage { // Define these after TestAllTypes to make sure the compiler can handle // that. message ForeignMessage { - optional int32 c = 1; - optional int32 d = 2; + int32 c = 1; + int32 d = 2; } enum ForeignEnum { FOREIGN_FOO = 4; FOREIGN_BAR = 5; FOREIGN_BAZ = 6; - FOREIGN_BAX = 32; // (1 << 32) to generate a 64b bitmask would be incorrect. - FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache. + FOREIGN_BAX = 32; // (1 << 32) to generate a 64b bitmask would be incorrect. + FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache. } enum TestDeprecatedEnum { option deprecated = true; + TEST_DEPRECATED_ENUM_UNSPECIFIED = 0; TEST_DEPRECATED_ENUM_VALUE1 = 1; TEST_DEPRECATED_ENUM_VALUE2 = 2; @@ -210,13 +318,16 @@ enum TestDeprecatedEnum { message TestReservedFields { reserved 2, 15, 9 to 11; - reserved "bar", "baz"; + + reserved bar, baz; } enum TestReservedEnumFields { UNKNOWN = 0; + reserved 2, 15, 9 to 11; - reserved "bar", "baz"; + + reserved bar, baz; } message TestAllExtensions { @@ -225,143 +336,210 @@ message TestAllExtensions { extend TestAllExtensions { // Singular - optional int32 optional_int32_extension = 1; - optional int64 optional_int64_extension = 2; - optional uint32 optional_uint32_extension = 3; - optional uint64 optional_uint64_extension = 4; - optional sint32 optional_sint32_extension = 5; - optional sint64 optional_sint64_extension = 6; - optional fixed32 optional_fixed32_extension = 7; - optional fixed64 optional_fixed64_extension = 8; - optional sfixed32 optional_sfixed32_extension = 9; - optional sfixed64 optional_sfixed64_extension = 10; - optional float optional_float_extension = 11; - optional double optional_double_extension = 12; - optional bool optional_bool_extension = 13; - optional string optional_string_extension = 14; - optional bytes optional_bytes_extension = 15; - - optional group OptionalGroup_extension = 16 { - optional int32 a = 17; - } - - optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; - optional ForeignMessage optional_foreign_message_extension = 19; - optional protobuf_unittest_import.ImportMessage - optional_import_message_extension = 20; - - optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; - optional ForeignEnum optional_foreign_enum_extension = 22; - optional protobuf_unittest_import.ImportEnum - optional_import_enum_extension = 23; + int32 optional_int32_extension = 1; + int64 optional_int64_extension = 2; + uint32 optional_uint32_extension = 3; + uint64 optional_uint64_extension = 4; + sint32 optional_sint32_extension = 5; + sint64 optional_sint64_extension = 6; + fixed32 optional_fixed32_extension = 7; + fixed64 optional_fixed64_extension = 8; + sfixed32 optional_sfixed32_extension = 9; + sfixed64 optional_sfixed64_extension = 10; + float optional_float_extension = 11; + double optional_double_extension = 12; + bool optional_bool_extension = 13; + string optional_string_extension = 14; + bytes optional_bytes_extension = 15; + OptionalGroup_extension optionalgroup_extension = 16 [ + features.message_encoding = DELIMITED + ]; + + TestAllTypes.NestedMessage optional_nested_message_extension = 18; + ForeignMessage optional_foreign_message_extension = 19; + protobuf_unittest_import.ImportMessage optional_import_message_extension = 20; + TestAllTypes.NestedEnum optional_nested_enum_extension = 21; + ForeignEnum optional_foreign_enum_extension = 22; + protobuf_unittest_import.ImportEnum optional_import_enum_extension = 23; + string optional_string_piece_extension = 24 [ + ctype = STRING_PIECE + ]; - optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; // TODO: ctype=CORD is not supported for extension. Add // ctype=CORD option back after it is supported. - optional string optional_cord_extension = 25; + string optional_cord_extension = 25; + protobuf_unittest_import.PublicImportMessage + optional_public_import_message_extension = 26; + TestAllTypes.NestedMessage optional_lazy_message_extension = 27 [ + lazy = true + ]; - optional protobuf_unittest_import.PublicImportMessage - optional_public_import_message_extension = 26; - - optional TestAllTypes.NestedMessage - optional_lazy_message_extension = 27 [lazy=true]; - optional TestAllTypes.NestedMessage - optional_unverified_lazy_message_extension = 28 [unverified_lazy=true]; + TestAllTypes.NestedMessage optional_unverified_lazy_message_extension = 28 [ + unverified_lazy = true + ]; // Repeated - repeated int32 repeated_int32_extension = 31; - repeated int64 repeated_int64_extension = 32; - repeated uint32 repeated_uint32_extension = 33; - repeated uint64 repeated_uint64_extension = 34; - repeated sint32 repeated_sint32_extension = 35; - repeated sint64 repeated_sint64_extension = 36; - repeated fixed32 repeated_fixed32_extension = 37; - repeated fixed64 repeated_fixed64_extension = 38; + repeated int32 repeated_int32_extension = 31; + repeated int64 repeated_int64_extension = 32; + repeated uint32 repeated_uint32_extension = 33; + repeated uint64 repeated_uint64_extension = 34; + repeated sint32 repeated_sint32_extension = 35; + repeated sint64 repeated_sint64_extension = 36; + repeated fixed32 repeated_fixed32_extension = 37; + repeated fixed64 repeated_fixed64_extension = 38; repeated sfixed32 repeated_sfixed32_extension = 39; repeated sfixed64 repeated_sfixed64_extension = 40; - repeated float repeated_float_extension = 41; - repeated double repeated_double_extension = 42; - repeated bool repeated_bool_extension = 43; - repeated string repeated_string_extension = 44; - repeated bytes repeated_bytes_extension = 45; - - repeated group RepeatedGroup_extension = 46 { - optional int32 a = 47; - } + repeated float repeated_float_extension = 41; + repeated double repeated_double_extension = 42; + repeated bool repeated_bool_extension = 43; + repeated string repeated_string_extension = 44; + repeated bytes repeated_bytes_extension = 45; + repeated RepeatedGroup_extension repeatedgroup_extension = 46 [ + features.message_encoding = DELIMITED + ]; repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; repeated ForeignMessage repeated_foreign_message_extension = 49; repeated protobuf_unittest_import.ImportMessage - repeated_import_message_extension = 50; - + repeated_import_message_extension = 50; repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; repeated ForeignEnum repeated_foreign_enum_extension = 52; - repeated protobuf_unittest_import.ImportEnum - repeated_import_enum_extension = 53; + repeated protobuf_unittest_import.ImportEnum repeated_import_enum_extension = 53; + repeated string repeated_string_piece_extension = 54 [ + ctype = STRING_PIECE + ]; - repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; // TODO: ctype=CORD is not supported for extension. Add // ctype=CORD option back after it is supported. repeated string repeated_cord_extension = 55; - - repeated TestAllTypes.NestedMessage - repeated_lazy_message_extension = 57 [lazy=true]; + repeated TestAllTypes.NestedMessage repeated_lazy_message_extension = 57 [ + lazy = true + ]; // Singular with defaults - optional int32 default_int32_extension = 61 [default = 41 ]; - optional int64 default_int64_extension = 62 [default = 42 ]; - optional uint32 default_uint32_extension = 63 [default = 43 ]; - optional uint64 default_uint64_extension = 64 [default = 44 ]; - optional sint32 default_sint32_extension = 65 [default = -45 ]; - optional sint64 default_sint64_extension = 66 [default = 46 ]; - optional fixed32 default_fixed32_extension = 67 [default = 47 ]; - optional fixed64 default_fixed64_extension = 68 [default = 48 ]; - optional sfixed32 default_sfixed32_extension = 69 [default = 49 ]; - optional sfixed64 default_sfixed64_extension = 70 [default = -50 ]; - optional float default_float_extension = 71 [default = 51.5 ]; - optional double default_double_extension = 72 [default = 52e3 ]; - optional bool default_bool_extension = 73 [default = true ]; - optional string default_string_extension = 74 [default = "hello"]; - optional bytes default_bytes_extension = 75 [default = "world"]; - - optional TestAllTypes.NestedEnum - default_nested_enum_extension = 81 [default = BAR]; - optional ForeignEnum - default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; - optional protobuf_unittest_import.ImportEnum - default_import_enum_extension = 83 [default = IMPORT_BAR]; - - optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, - default="abc"]; + int32 default_int32_extension = 61 [ + default = 41 + ]; + + int64 default_int64_extension = 62 [ + default = 42 + ]; + + uint32 default_uint32_extension = 63 [ + default = 43 + ]; + + uint64 default_uint64_extension = 64 [ + default = 44 + ]; + + sint32 default_sint32_extension = 65 [ + default = -45 + ]; + + sint64 default_sint64_extension = 66 [ + default = 46 + ]; + + fixed32 default_fixed32_extension = 67 [ + default = 47 + ]; + + fixed64 default_fixed64_extension = 68 [ + default = 48 + ]; + + sfixed32 default_sfixed32_extension = 69 [ + default = 49 + ]; + + sfixed64 default_sfixed64_extension = 70 [ + default = -50 + ]; + + float default_float_extension = 71 [ + default = 51.5 + ]; + + double default_double_extension = 72 [ + default = 5.2e4 + ]; + + bool default_bool_extension = 73 [ + default = true + ]; + + string default_string_extension = 74 [ + default = "hello" + ]; + + bytes default_bytes_extension = 75 [ + default = "world" + ]; + + TestAllTypes.NestedEnum default_nested_enum_extension = 81 [ + default = BAR + ]; + + ForeignEnum default_foreign_enum_extension = 82 [ + default = FOREIGN_BAR + ]; + + protobuf_unittest_import.ImportEnum default_import_enum_extension = 83 [ + default = IMPORT_BAR + ]; + + string default_string_piece_extension = 84 [ + ctype = STRING_PIECE, + default = "abc" + ]; + // TODO: ctype=CORD is not supported for extension. Add // ctype=CORD option back after it is supported. - optional string default_cord_extension = 85 [default="123"]; + string default_cord_extension = 85 [ + default = "123" + ]; // For oneof test - optional uint32 oneof_uint32_extension = 111; - optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112; - optional string oneof_string_extension = 113; - optional bytes oneof_bytes_extension = 114; + uint32 oneof_uint32_extension = 111; + TestAllTypes.NestedMessage oneof_nested_message_extension = 112; + string oneof_string_extension = 113; + bytes oneof_bytes_extension = 114; +} + +message OptionalGroup_extension { + int32 a = 17; +} + +message RepeatedGroup_extension { + int32 a = 47; } message TestMixedFieldsAndExtensions { - optional int32 a = 1; + int32 a = 1; repeated fixed32 b = 3; + extensions 2, 4; + extend TestMixedFieldsAndExtensions { - optional int32 c = 2; + int32 c = 2; repeated fixed32 d = 4; } } message TestGroup { - optional group OptionalGroup = 16 { - optional int32 a = 17; - optional int32 zz = 89; // fast table size must be at least 16, for this - // field to be parsed by the fast parser, since - // 89 - 17 = 72 is a multiple of 8. + message OptionalGroup { + int32 a = 17; + int32 zz = 89; // fast table size must be at least 16, for this + // field to be parsed by the fast parser, since + // 89 - 17 = 72 is a multiple of 8. } - optional ForeignEnum optional_foreign_enum = 22; + + OptionalGroup optionalgroup = 16 [ + features.message_encoding = DELIMITED + ]; + + ForeignEnum optional_foreign_enum = 22; } message TestGroupExtension { @@ -372,24 +550,32 @@ message TestNestedExtension { extend TestAllExtensions { // Check for bug where string extensions declared in tested scope did not // compile. - optional string test = 1002 [default="test"]; + string test = 1002 [ + default = "test" + ]; + // Used to test if generated extension name is correct when there are // underscores. - optional string nested_string_extension = 1003; + string nested_string_extension = 1003; } extend TestGroupExtension { - optional group OptionalGroup_extension = 16 { - optional int32 a = 17; - } - optional ForeignEnum optional_foreign_enum_extension = 22; + OptionalGroup_extension optionalgroup_extension = 16 [ + features.message_encoding = DELIMITED + ]; + + ForeignEnum optional_foreign_enum_extension = 22; + } + + message OptionalGroup_extension { + int32 a = 17; } } message TestChildExtension { - optional string a = 1; - optional string b = 2; - optional TestAllExtensions optional_extension = 3; + string a = 1; + string b = 2; + TestAllExtensions optional_extension = 3; } // Emulates wireformat data of TestChildExtension with dynamic extension @@ -397,35 +583,60 @@ message TestChildExtension { message TestChildExtensionData { message NestedTestAllExtensionsData { message NestedDynamicExtensions { - optional int32 a = 1; - optional int32 b = 2; + int32 a = 1; + int32 b = 2; } - optional NestedDynamicExtensions dynamic = 409707008; + + NestedDynamicExtensions dynamic = 409707008; } - optional string a = 1; - optional string b = 2; - optional NestedTestAllExtensionsData optional_extension = 3; + + string a = 1; + string b = 2; + NestedTestAllExtensionsData optional_extension = 3; } message TestNestedChildExtension { - optional int32 a = 1; - optional TestChildExtension child = 2; + int32 a = 1; + TestChildExtension child = 2; } // Emulates wireformat data of TestNestedChildExtension with dynamic extension // (DynamicExtension). message TestNestedChildExtensionData { - optional int32 a = 1; - optional TestChildExtensionData child = 2; + int32 a = 1; + TestChildExtensionData child = 2; } // Required and closed enum fields are considered unknown fields if the value is // not valid. We need to make sure it functions as expected. message TestRequiredEnum { - required ForeignEnum required_enum = 1; + ForeignEnum required_enum = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; // A dummy optional field. - optional int32 a = 2; + int32 a = 2; +} + +// Required and open enum accepts invalid enum values. +enum ForeignOpenEnum { + option features.enum_type = OPEN; + + FOREIGN_OPEN_UNKNOWN = 0; + FOREIGN_OPEN_FOO = 4; + FOREIGN_OPEN_BAR = 5; + FOREIGN_OPEN_BAZ = 6; + FOREIGN_OPEN_BAX = 32; // (1 << 32) to generate a 64b bitmask would be + // incorrect. +} + +message TestRequiredOpenEnum { + ForeignOpenEnum required_enum = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; + + // A dummy optional field. + int32 a = 2; } // TestRequiredEnum + using enum values that won't fit to 64 bitmask. @@ -434,13 +645,15 @@ message TestRequiredEnumNoMask { UNSPECIFIED = 0; FOO = 2; BAR = 100; - BAZ = -1; // Intentionally negative. + BAZ = -1; // Intentionally negative. } - required NestedEnum required_enum = 1; + NestedEnum required_enum = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; // A dummy optional field. - optional int32 a = 2; + int32 a = 2; } message TestRequiredEnumMulti { @@ -453,10 +666,18 @@ message TestRequiredEnumMulti { // Intentionally placed in descending field number to force sorting in closed // enum verification. - required NestedEnum required_enum_4 = 4; - optional int32 a_3 = 3; - required NestedEnum required_enum_2 = 2; - required ForeignEnum required_enum_1 = 1; + NestedEnum required_enum_4 = 4 [ + features.field_presence = LEGACY_REQUIRED + ]; + + int32 a_3 = 3; + NestedEnum required_enum_2 = 2 [ + features.field_presence = LEGACY_REQUIRED + ]; + + ForeignEnum required_enum_1 = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; } message TestRequiredNoMaskMulti { @@ -470,14 +691,30 @@ message TestRequiredNoMaskMulti { // Intentionally placed in descending field number to force sorting in closed // enum verification. Also, using large field numbers to use tag only // matching for required fields. - required fixed32 required_fixed32_80 = 80; - required fixed32 required_fixed32_70 = 70; + fixed32 required_fixed32_80 = 80 [ + features.field_presence = LEGACY_REQUIRED + ]; + + fixed32 required_fixed32_70 = 70 [ + features.field_presence = LEGACY_REQUIRED + ]; + + NestedEnum required_enum_64 = 64 [ + features.field_presence = LEGACY_REQUIRED + ]; + + NestedEnum required_enum_4 = 4 [ + features.field_presence = LEGACY_REQUIRED + ]; + + int32 a_3 = 3; + NestedEnum required_enum_2 = 2 [ + features.field_presence = LEGACY_REQUIRED + ]; - required NestedEnum required_enum_64 = 64; - required NestedEnum required_enum_4 = 4; - optional int32 a_3 = 3; - required NestedEnum required_enum_2 = 2; - required ForeignEnum required_enum_1 = 1; + ForeignEnum required_enum_1 = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; } // We have separate messages for testing required fields because it's @@ -486,82 +723,93 @@ message TestRequiredNoMaskMulti { // required filed because the code output is basically identical to // optional fields for all types. message TestRequired { - required int32 a = 1; - optional int32 dummy2 = 2; - required int32 b = 3; + int32 a = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; + + int32 dummy2 = 2; + int32 b = 3 [ + features.field_presence = LEGACY_REQUIRED + ]; extend TestAllExtensions { - optional TestRequired single = 1000; - repeated TestRequired multi = 1001; + TestRequired single = 1000; + repeated TestRequired multi = 1001; } // Pad the field count to 32 so that we can test that IsInitialized() // properly checks multiple elements of has_bits_. - optional int32 dummy4 = 4; - optional int32 dummy5 = 5; - optional int32 dummy6 = 6; - optional int32 dummy7 = 7; - optional int32 dummy8 = 8; - optional int32 dummy9 = 9; - optional int32 dummy10 = 10; - optional int32 dummy11 = 11; - optional int32 dummy12 = 12; - optional int32 dummy13 = 13; - optional int32 dummy14 = 14; - optional int32 dummy15 = 15; - optional int32 dummy16 = 16; - optional int32 dummy17 = 17; - optional int32 dummy18 = 18; - optional int32 dummy19 = 19; - optional int32 dummy20 = 20; - optional int32 dummy21 = 21; - optional int32 dummy22 = 22; - optional int32 dummy23 = 23; - optional int32 dummy24 = 24; - optional int32 dummy25 = 25; - optional int32 dummy26 = 26; - optional int32 dummy27 = 27; - optional int32 dummy28 = 28; - optional int32 dummy29 = 29; - optional int32 dummy30 = 30; - optional int32 dummy31 = 31; - optional int32 dummy32 = 32; - - required int32 c = 33; + int32 dummy4 = 4; + int32 dummy5 = 5; + int32 dummy6 = 6; + int32 dummy7 = 7; + int32 dummy8 = 8; + int32 dummy9 = 9; + int32 dummy10 = 10; + int32 dummy11 = 11; + int32 dummy12 = 12; + int32 dummy13 = 13; + int32 dummy14 = 14; + int32 dummy15 = 15; + int32 dummy16 = 16; + int32 dummy17 = 17; + int32 dummy18 = 18; + int32 dummy19 = 19; + int32 dummy20 = 20; + int32 dummy21 = 21; + int32 dummy22 = 22; + int32 dummy23 = 23; + int32 dummy24 = 24; + int32 dummy25 = 25; + int32 dummy26 = 26; + int32 dummy27 = 27; + int32 dummy28 = 28; + int32 dummy29 = 29; + int32 dummy30 = 30; + int32 dummy31 = 31; + int32 dummy32 = 32; + int32 c = 33 [ + features.field_presence = LEGACY_REQUIRED + ]; // Add an optional child message to make this non-trivial for go/pdlazy. - optional ForeignMessage optional_foreign = 34; + ForeignMessage optional_foreign = 34; } message TestRequiredForeign { - optional TestRequired optional_message = 1; + TestRequired optional_message = 1; repeated TestRequired repeated_message = 2; - optional int32 dummy = 3; + int32 dummy = 3; // Missing required fields must not affect verification of child messages. - optional NestedTestAllTypes optional_lazy_message = 4 [lazy = true]; + NestedTestAllTypes optional_lazy_message = 4 [ + lazy = true + ]; } message TestRequiredMessage { - optional TestRequired optional_message = 1; + TestRequired optional_message = 1; repeated TestRequired repeated_message = 2; - required TestRequired required_message = 3; + TestRequired required_message = 3 [ + features.field_presence = LEGACY_REQUIRED + ]; } message TestNestedRequiredForeign { - optional TestNestedRequiredForeign child = 1; - optional TestRequiredForeign payload = 2; - optional int32 dummy = 3; + TestNestedRequiredForeign child = 1; + TestRequiredForeign payload = 2; + int32 dummy = 3; + // optional message to test required closed enum. - optional TestRequiredEnum required_enum = 5; - optional TestRequiredEnumNoMask required_enum_no_mask = 6; - optional TestRequiredEnumMulti required_enum_multi = 7; - optional TestRequiredNoMaskMulti required_no_mask = 9; + TestRequiredEnum required_enum = 5; + TestRequiredEnumNoMask required_enum_no_mask = 6; + TestRequiredEnumMulti required_enum_multi = 7; + TestRequiredNoMaskMulti required_no_mask = 9; } // Test that we can use NestedMessage from outside TestAllTypes. message TestForeignNested { - optional TestAllTypes.NestedMessage foreign_nested = 1; + TestAllTypes.NestedMessage foreign_nested = 1; } // TestEmptyMessage is used to test unknown field support. @@ -577,9 +825,10 @@ message TestEmptyMessageWithExtensions { // Needed for a Python test. message TestPickleNestedMessage { message NestedMessage { - optional int32 bb = 1; + int32 bb = 1; + message NestedNestedMessage { - optional int32 cc = 1; + int32 cc = 1; } } } @@ -594,81 +843,114 @@ message TestMultipleExtensionRanges { message TestReallyLargeTagNumber { // The largest possible tag number is 2^28 - 1, since the wire format uses // three bits to communicate wire type. - optional int32 a = 1; - optional int32 bb = 268435455; + int32 a = 1; + int32 bb = 268435455; } message TestRecursiveMessage { - optional TestRecursiveMessage a = 1; - optional int32 i = 2; + TestRecursiveMessage a = 1; + int32 i = 2; } // Test that mutual recursion works. message TestMutualRecursionA { message SubMessage { - optional TestMutualRecursionB b = 1; + TestMutualRecursionB b = 1; } - optional TestMutualRecursionB bb = 1; - optional group SubGroup = 2 { - optional SubMessage sub_message = 3; // Needed because of bug in javatest - optional TestAllTypes not_in_this_scc = 4; + + TestMutualRecursionB bb = 1; + + message SubGroup { + SubMessage sub_message = 3; // Needed because of bug in javatest + TestAllTypes not_in_this_scc = 4; } - repeated group SubGroupR = 5 { - optional TestAllTypes payload = 6; + + SubGroup subgroup = 2 [ + features.message_encoding = DELIMITED + ]; + + message SubGroupR { + TestAllTypes payload = 6; } + + repeated SubGroupR subgroupr = 5 [ + features.message_encoding = DELIMITED + ]; } message TestMutualRecursionB { - optional TestMutualRecursionA a = 1; - optional int32 optional_int32 = 2; + TestMutualRecursionA a = 1; + int32 optional_int32 = 2; } message TestIsInitialized { message SubMessage { - optional group SubGroup = 1 { - required int32 i = 2; + message SubGroup { + int32 i = 2 [ + features.field_presence = LEGACY_REQUIRED + ]; } + + SubGroup subgroup = 1 [ + features.message_encoding = DELIMITED + ]; } - optional SubMessage sub_message = 1; + + SubMessage sub_message = 1; } // Test that groups have disjoint field numbers from their siblings and // parents. This is NOT possible in proto1; only google.protobuf. When attempting // to compile with proto1, this will emit an error; so we only include it // in protobuf_unittest_proto. -message TestDupFieldNumber { // NO_PROTO1 - optional int32 a = 1; // NO_PROTO1 - optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 - optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 -} // NO_PROTO1 +message TestDupFieldNumber {// NO_PROTO1 + int32 a = 1; // NO_PROTO1 + message Foo { // NO_PROTO1 + int32 a = 1; // NO_PROTO1 + } // NO_PROTO1 + Foo foo = 2 [features.message_encoding = DELIMITED]; // NO_PROTO1 + message Bar { // NO_PROTO1 + int32 a = 1; // NO_PROTO1 + } // NO_PROTO1 + Bar bar = 3 [features.message_encoding = DELIMITED]; // NO_PROTO1 +} // NO_PROTO1 // Additional messages for testing lazy fields. message TestEagerMessage { - optional TestAllTypes sub_message = 1 [lazy=false]; + TestAllTypes sub_message = 1 [ + lazy = false + ]; } + message TestLazyMessage { - optional TestAllTypes sub_message = 1 [lazy=true]; + TestAllTypes sub_message = 1 [ + lazy = true + ]; } + message TestLazyMessageRepeated { repeated TestLazyMessage repeated_message = 1; } + message TestEagerMaybeLazy { message NestedMessage { - optional TestPackedTypes packed = 1; + TestPackedTypes packed = 1; } - optional TestAllTypes message_foo = 1; - optional TestAllTypes message_bar = 2; - optional NestedMessage message_baz = 3; + + TestAllTypes message_foo = 1; + TestAllTypes message_bar = 2; + NestedMessage message_baz = 3; } + // Needed for a Python test. message TestNestedMessageHasBits { message NestedMessage { repeated int32 nestedmessage_repeated_int32 = 1; repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; } - optional NestedMessage optional_nested_message = 1; -} + NestedMessage optional_nested_message = 1; +} // Test an enum that has multiple values with the same number. enum TestEnumWithDupValue { @@ -695,122 +977,217 @@ enum TestSparseEnum { // Test message with CamelCase field names. This violates Protocol Buffer // standard style. message TestCamelCaseFieldNames { - optional int32 PrimitiveField = 1; - optional string StringField = 2; - optional ForeignEnum EnumField = 3; - optional ForeignMessage MessageField = 4; - optional string StringPieceField = 5 [ctype=STRING_PIECE]; - optional string CordField = 6 [ctype=CORD]; + int32 PrimitiveField = 1; + string StringField = 2; + ForeignEnum EnumField = 3; + ForeignMessage MessageField = 4; + string StringPieceField = 5 [ + ctype = STRING_PIECE + ]; + + string CordField = 6 [ + ctype = CORD + ]; repeated int32 RepeatedPrimitiveField = 7; repeated string RepeatedStringField = 8; repeated ForeignEnum RepeatedEnumField = 9; repeated ForeignMessage RepeatedMessageField = 10; - repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; - repeated string RepeatedCordField = 12 [ctype=CORD]; -} + repeated string RepeatedStringPieceField = 11 [ + ctype = STRING_PIECE + ]; + repeated string RepeatedCordField = 12 [ + ctype = CORD + ]; +} // We list fields out of order, to ensure that we're using field number and not // field index to determine serialization order. message TestFieldOrderings { - optional string my_string = 11; + string my_string = 11; + extensions 2 to 10; - optional int64 my_int = 1; + + int64 my_int = 1; + extensions 12 to 100; - optional float my_float = 101; + + float my_float = 101; + message NestedMessage { - optional int64 oo = 2; + int64 oo = 2; + // The field name "b" fails to compile in proto1 because it conflicts with // a local variable named "b" in one of the generated methods. Doh. // This file needs to compile in proto1 to test backwards-compatibility. - optional int32 bb = 1; + int32 bb = 1; } - optional NestedMessage optional_nested_message = 200; + NestedMessage optional_nested_message = 200; } extend TestFieldOrderings { - optional string my_extension_string = 50; - optional int32 my_extension_int = 5; + string my_extension_string = 50; + int32 my_extension_int = 5; } message TestExtensionOrderings1 { extend TestFieldOrderings { - optional TestExtensionOrderings1 test_ext_orderings1 = 13; + TestExtensionOrderings1 test_ext_orderings1 = 13; } - optional string my_string = 1; + + string my_string = 1; } message TestExtensionOrderings2 { extend TestFieldOrderings { - optional TestExtensionOrderings2 test_ext_orderings2 = 12; + TestExtensionOrderings2 test_ext_orderings2 = 12; } + message TestExtensionOrderings3 { extend TestFieldOrderings { - optional TestExtensionOrderings3 test_ext_orderings3 = 14; + TestExtensionOrderings3 test_ext_orderings3 = 14; } - optional string my_string = 1; + + string my_string = 1; } - optional string my_string = 1; + + string my_string = 1; } message TestExtremeDefaultValues { - optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; - optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; - optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; - optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; - optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; - optional int32 really_small_int32 = 21 [default = -0x80000000]; - optional int64 really_small_int64 = 22 [default = -0x8000000000000000]; + bytes escaped_bytes = 1 [ + default = + "\0\001\a\b\f\n\r\t\v\\\'\"\xfe" + ]; + + uint32 large_uint32 = 2 [ + default = 0xFFFFFFFF + ]; + + uint64 large_uint64 = 3 [ + default = 0xFFFFFFFFFFFFFFFF + ]; + + int32 small_int32 = 4 [ + default = -0x7FFFFFFF + ]; + + int64 small_int64 = 5 [ + default = -0x7FFFFFFFFFFFFFFF + ]; + + int32 really_small_int32 = 21 [ + default = -0x80000000 + ]; + + int64 really_small_int64 = 22 [ + default = -0x8000000000000000 + ]; // The default value here is UTF-8 for "\u1234". (We could also just type // the UTF-8 text directly into this text file rather than escape it, but // lots of people use editors that would be confused by this.) - optional string utf8_string = 6 [default = "\341\210\264"]; + string utf8_string = 6 [ + default = "\341\210\264" + ]; // Tests for single-precision floating-point values. - optional float zero_float = 7 [default = 0]; - optional float one_float = 8 [default = 1]; - optional float small_float = 9 [default = 1.5]; - optional float negative_one_float = 10 [default = -1]; - optional float negative_float = 11 [default = -1.5]; + float zero_float = 7 [ + default = 0 + ]; + + float one_float = 8 [ + default = 1 + ]; + + float small_float = 9 [ + default = 1.5 + ]; + + float negative_one_float = 10 [ + default = -1 + ]; + + float negative_float = 11 [ + default = -1.5 + ]; + // Using exponents - optional float large_float = 12 [default = 2E8]; - optional float small_negative_float = 13 [default = -8e-28]; + float large_float = 12 [ + default = 2e8 + ]; + + float small_negative_float = 13 [ + default = -8e-28 + ]; // Text for nonfinite floating-point values. - optional double inf_double = 14 [default = inf]; - optional double neg_inf_double = 15 [default = -inf]; - optional double nan_double = 16 [default = nan]; - optional float inf_float = 17 [default = inf]; - optional float neg_inf_float = 18 [default = -inf]; - optional float nan_float = 19 [default = nan]; + double inf_double = 14 [ + default = inf + ]; + + double neg_inf_double = 15 [ + default = -inf + ]; + + double nan_double = 16 [ + default = nan + ]; + + float inf_float = 17 [ + default = inf + ]; + + float neg_inf_float = 18 [ + default = -inf + ]; + + float nan_float = 19 [ + default = nan + ]; // Tests for C++ trigraphs. // Trigraphs should be escaped in C++ generated files, but they should not be // escaped for other languages. // Note that in .proto file, "\?" is a valid way to escape ? in string // literals. - optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"]; + string cpp_trigraph = 20 [ + default = "? \? ?? \?? \??? ??/ ?\?-" + ]; // String defaults containing the character '\000' - optional string string_with_zero = 23 [default = "hel\000lo"]; - optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; - optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, - default="ab\000c"]; - optional string cord_with_zero = 26 [ctype=CORD, - default="12\0003"]; - optional string replacement_string = 27 [default="${unknown}"]; + string string_with_zero = 23 [ + default = "hel\000lo" + ]; + + bytes bytes_with_zero = 24 [ + default = "wor\000ld" + ]; + + string string_piece_with_zero = 25 [ + ctype = STRING_PIECE, + default = "ab\000c" + ]; + + string cord_with_zero = 26 [ + ctype = CORD, + default = "12\0003" + ]; + + string replacement_string = 27 [ + default = "${unknown}" + ]; } message SparseEnumMessage { - optional TestSparseEnum sparse_enum = 1; + TestSparseEnum sparse_enum = 1; } // Test String and Bytes: string is for valid UTF-8 strings message OneString { - optional string data = 1; + string data = 1; } message MoreString { @@ -818,7 +1195,7 @@ message MoreString { } message OneBytes { - optional bytes data = 1; + bytes data = 1; } message MoreBytes { @@ -826,59 +1203,59 @@ message MoreBytes { } message ManyOptionalString { - optional string str1 = 1; - optional string str2 = 2; - optional string str3 = 3; - optional string str4 = 4; - optional string str5 = 5; - optional string str6 = 6; - optional string str7 = 7; - optional string str8 = 8; - optional string str9 = 9; - optional string str10 = 10; - optional string str11 = 11; - optional string str12 = 12; - optional string str13 = 13; - optional string str14 = 14; - optional string str15 = 15; - optional string str16 = 16; - optional string str17 = 17; - optional string str18 = 18; - optional string str19 = 19; - optional string str20 = 20; - optional string str21 = 21; - optional string str22 = 22; - optional string str23 = 23; - optional string str24 = 24; - optional string str25 = 25; - optional string str26 = 26; - optional string str27 = 27; - optional string str28 = 28; - optional string str29 = 29; - optional string str30 = 30; - optional string str31 = 31; - optional string str32 = 32; + string str1 = 1; + string str2 = 2; + string str3 = 3; + string str4 = 4; + string str5 = 5; + string str6 = 6; + string str7 = 7; + string str8 = 8; + string str9 = 9; + string str10 = 10; + string str11 = 11; + string str12 = 12; + string str13 = 13; + string str14 = 14; + string str15 = 15; + string str16 = 16; + string str17 = 17; + string str18 = 18; + string str19 = 19; + string str20 = 20; + string str21 = 21; + string str22 = 22; + string str23 = 23; + string str24 = 24; + string str25 = 25; + string str26 = 26; + string str27 = 27; + string str28 = 28; + string str29 = 29; + string str30 = 30; + string str31 = 31; + string str32 = 32; } // Test int32, uint32, int64, uint64, and bool are all compatible message Int32Message { - optional int32 data = 1; + int32 data = 1; } message Uint32Message { - optional uint32 data = 1; + uint32 data = 1; } message Int64Message { - optional int64 data = 1; + int64 data = 1; } message Uint64Message { - optional uint64 data = 1; + uint64 data = 1; } message BoolMessage { - optional bool data = 1; + bool data = 1; } // Test oneofs. @@ -887,60 +1264,120 @@ message TestOneof { int32 foo_int = 1; string foo_string = 2; TestAllTypes foo_message = 3; - group FooGroup = 4 { - optional int32 a = 5; - optional string b = 6; - } + FooGroup foogroup = 4 [ + features.message_encoding = DELIMITED + ]; + } + + message FooGroup { + int32 a = 5; + string b = 6; } } message TestOneofBackwardsCompatible { - optional int32 foo_int = 1; - optional string foo_string = 2; - optional TestAllTypes foo_message = 3; - optional group FooGroup = 4 { - optional int32 a = 5; - optional string b = 6; + int32 foo_int = 1; + string foo_string = 2; + TestAllTypes foo_message = 3; + + message FooGroup { + int32 a = 5; + string b = 6; } + + FooGroup foogroup = 4 [ + features.message_encoding = DELIMITED + ]; } message TestOneof2 { oneof foo { int32 foo_int = 1; string foo_string = 2; - string foo_cord = 3 [ctype=CORD]; - string foo_string_piece = 4 [ctype=STRING_PIECE]; + string foo_cord = 3 [ + ctype = CORD + ]; + + string foo_string_piece = 4 [ + ctype = STRING_PIECE + ]; + bytes foo_bytes = 5; NestedEnum foo_enum = 6; NestedMessage foo_message = 7; - group FooGroup = 8 { - optional int32 a = 9; - optional string b = 10; - } - NestedMessage foo_lazy_message = 11 [lazy=true]; - bytes foo_bytes_cord = 30 [ctype=CORD]; + FooGroup foogroup = 8 [ + features.message_encoding = DELIMITED + ]; + + NestedMessage foo_lazy_message = 11 [ + lazy = true + ]; + + bytes foo_bytes_cord = 30 [ + ctype = CORD + ]; + } + + message FooGroup { + int32 a = 9; + string b = 10; } oneof bar { - int32 bar_int = 12 [default = 5]; - string bar_string = 13 [default = "STRING"]; - string bar_cord = 14 [ctype=CORD, default = "CORD"]; - string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; - bytes bar_bytes = 16 [default = "BYTES"]; - NestedEnum bar_enum = 17 [default = BAR]; - string bar_string_with_empty_default = 20 [default = ""]; - string bar_cord_with_empty_default = 21 [ctype=CORD, default = ""]; - string bar_string_piece_with_empty_default = 22 [ctype=STRING_PIECE, default = ""]; - bytes bar_bytes_with_empty_default = 23 [default = ""]; + int32 bar_int = 12 [ + default = 5 + ]; + + string bar_string = 13 [ + default = "STRING" + ]; + + string bar_cord = 14 [ + ctype = CORD, + default = "CORD" + ]; + + string bar_string_piece = 15 [ + ctype = STRING_PIECE, + default = "SPIECE" + ]; + + bytes bar_bytes = 16 [ + default = "BYTES" + ]; + + NestedEnum bar_enum = 17 [ + default = BAR + ]; + + string bar_string_with_empty_default = 20 [ + default = "" + ]; + + string bar_cord_with_empty_default = 21 [ + ctype = CORD, + default = "" + ]; + + string bar_string_piece_with_empty_default = 22 [ + ctype = STRING_PIECE, + default = "" + ]; + + bytes bar_bytes_with_empty_default = 23 [ + default = "" + ]; } - optional int32 baz_int = 18; - optional string baz_string = 19 [default = "BAZ"]; + int32 baz_int = 18; + string baz_string = 19 [ + default = "BAZ" + ]; message NestedMessage { - optional int64 moo_int = 1; + int64 moo_int = 1; repeated int32 corge_int = 2; - optional NestedMessage child = 3; + NestedMessage child = 3; } enum NestedEnum { @@ -955,49 +1392,95 @@ message TestRequiredOneof { int32 foo_int = 1; string foo_string = 2; NestedMessage foo_message = 3; - NestedMessage foo_lazy_message = 4 [lazy = true]; + NestedMessage foo_lazy_message = 4 [ + lazy = true + ]; } + message NestedMessage { - required double required_double = 1; + double required_double = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; } } // Test messages for packed fields message TestPackedTypes { - repeated int32 packed_int32 = 90 [packed = true]; - repeated int64 packed_int64 = 91 [packed = true]; - repeated uint32 packed_uint32 = 92 [packed = true]; - repeated uint64 packed_uint64 = 93 [packed = true]; - repeated sint32 packed_sint32 = 94 [packed = true]; - repeated sint64 packed_sint64 = 95 [packed = true]; - repeated fixed32 packed_fixed32 = 96 [packed = true]; - repeated fixed64 packed_fixed64 = 97 [packed = true]; - repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - repeated float packed_float = 100 [packed = true]; - repeated double packed_double = 101 [packed = true]; - repeated bool packed_bool = 102 [packed = true]; - repeated ForeignEnum packed_enum = 103 [packed = true]; + repeated int32 packed_int32 = 90 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int64 packed_int64 = 91 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint32 packed_uint32 = 92 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint64 packed_uint64 = 93 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint32 packed_sint32 = 94 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint64 packed_sint64 = 95 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed32 packed_fixed32 = 96 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed64 packed_fixed64 = 97 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed32 packed_sfixed32 = 98 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed64 packed_sfixed64 = 99 [ + features.repeated_field_encoding = PACKED + ]; + + repeated float packed_float = 100 [ + features.repeated_field_encoding = PACKED + ]; + + repeated double packed_double = 101 [ + features.repeated_field_encoding = PACKED + ]; + + repeated bool packed_bool = 102 [ + features.repeated_field_encoding = PACKED + ]; + + repeated ForeignEnum packed_enum = 103 [ + features.repeated_field_encoding = PACKED + ]; } // A message with the same fields as TestPackedTypes, but without packing. Used // to test packed <-> unpacked wire compatibility. message TestUnpackedTypes { - repeated int32 unpacked_int32 = 90 [packed = false]; - repeated int64 unpacked_int64 = 91 [packed = false]; - repeated uint32 unpacked_uint32 = 92 [packed = false]; - repeated uint64 unpacked_uint64 = 93 [packed = false]; - repeated sint32 unpacked_sint32 = 94 [packed = false]; - repeated sint64 unpacked_sint64 = 95 [packed = false]; - repeated fixed32 unpacked_fixed32 = 96 [packed = false]; - repeated fixed64 unpacked_fixed64 = 97 [packed = false]; - repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; - repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; - repeated float unpacked_float = 100 [packed = false]; - repeated double unpacked_double = 101 [packed = false]; - repeated bool unpacked_bool = 102 [packed = false]; - repeated ForeignEnum unpacked_enum = 103 [packed = false]; + repeated int32 unpacked_int32 = 90; + repeated int64 unpacked_int64 = 91; + repeated uint32 unpacked_uint32 = 92; + repeated uint64 unpacked_uint64 = 93; + repeated sint32 unpacked_sint32 = 94; + repeated sint64 unpacked_sint64 = 95; + repeated fixed32 unpacked_fixed32 = 96; + repeated fixed64 unpacked_fixed64 = 97; + repeated sfixed32 unpacked_sfixed32 = 98; + repeated sfixed64 unpacked_sfixed64 = 99; + repeated float unpacked_float = 100; + repeated double unpacked_double = 101; + repeated bool unpacked_bool = 102; + repeated ForeignEnum unpacked_enum = 103; } message TestPackedExtensions { @@ -1005,20 +1488,61 @@ message TestPackedExtensions { } extend TestPackedExtensions { - repeated int32 packed_int32_extension = 90 [packed = true]; - repeated int64 packed_int64_extension = 91 [packed = true]; - repeated uint32 packed_uint32_extension = 92 [packed = true]; - repeated uint64 packed_uint64_extension = 93 [packed = true]; - repeated sint32 packed_sint32_extension = 94 [packed = true]; - repeated sint64 packed_sint64_extension = 95 [packed = true]; - repeated fixed32 packed_fixed32_extension = 96 [packed = true]; - repeated fixed64 packed_fixed64_extension = 97 [packed = true]; - repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; - repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; - repeated float packed_float_extension = 100 [packed = true]; - repeated double packed_double_extension = 101 [packed = true]; - repeated bool packed_bool_extension = 102 [packed = true]; - repeated ForeignEnum packed_enum_extension = 103 [packed = true]; + repeated int32 packed_int32_extension = 90 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int64 packed_int64_extension = 91 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint32 packed_uint32_extension = 92 [ + features.repeated_field_encoding = PACKED + ]; + + repeated uint64 packed_uint64_extension = 93 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint32 packed_sint32_extension = 94 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sint64 packed_sint64_extension = 95 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed32 packed_fixed32_extension = 96 [ + features.repeated_field_encoding = PACKED + ]; + + repeated fixed64 packed_fixed64_extension = 97 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed32 packed_sfixed32_extension = 98 [ + features.repeated_field_encoding = PACKED + ]; + + repeated sfixed64 packed_sfixed64_extension = 99 [ + features.repeated_field_encoding = PACKED + ]; + + repeated float packed_float_extension = 100 [ + features.repeated_field_encoding = PACKED + ]; + + repeated double packed_double_extension = 101 [ + features.repeated_field_encoding = PACKED + ]; + + repeated bool packed_bool_extension = 102 [ + features.repeated_field_encoding = PACKED + ]; + + repeated ForeignEnum packed_enum_extension = 103 [ + features.repeated_field_encoding = PACKED + ]; } message TestUnpackedExtensions { @@ -1026,20 +1550,20 @@ message TestUnpackedExtensions { } extend TestUnpackedExtensions { - repeated int32 unpacked_int32_extension = 90 [packed = false]; - repeated int64 unpacked_int64_extension = 91 [packed = false]; - repeated uint32 unpacked_uint32_extension = 92 [packed = false]; - repeated uint64 unpacked_uint64_extension = 93 [packed = false]; - repeated sint32 unpacked_sint32_extension = 94 [packed = false]; - repeated sint64 unpacked_sint64_extension = 95 [packed = false]; - repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; - repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; - repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; - repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; - repeated float unpacked_float_extension = 100 [packed = false]; - repeated double unpacked_double_extension = 101 [packed = false]; - repeated bool unpacked_bool_extension = 102 [packed = false]; - repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; + repeated int32 unpacked_int32_extension = 90; + repeated int64 unpacked_int64_extension = 91; + repeated uint32 unpacked_uint32_extension = 92; + repeated uint64 unpacked_uint64_extension = 93; + repeated sint32 unpacked_sint32_extension = 94; + repeated sint64 unpacked_sint64_extension = 95; + repeated fixed32 unpacked_fixed32_extension = 96; + repeated fixed64 unpacked_fixed64_extension = 97; + repeated sfixed32 unpacked_sfixed32_extension = 98; + repeated sfixed64 unpacked_sfixed64_extension = 99; + repeated float unpacked_float_extension = 100; + repeated double unpacked_double_extension = 101; + repeated bool unpacked_bool_extension = 102; + repeated ForeignEnum unpacked_enum_extension = 103; } // Used by ExtensionSetTest/DynamicExtensions. The test actually builds @@ -1051,25 +1575,25 @@ message TestDynamicExtensions { DYNAMIC_BAR = 2201; DYNAMIC_BAZ = 2202; } + message DynamicMessageType { - optional int32 dynamic_field = 2100; + int32 dynamic_field = 2100; } - optional fixed32 scalar_extension = 2000; - optional ForeignEnum enum_extension = 2001; - optional DynamicEnumType dynamic_enum_extension = 2002; - - optional ForeignMessage message_extension = 2003; - optional DynamicMessageType dynamic_message_extension = 2004; - + fixed32 scalar_extension = 2000; + ForeignEnum enum_extension = 2001; + DynamicEnumType dynamic_enum_extension = 2002; + ForeignMessage message_extension = 2003; + DynamicMessageType dynamic_message_extension = 2004; repeated string repeated_extension = 2005; - repeated sint32 packed_extension = 2006 [packed = true]; + repeated sint32 packed_extension = 2006 [ + features.repeated_field_encoding = PACKED + ]; } message TestRepeatedString { repeated string repeated_string1 = 1; repeated string repeated_string2 = 2; - repeated bytes repeated_bytes11 = 11; repeated bytes repeated_bytes12 = 12; } @@ -1079,16 +1603,17 @@ message TestRepeatedScalarDifferentTagSizes { // used in order to get a tag of the right size; all of the repeated fields // in TestAllTypes didn't trigger the check. repeated fixed32 repeated_fixed32 = 12; + // Check for a varint type, just for good measure. - repeated int32 repeated_int32 = 13; + repeated int32 repeated_int32 = 13; // These have two-byte tags. repeated fixed64 repeated_fixed64 = 2046; - repeated int64 repeated_int64 = 2047; + repeated int64 repeated_int64 = 2047; // Three byte tags. - repeated float repeated_float = 262142; - repeated uint64 repeated_uint64 = 262143; + repeated float repeated_float = 262142; + repeated uint64 repeated_uint64 = 262143; } // Test that if an optional or required message/group field appears multiple @@ -1103,27 +1628,54 @@ message TestParsingMerge { repeated TestAllTypes field1 = 1; repeated TestAllTypes field2 = 2; repeated TestAllTypes field3 = 3; - repeated group Group1 = 10 { - optional TestAllTypes field1 = 11; + + message Group1 { + TestAllTypes field1 = 11; } - repeated group Group2 = 20 { - optional TestAllTypes field1 = 21; + + repeated Group1 group1 = 10 [ + features.message_encoding = DELIMITED + ]; + + message Group2 { + TestAllTypes field1 = 21; } + + repeated Group2 group2 = 20 [ + features.message_encoding = DELIMITED + ]; + repeated TestAllTypes ext1 = 1000; repeated TestAllTypes ext2 = 1001; } - required TestAllTypes required_all_types = 1; - optional TestAllTypes optional_all_types = 2; + + TestAllTypes required_all_types = 1 [ + features.field_presence = LEGACY_REQUIRED + ]; + + TestAllTypes optional_all_types = 2; repeated TestAllTypes repeated_all_types = 3; - optional group OptionalGroup = 10 { - optional TestAllTypes optional_group_all_types = 11; + + message OptionalGroup { + TestAllTypes optional_group_all_types = 11; } - repeated group RepeatedGroup = 20 { - optional TestAllTypes repeated_group_all_types = 21; + + OptionalGroup optionalgroup = 10 [ + features.message_encoding = DELIMITED + ]; + + message RepeatedGroup { + TestAllTypes repeated_group_all_types = 21; } + + repeated RepeatedGroup repeatedgroup = 20 [ + features.message_encoding = DELIMITED + ]; + extensions 1000 to max; + extend TestParsingMerge { - optional TestAllTypes optional_ext = 1000; + TestAllTypes optional_ext = 1000; repeated TestAllTypes repeated_ext = 1001; } } @@ -1131,65 +1683,104 @@ message TestParsingMerge { // Test that the correct exception is thrown by parseFrom in a corner case // involving merging, extensions, and required fields. message TestMergeException { - optional TestAllExtensions all_extensions = 1; + TestAllExtensions all_extensions = 1; } message TestCommentInjectionMessage { // */ <- This should not close the generated doc comment - optional string a = 1 [default="*/ <- Neither should this."]; + string a = 1 [ + default = "*/ <- Neither should this." + ]; } // Used to check that the c++ code generator re-orders messages to reduce // padding. message TestMessageSize { - optional bool m1 = 1; - optional int64 m2 = 2; - optional bool m3 = 3; - optional string m4 = 4; - optional int32 m5 = 5; - optional int64 m6 = 6; + bool m1 = 1; + int64 m2 = 2; + bool m3 = 3; + string m4 = 4; + int32 m5 = 5; + int64 m6 = 6; +} + +message OpenEnumMessage { + enum TestEnum { + option features.enum_type = OPEN; + + UNKNOWN = 0; + FOO = 1; + BAR = 2; + BAZ = 3; + } + + TestEnum opt_open = 1; + + ForeignEnum opt_closed = 2; + repeated TestEnum repeated_open = 3; + + repeated ForeignEnum repeated_closed = 4; } // Test that RPC services work. -message FooRequest {} -message FooResponse {} +message FooRequest { +} -message FooClientMessage {} -message FooServerMessage{} +message FooResponse { +} + +message FooClientMessage { +} + +message FooServerMessage { +} service TestService { rpc Foo(FooRequest) returns (FooResponse); + rpc Bar(BarRequest) returns (BarResponse); } -message BarRequest {} -message BarResponse {} +message BarRequest { +} + +message BarResponse { +} message TestJsonName { - optional int32 field_name1 = 1; - optional int32 fieldName2 = 2; - optional int32 FieldName3 = 3; - optional int32 _field_name4 = 4; - optional int32 FIELD_NAME5 = 5; - optional int32 field_name6 = 6 [json_name = "@type"]; - optional int32 fieldname7 = 7; + int32 field_name1 = 1; + int32 fieldName2 = 2; + int32 FieldName3 = 3; + int32 _field_name4 = 4; + int32 FIELD_NAME5 = 5; + int32 field_name6 = 6 [ + json_name = "@type" + ]; + + int32 fieldname7 = 7; } message TestHugeFieldNumbers { - optional int32 optional_int32 = 536870000; - optional int32 fixed_32 = 536870001; - repeated int32 repeated_int32 = 536870002 [packed = false]; - repeated int32 packed_int32 = 536870003 [packed = true]; - - optional ForeignEnum optional_enum = 536870004; - optional string optional_string = 536870005; - optional bytes optional_bytes = 536870006; - optional ForeignMessage optional_message = 536870007; - - optional group OptionalGroup = 536870008 { - optional int32 group_a = 536870009; + int32 optional_int32 = 536870000; + int32 fixed_32 = 536870001; + repeated int32 repeated_int32 = 536870002; + repeated int32 packed_int32 = 536870003 [ + features.repeated_field_encoding = PACKED + ]; + + ForeignEnum optional_enum = 536870004; + string optional_string = 536870005; + bytes optional_bytes = 536870006; + ForeignMessage optional_message = 536870007; + + message OptionalGroup { + int32 group_a = 536870009; } + OptionalGroup optionalgroup = 536870008 [ + features.message_encoding = DELIMITED + ]; + map string_string_map = 536870010; oneof oneof_field { @@ -1199,63 +1790,82 @@ message TestHugeFieldNumbers { bytes oneof_bytes = 536870014; } - extensions 536860000 to 536869999 [declaration = { - number: 536860000 - full_name: ".protobuf_unittest.test_all_types" - type: ".protobuf_unittest.TestAllTypes" - }]; + extensions 536860000 to 536869999 [ + declaration = { + number: 536860000 + full_name: ".protobuf_unittest.test_all_types" + type: ".protobuf_unittest.TestAllTypes" + } + ]; } extend TestHugeFieldNumbers { - optional TestAllTypes test_all_types = 536860000; + TestAllTypes test_all_types = 536860000; } message TestExtensionInsideTable { - optional int32 field1 = 1; - optional int32 field2 = 2; - optional int32 field3 = 3; - optional int32 field4 = 4; - extensions 5 to 5; - optional int32 field6 = 6; - optional int32 field7 = 7; - optional int32 field8 = 8; - optional int32 field9 = 9; - optional int32 field10 = 10; + int32 field1 = 1; + int32 field2 = 2; + int32 field3 = 3; + int32 field4 = 4; + + extensions 5; + + int32 field6 = 6; + int32 field7 = 7; + int32 field8 = 8; + int32 field9 = 9; + int32 field10 = 10; } extend TestExtensionInsideTable { - optional int32 test_extension_inside_table_extension = 5; + int32 test_extension_inside_table_extension = 5; } // NOTE: Intentionally nested to mirror go/glep. message TestNestedGroupExtensionOuter { - optional group Layer1OptionalGroup = 1 { - repeated group Layer2RepeatedGroup = 2 { + message Layer1OptionalGroup { + message Layer2RepeatedGroup { extensions 3 - // NOTE: extension metadata is not supported due to targets such as - // `//google/protobuf_legacy_opensource/src:shell_scripts_test`, - // eee https://screenshot.googleplex.com/Axz2QD8nxjdpyFF - //[metadata = { - // NOTE: can't write type there due to some clever build gen code at - // http://google3/google/protobuf/BUILD;l=1247;rcl=411090862 - // type: "protobuf_unittest.TestNestedGroupExtensionInnerExtension", - // name: "inner", - // }] - ; - optional string another_field = 6; + // NOTE: extension metadata is not supported due to targets such as + // `//google/protobuf_legacy_opensource/src:shell_scripts_test`, + // eee https://screenshot.googleplex.com/Axz2QD8nxjdpyFF + // [metadata = { + // NOTE: can't write type there due to some clever build gen code at + // http://google3/google/protobuf/BUILD;l=1247;rcl=411090862 + // type: "protobuf_unittest.TestNestedGroupExtensionInnerExtension", + // name: "inner", + // }] + ; + + string another_field = 6; } - repeated group Layer2AnotherOptionalRepeatedGroup = 4 { - optional string but_why_tho = 5; + + repeated Layer2RepeatedGroup layer2repeatedgroup = 2 [ + features.message_encoding = DELIMITED + ]; + + message Layer2AnotherOptionalRepeatedGroup { + string but_why_tho = 5; } + + repeated Layer2AnotherOptionalRepeatedGroup + layer2anotheroptionalrepeatedgroup = 4 [ + features.message_encoding = DELIMITED + ]; } + + Layer1OptionalGroup layer1optionalgroup = 1 [ + features.message_encoding = DELIMITED + ]; } message TestNestedGroupExtensionInnerExtension { - optional string inner_name= 1; + string inner_name = 1; } extend TestNestedGroupExtensionOuter.Layer1OptionalGroup.Layer2RepeatedGroup { - optional TestNestedGroupExtensionInnerExtension inner = 3; + TestNestedGroupExtensionInnerExtension inner = 3; } enum VeryLargeEnum { @@ -1360,163 +1970,147 @@ enum VeryLargeEnum { ENUM_LABEL_98 = 98; ENUM_LABEL_99 = 99; ENUM_LABEL_100 = 100; -}; +} message TestExtensionRangeSerialize { - optional int32 foo_one = 1; + int32 foo_one = 1; - extensions 2 to 2; + extensions 2; extensions 3 to 4; - optional int32 foo_two = 6; - optional int32 foo_three = 7; + int32 foo_two = 6; + int32 foo_three = 7; extensions 9 to 10; - optional int32 foo_four = 13; + int32 foo_four = 13; extensions 15 to 15; extensions 17 to 17; extensions 19 to 19; extend TestExtensionRangeSerialize { - optional int32 bar_one = 2; - optional int32 bar_two = 4; - - optional int32 bar_three = 10; - - optional int32 bar_four = 15; - optional int32 bar_five = 19; + int32 bar_one = 2; + int32 bar_two = 4; + int32 bar_three = 10; + int32 bar_four = 15; + int32 bar_five = 19; } } message TestVerifyInt32Simple { - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; + int32 optional_int32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; } message TestVerifyInt32 { - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + int32 optional_int32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyMostlyInt32 { - optional int64 optional_int64_30 = 30; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_3 = 3; - optional int32 optional_int32_4 = 4; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + int64 optional_int64_30 = 30; + int32 optional_int32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_3 = 3; + int32 optional_int32_4 = 4; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyMostlyInt32BigFieldNumber { - optional int64 optional_int64_30 = 30; - optional int32 optional_int32_300 = 300; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_3 = 3; - optional int32 optional_int32_4 = 4; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + int64 optional_int64_30 = 30; + int32 optional_int32_300 = 300; + int32 optional_int32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_3 = 3; + int32 optional_int32_4 = 4; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyUint32Simple { - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; + uint32 optional_uint32_1 = 1; + uint32 optional_uint32_2 = 2; + uint32 optional_uint32_63 = 63; + uint32 optional_uint32_64 = 64; } message TestVerifyUint32 { - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + uint32 optional_uint32_1 = 1; + uint32 optional_uint32_2 = 2; + uint32 optional_uint32_63 = 63; + uint32 optional_uint32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyOneUint32 { - optional uint32 optional_uint32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + uint32 optional_uint32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyOneInt32BigFieldNumber { - optional int32 optional_int32_65 = 65; - - optional int64 optional_int64_1 = 1; - optional int64 optional_int64_2 = 2; - optional int64 optional_int64_63 = 63; - optional int64 optional_int64_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + int32 optional_int32_65 = 65; + int64 optional_int64_1 = 1; + int64 optional_int64_2 = 2; + int64 optional_int64_63 = 63; + int64 optional_int64_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyInt32BigFieldNumber { - optional int32 optional_int32_1000 = 1000; - optional int32 optional_int32_65 = 65; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + int32 optional_int32_1000 = 1000; + int32 optional_int32_65 = 65; + int32 optional_int32_1 = 1; + int32 optional_int32_2 = 2; + int32 optional_int32_63 = 63; + int32 optional_int32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyUint32BigFieldNumber { - optional uint32 optional_uint32_1000 = 1000; - optional uint32 optional_uint32_65 = 65; - - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; + uint32 optional_uint32_1000 = 1000; + uint32 optional_uint32_65 = 65; + uint32 optional_uint32_1 = 1; + uint32 optional_uint32_2 = 2; + uint32 optional_uint32_63 = 63; + uint32 optional_uint32_64 = 64; + TestAllTypes optional_all_types = 9; + repeated TestAllTypes repeated_all_types = 10; } message TestVerifyBigFieldNumberUint32 { message Nested { - optional uint32 optional_uint32_5000 = 5000; - optional uint32 optional_uint32_1000 = 1000; - optional uint32 optional_uint32_66 = 66; - optional uint32 optional_uint32_65 = 65; - - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional Nested optional_nested = 9; + uint32 optional_uint32_5000 = 5000; + uint32 optional_uint32_1000 = 1000; + uint32 optional_uint32_66 = 66; + uint32 optional_uint32_65 = 65; + uint32 optional_uint32_1 = 1; + uint32 optional_uint32_2 = 2; + uint32 optional_uint32_63 = 63; + uint32 optional_uint32_64 = 64; + Nested optional_nested = 9; repeated Nested repeated_nested = 10; } - optional Nested optional_nested = 1; + + Nested optional_nested = 1; } // This message contains different kind of enums to exercise the different @@ -1526,31 +2120,49 @@ message EnumParseTester { SEQ_SMALL_0_DEFAULT = 0; SEQ_SMALL_0_1 = 1; SEQ_SMALL_0_2 = 2; - }; - optional SeqSmall0 optional_seq_small_0_lowfield = 1; - optional SeqSmall0 optional_seq_small_0_midfield = 1001; - optional SeqSmall0 optional_seq_small_0_hifield = 1000001; + } + + SeqSmall0 optional_seq_small_0_lowfield = 1; + SeqSmall0 optional_seq_small_0_midfield = 1001; + SeqSmall0 optional_seq_small_0_hifield = 1000001; repeated SeqSmall0 repeated_seq_small_0_lowfield = 2; repeated SeqSmall0 repeated_seq_small_0_midfield = 1002; repeated SeqSmall0 repeated_seq_small_0_hifield = 1000002; - repeated SeqSmall0 packed_seq_small_0_lowfield = 3 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_midfield = 1003 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_hifield = 1000003 [packed = true]; + repeated SeqSmall0 packed_seq_small_0_lowfield = 3 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqSmall0 packed_seq_small_0_midfield = 1003 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqSmall0 packed_seq_small_0_hifield = 1000003 [ + features.repeated_field_encoding = PACKED + ]; enum SeqSmall1 { SEQ_SMALL_1_DEFAULT = 1; SEQ_SMALL_1_2 = 2; SEQ_SMALL_1_3 = 3; - }; - optional SeqSmall1 optional_seq_small_1_lowfield = 4; - optional SeqSmall1 optional_seq_small_1_midfield = 1004; - optional SeqSmall1 optional_seq_small_1_hifield = 1000004; + } + + SeqSmall1 optional_seq_small_1_lowfield = 4; + SeqSmall1 optional_seq_small_1_midfield = 1004; + SeqSmall1 optional_seq_small_1_hifield = 1000004; repeated SeqSmall1 repeated_seq_small_1_lowfield = 5; repeated SeqSmall1 repeated_seq_small_1_midfield = 1005; repeated SeqSmall1 repeated_seq_small_1_hifield = 1000005; - repeated SeqSmall1 packed_seq_small_1_lowfield = 6 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_midfield = 1006 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_hifield = 1000006 [packed = true]; + repeated SeqSmall1 packed_seq_small_1_lowfield = 6 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqSmall1 packed_seq_small_1_midfield = 1006 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqSmall1 packed_seq_small_1_hifield = 1000006 [ + features.repeated_field_encoding = PACKED + ]; enum SeqLarge { SEQ_LARGE_DEFAULT = -1; @@ -1588,16 +2200,25 @@ message EnumParseTester { SEQ_LARGE_31 = 31; SEQ_LARGE_32 = 32; SEQ_LARGE_33 = 33; - }; - optional SeqLarge optional_seq_large_lowfield = 7; - optional SeqLarge optional_seq_large_midfield = 1007; - optional SeqLarge optional_seq_large_hifield = 1000007; + } + + SeqLarge optional_seq_large_lowfield = 7; + SeqLarge optional_seq_large_midfield = 1007; + SeqLarge optional_seq_large_hifield = 1000007; repeated SeqLarge repeated_seq_large_lowfield = 8; repeated SeqLarge repeated_seq_large_midfield = 1008; repeated SeqLarge repeated_seq_large_hifield = 1000008; - repeated SeqLarge packed_seq_large_lowfield = 9 [packed = true]; - repeated SeqLarge packed_seq_large_midfield = 1009 [packed = true]; - repeated SeqLarge packed_seq_large_hifield = 1000009 [packed = true]; + repeated SeqLarge packed_seq_large_lowfield = 9 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqLarge packed_seq_large_midfield = 1009 [ + features.repeated_field_encoding = PACKED + ]; + + repeated SeqLarge packed_seq_large_hifield = 1000009 [ + features.repeated_field_encoding = PACKED + ]; enum Arbitrary { ARBITRARY_DEFAULT = -123123; @@ -1606,156 +2227,232 @@ message EnumParseTester { ARBITRARY_3 = 213213; ARBITRARY_MIN = -2147483648; ARBITRARY_MAX = 2147483647; - }; - optional Arbitrary optional_arbitrary_lowfield = 10; - optional Arbitrary optional_arbitrary_midfield = 1010; - optional Arbitrary optional_arbitrary_hifield = 1000010; + } + + Arbitrary optional_arbitrary_lowfield = 10; + Arbitrary optional_arbitrary_midfield = 1010; + Arbitrary optional_arbitrary_hifield = 1000010; repeated Arbitrary repeated_arbitrary_lowfield = 11; repeated Arbitrary repeated_arbitrary_midfield = 1011; repeated Arbitrary repeated_arbitrary_hifield = 1000011; - repeated Arbitrary packed_arbitrary_lowfield = 12 [packed = true]; - repeated Arbitrary packed_arbitrary_midfield = 1012 [packed = true]; - repeated Arbitrary packed_arbitrary_hifield = 1000012 [packed = true]; + repeated Arbitrary packed_arbitrary_lowfield = 12 [ + features.repeated_field_encoding = PACKED + ]; + + repeated Arbitrary packed_arbitrary_midfield = 1012 [ + features.repeated_field_encoding = PACKED + ]; + + repeated Arbitrary packed_arbitrary_hifield = 1000012 [ + features.repeated_field_encoding = PACKED + ]; extensions 2000000 to max; + extend EnumParseTester { - optional Arbitrary optional_arbitrary_ext = 2000000; + Arbitrary optional_arbitrary_ext = 2000000; repeated Arbitrary repeated_arbitrary_ext = 2000001; - repeated Arbitrary packed_arbitrary_ext = 2000002 [packed = true]; + repeated Arbitrary packed_arbitrary_ext = 2000002 [ + features.repeated_field_encoding = PACKED + ]; } // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; + int32 other_field = 99; } // This message contains different kind of bool fields to exercise the different // parsers in table-drived. message BoolParseTester { - optional bool optional_bool_lowfield = 1; - optional bool optional_bool_midfield = 1001; - optional bool optional_bool_hifield = 1000001; + bool optional_bool_lowfield = 1; + bool optional_bool_midfield = 1001; + bool optional_bool_hifield = 1000001; repeated bool repeated_bool_lowfield = 2; repeated bool repeated_bool_midfield = 1002; repeated bool repeated_bool_hifield = 1000002; - repeated bool packed_bool_lowfield = 3 [packed = true]; - repeated bool packed_bool_midfield = 1003 [packed = true]; - repeated bool packed_bool_hifield = 1000003 [packed = true]; + repeated bool packed_bool_lowfield = 3 [ + features.repeated_field_encoding = PACKED + ]; + + repeated bool packed_bool_midfield = 1003 [ + features.repeated_field_encoding = PACKED + ]; + + repeated bool packed_bool_hifield = 1000003 [ + features.repeated_field_encoding = PACKED + ]; extensions 2000000 to max; + extend BoolParseTester { - optional bool optional_bool_ext = 2000000; + bool optional_bool_ext = 2000000; repeated bool repeated_bool_ext = 2000001; - repeated bool packed_bool_ext = 2000002 [packed = true]; + repeated bool packed_bool_ext = 2000002 [ + features.repeated_field_encoding = PACKED + ]; } // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; + int32 other_field = 99; } message Int32ParseTester { - optional int32 optional_int32_lowfield = 1; - optional int32 optional_int32_midfield = 1001; - optional int32 optional_int32_hifield = 1000001; + int32 optional_int32_lowfield = 1; + int32 optional_int32_midfield = 1001; + int32 optional_int32_hifield = 1000001; repeated int32 repeated_int32_lowfield = 2; repeated int32 repeated_int32_midfield = 1002; repeated int32 repeated_int32_hifield = 1000002; - repeated int32 packed_int32_lowfield = 3 [packed = true]; - repeated int32 packed_int32_midfield = 1003 [packed = true]; - repeated int32 packed_int32_hifield = 1000003 [packed = true]; + repeated int32 packed_int32_lowfield = 3 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int32 packed_int32_midfield = 1003 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int32 packed_int32_hifield = 1000003 [ + features.repeated_field_encoding = PACKED + ]; extensions 2000000 to max; + extend Int32ParseTester { - optional int32 optional_int32_ext = 2000000; + int32 optional_int32_ext = 2000000; repeated int32 repeated_int32_ext = 2000001; - repeated int32 packed_int32_ext = 2000002 [packed = true]; + repeated int32 packed_int32_ext = 2000002 [ + features.repeated_field_encoding = PACKED + ]; } // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; + int32 other_field = 99; } message Int64ParseTester { - optional int64 optional_int64_lowfield = 1; - optional int64 optional_int64_midfield = 1001; - optional int64 optional_int64_hifield = 1000001; + int64 optional_int64_lowfield = 1; + int64 optional_int64_midfield = 1001; + int64 optional_int64_hifield = 1000001; repeated int64 repeated_int64_lowfield = 2; repeated int64 repeated_int64_midfield = 1002; repeated int64 repeated_int64_hifield = 1000002; - repeated int64 packed_int64_lowfield = 3 [packed = true]; - repeated int64 packed_int64_midfield = 1003 [packed = true]; - repeated int64 packed_int64_hifield = 1000003 [packed = true]; + repeated int64 packed_int64_lowfield = 3 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int64 packed_int64_midfield = 1003 [ + features.repeated_field_encoding = PACKED + ]; + + repeated int64 packed_int64_hifield = 1000003 [ + features.repeated_field_encoding = PACKED + ]; extensions 2000000 to max; + extend Int64ParseTester { - optional int64 optional_int64_ext = 2000000; + int64 optional_int64_ext = 2000000; repeated int64 repeated_int64_ext = 2000001; - repeated int64 packed_int64_ext = 2000002 [packed = true]; + repeated int64 packed_int64_ext = 2000002 [ + features.repeated_field_encoding = PACKED + ]; } // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; + int32 other_field = 99; } message InlinedStringIdxRegressionProto { // We mix data to make sure aux ids and inlined string idx do not match. // aux_idx == inlined_string_idx == 1 - optional string str1 = 1; + string str1 = 1; + // aux_idx == 2 - optional InlinedStringIdxRegressionProto sub = 2; + InlinedStringIdxRegressionProto sub = 2; + // aux_idx == 3, inlined_string_idx == 2 - optional string str2 = 3; + string str2 = 3; + // aux_idx == 4, inlined_string_idx == 3 - optional bytes str3 = 4; + bytes str3 = 4; } message StringParseTester { - optional string optional_string_lowfield = 1; - optional string optional_string_midfield = 1001; - optional string optional_string_hifield = 1000001; + string optional_string_lowfield = 1; + string optional_string_midfield = 1001; + string optional_string_hifield = 1000001; repeated string repeated_string_lowfield = 2; repeated string repeated_string_midfield = 1002; repeated string repeated_string_hifield = 1000002; extensions 2000000 to max; + extend StringParseTester { - optional string optional_string_ext = 2000000; + string optional_string_ext = 2000000; repeated string repeated_string_ext = 2000001; } } -message BadFieldNames{ - optional int32 OptionalInt32 = 1; - optional int32 for = 2; +message BadFieldNames { + int32 OptionalInt32 = 1; + int32 for = 2; } message TestNestedMessageRedaction { - optional string optional_unredacted_nested_string = 1; - optional string optional_redacted_nested_string = 2 [debug_redact = true]; + string optional_unredacted_nested_string = 1; + string optional_redacted_nested_string = 2 [ + debug_redact = true + ]; } message RedactedFields { - optional string optional_redacted_string = 1 [debug_redact = true]; - optional string optional_unredacted_string = 2; - repeated string repeated_redacted_string = 3 [debug_redact = true]; + string optional_redacted_string = 1 [ + debug_redact = true + ]; + + string optional_unredacted_string = 2; + repeated string repeated_redacted_string = 3 [ + debug_redact = true + ]; + repeated string repeated_unredacted_string = 4; - optional TestNestedMessageRedaction optional_redacted_message = 5 [debug_redact = true]; - optional TestNestedMessageRedaction optional_unredacted_message = 6; - repeated TestNestedMessageRedaction repeated_redacted_message = 7 - [debug_redact = true]; + TestNestedMessageRedaction optional_redacted_message = 5 [ + debug_redact = true + ]; + + TestNestedMessageRedaction optional_unredacted_message = 6; + repeated TestNestedMessageRedaction repeated_redacted_message = 7 [ + debug_redact = true + ]; + repeated TestNestedMessageRedaction repeated_unredacted_message = 8; - map map_redacted_string = 9 [debug_redact = true]; + map map_redacted_string = 9 [ + debug_redact = true + ]; + map map_unredacted_string = 10; - optional string optional_redacted_false_string = 11 [debug_redact = false]; + string optional_redacted_false_string = 11 [ + debug_redact = false + ]; + extensions 20 to 30; } extend RedactedFields { - optional string redacted_extension = 20 [debug_redact = true]; + string redacted_extension = 20 [ + debug_redact = true + ]; } -message TestCord{ - optional bytes optional_bytes_cord = 1 [ctype=CORD]; - optional bytes optional_bytes_cord_default = 2 [ctype=CORD, default = "hello"]; +message TestCord { + bytes optional_bytes_cord = 1 [ + ctype = CORD + ]; + + bytes optional_bytes_cord_default = 2 [ + ctype = CORD, + default = "hello" + ]; } message TestPackedEnumSmallRange { @@ -1765,7 +2462,10 @@ message TestPackedEnumSmallRange { BAR = 2; BAZ = 3; } - repeated NestedEnum vals = 1 [packed = true]; + + repeated NestedEnum vals = 1 [ + features.repeated_field_encoding = PACKED + ]; } message EnumsForBenchmark { @@ -1787,6 +2487,7 @@ message EnumsForBenchmark { A14 = 14; A15 = 15; } + // Has a few holes, bitmap can be used. enum AlmostFlat { B0 = 0; @@ -1806,6 +2507,7 @@ message EnumsForBenchmark { B17 = 17; B19 = 19; } + enum Sparse { C536 = 536; C8387 = 8387; @@ -1862,25 +2564,39 @@ message TestMessageWithManyRepeatedPtrFields { } message MessageCreatorZeroInit { - optional int32 i = 1; - optional double d = 2; - optional MessageCreatorZeroInit m = 3; + int32 i = 1; + double d = 2; + MessageCreatorZeroInit m = 3; + oneof one { string os = 10; - string oc = 11 [ctype=CORD]; + string oc = 11 [ + ctype = CORD + ]; + fixed64 of = 12; - MessageCreatorZeroInit ol = 13 [lazy=true]; + MessageCreatorZeroInit ol = 13 [ + lazy = true + ]; } } message MessageCreatorMemcpy { - optional string s = 1; - repeated int32 i = 2 [packed=true]; - optional MessageCreatorMemcpy m = 3 [lazy=true]; + string s = 1; + repeated int32 i = 2 [ + features.repeated_field_encoding = PACKED + ]; + + MessageCreatorMemcpy m = 3 [ + lazy = true + ]; + map m2 = 4; } message MessageCreatorFunc { // This one is ArenaDtorNeeds::kRequired so we must run the constructor. - optional string c = 3 [ctype=CORD]; + string c = 3 [ + ctype = CORD + ]; }