Merge pull request #7344 from haberman/sync-integrate

Integrate from Piper @304070343 for C++, Java, and Python
pull/7348/head
Joshua Haberman 5 years ago committed by GitHub
commit e667bf6eaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 2
      benchmarks/datasets/google_message2/benchmark_message2.proto
  3. 5
      benchmarks/datasets/google_message3/benchmark_message3.proto
  4. 47
      benchmarks/datasets/google_message3/benchmark_message3_1.proto
  5. 14
      benchmarks/datasets/google_message3/benchmark_message3_2.proto
  6. 11
      benchmarks/datasets/google_message3/benchmark_message3_3.proto
  7. 32
      benchmarks/datasets/google_message3/benchmark_message3_4.proto
  8. 42
      benchmarks/datasets/google_message3/benchmark_message3_5.proto
  9. 14
      benchmarks/datasets/google_message3/benchmark_message3_6.proto
  10. 12
      benchmarks/datasets/google_message3/benchmark_message3_7.proto
  11. 8
      benchmarks/datasets/google_message3/benchmark_message3_8.proto
  12. 15
      benchmarks/datasets/google_message4/benchmark_message4.proto
  13. 23
      benchmarks/datasets/google_message4/benchmark_message4_1.proto
  14. 21
      benchmarks/datasets/google_message4/benchmark_message4_2.proto
  15. 5
      benchmarks/datasets/google_message4/benchmark_message4_3.proto
  16. 2
      cmake/tests.cmake
  17. 4
      conformance/binary_json_conformance_suite.cc
  18. 3
      conformance/conformance_python.py
  19. 60
      conformance/text_format_conformance_suite.cc
  20. 2
      csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs
  21. BIN
      csharp/src/Google.Protobuf.Test/testprotos.pb
  22. 250
      csharp/src/Google.Protobuf/Reflection/Descriptor.cs
  23. 20
      java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
  24. 2
      java/core/src/main/java/com/google/protobuf/CodedInputStream.java
  25. 35
      java/core/src/main/java/com/google/protobuf/Descriptors.java
  26. 20
      java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
  27. 20
      java/core/src/main/java/com/google/protobuf/FloatArrayList.java
  28. 6
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
  29. 76
      java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
  30. 20
      java/core/src/main/java/com/google/protobuf/IntArrayList.java
  31. 20
      java/core/src/main/java/com/google/protobuf/LongArrayList.java
  32. 120
      java/core/src/main/java/com/google/protobuf/MessageSchema.java
  33. 2
      java/core/src/main/java/com/google/protobuf/RawMessageInfo.java
  34. 8
      java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
  35. 8
      java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
  36. 145
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  37. 8
      java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
  38. 62
      java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
  39. 62
      java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
  40. 2
      java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
  41. 62
      java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
  42. 62
      java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
  43. 62
      java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
  44. 38
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  45. 24
      java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java
  46. 31
      java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
  47. 2
      java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
  48. 4
      java/util/src/main/java/com/google/protobuf/util/Values.java
  49. 36
      java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
  50. 13
      java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
  51. 2
      js/message_test.js
  52. 1
      php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
  53. 69
      php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
  54. 6
      php/src/Google/Protobuf/Internal/FileOptions.php
  55. 93
      python/google/protobuf/descriptor.py
  56. 82
      python/google/protobuf/descriptor_pool.py
  57. 6
      python/google/protobuf/internal/decoder.py
  58. 75
      python/google/protobuf/internal/descriptor_pool_test.py
  59. 4
      python/google/protobuf/internal/descriptor_test.py
  60. 4
      python/google/protobuf/internal/extension_dict.py
  61. 4
      python/google/protobuf/internal/json_format_test.py
  62. 20
      python/google/protobuf/internal/message_test.py
  63. 14
      python/google/protobuf/internal/python_message.py
  64. 57
      python/google/protobuf/internal/reflection_test.py
  65. 18
      python/google/protobuf/internal/text_format_test.py
  66. 12
      python/google/protobuf/internal/type_checkers.py
  67. 6
      python/google/protobuf/json_format.py
  68. 2
      python/google/protobuf/message_factory.py
  69. 11
      python/google/protobuf/pyext/message.cc
  70. 9
      python/google/protobuf/pyext/message_module.cc
  71. 62
      python/google/protobuf/text_format.py
  72. 51
      python/setup.py
  73. 5
      src/Makefile.am
  74. 59
      src/google/protobuf/any.pb.cc
  75. 141
      src/google/protobuf/any.pb.h
  76. 206
      src/google/protobuf/api.pb.cc
  77. 504
      src/google/protobuf/api.pb.h
  78. 37
      src/google/protobuf/arena.h
  79. 10
      src/google/protobuf/compiler/code_generator.h
  80. 227
      src/google/protobuf/compiler/command_line_interface.cc
  81. 29
      src/google/protobuf/compiler/command_line_interface.h
  82. 136
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  83. 4
      src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
  84. 7
      src/google/protobuf/compiler/cpp/cpp_extension.cc
  85. 24
      src/google/protobuf/compiler/cpp/cpp_file.cc
  86. 2
      src/google/protobuf/compiler/cpp/cpp_generator.cc
  87. 9
      src/google/protobuf/compiler/cpp/cpp_generator.h
  88. 205
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  89. 52
      src/google/protobuf/compiler/cpp/cpp_helpers.h
  90. 1048
      src/google/protobuf/compiler/cpp/cpp_message.cc
  91. 5
      src/google/protobuf/compiler/cpp/cpp_message.h
  92. 175
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  93. 4
      src/google/protobuf/compiler/cpp/cpp_options.h
  94. 76
      src/google/protobuf/compiler/cpp/cpp_string_field.cc
  95. 4
      src/google/protobuf/compiler/cpp/cpp_unittest.inc
  96. 5
      src/google/protobuf/compiler/importer.cc
  97. 3
      src/google/protobuf/compiler/importer.h
  98. 8
      src/google/protobuf/compiler/importer_unittest.cc
  99. 31
      src/google/protobuf/compiler/java/java_enum.cc
  100. 70
      src/google/protobuf/compiler/java/java_enum_field.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -524,6 +524,7 @@ RELATIVE_TEST_PROTOS = [
"google/protobuf/unittest_proto3_arena.proto", "google/protobuf/unittest_proto3_arena.proto",
"google/protobuf/unittest_proto3_arena_lite.proto", "google/protobuf/unittest_proto3_arena_lite.proto",
"google/protobuf/unittest_proto3_lite.proto", "google/protobuf/unittest_proto3_lite.proto",
"google/protobuf/unittest_proto3_optional.proto",
"google/protobuf/unittest_well_known_types.proto", "google/protobuf/unittest_well_known_types.proto",
"google/protobuf/util/internal/testdata/anys.proto", "google/protobuf/util/internal/testdata/anys.proto",
"google/protobuf/util/internal/testdata/books.proto", "google/protobuf/util/internal/testdata/books.proto",

@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
// Benchmark messages for proto2. // Benchmark messages for proto2.
syntax = "proto2"; syntax = "proto2";

@ -28,8 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_1.proto"; import "datasets/google_message3/benchmark_message3_1.proto";
import "datasets/google_message3/benchmark_message3_2.proto"; import "datasets/google_message3/benchmark_message3_2.proto";
import "datasets/google_message3/benchmark_message3_3.proto"; import "datasets/google_message3/benchmark_message3_3.proto";
@ -37,7 +41,6 @@ import "datasets/google_message3/benchmark_message3_4.proto";
import "datasets/google_message3/benchmark_message3_5.proto"; import "datasets/google_message3/benchmark_message3_5.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";

@ -28,14 +28,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_2.proto"; import "datasets/google_message3/benchmark_message3_2.proto";
import "datasets/google_message3/benchmark_message3_3.proto"; import "datasets/google_message3/benchmark_message3_3.proto";
import "datasets/google_message3/benchmark_message3_5.proto"; import "datasets/google_message3/benchmark_message3_5.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -130,15 +133,13 @@ message Message36876 {
optional int32 field37047 = 115; optional int32 field37047 = 115;
optional int32 field37048 = 157; optional int32 field37048 = 157;
} }
repeated group Message36878 = 168 { repeated group Message36878 = 168 {}
}
repeated group Message36879 = 55 { repeated group Message36879 = 55 {
required string field37050 = 56; required string field37050 = 56;
optional int32 field37051 = 69; optional int32 field37051 = 69;
} }
repeated .benchmarks.google_message3.UnusedEmptyMessage field36984 = 78; repeated .benchmarks.google_message3.UnusedEmptyMessage field36984 = 78;
optional group Message36880 = 137 { optional group Message36880 = 137 {}
}
optional uint64 field36986 = 59; optional uint64 field36986 = 59;
optional bytes field36987 = 121; optional bytes field36987 = 121;
optional .benchmarks.google_message3.UnusedEmptyMessage field36988 = 2; optional .benchmarks.google_message3.UnusedEmptyMessage field36988 = 2;
@ -154,11 +155,9 @@ message Message36876 {
optional int32 field36998 = 47; optional int32 field36998 = 47;
optional int32 field36999 = 48; optional int32 field36999 = 48;
optional .benchmarks.google_message3.UnusedEmptyMessage field37000 = 68; optional .benchmarks.google_message3.UnusedEmptyMessage field37000 = 68;
repeated group Message36881 = 23 { repeated group Message36881 = 23 {}
}
optional .benchmarks.google_message3.Message4144 field37002 = 125; optional .benchmarks.google_message3.Message4144 field37002 = 125;
repeated group Message36882 = 35 { repeated group Message36882 = 35 {}
}
optional .benchmarks.google_message3.UnusedEmptyMessage field37004 = 49; optional .benchmarks.google_message3.UnusedEmptyMessage field37004 = 49;
optional .benchmarks.google_message3.Message18921 field37005 = 52; optional .benchmarks.google_message3.Message18921 field37005 = 52;
optional .benchmarks.google_message3.Message36858 field37006 = 46; optional .benchmarks.google_message3.Message36858 field37006 = 46;
@ -171,20 +170,15 @@ message Message36876 {
optional .benchmarks.google_message3.Message0 field37013 = 143; optional .benchmarks.google_message3.Message0 field37013 = 143;
optional .benchmarks.google_message3.UnusedEmptyMessage field37014 = 53; optional .benchmarks.google_message3.UnusedEmptyMessage field37014 = 53;
optional .benchmarks.google_message3.Message36869 field37015 = 15; optional .benchmarks.google_message3.Message36869 field37015 = 15;
optional group Message36883 = 3 { optional group Message36883 = 3 {}
} repeated group Message36884 = 16 {}
repeated group Message36884 = 16 { repeated group Message36885 = 27 {}
} optional group Message36886 = 32 {}
repeated group Message36885 = 27 {
}
optional group Message36886 = 32 {
}
repeated .benchmarks.google_message3.UnusedEnum field37020 = 71; repeated .benchmarks.google_message3.UnusedEnum field37020 = 71;
repeated int32 field37021 = 70; repeated int32 field37021 = 70;
optional .benchmarks.google_message3.UnusedEmptyMessage field37022 = 66; optional .benchmarks.google_message3.UnusedEmptyMessage field37022 = 66;
optional .benchmarks.google_message3.Message13090 field37023 = 67; optional .benchmarks.google_message3.Message13090 field37023 = 67;
optional group Message36887 = 62 { optional group Message36887 = 62 {}
}
repeated .benchmarks.google_message3.Message10155 field37025 = 50; repeated .benchmarks.google_message3.Message10155 field37025 = 50;
repeated .benchmarks.google_message3.Message11874 field37026 = 151; repeated .benchmarks.google_message3.Message11874 field37026 = 151;
optional string field37027 = 12; optional string field37027 = 12;
@ -232,8 +226,7 @@ message Message36876 {
optional int32 field37118 = 160; optional int32 field37118 = 160;
repeated string field37119 = 161; repeated string field37119 = 161;
} }
repeated group Message36910 = 119 { repeated group Message36910 = 119 {}
}
optional group Message36911 = 126 { optional group Message36911 = 126 {
optional .benchmarks.google_message3.UnusedEmptyMessage field37121 = 127; optional .benchmarks.google_message3.UnusedEmptyMessage field37121 = 127;
optional .benchmarks.google_message3.Message35538 field37122 = 130; optional .benchmarks.google_message3.Message35538 field37122 = 130;
@ -247,11 +240,9 @@ message Message36876 {
optional .benchmarks.google_message3.UnusedEmptyMessage field37042 = 155; optional .benchmarks.google_message3.UnusedEmptyMessage field37042 = 155;
} }
message Message1328 { message Message1328 {}
}
message Message6850 { message Message6850 {}
}
message Message6863 { message Message6863 {
optional .benchmarks.google_message3.Enum6858 field6931 = 1; optional .benchmarks.google_message3.Enum6858 field6931 = 1;
@ -289,8 +280,7 @@ message Message6863 {
optional bool field6963 = 34; optional bool field6963 = 34;
} }
message Message6871 { message Message6871 {}
}
message Message7547 { message Message7547 {
required bytes field7549 = 1; required bytes field7549 = 1;
@ -312,8 +302,7 @@ message Message7648 {
optional bool field7680 = 12; optional bool field7680 = 12;
} }
message Message7865 { message Message7865 {}
}
message Message7928 { message Message7928 {
optional string field7940 = 1; optional string field7940 = 1;

@ -28,14 +28,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_3.proto"; import "datasets/google_message3/benchmark_message3_3.proto";
import "datasets/google_message3/benchmark_message3_4.proto"; import "datasets/google_message3/benchmark_message3_4.proto";
import "datasets/google_message3/benchmark_message3_5.proto"; import "datasets/google_message3/benchmark_message3_5.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -109,8 +112,7 @@ message Message24391 {
repeated string field24655 = 6; repeated string field24655 = 6;
} }
message Message27454 { message Message27454 {}
}
message Message27357 { message Message27357 {
optional string field27410 = 1; optional string field27410 = 1;
@ -192,8 +194,7 @@ message Message36869 {
} }
message Message33968 { message Message33968 {
repeated group Message33969 = 1 { repeated group Message33969 = 1 {}
}
repeated .benchmarks.google_message3.Message33958 field33989 = 3; repeated .benchmarks.google_message3.Message33958 field33989 = 3;
optional .benchmarks.google_message3.UnusedEmptyMessage field33990 = 106; optional .benchmarks.google_message3.UnusedEmptyMessage field33990 = 106;
optional bool field33991 = 108; optional bool field33991 = 108;
@ -268,8 +269,7 @@ message Message35573 {
optional string field35696 = 1000; optional string field35696 = 1000;
optional string field35697 = 1004; optional string field35697 = 1004;
optional int32 field35698 = 1003; optional int32 field35698 = 1003;
repeated group Message35574 = 1012 { repeated group Message35574 = 1012 {}
}
optional int64 field35700 = 1011; optional int64 field35700 = 1011;
optional int64 field35701 = 1005; optional int64 field35701 = 1005;
optional int64 field35702 = 1006; optional int64 field35702 = 1006;

@ -28,13 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_4.proto"; import "datasets/google_message3/benchmark_message3_4.proto";
import "datasets/google_message3/benchmark_message3_5.proto"; import "datasets/google_message3/benchmark_message3_5.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -96,8 +99,7 @@ message Message2356 {
optional bytes field2410 = 124; optional bytes field2410 = 124;
} }
optional string field2389 = 120; optional string field2389 = 120;
optional group Message2358 = 107 { optional group Message2358 = 107 {}
}
repeated group Message2359 = 40 { repeated group Message2359 = 40 {
optional string field2413 = 41; optional string field2413 = 41;
optional string field2414 = 42; optional string field2414 = 42;
@ -438,8 +440,7 @@ message Message16724 {
optional bool field16773 = 13; optional bool field16773 = 13;
} }
message Message17728 { message Message17728 {}
}
message Message24356 { message Message24356 {
optional string field24559 = 1; optional string field24559 = 1;

@ -28,19 +28,21 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_5.proto"; import "datasets/google_message3/benchmark_message3_5.proto";
import "datasets/google_message3/benchmark_message3_6.proto"; import "datasets/google_message3/benchmark_message3_6.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
message Message24346 { message Message24346 {}
}
message Message24401 { message Message24401 {
optional .benchmarks.google_message3.Message24400 field24679 = 1; optional .benchmarks.google_message3.Message24400 field24679 = 1;
@ -219,12 +221,9 @@ message Message13083 {
optional float field13099 = 45; optional float field13099 = 45;
optional uint64 field13100 = 46; optional uint64 field13100 = 46;
optional float field13101 = 47; optional float field13101 = 47;
optional group Message13085 = 16 { optional group Message13085 = 16 {}
} repeated group Message13086 = 23 {}
repeated group Message13086 = 23 { repeated group Message13087 = 29 {}
}
repeated group Message13087 = 29 {
}
optional .benchmarks.google_message3.UnusedEmptyMessage field13105 = 43; optional .benchmarks.google_message3.UnusedEmptyMessage field13105 = 43;
} }
@ -292,12 +291,10 @@ message Message16816 {
optional float field16826 = 1; optional float field16826 = 1;
optional .benchmarks.google_message3.Enum16819 field16827 = 2; optional .benchmarks.google_message3.Enum16819 field16827 = 2;
optional float field16828 = 3; optional float field16828 = 3;
repeated group Message16817 = 4 { repeated group Message16817 = 4 {}
}
optional bool field16830 = 7; optional bool field16830 = 7;
optional bool field16831 = 8; optional bool field16831 = 8;
repeated group Message16818 = 12 { repeated group Message16818 = 12 {}
}
optional string field16833 = 10; optional string field16833 = 10;
optional bool field16834 = 13; optional bool field16834 = 13;
optional bool field16835 = 14; optional bool field16835 = 14;
@ -338,11 +335,9 @@ message Message1374 {
optional string field1376 = 2; optional string field1376 = 2;
} }
message Message18943 { message Message18943 {}
}
message Message18944 { message Message18944 {}
}
message Message18856 { message Message18856 {
optional string field18857 = 1; optional string field18857 = 1;
@ -466,8 +461,7 @@ message Message8475 {
optional int64 field8482 = 2; optional int64 field8482 = 2;
} }
message Message12559 { message Message12559 {}
}
message Message12817 { message Message12817 {
optional int32 field12826 = 1; optional int32 field12826 = 1;

@ -28,21 +28,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_6.proto"; import "datasets/google_message3/benchmark_message3_6.proto";
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
message Message24377 { message Message24377 {}
}
message Message24378 { message Message24378 {}
}
message Message24400 { message Message24400 {
optional int32 field24674 = 1; optional int32 field24674 = 1;
@ -52,11 +53,9 @@ message Message24400 {
optional int32 field24678 = 5; optional int32 field24678 = 5;
} }
message Message24380 { message Message24380 {}
}
message Message24381 { message Message24381 {}
}
message Message719 { message Message719 {
repeated string field881 = 1; repeated string field881 = 1;
@ -133,6 +132,7 @@ message Message697 {
message Message0 { message Message0 {
option message_set_wire_format = true; option message_set_wire_format = true;
extensions 4 to 2147483646; extensions 4 to 2147483646;
} }
@ -223,7 +223,8 @@ message Message10155 {
optional fixed64 field10232 = 13; optional fixed64 field10232 = 13;
optional fixed64 field10233 = 20; optional fixed64 field10233 = 20;
optional bool field10234 = 79; optional bool field10234 = 79;
repeated .benchmarks.google_message3.Enum10167 field10235 = 80 [packed = true]; repeated .benchmarks.google_message3.Enum10167 field10235 = 80
[packed = true];
optional int32 field10236 = 14; optional int32 field10236 = 14;
optional int32 field10237 = 15; optional int32 field10237 = 15;
optional int32 field10238 = 28; optional int32 field10238 = 28;
@ -315,25 +316,20 @@ message Message13145 {
extensions 1000 to 536870911; extensions 1000 to 536870911;
} }
message Message16686 { message Message16686 {}
}
message Message12796 { message Message12796 {
repeated fixed64 field12800 = 1; repeated fixed64 field12800 = 1;
optional uint64 field12801 = 2; optional uint64 field12801 = 2;
} }
message Message6722 { message Message6722 {}
}
message Message6727 { message Message6727 {}
}
message Message6724 { message Message6724 {}
}
message Message6735 { message Message6735 {}
}
message Message8183 { message Message8183 {
optional string field8226 = 1; optional string field8226 = 1;
@ -355,8 +351,7 @@ message Message8301 {
extensions 64 to 536870911; extensions 64 to 536870911;
} }
message Message8456 { message Message8456 {}
}
message Message8302 { message Message8302 {
optional string field8339 = 1; optional string field8339 = 1;
@ -383,8 +378,7 @@ message Message8302 {
extensions 64 to 536870911; extensions 64 to 536870911;
} }
message Message8457 { message Message8457 {}
}
message Message8449 { message Message8449 {
optional string field8458 = 1; optional string field8458 = 1;

@ -28,17 +28,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message3;
import "datasets/google_message3/benchmark_message3_7.proto"; import "datasets/google_message3/benchmark_message3_7.proto";
import "datasets/google_message3/benchmark_message3_8.proto"; import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
message Message10576 { message Message10576 {}
}
message Message10154 { message Message10154 {
optional bytes field10192 = 1; optional bytes field10192 = 1;
@ -373,8 +375,7 @@ message Message8939 {
optional string field9012 = 3; optional string field9012 = 3;
repeated string field9013 = 4; repeated string field9013 = 4;
optional string field9014 = 5; optional string field9014 = 5;
repeated group Message8940 = 11 { repeated group Message8940 = 11 {}
}
optional int64 field9016 = 21; optional int64 field9016 = 21;
optional int64 field9017 = 22; optional int64 field9017 = 22;
optional int64 field9018 = 23; optional int64 field9018 = 23;
@ -453,8 +454,7 @@ message Message9627 {
optional float field9672 = 5; optional float field9672 = 5;
} }
message Message11020 { message Message11020 {}
}
message Message11013 { message Message11013 {
optional bytes field11757 = 19; optional bytes field11757 = 19;

@ -35,8 +35,7 @@ package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
message Message11018 { message Message11018 {}
}
message Message10800 { message Message10800 {
optional string field10808 = 1; optional string field10808 = 1;
@ -45,8 +44,7 @@ message Message10800 {
optional float field10811 = 4; optional float field10811 = 4;
} }
message Message10802 { message Message10802 {}
}
message Message10748 { message Message10748 {
optional string field10750 = 1; optional string field10750 = 1;
@ -69,16 +67,14 @@ message Message708 {
repeated string field828 = 5; repeated string field828 = 5;
} }
message Message8942 { message Message8942 {}
}
message Message11011 { message Message11011 {
required bytes field11752 = 1; required bytes field11752 = 1;
required bytes field11753 = 2; required bytes field11753 = 2;
} }
message UnusedEmptyMessage { message UnusedEmptyMessage {}
}
message Message741 { message Message741 {
repeated string field936 = 1; repeated string field936 = 1;

@ -639,9 +639,7 @@ enum Enum10325 {
ENUM_VALUE10334 = 8; ENUM_VALUE10334 = 8;
} }
enum Enum10335 { enum Enum10335 { ENUM_VALUE10336 = 0; }
ENUM_VALUE10336 = 0;
}
enum Enum10337 { enum Enum10337 {
ENUM_VALUE10338 = 0; ENUM_VALUE10338 = 0;
@ -1887,9 +1885,7 @@ enum Enum33960 {
ENUM_VALUE33967 = 6; ENUM_VALUE33967 = 6;
} }
enum Enum34388 { enum Enum34388 { ENUM_VALUE34389 = 1; }
ENUM_VALUE34389 = 1;
}
enum Enum35477 { enum Enum35477 {
ENUM_VALUE35478 = 4; ENUM_VALUE35478 = 4;

@ -28,12 +28,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message4;
import "datasets/google_message4/benchmark_message4_1.proto"; import "datasets/google_message4/benchmark_message4_1.proto";
import "datasets/google_message4/benchmark_message4_2.proto"; import "datasets/google_message4/benchmark_message4_2.proto";
import "datasets/google_message4/benchmark_message4_3.proto"; import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -176,8 +179,7 @@ message Message176 {
optional .benchmarks.google_message4.UnusedEnum field455 = 37; optional .benchmarks.google_message4.UnusedEnum field455 = 37;
optional .benchmarks.google_message4.UnusedEnum field456 = 34; optional .benchmarks.google_message4.UnusedEnum field456 = 34;
optional int32 field457 = 35; optional int32 field457 = 35;
repeated group Message178 = 101 { repeated group Message178 = 101 {}
}
optional bool field459 = 52; optional bool field459 = 52;
optional uint64 field460 = 58; optional uint64 field460 = 58;
optional uint64 field461 = 59; optional uint64 field461 = 59;
@ -458,10 +460,8 @@ message Message2356 {
optional bytes field2410 = 124; optional bytes field2410 = 124;
} }
optional string field2389 = 120; optional string field2389 = 120;
optional group Message2358 = 107 { optional group Message2358 = 107 {}
} repeated group Message2359 = 40 {}
repeated group Message2359 = 40 {
}
optional int32 field2392 = 50; optional int32 field2392 = 50;
optional .benchmarks.google_message4.UnusedEmptyMessage field2393 = 60; optional .benchmarks.google_message4.UnusedEmptyMessage field2393 = 60;
optional .benchmarks.google_message4.UnusedEmptyMessage field2394 = 70; optional .benchmarks.google_message4.UnusedEmptyMessage field2394 = 70;
@ -473,6 +473,7 @@ message Message2356 {
message Message0 { message Message0 {
option message_set_wire_format = true; option message_set_wire_format = true;
extensions 4 to 2147483646; extensions 4 to 2147483646;
} }

@ -28,11 +28,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// LINT: ALLOW_GROUPS
syntax = "proto2"; syntax = "proto2";
package benchmarks.google_message4;
import "datasets/google_message4/benchmark_message4_2.proto"; import "datasets/google_message4/benchmark_message4_2.proto";
import "datasets/google_message4/benchmark_message4_3.proto"; import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -46,8 +49,7 @@ message Message12686 {
optional .benchmarks.google_message4.Message12685 field12700 = 2; optional .benchmarks.google_message4.Message12685 field12700 = 2;
} }
message Message11949 { message Message11949 {}
}
message Message11975 { message Message11975 {
optional string field11992 = 1; optional string field11992 = 1;
@ -134,8 +136,7 @@ message Message3061 {
} }
optional .benchmarks.google_message4.UnusedEmptyMessage field3315 = 39; optional .benchmarks.google_message4.UnusedEmptyMessage field3315 = 39;
optional int32 field3316 = 76; optional int32 field3316 = 76;
optional group Message3065 = 63 { optional group Message3065 = 63 {}
}
optional .benchmarks.google_message4.Enum2806 field3318 = 54; optional .benchmarks.google_message4.Enum2806 field3318 = 54;
optional int32 field3319 = 46; optional int32 field3319 = 46;
repeated string field3320 = 24; repeated string field3320 = 24;
@ -163,8 +164,7 @@ message Message3061 {
optional int32 field3333 = 17; optional int32 field3333 = 17;
} }
message Message12949 { message Message12949 {}
}
message Message8572 { message Message8572 {
optional bytes field8647 = 1; optional bytes field8647 = 1;
@ -269,11 +269,9 @@ message Message12825 {
repeated .benchmarks.google_message4.UnusedEmptyMessage field12868 = 7; repeated .benchmarks.google_message4.UnusedEmptyMessage field12868 = 7;
} }
message Message8590 { message Message8590 {}
}
message Message8587 { message Message8587 {}
}
message Message1374 { message Message1374 {
required string field1375 = 1; required string field1375 = 1;
@ -453,8 +451,7 @@ message Message3052 {
optional string field3262 = 9; optional string field3262 = 9;
} }
message Message8575 { message Message8575 {}
}
message Message7843 { message Message7843 {
optional bool field7844 = 5; optional bool field7844 = 5;

@ -30,9 +30,10 @@
syntax = "proto2"; syntax = "proto2";
import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4; package benchmarks.google_message4;
import "datasets/google_message4/benchmark_message4_3.proto";
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks"; option java_package = "com.google.protobuf.benchmarks";
@ -132,8 +133,7 @@ message Message5881 {
optional .benchmarks.google_message4.Message5880 field5902 = 6; optional .benchmarks.google_message4.Message5880 field5902 = 6;
} }
message Message6110 { message Message6110 {}
}
message Message6107 { message Message6107 {
optional .benchmarks.google_message4.Message4016 field6134 = 1; optional .benchmarks.google_message4.Message4016 field6134 = 1;
@ -211,8 +211,7 @@ message Message3850 {
optional bool field3929 = 14; optional bool field3929 = 14;
} }
message Message7865 { message Message7865 {}
}
message Message7511 { message Message7511 {
optional bool field7523 = 1; optional bool field7523 = 1;
@ -224,8 +223,7 @@ message Message7511 {
optional int32 field7529 = 7; optional int32 field7529 = 7;
} }
message Message3920 { message Message3920 {}
}
message Message7928 { message Message7928 {
optional string field7940 = 1; optional string field7940 = 1;
@ -261,8 +259,7 @@ message Message6054 {
optional string field6090 = 2; optional string field6090 = 2;
} }
message Message6127 { message Message6127 {}
}
message Message6052 { message Message6052 {
required string field6084 = 1; required string field6084 = 1;
@ -302,8 +299,7 @@ message Message4016 {
required int32 field4020 = 4; required int32 field4020 = 4;
} }
message Message6108 { message Message6108 {}
}
message Message5907 { message Message5907 {
optional .benchmarks.google_message4.Message5903 field5967 = 1; optional .benchmarks.google_message4.Message5903 field5967 = 1;
@ -312,8 +308,7 @@ message Message5907 {
optional .benchmarks.google_message4.Message5903 field5970 = 4; optional .benchmarks.google_message4.Message5903 field5970 = 4;
} }
message UnusedEmptyMessage { message UnusedEmptyMessage {}
}
message Message5903 { message Message5903 {
required int32 field5965 = 1; required int32 field5965 = 1;

@ -77,6 +77,7 @@ enum Enum2806 {
enum Enum2851 { enum Enum2851 {
option allow_alias = true; option allow_alias = true;
ENUM_VALUE2852 = 0; ENUM_VALUE2852 = 0;
ENUM_VALUE2853 = 0; ENUM_VALUE2853 = 0;
ENUM_VALUE2854 = 1; ENUM_VALUE2854 = 1;
@ -747,9 +748,7 @@ enum Enum10325 {
ENUM_VALUE10334 = 8; ENUM_VALUE10334 = 8;
} }
enum Enum10335 { enum Enum10335 { ENUM_VALUE10336 = 0; }
ENUM_VALUE10336 = 0;
}
enum Enum10337 { enum Enum10337 {
ENUM_VALUE10338 = 0; ENUM_VALUE10338 = 0;

@ -67,6 +67,7 @@ set(tests_protos
google/protobuf/unittest_proto3_arena.proto google/protobuf/unittest_proto3_arena.proto
google/protobuf/unittest_proto3_arena_lite.proto google/protobuf/unittest_proto3_arena_lite.proto
google/protobuf/unittest_proto3_lite.proto google/protobuf/unittest_proto3_lite.proto
google/protobuf/unittest_proto3_optional.proto
google/protobuf/unittest_well_known_types.proto google/protobuf/unittest_well_known_types.proto
google/protobuf/util/internal/testdata/anys.proto google/protobuf/util/internal/testdata/anys.proto
google/protobuf/util/internal/testdata/books.proto google/protobuf/util/internal/testdata/books.proto
@ -93,6 +94,7 @@ macro(compile_proto_file filename)
COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
--proto_path=${protobuf_source_dir}/src --proto_path=${protobuf_source_dir}/src
--cpp_out=${protobuf_source_dir}/src --cpp_out=${protobuf_source_dir}/src
--experimental_allow_proto3_optional
) )
endmacro(compile_proto_file) endmacro(compile_proto_file)

@ -2156,12 +2156,12 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() {
{ {
TestAllTypesProto3 message; TestAllTypesProto3 message;
message.set_optional_double( message.set_optional_double(
WireFormatLite::DecodeDouble(0x7FFA123456789ABCLL)); WireFormatLite::DecodeDouble(int64{0x7FFA123456789ABC}));
RunValidJsonTestWithProtobufInput( RunValidJsonTestWithProtobufInput(
"DoubleFieldNormalizeQuietNan", REQUIRED, message, "DoubleFieldNormalizeQuietNan", REQUIRED, message,
"optional_double: nan"); "optional_double: nan");
message.set_optional_double( message.set_optional_double(
WireFormatLite::DecodeDouble(0xFFFBCBA987654321LL)); WireFormatLite::DecodeDouble(uint64{0xFFFBCBA987654321}));
RunValidJsonTestWithProtobufInput( RunValidJsonTestWithProtobufInput(
"DoubleFieldNormalizeSignalingNan", REQUIRED, message, "DoubleFieldNormalizeSignalingNan", REQUIRED, message,
"optional_double: nan"); "optional_double: nan");

@ -157,7 +157,8 @@ def do_test(request):
elif request.requested_output_format == conformance_pb2.JSON: elif request.requested_output_format == conformance_pb2.JSON:
try: try:
response.json_payload = json_format.MessageToJson(test_message) response.json_payload = json_format.MessageToJson(
test_message, float_precision=None)
except Exception as e: except Exception as e:
response.serialize_error = str(e) response.serialize_error = str(e)
return response return response

@ -313,6 +313,66 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() {
} }
} }
)"); )");
// Map fields
TestAllTypesProto3 prototype;
(*prototype.mutable_map_string_string())["c"] = "value";
(*prototype.mutable_map_string_string())["b"] = "value";
(*prototype.mutable_map_string_string())["a"] = "value";
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapStringKeys",
REQUIRED,
R"(
map_string_string {
key: "a"
value: "value"
}
map_string_string {
key: "b"
value: "value"
}
map_string_string {
key: "c"
value: "value"
}
)",
prototype);
prototype.Clear();
(*prototype.mutable_map_int32_int32())[3] = 0;
(*prototype.mutable_map_int32_int32())[2] = 0;
(*prototype.mutable_map_int32_int32())[1] = 0;
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapIntKeys", REQUIRED,
R"(
map_int32_int32 {
key: 1
value: 0
}
map_int32_int32 {
key: 2
value: 0
}
map_int32_int32 {
key: 3
value: 0
}
)",
prototype);
prototype.Clear();
(*prototype.mutable_map_bool_bool())[true] = false;
(*prototype.mutable_map_bool_bool())[false] = false;
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapBoolKeys", REQUIRED,
R"(
map_bool_bool {
key: false
value: false
}
map_bool_bool {
key: true
value: false
}
)",
prototype);
} }
} // namespace protobuf } // namespace protobuf

@ -4314,7 +4314,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
} }
/// <summary> /// <summary>
/// This proto includes a recusively nested message. /// This proto includes a recursively nested message.
/// </summary> /// </summary>
public sealed partial class NestedTestAllTypes : pb::IMessage<NestedTestAllTypes> { public sealed partial class NestedTestAllTypes : pb::IMessage<NestedTestAllTypes> {
private static readonly pb::MessageParser<NestedTestAllTypes> _parser = new pb::MessageParser<NestedTestAllTypes>(() => new NestedTestAllTypes()); private static readonly pb::MessageParser<NestedTestAllTypes> _parser = new pb::MessageParser<NestedTestAllTypes>(() => new NestedTestAllTypes());

@ -54,7 +54,7 @@ namespace Google.Protobuf.Reflection {
"b2J1Zi5FeHRlbnNpb25SYW5nZU9wdGlvbnMaKwoNUmVzZXJ2ZWRSYW5nZRIN", "b2J1Zi5FeHRlbnNpb25SYW5nZU9wdGlvbnMaKwoNUmVzZXJ2ZWRSYW5nZRIN",
"CgVzdGFydBgBIAEoBRILCgNlbmQYAiABKAUiZwoVRXh0ZW5zaW9uUmFuZ2VP", "CgVzdGFydBgBIAEoBRILCgNlbmQYAiABKAUiZwoVRXh0ZW5zaW9uUmFuZ2VP",
"cHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2ds", "cHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2ds",
"ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIivAUK", "ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi1QUK",
"FEZpZWxkRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSDgoGbnVtYmVy", "FEZpZWxkRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSDgoGbnVtYmVy",
"GAMgASgFEjoKBWxhYmVsGAQgASgOMisuZ29vZ2xlLnByb3RvYnVmLkZpZWxk", "GAMgASgFEjoKBWxhYmVsGAQgASgOMisuZ29vZ2xlLnByb3RvYnVmLkZpZWxk",
"RGVzY3JpcHRvclByb3RvLkxhYmVsEjgKBHR5cGUYBSABKA4yKi5nb29nbGUu", "RGVzY3JpcHRvclByb3RvLkxhYmVsEjgKBHR5cGUYBSABKA4yKi5nb29nbGUu",
@ -62,102 +62,103 @@ namespace Google.Protobuf.Reflection {
"bWUYBiABKAkSEAoIZXh0ZW5kZWUYAiABKAkSFQoNZGVmYXVsdF92YWx1ZRgH", "bWUYBiABKAkSEAoIZXh0ZW5kZWUYAiABKAkSFQoNZGVmYXVsdF92YWx1ZRgH",
"IAEoCRITCgtvbmVvZl9pbmRleBgJIAEoBRIRCglqc29uX25hbWUYCiABKAkS", "IAEoCRITCgtvbmVvZl9pbmRleBgJIAEoBRIRCglqc29uX25hbWUYCiABKAkS",
"LgoHb3B0aW9ucxgIIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlv", "LgoHb3B0aW9ucxgIIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlv",
"bnMitgIKBFR5cGUSDwoLVFlQRV9ET1VCTEUQARIOCgpUWVBFX0ZMT0FUEAIS", "bnMSFwoPcHJvdG8zX29wdGlvbmFsGBEgASgIIrYCCgRUeXBlEg8KC1RZUEVf",
"DgoKVFlQRV9JTlQ2NBADEg8KC1RZUEVfVUlOVDY0EAQSDgoKVFlQRV9JTlQz", "RE9VQkxFEAESDgoKVFlQRV9GTE9BVBACEg4KClRZUEVfSU5UNjQQAxIPCgtU",
"MhAFEhAKDFRZUEVfRklYRUQ2NBAGEhAKDFRZUEVfRklYRUQzMhAHEg0KCVRZ", "WVBFX1VJTlQ2NBAEEg4KClRZUEVfSU5UMzIQBRIQCgxUWVBFX0ZJWEVENjQQ",
"UEVfQk9PTBAIEg8KC1RZUEVfU1RSSU5HEAkSDgoKVFlQRV9HUk9VUBAKEhAK", "BhIQCgxUWVBFX0ZJWEVEMzIQBxINCglUWVBFX0JPT0wQCBIPCgtUWVBFX1NU",
"DFRZUEVfTUVTU0FHRRALEg4KClRZUEVfQllURVMQDBIPCgtUWVBFX1VJTlQz", "UklORxAJEg4KClRZUEVfR1JPVVAQChIQCgxUWVBFX01FU1NBR0UQCxIOCgpU",
"MhANEg0KCVRZUEVfRU5VTRAOEhEKDVRZUEVfU0ZJWEVEMzIQDxIRCg1UWVBF", "WVBFX0JZVEVTEAwSDwoLVFlQRV9VSU5UMzIQDRINCglUWVBFX0VOVU0QDhIR",
"X1NGSVhFRDY0EBASDwoLVFlQRV9TSU5UMzIQERIPCgtUWVBFX1NJTlQ2NBAS", "Cg1UWVBFX1NGSVhFRDMyEA8SEQoNVFlQRV9TRklYRUQ2NBAQEg8KC1RZUEVf",
"IkMKBUxhYmVsEhIKDkxBQkVMX09QVElPTkFMEAESEgoOTEFCRUxfUkVRVUlS", "U0lOVDMyEBESDwoLVFlQRV9TSU5UNjQQEiJDCgVMYWJlbBISCg5MQUJFTF9P",
"RUQQAhISCg5MQUJFTF9SRVBFQVRFRBADIlQKFE9uZW9mRGVzY3JpcHRvclBy", "UFRJT05BTBABEhIKDkxBQkVMX1JFUVVJUkVEEAISEgoOTEFCRUxfUkVQRUFU",
"b3RvEgwKBG5hbWUYASABKAkSLgoHb3B0aW9ucxgCIAEoCzIdLmdvb2dsZS5w", "RUQQAyJUChRPbmVvZkRlc2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEi4K",
"cm90b2J1Zi5PbmVvZk9wdGlvbnMipAIKE0VudW1EZXNjcmlwdG9yUHJvdG8S", "B29wdGlvbnMYAiABKAsyHS5nb29nbGUucHJvdG9idWYuT25lb2ZPcHRpb25z",
"DAoEbmFtZRgBIAEoCRI4CgV2YWx1ZRgCIAMoCzIpLmdvb2dsZS5wcm90b2J1", "IqQCChNFbnVtRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSOAoFdmFs",
"Zi5FbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8SLQoHb3B0aW9ucxgDIAEoCzIc", "dWUYAiADKAsyKS5nb29nbGUucHJvdG9idWYuRW51bVZhbHVlRGVzY3JpcHRv",
"Lmdvb2dsZS5wcm90b2J1Zi5FbnVtT3B0aW9ucxJOCg5yZXNlcnZlZF9yYW5n", "clByb3RvEi0KB29wdGlvbnMYAyABKAsyHC5nb29nbGUucHJvdG9idWYuRW51",
"ZRgEIAMoCzI2Lmdvb2dsZS5wcm90b2J1Zi5FbnVtRGVzY3JpcHRvclByb3Rv", "bU9wdGlvbnMSTgoOcmVzZXJ2ZWRfcmFuZ2UYBCADKAsyNi5nb29nbGUucHJv",
"LkVudW1SZXNlcnZlZFJhbmdlEhUKDXJlc2VydmVkX25hbWUYBSADKAkaLwoR", "dG9idWYuRW51bURlc2NyaXB0b3JQcm90by5FbnVtUmVzZXJ2ZWRSYW5nZRIV",
"RW51bVJlc2VydmVkUmFuZ2USDQoFc3RhcnQYASABKAUSCwoDZW5kGAIgASgF", "Cg1yZXNlcnZlZF9uYW1lGAUgAygJGi8KEUVudW1SZXNlcnZlZFJhbmdlEg0K",
"ImwKGEVudW1WYWx1ZURlc2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEg4K", "BXN0YXJ0GAEgASgFEgsKA2VuZBgCIAEoBSJsChhFbnVtVmFsdWVEZXNjcmlw",
"Bm51bWJlchgCIAEoBRIyCgdvcHRpb25zGAMgASgLMiEuZ29vZ2xlLnByb3Rv", "dG9yUHJvdG8SDAoEbmFtZRgBIAEoCRIOCgZudW1iZXIYAiABKAUSMgoHb3B0",
"YnVmLkVudW1WYWx1ZU9wdGlvbnMikAEKFlNlcnZpY2VEZXNjcmlwdG9yUHJv", "aW9ucxgDIAEoCzIhLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVPcHRpb25z",
"dG8SDAoEbmFtZRgBIAEoCRI2CgZtZXRob2QYAiADKAsyJi5nb29nbGUucHJv", "IpABChZTZXJ2aWNlRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSNgoG",
"dG9idWYuTWV0aG9kRGVzY3JpcHRvclByb3RvEjAKB29wdGlvbnMYAyABKAsy", "bWV0aG9kGAIgAygLMiYuZ29vZ2xlLnByb3RvYnVmLk1ldGhvZERlc2NyaXB0",
"Hy5nb29nbGUucHJvdG9idWYuU2VydmljZU9wdGlvbnMiwQEKFU1ldGhvZERl", "b3JQcm90bxIwCgdvcHRpb25zGAMgASgLMh8uZ29vZ2xlLnByb3RvYnVmLlNl",
"c2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEhIKCmlucHV0X3R5cGUYAiAB", "cnZpY2VPcHRpb25zIsEBChVNZXRob2REZXNjcmlwdG9yUHJvdG8SDAoEbmFt",
"KAkSEwoLb3V0cHV0X3R5cGUYAyABKAkSLwoHb3B0aW9ucxgEIAEoCzIeLmdv", "ZRgBIAEoCRISCgppbnB1dF90eXBlGAIgASgJEhMKC291dHB1dF90eXBlGAMg",
"b2dsZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zEh8KEGNsaWVudF9zdHJlYW1p", "ASgJEi8KB29wdGlvbnMYBCABKAsyHi5nb29nbGUucHJvdG9idWYuTWV0aG9k",
"bmcYBSABKAg6BWZhbHNlEh8KEHNlcnZlcl9zdHJlYW1pbmcYBiABKAg6BWZh", "T3B0aW9ucxIfChBjbGllbnRfc3RyZWFtaW5nGAUgASgIOgVmYWxzZRIfChBz",
"bHNlIqYGCgtGaWxlT3B0aW9ucxIUCgxqYXZhX3BhY2thZ2UYASABKAkSHAoU", "ZXJ2ZXJfc3RyZWFtaW5nGAYgASgIOgVmYWxzZSKlBgoLRmlsZU9wdGlvbnMS",
"amF2YV9vdXRlcl9jbGFzc25hbWUYCCABKAkSIgoTamF2YV9tdWx0aXBsZV9m", "FAoMamF2YV9wYWNrYWdlGAEgASgJEhwKFGphdmFfb3V0ZXJfY2xhc3NuYW1l",
"aWxlcxgKIAEoCDoFZmFsc2USKQodamF2YV9nZW5lcmF0ZV9lcXVhbHNfYW5k", "GAggASgJEiIKE2phdmFfbXVsdGlwbGVfZmlsZXMYCiABKAg6BWZhbHNlEikK",
"X2hhc2gYFCABKAhCAhgBEiUKFmphdmFfc3RyaW5nX2NoZWNrX3V0ZjgYGyAB", "HWphdmFfZ2VuZXJhdGVfZXF1YWxzX2FuZF9oYXNoGBQgASgIQgIYARIlChZq",
"KAg6BWZhbHNlEkYKDG9wdGltaXplX2ZvchgJIAEoDjIpLmdvb2dsZS5wcm90", "YXZhX3N0cmluZ19jaGVja191dGY4GBsgASgIOgVmYWxzZRJGCgxvcHRpbWl6",
"b2J1Zi5GaWxlT3B0aW9ucy5PcHRpbWl6ZU1vZGU6BVNQRUVEEhIKCmdvX3Bh", "ZV9mb3IYCSABKA4yKS5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMuT3B0",
"Y2thZ2UYCyABKAkSIgoTY2NfZ2VuZXJpY19zZXJ2aWNlcxgQIAEoCDoFZmFs", "aW1pemVNb2RlOgVTUEVFRBISCgpnb19wYWNrYWdlGAsgASgJEiIKE2NjX2dl",
"c2USJAoVamF2YV9nZW5lcmljX3NlcnZpY2VzGBEgASgIOgVmYWxzZRIiChNw", "bmVyaWNfc2VydmljZXMYECABKAg6BWZhbHNlEiQKFWphdmFfZ2VuZXJpY19z",
"eV9nZW5lcmljX3NlcnZpY2VzGBIgASgIOgVmYWxzZRIjChRwaHBfZ2VuZXJp", "ZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoTcHlfZ2VuZXJpY19zZXJ2aWNlcxgS",
"Y19zZXJ2aWNlcxgqIAEoCDoFZmFsc2USGQoKZGVwcmVjYXRlZBgXIAEoCDoF", "IAEoCDoFZmFsc2USIwoUcGhwX2dlbmVyaWNfc2VydmljZXMYKiABKAg6BWZh",
"ZmFsc2USHwoQY2NfZW5hYmxlX2FyZW5hcxgfIAEoCDoFZmFsc2USGQoRb2Jq", "bHNlEhkKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlEh4KEGNjX2VuYWJsZV9h",
"Y19jbGFzc19wcmVmaXgYJCABKAkSGAoQY3NoYXJwX25hbWVzcGFjZRglIAEo", "cmVuYXMYHyABKAg6BHRydWUSGQoRb2JqY19jbGFzc19wcmVmaXgYJCABKAkS",
"CRIUCgxzd2lmdF9wcmVmaXgYJyABKAkSGAoQcGhwX2NsYXNzX3ByZWZpeBgo", "GAoQY3NoYXJwX25hbWVzcGFjZRglIAEoCRIUCgxzd2lmdF9wcmVmaXgYJyAB",
"IAEoCRIVCg1waHBfbmFtZXNwYWNlGCkgASgJEh4KFnBocF9tZXRhZGF0YV9u", "KAkSGAoQcGhwX2NsYXNzX3ByZWZpeBgoIAEoCRIVCg1waHBfbmFtZXNwYWNl",
"YW1lc3BhY2UYLCABKAkSFAoMcnVieV9wYWNrYWdlGC0gASgJEkMKFHVuaW50", "GCkgASgJEh4KFnBocF9tZXRhZGF0YV9uYW1lc3BhY2UYLCABKAkSFAoMcnVi",
"ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", "eV9wYWNrYWdlGC0gASgJEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo",
"dGVycHJldGVkT3B0aW9uIjoKDE9wdGltaXplTW9kZRIJCgVTUEVFRBABEg0K", "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIjoKDE9w",
"CUNPREVfU0laRRACEhAKDExJVEVfUlVOVElNRRADKgkI6AcQgICAgAJKBAgm", "dGltaXplTW9kZRIJCgVTUEVFRBABEg0KCUNPREVfU0laRRACEhAKDExJVEVf",
"ECci8gEKDk1lc3NhZ2VPcHRpb25zEiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9y", "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECci8gEKDk1lc3NhZ2VPcHRpb25z",
"bWF0GAEgASgIOgVmYWxzZRIuCh9ub19zdGFuZGFyZF9kZXNjcmlwdG9yX2Fj", "EiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9ybWF0GAEgASgIOgVmYWxzZRIuCh9u",
"Y2Vzc29yGAIgASgIOgVmYWxzZRIZCgpkZXByZWNhdGVkGAMgASgIOgVmYWxz", "b19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZRIZ",
"ZRIRCgltYXBfZW50cnkYByABKAgSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y", "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRIRCgltYXBfZW50cnkYByABKAgS",
"5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24q",
"CQjoBxCAgICAAkoECAgQCUoECAkQCiKeAwoMRmllbGRPcHRpb25zEjoKBWN0",
"eXBlGAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlw",
"ZToGU1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5n",
"b29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFM",
"EhMKBGxhenkYBSABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZh",
"bHNlEhMKBHdlYWsYCiABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0",
"aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0",
"aW9uIi8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdf",
"UElFQ0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5H",
"EAESDQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJeCgxPbmVvZk9w",
"dGlvbnMSQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xl",
"LnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoL",
"RW51bU9wdGlvbnMSEwoLYWxsb3dfYWxpYXMYAiABKAgSGQoKZGVwcmVjYXRl",
"ZBgDIAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygL",
"MiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCA",
"gICAAkoECAUQBiJ9ChBFbnVtVmFsdWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQY",
"ASABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIk",
"Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICA",
"gAIiewoOU2VydmljZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFs",
"c2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnBy",
"b3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiKtAgoNTWV0",
"aG9kT3B0aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJfChFpZGVt",
"cG90ZW5jeV9sZXZlbBgiIAEoDjIvLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RP",
"cHRpb25zLklkZW1wb3RlbmN5TGV2ZWw6E0lERU1QT1RFTkNZX1VOS05PV04S",
"QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv",
"YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24iUAoQSWRlbXBvdGVuY3lMZXZlbBIX", "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAgQCUoECAkQ",
"ChNJREVNUE9URU5DWV9VTktOT1dOEAASEwoPTk9fU0lERV9FRkZFQ1RTEAES", "CiKeAwoMRmllbGRPcHRpb25zEjoKBWN0eXBlGAEgASgOMiMuZ29vZ2xlLnBy",
"DgoKSURFTVBPVEVOVBACKgkI6AcQgICAgAIingIKE1VuaW50ZXJwcmV0ZWRP", "b3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToGU1RSSU5HEg4KBnBhY2tlZBgC",
"cHRpb24SOwoEbmFtZRgCIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5VbmludGVy", "IAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29nbGUucHJvdG9idWYuRmllbGRP",
"cHJldGVkT3B0aW9uLk5hbWVQYXJ0EhgKEGlkZW50aWZpZXJfdmFsdWUYAyAB", "cHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMKBGxhenkYBSABKAg6BWZhbHNl",
"KAkSGgoScG9zaXRpdmVfaW50X3ZhbHVlGAQgASgEEhoKEm5lZ2F0aXZlX2lu", "EhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEhMKBHdlYWsYCiABKAg6BWZh",
"dF92YWx1ZRgFIAEoAxIUCgxkb3VibGVfdmFsdWUYBiABKAESFAoMc3RyaW5n", "bHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5w",
"X3ZhbHVlGAcgASgMEhcKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCRozCghOYW1l", "cm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIi8KBUNUeXBlEgoKBlNUUklO",
"UGFydBIRCgluYW1lX3BhcnQYASACKAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigI", "RxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElFQ0UQAiI1CgZKU1R5cGUSDQoJ",
"ItUBCg5Tb3VyY2VDb2RlSW5mbxI6Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2ds", "SlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAESDQoJSlNfTlVNQkVSEAIqCQjo",
"ZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvbhqGAQoITG9jYXRp", "BxCAgICAAkoECAQQBSJeCgxPbmVvZk9wdGlvbnMSQwoUdW5pbnRlcnByZXRl",
"b24SEAoEcGF0aBgBIAMoBUICEAESEAoEc3BhbhgCIAMoBUICEAESGAoQbGVh", "ZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0",
"ZGluZ19jb21tZW50cxgDIAEoCRIZChF0cmFpbGluZ19jb21tZW50cxgEIAEo", "ZWRPcHRpb24qCQjoBxCAgICAAiKTAQoLRW51bU9wdGlvbnMSEwoLYWxsb3df",
"CRIhChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJIqcBChFHZW5l", "YWxpYXMYAiABKAgSGQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USQwoUdW5p",
"cmF0ZWRDb2RlSW5mbxJBCgphbm5vdGF0aW9uGAEgAygLMi0uZ29vZ2xlLnBy", "bnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVu",
"b3RvYnVmLkdlbmVyYXRlZENvZGVJbmZvLkFubm90YXRpb24aTwoKQW5ub3Rh", "aW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAUQBiJ9ChBFbnVtVmFs",
"dGlvbhIQCgRwYXRoGAEgAygFQgIQARITCgtzb3VyY2VfZmlsZRgCIAEoCRIN", "dWVPcHRpb25zEhkKCmRlcHJlY2F0ZWQYASABKAg6BWZhbHNlEkMKFHVuaW50",
"CgViZWdpbhgDIAEoBRILCgNlbmQYBCABKAVCjwEKE2NvbS5nb29nbGUucHJv", "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu",
"dG9idWZCEERlc2NyaXB0b3JQcm90b3NIAVo+Z2l0aHViLmNvbS9nb2xhbmcv", "dGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIiewoOU2VydmljZU9wdGlvbnMS",
"cHJvdG9idWYvcHJvdG9jLWdlbi1nby9kZXNjcmlwdG9yO2Rlc2NyaXB0b3L4", "GQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9v",
"AQGiAgNHUEKqAhpHb29nbGUuUHJvdG9idWYuUmVmbGVjdGlvbg==")); "cHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRP",
"cHRpb24qCQjoBxCAgICAAiKtAgoNTWV0aG9kT3B0aW9ucxIZCgpkZXByZWNh",
"dGVkGCEgASgIOgVmYWxzZRJfChFpZGVtcG90ZW5jeV9sZXZlbBgiIAEoDjIv",
"Lmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zLklkZW1wb3RlbmN5TGV2",
"ZWw6E0lERU1QT1RFTkNZX1VOS05PV04SQwoUdW5pbnRlcnByZXRlZF9vcHRp",
"b24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRp",
"b24iUAoQSWRlbXBvdGVuY3lMZXZlbBIXChNJREVNUE9URU5DWV9VTktOT1dO",
"EAASEwoPTk9fU0lERV9FRkZFQ1RTEAESDgoKSURFTVBPVEVOVBACKgkI6AcQ",
"gICAgAIingIKE1VuaW50ZXJwcmV0ZWRPcHRpb24SOwoEbmFtZRgCIAMoCzIt",
"Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uLk5hbWVQYXJ0",
"EhgKEGlkZW50aWZpZXJfdmFsdWUYAyABKAkSGgoScG9zaXRpdmVfaW50X3Zh",
"bHVlGAQgASgEEhoKEm5lZ2F0aXZlX2ludF92YWx1ZRgFIAEoAxIUCgxkb3Vi",
"bGVfdmFsdWUYBiABKAESFAoMc3RyaW5nX3ZhbHVlGAcgASgMEhcKD2FnZ3Jl",
"Z2F0ZV92YWx1ZRgIIAEoCRozCghOYW1lUGFydBIRCgluYW1lX3BhcnQYASAC",
"KAkSFAoMaXNfZXh0ZW5zaW9uGAIgAigIItUBCg5Tb3VyY2VDb2RlSW5mbxI6",
"Cghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2Rl",
"SW5mby5Mb2NhdGlvbhqGAQoITG9jYXRpb24SEAoEcGF0aBgBIAMoBUICEAES",
"EAoEc3BhbhgCIAMoBUICEAESGAoQbGVhZGluZ19jb21tZW50cxgDIAEoCRIZ",
"ChF0cmFpbGluZ19jb21tZW50cxgEIAEoCRIhChlsZWFkaW5nX2RldGFjaGVk",
"X2NvbW1lbnRzGAYgAygJIqcBChFHZW5lcmF0ZWRDb2RlSW5mbxJBCgphbm5v",
"dGF0aW9uGAEgAygLMi0uZ29vZ2xlLnByb3RvYnVmLkdlbmVyYXRlZENvZGVJ",
"bmZvLkFubm90YXRpb24aTwoKQW5ub3RhdGlvbhIQCgRwYXRoGAEgAygFQgIQ",
"ARITCgtzb3VyY2VfZmlsZRgCIAEoCRINCgViZWdpbhgDIAEoBRILCgNlbmQY",
"BCABKAVCjwEKE2NvbS5nb29nbGUucHJvdG9idWZCEERlc2NyaXB0b3JQcm90",
"b3NIAVo+Z2l0aHViLmNvbS9nb2xhbmcvcHJvdG9idWYvcHJvdG9jLWdlbi1n",
"by9kZXNjcmlwdG9yO2Rlc2NyaXB0b3L4AQGiAgNHUEKqAhpHb29nbGUuUHJv",
"dG9idWYuUmVmbGVjdGlvbg=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
@ -166,7 +167,7 @@ namespace Google.Protobuf.Reflection {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto), global::Google.Protobuf.Reflection.DescriptorProto.Parser, new[]{ "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser, new[]{ "Start", "End", "Options" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto), global::Google.Protobuf.Reflection.DescriptorProto.Parser, new[]{ "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser, new[]{ "Start", "End", "Options" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ExtensionRangeOptions), global::Google.Protobuf.Reflection.ExtensionRangeOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ExtensionRangeOptions), global::Google.Protobuf.Reflection.ExtensionRangeOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto), global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser, new[]{ "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type), typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto), global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser, new[]{ "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options", "Proto3Optional" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type), typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.OneofDescriptorProto), global::Google.Protobuf.Reflection.OneofDescriptorProto.Parser, new[]{ "Name", "Options" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.OneofDescriptorProto), global::Google.Protobuf.Reflection.OneofDescriptorProto.Parser, new[]{ "Name", "Options" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumDescriptorProto), global::Google.Protobuf.Reflection.EnumDescriptorProto.Parser, new[]{ "Name", "Value", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange), global::Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumDescriptorProto), global::Google.Protobuf.Reflection.EnumDescriptorProto.Parser, new[]{ "Name", "Value", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange), global::Google.Protobuf.Reflection.EnumDescriptorProto.Types.EnumReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumValueDescriptorProto), global::Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser, new[]{ "Name", "Number", "Options" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumValueDescriptorProto), global::Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser, new[]{ "Name", "Number", "Options" }, null, null, null, null),
@ -1791,6 +1792,7 @@ namespace Google.Protobuf.Reflection {
oneofIndex_ = other.oneofIndex_; oneofIndex_ = other.oneofIndex_;
jsonName_ = other.jsonName_; jsonName_ = other.jsonName_;
options_ = other.HasOptions ? other.options_.Clone() : null; options_ = other.HasOptions ? other.options_.Clone() : null;
proto3Optional_ = other.proto3Optional_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
} }
@ -2063,6 +2065,42 @@ namespace Google.Protobuf.Reflection {
options_ = null; options_ = null;
} }
/// <summary>Field number for the "proto3_optional" field.</summary>
public const int Proto3OptionalFieldNumber = 17;
private readonly static bool Proto3OptionalDefaultValue = false;
private bool proto3Optional_;
/// <summary>
/// If true, this is a proto3 "optional". When a proto3 field is optional, it
/// tracks presence regardless of field type.
///
/// For message fields this doesn't create any semantic change, since
/// non-repeated message fields always track presence. However it still
/// indicates the semantic detail of whether the user wrote "optional" or not.
/// This can be useful for round-tripping the .proto file.
///
/// Proto2 optional fields do not set this flag, because they already indicate
/// optional with `LABEL_OPTIONAL`.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Proto3Optional {
get { if ((_hasBits0 & 16) != 0) { return proto3Optional_; } else { return Proto3OptionalDefaultValue; } }
set {
_hasBits0 |= 16;
proto3Optional_ = value;
}
}
/// <summary>Gets whether the "proto3_optional" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasProto3Optional {
get { return (_hasBits0 & 16) != 0; }
}
/// <summary>Clears the value of the "proto3_optional" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearProto3Optional() {
_hasBits0 &= ~16;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) { public override bool Equals(object other) {
return Equals(other as FieldDescriptorProto); return Equals(other as FieldDescriptorProto);
@ -2086,6 +2124,7 @@ namespace Google.Protobuf.Reflection {
if (OneofIndex != other.OneofIndex) return false; if (OneofIndex != other.OneofIndex) return false;
if (JsonName != other.JsonName) return false; if (JsonName != other.JsonName) return false;
if (!object.Equals(Options, other.Options)) return false; if (!object.Equals(Options, other.Options)) return false;
if (Proto3Optional != other.Proto3Optional) return false;
return Equals(_unknownFields, other._unknownFields); return Equals(_unknownFields, other._unknownFields);
} }
@ -2102,6 +2141,7 @@ namespace Google.Protobuf.Reflection {
if (HasOneofIndex) hash ^= OneofIndex.GetHashCode(); if (HasOneofIndex) hash ^= OneofIndex.GetHashCode();
if (HasJsonName) hash ^= JsonName.GetHashCode(); if (HasJsonName) hash ^= JsonName.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode(); if (HasOptions) hash ^= Options.GetHashCode();
if (HasProto3Optional) hash ^= Proto3Optional.GetHashCode();
if (_unknownFields != null) { if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode(); hash ^= _unknownFields.GetHashCode();
} }
@ -2155,6 +2195,10 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(82); output.WriteRawTag(82);
output.WriteString(JsonName); output.WriteString(JsonName);
} }
if (HasProto3Optional) {
output.WriteRawTag(136, 1);
output.WriteBool(Proto3Optional);
}
if (_unknownFields != null) { if (_unknownFields != null) {
_unknownFields.WriteTo(output); _unknownFields.WriteTo(output);
} }
@ -2193,6 +2237,9 @@ namespace Google.Protobuf.Reflection {
if (HasOptions) { if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options); size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
} }
if (HasProto3Optional) {
size += 2 + 1;
}
if (_unknownFields != null) { if (_unknownFields != null) {
size += _unknownFields.CalculateSize(); size += _unknownFields.CalculateSize();
} }
@ -2237,6 +2284,9 @@ namespace Google.Protobuf.Reflection {
} }
Options.MergeFrom(other.Options); Options.MergeFrom(other.Options);
} }
if (other.HasProto3Optional) {
Proto3Optional = other.Proto3Optional;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
} }
@ -2291,6 +2341,10 @@ namespace Google.Protobuf.Reflection {
JsonName = input.ReadString(); JsonName = input.ReadString();
break; break;
} }
case 136: {
Proto3Optional = input.ReadBool();
break;
}
} }
} }
} }
@ -4222,7 +4276,7 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "cc_enable_arenas" field.</summary> /// <summary>Field number for the "cc_enable_arenas" field.</summary>
public const int CcEnableArenasFieldNumber = 31; public const int CcEnableArenasFieldNumber = 31;
private readonly static bool CcEnableArenasDefaultValue = false; private readonly static bool CcEnableArenasDefaultValue = true;
private bool ccEnableArenas_; private bool ccEnableArenas_;
/// <summary> /// <summary>

@ -140,6 +140,26 @@ final class BooleanArrayList extends AbstractProtobufList<Boolean>
return array[index]; return array[index];
} }
@Override
public int indexOf(Object element) {
if (!(element instanceof Boolean)) {
return -1;
}
boolean unboxedElement = (Boolean) element;
int numElems = size();
for (int i = 0; i < numElems; i++) {
if (array[i] == unboxedElement) {
return i;
}
}
return -1;
}
@Override
public boolean contains(Object element) {
return indexOf(element) != -1;
}
@Override @Override
public int size() { public int size() {
return size; return size;

@ -484,7 +484,7 @@ public abstract class CodedInputStream {
* Returns true if the stream has reached the end of the input. This is the case if either the end * Returns true if the stream has reached the end of the input. This is the case if either the end
* of the underlying input source has been reached or if the stream has reached a limit created * of the underlying input source has been reached or if the stream has reached a limit created
* using {@link #pushLimit(int)}. This function may get blocked when using StreamDecoder as it * using {@link #pushLimit(int)}. This function may get blocked when using StreamDecoder as it
* invokes {@link #StreamDecoder.tryRefillBuffer(int)} in this function which will try to read * invokes {@link StreamDecoder#tryRefillBuffer(int)} in this function which will try to read
* bytes from input. * bytes from input.
*/ */
public abstract boolean isAtEnd() throws IOException; public abstract boolean isAtEnd() throws IOException;

@ -1125,6 +1125,34 @@ public final class Descriptors {
return containingOneof; return containingOneof;
} }
/**
* Returns true if this field was syntactically written with "optional" in the .proto file.
* Excludes singular proto3 fields that do not have a label.
*/
public boolean hasOptionalKeyword() {
return isProto3Optional
|| (file.getSyntax() == Syntax.PROTO2 && isOptional() && getContainingOneof() == null);
}
/**
* Returns true if this is a non-oneof field that tracks presence.
*
* <p>This includes all "required" and "optional" fields in the .proto file, but excludes oneof
* fields and singular proto3 fields without "optional".
*
* <p>In implementations that use hasbits, this method will probably indicate whether this field
* uses a hasbit.
*/
boolean isSingularWithPresence() {
if (isRepeated()) {
return false;
}
if (getContainingOneof() != null && !getContainingOneof().isSynthetic()) {
return false;
}
return getType() == Type.MESSAGE || isProto3Optional || file.getSyntax() == Syntax.PROTO2;
}
/** /**
* For extensions defined nested within message types, gets the outer type. Not valid for * For extensions defined nested within message types, gets the outer type. Not valid for
* non-extension fields. For example, consider this {@code .proto} file: * non-extension fields. For example, consider this {@code .proto} file:
@ -1203,6 +1231,7 @@ public final class Descriptors {
private final String jsonName; private final String jsonName;
private final FileDescriptor file; private final FileDescriptor file;
private final Descriptor extensionScope; private final Descriptor extensionScope;
private final boolean isProto3Optional;
// Possibly initialized during cross-linking. // Possibly initialized during cross-linking.
private Type type; private Type type;
@ -1327,6 +1356,8 @@ public final class Descriptors {
type = Type.valueOf(proto.getType()); type = Type.valueOf(proto.getType());
} }
isProto3Optional = proto.getProto3Optional();
if (getNumber() <= 0) { if (getNumber() <= 0) {
throw new DescriptorValidationException(this, "Field numbers must be positive integers."); throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
} }
@ -2627,6 +2658,10 @@ public final class Descriptors {
return proto.getOptions(); return proto.getOptions();
} }
public boolean isSynthetic() {
return fields.length == 1 && fields[0].isProto3Optional;
}
/** Get a list of this message type's fields. */ /** Get a list of this message type's fields. */
public List<FieldDescriptor> getFields() { public List<FieldDescriptor> getFields() {
return Collections.unmodifiableList(Arrays.asList(fields)); return Collections.unmodifiableList(Arrays.asList(fields));

@ -140,6 +140,26 @@ final class DoubleArrayList extends AbstractProtobufList<Double>
return array[index]; return array[index];
} }
@Override
public int indexOf(Object element) {
if (!(element instanceof Double)) {
return -1;
}
double unboxedElement = (Double) element;
int numElems = size();
for (int i = 0; i < numElems; i++) {
if (array[i] == unboxedElement) {
return i;
}
}
return -1;
}
@Override
public boolean contains(Object element) {
return indexOf(element) != -1;
}
@Override @Override
public int size() { public int size() {
return size; return size;

@ -139,6 +139,26 @@ final class FloatArrayList extends AbstractProtobufList<Float>
return array[index]; return array[index];
} }
@Override
public int indexOf(Object element) {
if (!(element instanceof Float)) {
return -1;
}
float unboxedElement = (Float) element;
int numElems = size();
for (int i = 0; i < numElems; i++) {
if (array[i] == unboxedElement) {
return i;
}
}
return -1;
}
@Override
public boolean contains(Object element) {
return indexOf(element) != -1;
}
@Override @Override
public int size() { public int size() {
return size; return size;

@ -121,7 +121,11 @@ public abstract class GeneratedMessageLite<
return true; return true;
} }
if (!getDefaultInstanceForType().getClass().isInstance(other)) { if (other == null) {
return false;
}
if (this.getClass() != other.getClass()) {
return false; return false;
} }

@ -1987,9 +1987,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
int oneofsSize = oneofs.length; int oneofsSize = oneofs.length;
for (int i = 0; i < oneofsSize; i++) { for (int i = 0; i < oneofsSize; i++) {
oneofs[i] = new OneofAccessor( oneofs[i] =
descriptor, camelCaseNames[i + fieldsSize], new OneofAccessor(
messageClass, builderClass); descriptor, i, camelCaseNames[i + fieldsSize], messageClass, builderClass);
} }
initialized = true; initialized = true;
camelCaseNames = null; camelCaseNames = null;
@ -2057,14 +2057,22 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
/** OneofAccessor provides access to a single oneof. */ /** OneofAccessor provides access to a single oneof. */
private static class OneofAccessor { private static class OneofAccessor {
OneofAccessor( OneofAccessor(
final Descriptor descriptor, final String camelCaseName, final Descriptor descriptor,
final int oneofIndex,
final String camelCaseName,
final Class<? extends GeneratedMessageV3> messageClass, final Class<? extends GeneratedMessageV3> messageClass,
final Class<? extends Builder> builderClass) { final Class<? extends Builder> builderClass) {
this.descriptor = descriptor; this.descriptor = descriptor;
caseMethod = OneofDescriptor oneofDescriptor = descriptor.getOneofs().get(oneofIndex);
getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); if (oneofDescriptor.isSynthetic()) {
caseMethodBuilder = caseMethod = null;
getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); caseMethodBuilder = null;
fieldDescriptor = oneofDescriptor.getFields().get(0);
} else {
caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
fieldDescriptor = null;
}
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
} }
@ -2072,33 +2080,51 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
private final Method caseMethod; private final Method caseMethod;
private final Method caseMethodBuilder; private final Method caseMethodBuilder;
private final Method clearMethod; private final Method clearMethod;
private final FieldDescriptor fieldDescriptor;
public boolean has(final GeneratedMessageV3 message) { public boolean has(final GeneratedMessageV3 message) {
if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) { if (fieldDescriptor != null) {
return false; return message.hasField(fieldDescriptor);
} else {
if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
return false;
}
} }
return true; return true;
} }
public boolean has(GeneratedMessageV3.Builder builder) { public boolean has(GeneratedMessageV3.Builder builder) {
if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) { if (fieldDescriptor != null) {
return false; return builder.hasField(fieldDescriptor);
} else {
if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
return false;
}
} }
return true; return true;
} }
public FieldDescriptor get(final GeneratedMessageV3 message) { public FieldDescriptor get(final GeneratedMessageV3 message) {
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber(); if (fieldDescriptor != null) {
if (fieldNumber > 0) { return message.hasField(fieldDescriptor) ? fieldDescriptor : null;
return descriptor.findFieldByNumber(fieldNumber); } else {
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
if (fieldNumber > 0) {
return descriptor.findFieldByNumber(fieldNumber);
}
} }
return null; return null;
} }
public FieldDescriptor get(GeneratedMessageV3.Builder builder) { public FieldDescriptor get(GeneratedMessageV3.Builder builder) {
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber(); if (fieldDescriptor != null) {
if (fieldNumber > 0) { return builder.hasField(fieldDescriptor) ? fieldDescriptor : null;
return descriptor.findFieldByNumber(fieldNumber); } else {
int fieldNumber =
((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
if (fieldNumber > 0) {
return descriptor.findFieldByNumber(fieldNumber);
}
} }
return null; return null;
} }
@ -2108,10 +2134,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
} }
} }
private static boolean supportFieldPresence(FileDescriptor file) {
return file.getSyntax() == FileDescriptor.Syntax.PROTO2;
}
// --------------------------------------------------------------- // ---------------------------------------------------------------
private static class SingularFieldAccessor implements FieldAccessor { private static class SingularFieldAccessor implements FieldAccessor {
@ -2216,9 +2238,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
final Class<? extends GeneratedMessageV3> messageClass, final Class<? extends GeneratedMessageV3> messageClass,
final Class<? extends Builder> builderClass, final Class<? extends Builder> builderClass,
final String containingOneofCamelCaseName) { final String containingOneofCamelCaseName) {
isOneofField = descriptor.getContainingOneof() != null; isOneofField =
hasHasMethod = supportFieldPresence(descriptor.getFile()) descriptor.getContainingOneof() != null
|| (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); && !descriptor.getContainingOneof().isSynthetic();
hasHasMethod =
descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2
|| descriptor.hasOptionalKeyword()
|| (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
ReflectionInvoker reflectionInvoker = ReflectionInvoker reflectionInvoker =
new ReflectionInvoker( new ReflectionInvoker(
descriptor, descriptor,

@ -139,6 +139,26 @@ final class IntArrayList extends AbstractProtobufList<Integer>
return array[index]; return array[index];
} }
@Override
public int indexOf(Object element) {
if (!(element instanceof Integer)) {
return -1;
}
int unboxedElement = (Integer) element;
int numElems = size();
for (int i = 0; i < numElems; i++) {
if (array[i] == unboxedElement) {
return i;
}
}
return -1;
}
@Override
public boolean contains(Object element) {
return indexOf(element) != -1;
}
@Override @Override
public int size() { public int size() {
return size; return size;

@ -139,6 +139,26 @@ final class LongArrayList extends AbstractProtobufList<Long>
return array[index]; return array[index];
} }
@Override
public int indexOf(Object element) {
if (!(element instanceof Long)) {
return -1;
}
long unboxedElement = (Long) element;
int numElems = size();
for (int i = 0; i < numElems; i++) {
if (array[i] == unboxedElement) {
return i;
}
}
return -1;
}
@Override
public boolean contains(Object element) {
return indexOf(element) != -1;
}
@Override @Override
public int size() { public int size() {
return size; return size;

@ -89,6 +89,7 @@ final class MessageSchema<T> implements Schema<T> {
private static final int FIELD_TYPE_MASK = 0x0FF00000; private static final int FIELD_TYPE_MASK = 0x0FF00000;
private static final int REQUIRED_MASK = 0x10000000; private static final int REQUIRED_MASK = 0x10000000;
private static final int ENFORCE_UTF8_MASK = 0x20000000; private static final int ENFORCE_UTF8_MASK = 0x20000000;
private static final int NO_PRESENCE_SENTINEL = -1 & OFFSET_MASK;
private static final int[] EMPTY_INT_ARRAY = new int[0]; private static final int[] EMPTY_INT_ARRAY = new int[0];
/** An offset applied to the field type ID for scalar fields that are a member of a oneof. */ /** An offset applied to the field type ID for scalar fields that are a member of a oneof. */
@ -118,6 +119,11 @@ final class MessageSchema<T> implements Schema<T> {
* [70 - 75] field presence mask shift (unused for oneof/repeated fields) * [70 - 75] field presence mask shift (unused for oneof/repeated fields)
* [76 - 95] presence field offset / oneof case field offset / cached size field offset * [76 - 95] presence field offset / oneof case field offset / cached size field offset
* </pre> * </pre>
*
* Note that presence field offset can only use 20 bits - 1. All bits set to 1 is the sentinel
* value for non-presence. This is not validated at runtime, we simply assume message layouts
* will not exceed 1MB (assuming ~10 bytes per field, that implies 100k fields which should hit
* other javac limits first).
*/ */
private final int[] buffer; private final int[] buffer;
@ -260,7 +266,7 @@ final class MessageSchema<T> implements Schema<T> {
} }
next = result | (next << shift); next = result | (next << shift);
} }
final int flags = next; final int unusedFlags = next;
next = info.charAt(i++); next = info.charAt(i++);
if (next >= 0xD800) { if (next >= 0xD800) {
@ -464,8 +470,7 @@ final class MessageSchema<T> implements Schema<T> {
|| oneofFieldType == 17 /* FieldType.GROUP */) { || oneofFieldType == 17 /* FieldType.GROUP */) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
} else if (oneofFieldType == 12 /* FieldType.ENUM */) { } else if (oneofFieldType == 12 /* FieldType.ENUM */) {
// proto2 if (!isProto3) {
if ((flags & 0x1) == 0x1) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
} }
} }
@ -508,7 +513,7 @@ final class MessageSchema<T> implements Schema<T> {
} else if (fieldType == 12 /* FieldType.ENUM */ } else if (fieldType == 12 /* FieldType.ENUM */
|| fieldType == 30 /* FieldType.ENUM_LIST */ || fieldType == 30 /* FieldType.ENUM_LIST */
|| fieldType == 44 /* FieldType.ENUM_LIST_PACKED */) { || fieldType == 44 /* FieldType.ENUM_LIST_PACKED */) {
if ((flags & 0x1) == 0x1) { if (!isProto3) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++]; objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
} }
} else if (fieldType == 50 /* FieldType.MAP */) { } else if (fieldType == 50 /* FieldType.MAP */) {
@ -520,7 +525,8 @@ final class MessageSchema<T> implements Schema<T> {
} }
fieldOffset = (int) unsafe.objectFieldOffset(field); fieldOffset = (int) unsafe.objectFieldOffset(field);
if ((flags & 0x1) == 0x1 && fieldType <= 17 /* FieldType.GROUP */) { boolean hasHasBit = (fieldTypeWithExtraBits & 0x1000) == 0x1000;
if (hasHasBit && fieldType <= 17 /* FieldType.GROUP */) {
next = info.charAt(i++); next = info.charAt(i++);
if (next >= 0xD800) { if (next >= 0xD800) {
int result = next & 0x1FFF; int result = next & 0x1FFF;
@ -546,7 +552,7 @@ final class MessageSchema<T> implements Schema<T> {
presenceFieldOffset = (int) unsafe.objectFieldOffset(hasBitsField); presenceFieldOffset = (int) unsafe.objectFieldOffset(hasBitsField);
presenceMaskShift = hasBitsIndex % 32; presenceMaskShift = hasBitsIndex % 32;
} else { } else {
presenceFieldOffset = 0; presenceFieldOffset = NO_PRESENCE_SENTINEL;
presenceMaskShift = 0; presenceMaskShift = 0;
} }
@ -662,7 +668,7 @@ final class MessageSchema<T> implements Schema<T> {
// We found the entry for the next field. Store the entry in the manifest for // We found the entry for the next field. Store the entry in the manifest for
// this field and increment the field index. // this field and increment the field index.
storeFieldData(fi, buffer, bufferIndex, isProto3, objects); storeFieldData(fi, buffer, bufferIndex, objects);
// Convert field number to index // Convert field number to index
if (checkInitializedIndex < checkInitialized.length if (checkInitializedIndex < checkInitialized.length
@ -719,7 +725,7 @@ final class MessageSchema<T> implements Schema<T> {
} }
private static void storeFieldData( private static void storeFieldData(
FieldInfo fi, int[] buffer, int bufferIndex, boolean proto3, Object[] objects) { FieldInfo fi, int[] buffer, int bufferIndex, Object[] objects) {
final int fieldOffset; final int fieldOffset;
final int typeId; final int typeId;
final int presenceMaskShift; final int presenceMaskShift;
@ -735,8 +741,13 @@ final class MessageSchema<T> implements Schema<T> {
FieldType type = fi.getType(); FieldType type = fi.getType();
fieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getField()); fieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getField());
typeId = type.id(); typeId = type.id();
if (!proto3 && !type.isList() && !type.isMap()) { if (!type.isList() && !type.isMap()) {
presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getPresenceField()); Field presenceField = fi.getPresenceField();
if (presenceField == null) {
presenceFieldOffset = NO_PRESENCE_SENTINEL;
} else {
presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(presenceField);
}
presenceMaskShift = Integer.numberOfTrailingZeros(fi.getPresenceMask()); presenceMaskShift = Integer.numberOfTrailingZeros(fi.getPresenceMask());
} else { } else {
if (fi.getCachedSizeField() == null) { if (fi.getCachedSizeField() == null) {
@ -1408,13 +1419,13 @@ final class MessageSchema<T> implements Schema<T> {
public int getSerializedSize(T message) { public int getSerializedSize(T message) {
return proto3 ? getSerializedSizeProto3(message) : getSerializedSizeProto2(message); return proto3 ? getSerializedSizeProto3(message) : getSerializedSizeProto2(message);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private int getSerializedSizeProto2(T message) { private int getSerializedSizeProto2(T message) {
int size = 0; int size = 0;
final sun.misc.Unsafe unsafe = UNSAFE; final sun.misc.Unsafe unsafe = UNSAFE;
int currentPresenceFieldOffset = -1; int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0; int currentPresenceField = 0;
for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) { for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) {
final int typeAndOffset = typeAndOffsetAt(i); final int typeAndOffset = typeAndOffsetAt(i);
@ -2548,7 +2559,7 @@ final class MessageSchema<T> implements Schema<T> {
nextExtension = extensionIterator.next(); nextExtension = extensionIterator.next();
} }
} }
int currentPresenceFieldOffset = -1; int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0; int currentPresenceField = 0;
final int bufferLength = buffer.length; final int bufferLength = buffer.length;
final sun.misc.Unsafe unsafe = UNSAFE; final sun.misc.Unsafe unsafe = UNSAFE;
@ -2924,7 +2935,6 @@ final class MessageSchema<T> implements Schema<T> {
nextExtension = extensionIterator.next(); nextExtension = extensionIterator.next();
} }
} }
final int bufferLength = buffer.length; final int bufferLength = buffer.length;
for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) { for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) {
final int typeAndOffset = typeAndOffsetAt(pos); final int typeAndOffset = typeAndOffsetAt(pos);
@ -4867,7 +4877,7 @@ final class MessageSchema<T> implements Schema<T> {
T message, byte[] data, int position, int limit, int endGroup, Registers registers) T message, byte[] data, int position, int limit, int endGroup, Registers registers)
throws IOException { throws IOException {
final sun.misc.Unsafe unsafe = UNSAFE; final sun.misc.Unsafe unsafe = UNSAFE;
int currentPresenceFieldOffset = -1; int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0; int currentPresenceField = 0;
int tag = 0; int tag = 0;
int oldNumber = -1; int oldNumber = -1;
@ -4901,7 +4911,7 @@ final class MessageSchema<T> implements Schema<T> {
// We cache the 32-bit has-bits integer value and only write it back when parsing a field // We cache the 32-bit has-bits integer value and only write it back when parsing a field
// using a different has-bits integer. // using a different has-bits integer.
if (presenceFieldOffset != currentPresenceFieldOffset) { if (presenceFieldOffset != currentPresenceFieldOffset) {
if (currentPresenceFieldOffset != -1) { if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
} }
currentPresenceFieldOffset = presenceFieldOffset; currentPresenceFieldOffset = presenceFieldOffset;
@ -5143,7 +5153,7 @@ final class MessageSchema<T> implements Schema<T> {
tag, data, position, limit, getMutableUnknownFields(message), registers); tag, data, position, limit, getMutableUnknownFields(message), registers);
} }
} }
if (currentPresenceFieldOffset != -1) { if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField); unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
} }
UnknownFieldSetLite unknownFields = null; UnknownFieldSetLite unknownFields = null;
@ -5175,6 +5185,8 @@ final class MessageSchema<T> implements Schema<T> {
private int parseProto3Message( private int parseProto3Message(
T message, byte[] data, int position, int limit, Registers registers) throws IOException { T message, byte[] data, int position, int limit, Registers registers) throws IOException {
final sun.misc.Unsafe unsafe = UNSAFE; final sun.misc.Unsafe unsafe = UNSAFE;
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0;
int tag = 0; int tag = 0;
int oldNumber = -1; int oldNumber = -1;
int pos = 0; int pos = 0;
@ -5200,11 +5212,30 @@ final class MessageSchema<T> implements Schema<T> {
final int fieldType = type(typeAndOffset); final int fieldType = type(typeAndOffset);
final long fieldOffset = offset(typeAndOffset); final long fieldOffset = offset(typeAndOffset);
if (fieldType <= 17) { if (fieldType <= 17) {
// Proto3 optional fields have has-bits.
final int presenceMaskAndOffset = buffer[pos + 2];
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
// We cache the 32-bit has-bits integer value and only write it back when parsing a field
// using a different has-bits integer.
//
// Note that for fields that do not have hasbits, we unconditionally write and discard
// the data.
if (presenceFieldOffset != currentPresenceFieldOffset) {
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
}
if (presenceFieldOffset != NO_PRESENCE_SENTINEL) {
currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset);
}
currentPresenceFieldOffset = presenceFieldOffset;
}
switch (fieldType) { switch (fieldType) {
case 0: // DOUBLE: case 0: // DOUBLE:
if (wireType == WireFormat.WIRETYPE_FIXED64) { if (wireType == WireFormat.WIRETYPE_FIXED64) {
UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position)); UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position));
position += 8; position += 8;
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5212,6 +5243,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_FIXED32) { if (wireType == WireFormat.WIRETYPE_FIXED32) {
UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position)); UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position));
position += 4; position += 4;
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5220,6 +5252,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_VARINT) { if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint64(data, position, registers); position = decodeVarint64(data, position, registers);
unsafe.putLong(message, fieldOffset, registers.long1); unsafe.putLong(message, fieldOffset, registers.long1);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5228,6 +5261,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_VARINT) { if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint32(data, position, registers); position = decodeVarint32(data, position, registers);
unsafe.putInt(message, fieldOffset, registers.int1); unsafe.putInt(message, fieldOffset, registers.int1);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5236,6 +5270,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_FIXED64) { if (wireType == WireFormat.WIRETYPE_FIXED64) {
unsafe.putLong(message, fieldOffset, decodeFixed64(data, position)); unsafe.putLong(message, fieldOffset, decodeFixed64(data, position));
position += 8; position += 8;
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5244,6 +5279,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_FIXED32) { if (wireType == WireFormat.WIRETYPE_FIXED32) {
unsafe.putInt(message, fieldOffset, decodeFixed32(data, position)); unsafe.putInt(message, fieldOffset, decodeFixed32(data, position));
position += 4; position += 4;
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5251,6 +5287,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_VARINT) { if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint64(data, position, registers); position = decodeVarint64(data, position, registers);
UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0); UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5262,6 +5299,7 @@ final class MessageSchema<T> implements Schema<T> {
position = decodeStringRequireUtf8(data, position, registers); position = decodeStringRequireUtf8(data, position, registers);
} }
unsafe.putObject(message, fieldOffset, registers.object1); unsafe.putObject(message, fieldOffset, registers.object1);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5277,6 +5315,7 @@ final class MessageSchema<T> implements Schema<T> {
unsafe.putObject( unsafe.putObject(
message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1)); message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1));
} }
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5284,6 +5323,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) {
position = decodeBytes(data, position, registers); position = decodeBytes(data, position, registers);
unsafe.putObject(message, fieldOffset, registers.object1); unsafe.putObject(message, fieldOffset, registers.object1);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5291,6 +5331,7 @@ final class MessageSchema<T> implements Schema<T> {
if (wireType == WireFormat.WIRETYPE_VARINT) { if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint32(data, position, registers); position = decodeVarint32(data, position, registers);
unsafe.putInt(message, fieldOffset, registers.int1); unsafe.putInt(message, fieldOffset, registers.int1);
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5299,6 +5340,7 @@ final class MessageSchema<T> implements Schema<T> {
position = decodeVarint32(data, position, registers); position = decodeVarint32(data, position, registers);
unsafe.putInt( unsafe.putInt(
message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1)); message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1));
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5307,6 +5349,7 @@ final class MessageSchema<T> implements Schema<T> {
position = decodeVarint64(data, position, registers); position = decodeVarint64(data, position, registers);
unsafe.putLong( unsafe.putLong(
message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1)); message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1));
currentPresenceField |= presenceMask;
continue; continue;
} }
break; break;
@ -5381,6 +5424,9 @@ final class MessageSchema<T> implements Schema<T> {
position = decodeUnknownField( position = decodeUnknownField(
tag, data, position, limit, getMutableUnknownFields(message), registers); tag, data, position, limit, getMutableUnknownFields(message), registers);
} }
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
}
if (position != limit) { if (position != limit) {
throw InvalidProtocolBufferException.parseFailure(); throw InvalidProtocolBufferException.parseFailure();
} }
@ -5502,28 +5548,26 @@ final class MessageSchema<T> implements Schema<T> {
@Override @Override
public final boolean isInitialized(T message) { public final boolean isInitialized(T message) {
int currentPresenceFieldOffset = -1; int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0; int currentPresenceField = 0;
for (int i = 0; i < checkInitializedCount; i++) { for (int i = 0; i < checkInitializedCount; i++) {
final int pos = intArray[i]; final int pos = intArray[i];
final int number = numberAt(pos); final int number = numberAt(pos);
final int typeAndOffset = typeAndOffsetAt(pos); final int typeAndOffset = typeAndOffsetAt(pos);
int presenceMaskAndOffset = 0; int presenceMaskAndOffset = buffer[pos + 2];
int presenceMask = 0; final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
if (!proto3) { int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
presenceMaskAndOffset = buffer[pos + 2]; if (presenceFieldOffset != currentPresenceFieldOffset) {
final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK; currentPresenceFieldOffset = presenceFieldOffset;
presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
if (presenceFieldOffset != currentPresenceFieldOffset) {
currentPresenceFieldOffset = presenceFieldOffset;
currentPresenceField = UNSAFE.getInt(message, (long) presenceFieldOffset); currentPresenceField = UNSAFE.getInt(message, (long) presenceFieldOffset);
} }
} }
if (isRequired(typeAndOffset)) { if (isRequired(typeAndOffset)) {
if (!isFieldPresent(message, pos, currentPresenceField, presenceMask)) { if (!isFieldPresent(
message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)) {
return false; return false;
} }
// If a required message field is set but has no required fields of it's own, we still // If a required message field is set but has no required fields of it's own, we still
@ -5534,7 +5578,8 @@ final class MessageSchema<T> implements Schema<T> {
switch (type(typeAndOffset)) { switch (type(typeAndOffset)) {
case 9: // MESSAGE case 9: // MESSAGE
case 17: // GROUP case 17: // GROUP
if (isFieldPresent(message, pos, currentPresenceField, presenceMask) if (isFieldPresent(
message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)
&& !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) { && !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) {
return false; return false;
} }
@ -5744,8 +5789,9 @@ final class MessageSchema<T> implements Schema<T> {
return isFieldPresent(message, pos) == isFieldPresent(other, pos); return isFieldPresent(message, pos) == isFieldPresent(other, pos);
} }
private boolean isFieldPresent(T message, int pos, int presenceField, int presenceMask) { private boolean isFieldPresent(
if (proto3) { T message, int pos, int presenceFieldOffset, int presenceField, int presenceMask) {
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
return isFieldPresent(message, pos); return isFieldPresent(message, pos);
} else { } else {
return (presenceField & presenceMask) != 0; return (presenceField & presenceMask) != 0;
@ -5753,7 +5799,9 @@ final class MessageSchema<T> implements Schema<T> {
} }
private boolean isFieldPresent(T message, int pos) { private boolean isFieldPresent(T message, int pos) {
if (proto3) { final int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
final int typeAndOffset = typeAndOffsetAt(pos); final int typeAndOffset = typeAndOffsetAt(pos);
final long offset = offset(typeAndOffset); final long offset = offset(typeAndOffset);
switch (type(typeAndOffset)) { switch (type(typeAndOffset)) {
@ -5804,20 +5852,18 @@ final class MessageSchema<T> implements Schema<T> {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} else { } else {
int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
return (UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) & presenceMask) != 0; return (UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) & presenceMask) != 0;
} }
} }
private void setFieldPresent(T message, int pos) { private void setFieldPresent(T message, int pos) {
if (proto3) { int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
// Proto3 doesn't have presence fields final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
return; return;
} }
int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS); final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
UnsafeUtil.putInt( UnsafeUtil.putInt(
message, message,
presenceFieldOffset, presenceFieldOffset,

@ -96,7 +96,7 @@ final class RawMessageInfo implements MessageInfo {
* If the field is in an oneof: * If the field is in an oneof:
* *
* <ul> * <ul>
* <li>[2]: oenof index * <li>[2]: oneof index
* </ul> * </ul>
* *
* For other types, the field entry only has field number and field type. * For other types, the field entry only has field number and field type.

@ -346,9 +346,8 @@ public class RepeatedFieldBuilder<
// If we can inspect the size, we can more efficiently add messages. // If we can inspect the size, we can more efficiently add messages.
int size = -1; int size = -1;
if (values instanceof Collection) { if (values instanceof Collection) {
@SuppressWarnings("unchecked") final Collection<?> collection = (Collection<?>) values;
final Collection<MType> collection = (Collection<MType>) values; if (collection.isEmpty()) {
if (collection.size() == 0) {
return this; return this;
} }
size = collection.size(); size = collection.size();
@ -408,8 +407,7 @@ public class RepeatedFieldBuilder<
/** /**
* Removes the element at the specified position in this list. Shifts any subsequent elements to * Removes the element at the specified position in this list. Shifts any subsequent elements to
* the left (subtracts one from their indices). Returns the element that was removed from the * the left (subtracts one from their indices).
* list.
* *
* @param index the index at which to remove the message * @param index the index at which to remove the message
*/ */

@ -346,9 +346,8 @@ public class RepeatedFieldBuilderV3<
// If we can inspect the size, we can more efficiently add messages. // If we can inspect the size, we can more efficiently add messages.
int size = -1; int size = -1;
if (values instanceof Collection) { if (values instanceof Collection) {
@SuppressWarnings("unchecked") final Collection<?> collection = (Collection<?>) values;
final Collection<MType> collection = (Collection<MType>) values; if (collection.isEmpty()) {
if (collection.size() == 0) {
return this; return this;
} }
size = collection.size(); size = collection.size();
@ -408,8 +407,7 @@ public class RepeatedFieldBuilderV3<
/** /**
* Removes the element at the specified position in this list. Shifts any subsequent elements to * Removes the element at the specified position in this list. Shifts any subsequent elements to
* the left (subtracts one from their indices). Returns the element that was removed from the * the left (subtracts one from their indices).
* list.
* *
* @param index the index at which to remove the message * @param index the index at which to remove the message
*/ */

@ -34,10 +34,12 @@ import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.MessageReflection.MergeTarget;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -137,7 +139,7 @@ public final class TextFormat {
/** /**
* Like {@code print()}, but writes directly to a {@code String} and returns it. * Like {@code print()}, but writes directly to a {@code String} and returns it.
* *
* @deprecated Use {@link MessageOrBuilder#toString()} * @deprecated Use {@code message.toString()}
*/ */
@Deprecated @Deprecated
public static String printToString(final MessageOrBuilder message) { public static String printToString(final MessageOrBuilder message) {
@ -419,7 +421,17 @@ public final class TextFormat {
private void printField( private void printField(
final FieldDescriptor field, final Object value, final TextGenerator generator) final FieldDescriptor field, final Object value, final TextGenerator generator)
throws IOException { throws IOException {
if (field.isRepeated()) { // Sort map field entries by key
if (field.isMapField()) {
List<MapEntryAdapter> adapters = new ArrayList<>();
for (Object entry : (List<?>) value) {
adapters.add(new MapEntryAdapter(entry, field));
}
Collections.sort(adapters);
for (MapEntryAdapter adapter : adapters) {
printSingleField(field, adapter.getEntry(), generator);
}
} else if (field.isRepeated()) {
// Repeated field. Print each element. // Repeated field. Print each element.
for (Object element : (List<?>) value) { for (Object element : (List<?>) value) {
printSingleField(field, element, generator); printSingleField(field, element, generator);
@ -429,6 +441,94 @@ public final class TextFormat {
} }
} }
/**
* An adapter class that can take a MapEntry or a MutableMapEntry and returns its key and entry.
* This class is created solely for the purpose of sorting map entries by its key and prevent
* duplicated logic by having a separate comparator for MapEntry and MutableMapEntry.
*/
private static class MapEntryAdapter implements Comparable<MapEntryAdapter> {
private Object entry;
@SuppressWarnings({"rawtypes"})
private MapEntry mapEntry;
private final FieldDescriptor.JavaType fieldType;
public MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
if (entry instanceof MapEntry) {
this.mapEntry = (MapEntry) entry;
} else {
this.entry = entry;
}
this.fieldType = extractFieldType(fieldDescriptor);
}
private static FieldDescriptor.JavaType extractFieldType(FieldDescriptor fieldDescriptor) {
return fieldDescriptor.getMessageType().getFields().get(0).getJavaType();
}
public Object getKey() {
if (mapEntry != null) {
return mapEntry.getKey();
}
return null;
}
public Object getEntry() {
if (mapEntry != null) {
return mapEntry;
}
return entry;
}
@Override
public int compareTo(MapEntryAdapter b) {
if (getKey() == null || b.getKey() == null) {
logger.info("Invalid key for map field.");
return -1;
}
switch (fieldType) {
case BOOLEAN:
boolean aBoolean = (boolean) getKey();
boolean bBoolean = (boolean) b.getKey();
if (aBoolean == bBoolean) {
return 0;
} else if (aBoolean) {
return 1;
} else {
return -1;
}
case LONG:
long aLong = (long) getKey();
long bLong = (long) b.getKey();
if (aLong < bLong) {
return -1;
} else if (aLong > bLong) {
return 1;
} else {
return 0;
}
case INT:
return (int) getKey() - (int) b.getKey();
case STRING:
String aString = (String) getKey();
String bString = (String) b.getKey();
if (aString == null && bString == null) {
return 0;
} else if (aString == null && bString != null) {
return -1;
} else if (aString != null && bString == null) {
return 1;
} else {
return aString.compareTo(bString);
}
default:
return 0;
}
}
}
/** /**
* Outputs a textual representation of the value of given field value. * Outputs a textual representation of the value of given field value.
* *
@ -1708,6 +1808,12 @@ public final class TextFormat {
final Descriptor type = target.getDescriptorForType(); final Descriptor type = target.getDescriptorForType();
ExtensionRegistry.ExtensionInfo extension = null; ExtensionRegistry.ExtensionInfo extension = null;
if ("google.protobuf.Any".equals(type.getFullName()) && tokenizer.tryConsume("[")) {
mergeAnyFieldValue(tokenizer, extensionRegistry, target, parseTreeBuilder, unknownFields,
type);
return;
}
if (tokenizer.tryConsume("[")) { if (tokenizer.tryConsume("[")) {
// An extension. // An extension.
final StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier()); final StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier());
@ -1928,9 +2034,13 @@ public final class TextFormat {
// Try to parse human readable format of Any in the form: [type_url]: { ... } // Try to parse human readable format of Any in the form: [type_url]: { ... }
if (field.getMessageType().getFullName().equals("google.protobuf.Any") if (field.getMessageType().getFullName().equals("google.protobuf.Any")
&& tokenizer.tryConsume("[")) { && tokenizer.tryConsume("[")) {
value = // Use Proto reflection here since depending on Any would intoduce a cyclic dependency
consumeAnyFieldValue( // (java_proto_library for any_java_proto depends on the protobuf_impl).
tokenizer, extensionRegistry, field, parseTreeBuilder, unknownFields); Message anyBuilder = DynamicMessage.getDefaultInstance(field.getMessageType());
MessageReflection.MergeTarget anyField = target.newMergeTargetForField(field, anyBuilder);
mergeAnyFieldValue(tokenizer, extensionRegistry, anyField, parseTreeBuilder,
unknownFields, field.getMessageType());
value = anyField.finish();
tokenizer.consume(endToken); tokenizer.consume(endToken);
} else { } else {
Message defaultInstance = (extension == null) ? null : extension.defaultInstance; Message defaultInstance = (extension == null) ? null : extension.defaultInstance;
@ -2052,12 +2162,13 @@ public final class TextFormat {
} }
} }
private Object consumeAnyFieldValue( private void mergeAnyFieldValue(
final Tokenizer tokenizer, final Tokenizer tokenizer,
final ExtensionRegistry extensionRegistry, final ExtensionRegistry extensionRegistry,
final FieldDescriptor field, MergeTarget target,
final TextFormatParseInfoTree.Builder parseTreeBuilder, final TextFormatParseInfoTree.Builder parseTreeBuilder,
List<UnknownField> unknownFields) List<UnknownField> unknownFields,
Descriptor anyDescriptor)
throws ParseException { throws ParseException {
// Try to parse human readable format of Any in the form: [type_url]: { ... } // Try to parse human readable format of Any in the form: [type_url]: { ... }
StringBuilder typeUrlBuilder = new StringBuilder(); StringBuilder typeUrlBuilder = new StringBuilder();
@ -2105,21 +2216,13 @@ public final class TextFormat {
mergeField(tokenizer, extensionRegistry, contentTarget, parseTreeBuilder, unknownFields); mergeField(tokenizer, extensionRegistry, contentTarget, parseTreeBuilder, unknownFields);
} }
// Serialize the content and put it back into an Any. Note that we can't depend on Any here target.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
// because of a cyclic dependency (java_proto_library for any_java_proto depends on the target.setField(
// protobuf_impl), so we need to construct the Any using proto reflection.
Descriptor anyDescriptor = field.getMessageType();
Message.Builder anyBuilder =
DynamicMessage.getDefaultInstance(anyDescriptor).newBuilderForType();
anyBuilder.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
anyBuilder.setField(
anyDescriptor.findFieldByName("value"), contentBuilder.build().toByteString()); anyDescriptor.findFieldByName("value"), contentBuilder.build().toByteString());
return anyBuilder.build();
} }
/** Skips the next field including the field's name and value. */ /** Skips the next field including the field's name and value. */
private void skipField(Tokenizer tokenizer) throws ParseException { private static void skipField(Tokenizer tokenizer) throws ParseException {
if (tokenizer.tryConsume("[")) { if (tokenizer.tryConsume("[")) {
// Extension name. // Extension name.
do { do {
@ -2151,7 +2254,7 @@ public final class TextFormat {
/** /**
* Skips the whole body of a message including the beginning delimiter and the ending delimiter. * Skips the whole body of a message including the beginning delimiter and the ending delimiter.
*/ */
private void skipFieldMessage(Tokenizer tokenizer) throws ParseException { private static void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
final String delimiter; final String delimiter;
if (tokenizer.tryConsume("<")) { if (tokenizer.tryConsume("<")) {
delimiter = ">"; delimiter = ">";
@ -2166,7 +2269,7 @@ public final class TextFormat {
} }
/** Skips a field value. */ /** Skips a field value. */
private void skipFieldValue(Tokenizer tokenizer) throws ParseException { private static void skipFieldValue(Tokenizer tokenizer) throws ParseException {
if (tokenizer.tryConsumeString()) { if (tokenizer.tryConsumeString()) {
while (tokenizer.tryConsumeString()) {} while (tokenizer.tryConsumeString()) {}
return; return;

@ -301,7 +301,7 @@ public final class UnknownFieldSetLite {
return size; return size;
} }
private static boolean equals(int[] tags1, int[] tags2, int count) { private static boolean tagsEquals(int[] tags1, int[] tags2, int count) {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
if (tags1[i] != tags2[i]) { if (tags1[i] != tags2[i]) {
return false; return false;
@ -310,7 +310,7 @@ public final class UnknownFieldSetLite {
return true; return true;
} }
private static boolean equals(Object[] objects1, Object[] objects2, int count) { private static boolean objectsEquals(Object[] objects1, Object[] objects2, int count) {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
if (!objects1[i].equals(objects2[i])) { if (!objects1[i].equals(objects2[i])) {
return false; return false;
@ -335,8 +335,8 @@ public final class UnknownFieldSetLite {
UnknownFieldSetLite other = (UnknownFieldSetLite) obj; UnknownFieldSetLite other = (UnknownFieldSetLite) obj;
if (count != other.count if (count != other.count
|| !equals(tags, other.tags, count) || !tagsEquals(tags, other.tags, count)
|| !equals(objects, other.objects, count)) { || !objectsEquals(objects, other.objects, count)) {
return false; return false;
} }

@ -140,6 +140,68 @@ public class BooleanArrayListTest extends TestCase {
} }
} }
public void testIndexOf_nullElement() {
assertEquals(-1, TERTIARY_LIST.indexOf(null));
}
public void testIndexOf_incompatibleElementType() {
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
}
public void testIndexOf_notInList() {
assertEquals(-1, UNARY_LIST.indexOf(false));
}
public void testIndexOf_notInListWithDuplicates() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
assertEquals(-1, listWithDupes.indexOf(false));
}
public void testIndexOf_inList() {
assertEquals(1, TERTIARY_LIST.indexOf(false));
}
public void testIndexOf_inListWithDuplicates_matchAtHead() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
assertEquals(0, listWithDupes.indexOf(true));
}
public void testIndexOf_inListWithDuplicates_matchMidList() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
assertEquals(1, listWithDupes.indexOf(true));
}
public void testContains_nullElement() {
assertEquals(false, TERTIARY_LIST.contains(null));
}
public void testContains_incompatibleElementType() {
assertEquals(false, TERTIARY_LIST.contains(new Object()));
}
public void testContains_notInList() {
assertEquals(false, UNARY_LIST.contains(false));
}
public void testContains_notInListWithDuplicates() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
assertEquals(false, listWithDupes.contains(false));
}
public void testContains_inList() {
assertEquals(true, TERTIARY_LIST.contains(false));
}
public void testContains_inListWithDuplicates_matchAtHead() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
assertEquals(true, listWithDupes.contains(true));
}
public void testContains_inListWithDuplicates_matchMidList() {
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
assertEquals(true, listWithDupes.contains(true));
}
public void testSize() { public void testSize() {
assertEquals(0, BooleanArrayList.emptyList().size()); assertEquals(0, BooleanArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size()); assertEquals(1, UNARY_LIST.size());

@ -139,6 +139,68 @@ public class DoubleArrayListTest extends TestCase {
} }
} }
public void testIndexOf_nullElement() {
assertEquals(-1, TERTIARY_LIST.indexOf(null));
}
public void testIndexOf_incompatibleElementType() {
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
}
public void testIndexOf_notInList() {
assertEquals(-1, UNARY_LIST.indexOf(2D));
}
public void testIndexOf_notInListWithDuplicates() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
assertEquals(-1, listWithDupes.indexOf(2D));
}
public void testIndexOf_inList() {
assertEquals(1, TERTIARY_LIST.indexOf(2D));
}
public void testIndexOf_inListWithDuplicates_matchAtHead() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
assertEquals(0, listWithDupes.indexOf(1D));
}
public void testIndexOf_inListWithDuplicates_matchMidList() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
assertEquals(1, listWithDupes.indexOf(1D));
}
public void testContains_nullElement() {
assertEquals(false, TERTIARY_LIST.contains(null));
}
public void testContains_incompatibleElementType() {
assertEquals(false, TERTIARY_LIST.contains(new Object()));
}
public void testContains_notInList() {
assertEquals(false, UNARY_LIST.contains(2D));
}
public void testContains_notInListWithDuplicates() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
assertEquals(false, listWithDupes.contains(2D));
}
public void testContains_inList() {
assertEquals(true, TERTIARY_LIST.contains(2D));
}
public void testContains_inListWithDuplicates_matchAtHead() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
assertEquals(true, listWithDupes.contains(1D));
}
public void testContains_inListWithDuplicates_matchMidList() {
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
assertEquals(true, listWithDupes.contains(1D));
}
public void testSize() { public void testSize() {
assertEquals(0, DoubleArrayList.emptyList().size()); assertEquals(0, DoubleArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size()); assertEquals(1, UNARY_LIST.size());

@ -34,6 +34,7 @@ import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.OneofDescriptor;
import com.google.protobuf.FieldPresenceTestProto.TestAllTypes; import com.google.protobuf.FieldPresenceTestProto.TestAllTypes;
import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly; import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly;
import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly; import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly;
@ -100,6 +101,7 @@ public class FieldPresenceTest extends TestCase {
UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OneofBytes"); UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OneofBytes");
} }
public void testOneofEquals() throws Exception { public void testOneofEquals() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder(); TestAllTypes.Builder builder = TestAllTypes.newBuilder();
TestAllTypes message1 = builder.build(); TestAllTypes message1 = builder.build();

@ -139,6 +139,68 @@ public class FloatArrayListTest extends TestCase {
} }
} }
public void testIndexOf_nullElement() {
assertEquals(-1, TERTIARY_LIST.indexOf(null));
}
public void testIndexOf_incompatibleElementType() {
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
}
public void testIndexOf_notInList() {
assertEquals(-1, UNARY_LIST.indexOf(2F));
}
public void testIndexOf_notInListWithDuplicates() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
assertEquals(-1, listWithDupes.indexOf(2F));
}
public void testIndexOf_inList() {
assertEquals(1, TERTIARY_LIST.indexOf(2F));
}
public void testIndexOf_inListWithDuplicates_matchAtHead() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
assertEquals(0, listWithDupes.indexOf(1F));
}
public void testIndexOf_inListWithDuplicates_matchMidList() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
assertEquals(1, listWithDupes.indexOf(1F));
}
public void testContains_nullElement() {
assertEquals(false, TERTIARY_LIST.contains(null));
}
public void testContains_incompatibleElementType() {
assertEquals(false, TERTIARY_LIST.contains(new Object()));
}
public void testContains_notInList() {
assertEquals(false, UNARY_LIST.contains(2F));
}
public void testContains_notInListWithDuplicates() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
assertEquals(false, listWithDupes.contains(2F));
}
public void testContains_inList() {
assertEquals(true, TERTIARY_LIST.contains(2F));
}
public void testContains_inListWithDuplicates_matchAtHead() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
assertEquals(true, listWithDupes.contains(1F));
}
public void testContains_inListWithDuplicates_matchMidList() {
FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
assertEquals(true, listWithDupes.contains(1F));
}
public void testSize() { public void testSize() {
assertEquals(0, FloatArrayList.emptyList().size()); assertEquals(0, FloatArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size()); assertEquals(1, UNARY_LIST.size());

@ -139,6 +139,68 @@ public class IntArrayListTest extends TestCase {
} }
} }
public void testIndexOf_nullElement() {
assertEquals(-1, TERTIARY_LIST.indexOf(null));
}
public void testIndexOf_incompatibleElementType() {
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
}
public void testIndexOf_notInList() {
assertEquals(-1, UNARY_LIST.indexOf(2));
}
public void testIndexOf_notInListWithDuplicates() {
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
assertEquals(-1, listWithDupes.indexOf(2));
}
public void testIndexOf_inList() {
assertEquals(1, TERTIARY_LIST.indexOf(2));
}
public void testIndexOf_inListWithDuplicates_matchAtHead() {
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
assertEquals(0, listWithDupes.indexOf(1));
}
public void testIndexOf_inListWithDuplicates_matchMidList() {
IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
assertEquals(1, listWithDupes.indexOf(1));
}
public void testContains_nullElement() {
assertEquals(false, TERTIARY_LIST.contains(null));
}
public void testContains_incompatibleElementType() {
assertEquals(false, TERTIARY_LIST.contains(new Object()));
}
public void testContains_notInList() {
assertEquals(false, UNARY_LIST.contains(2));
}
public void testContains_notInListWithDuplicates() {
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
assertEquals(false, listWithDupes.contains(2));
}
public void testContains_inList() {
assertEquals(true, TERTIARY_LIST.contains(2));
}
public void testContains_inListWithDuplicates_matchAtHead() {
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
assertEquals(true, listWithDupes.contains(1));
}
public void testContains_inListWithDuplicates_matchMidList() {
IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
assertEquals(true, listWithDupes.contains(1));
}
public void testSize() { public void testSize() {
assertEquals(0, IntArrayList.emptyList().size()); assertEquals(0, IntArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size()); assertEquals(1, UNARY_LIST.size());

@ -139,6 +139,68 @@ public class LongArrayListTest extends TestCase {
} }
} }
public void testIndexOf_nullElement() {
assertEquals(-1, TERTIARY_LIST.indexOf(null));
}
public void testIndexOf_incompatibleElementType() {
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
}
public void testIndexOf_notInList() {
assertEquals(-1, UNARY_LIST.indexOf(2L));
}
public void testIndexOf_notInListWithDuplicates() {
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
assertEquals(-1, listWithDupes.indexOf(2L));
}
public void testIndexOf_inList() {
assertEquals(1, TERTIARY_LIST.indexOf(2L));
}
public void testIndexOf_inListWithDuplicates_matchAtHead() {
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
assertEquals(0, listWithDupes.indexOf(1L));
}
public void testIndexOf_inListWithDuplicates_matchMidList() {
LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
assertEquals(1, listWithDupes.indexOf(1L));
}
public void testContains_nullElement() {
assertEquals(false, TERTIARY_LIST.contains(null));
}
public void testContains_incompatibleElementType() {
assertEquals(false, TERTIARY_LIST.contains(new Object()));
}
public void testContains_notInList() {
assertEquals(false, UNARY_LIST.contains(2L));
}
public void testContains_notInListWithDuplicates() {
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
assertEquals(false, listWithDupes.contains(2L));
}
public void testContains_inList() {
assertEquals(true, TERTIARY_LIST.contains(2L));
}
public void testContains_inListWithDuplicates_matchAtHead() {
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
assertEquals(true, listWithDupes.contains(1L));
}
public void testContains_inListWithDuplicates_matchMidList() {
LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
assertEquals(true, listWithDupes.contains(1L));
}
public void testSize() { public void testSize() {
assertEquals(0, LongArrayList.emptyList().size()); assertEquals(0, LongArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size()); assertEquals(1, UNARY_LIST.size());

@ -1536,4 +1536,42 @@ public class TextFormatTest extends TestCase {
index, line, column)); index, line, column));
} }
} }
public void testSortMapFields() throws Exception {
TestMap message =
TestMap.newBuilder()
.putStringToInt32Field("cherry", 30)
.putStringToInt32Field("banana", 20)
.putStringToInt32Field("apple", 10)
.putInt32ToStringField(30, "cherry")
.putInt32ToStringField(20, "banana")
.putInt32ToStringField(10, "apple")
.build();
String text =
"int32_to_string_field {\n"
+ " key: 10\n"
+ " value: \"apple\"\n"
+ "}\n"
+ "int32_to_string_field {\n"
+ " key: 20\n"
+ " value: \"banana\"\n"
+ "}\n"
+ "int32_to_string_field {\n"
+ " key: 30\n"
+ " value: \"cherry\"\n"
+ "}\n"
+ "string_to_int32_field {\n"
+ " key: \"apple\"\n"
+ " value: 10\n"
+ "}\n"
+ "string_to_int32_field {\n"
+ " key: \"banana\"\n"
+ " value: 20\n"
+ "}\n"
+ "string_to_int32_field {\n"
+ " key: \"cherry\"\n"
+ " value: 30\n"
+ "}\n";
assertEquals(text, TextFormat.printer().printToString(message));
}
} }

@ -177,16 +177,20 @@ public final class Proto2MessageLiteInfoFactory implements MessageInfoFactory {
// To update this after a proto change, run protoc on proto2_message_lite.proto and copy over // To update this after a proto change, run protoc on proto2_message_lite.proto and copy over
// the content of the generated buildMessageInfo() method here. // the content of the generated buildMessageInfo() method here.
java.lang.String info = java.lang.String info =
"\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u0000\u0000\u0002\u0001\u0001\u0003" "\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u1000\u0000\u0002\u1001\u0001\u0003"
+ "\u0002\u0002\u0004\u0003\u0003\u0005\u0004\u0004\u0006\u0005\u0005\u0007\u0006\u0006" + "\u1002\u0002\u0004\u1003\u0003\u0005\u1004\u0004\u0006\u1005\u0005\u0007\u1006\u0006\b\u1007\u0007"
+ "\b\u0007\u0007\t\b\b\n\u0409\t\u000b\n\n\f\u000b\u000b\r\f\f\u000e\r\r\u000f\u000e" + "\t\u1008\b\n"
+ "\u000e\u0010\u000f\u000f\u0011\u0010\u0010\u0012\u0012\u0013\u0013\u0014\u0014\u0015" + "\u1409\t\u000b\u100a\n"
+ "\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c" + "\f\u100b\u000b\r"
+ "\u001c\u001d\u001d\u001e\u001e\u001f\u001f !!\"\"##$$%%&&\'\'(())**++,,--..//00" + "\u100c\f\u000e\u100d\r"
+ "1\u0011\u00113153\u000064\u000075\u000086\u000097\u0000:8\u0000;9\u0000<:\u0000=" + "\u000f\u100e\u000e\u0010\u100f\u000f\u0011\u1010\u0010\u0012\u0012\u0013\u0013"
+ ";\u0000>\u043c\u0000?=\u0000@>\u0000A@\u0000BA\u0000CB\u0000DC\u0000ED\u0000G\u0500" + "\u0014\u0014\u0015\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c\u001c\u001d\u001d\u001e\u001e\u001f\u001f"
+ "#H\u0501$I\u0502%J\u0503&K\u0504\'L\u0505(M\u0506)N\u0507*O\u0508+P\u0509,Q\u050a" + " !!\"\"##$$%%&&\'\'"
+ "-R\u050b.S\u050c/T\u050d0U\u050e1V\u050f2W\u05103X\u05114"; + "(())**++,,--..//001\u1011\u0011315\u1033\u00006\u1034\u00007\u1035\u00008\u1036\u0000"
+ "9\u1037\u0000:\u1038\u0000;\u1039\u0000<\u103a\u0000=\u103b\u0000>\u143c\u0000?\u103d"
+ "\u0000@\u103e\u0000A\u1040\u0000B\u1041\u0000C\u1042\u0000D\u1043\u0000E\u1044\u0000"
+ "G\u1500#H\u1501$I\u1502%J\u1503&K\u1504\'L\u1505(M\u1506)N\u1507*O\u1508+P\u1509"
+ ",Q\u150a-R\u150b.S\u150c/T\u150d0U\u150e1V\u150f2W\u15103X\u15114";
return new RawMessageInfo(Proto2MessageLite.getDefaultInstance(), info, objects); return new RawMessageInfo(Proto2MessageLite.getDefaultInstance(), info, objects);
} }

@ -34,6 +34,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
@ -49,7 +50,7 @@ import java.util.List;
/** /**
* Utility helper functions to work with {@link com.google.protobuf.FieldMask}. * Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
*/ */
public class FieldMaskUtil { public final class FieldMaskUtil {
private static final String FIELD_PATH_SEPARATOR = ","; private static final String FIELD_PATH_SEPARATOR = ",";
private static final String FIELD_PATH_SEPARATOR_REGEX = ","; private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
private static final String FIELD_SEPARATOR_REGEX = "\\."; private static final String FIELD_SEPARATOR_REGEX = "\\.";
@ -83,7 +84,7 @@ public class FieldMaskUtil {
*/ */
public static FieldMask fromString(String value) { public static FieldMask fromString(String value) {
// TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead. // TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead.
return fromStringList(null, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX))); return fromStringList(Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
} }
/** /**
@ -103,14 +104,36 @@ public class FieldMaskUtil {
*/ */
// TODO(xiaofeng): Consider renaming fromStrings() // TODO(xiaofeng): Consider renaming fromStrings()
public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) { public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) {
return fromStringList(Internal.getDefaultInstance(type).getDescriptorForType(), paths);
}
/**
* Constructs a FieldMask for a list of field paths in a certain type.
*
* @throws IllegalArgumentException if any of the field path is not valid.
*/
public static FieldMask fromStringList(Descriptor descriptor, Iterable<String> paths) {
return fromStringList(Optional.of(descriptor), paths);
}
/**
* Constructs a FieldMask for a list of field paths in a certain type. Does not validate the given
* paths.
*/
public static FieldMask fromStringList(Iterable<String> paths) {
return fromStringList(Optional.<Descriptor>absent(), paths);
}
private static FieldMask fromStringList(Optional<Descriptor> descriptor, Iterable<String> paths) {
FieldMask.Builder builder = FieldMask.newBuilder(); FieldMask.Builder builder = FieldMask.newBuilder();
for (String path : paths) { for (String path : paths) {
if (path.isEmpty()) { if (path.isEmpty()) {
// Ignore empty field paths. // Ignore empty field paths.
continue; continue;
} }
if (type != null && !isValid(type, path)) { if (descriptor.isPresent() && !isValid(descriptor.get(), path)) {
throw new IllegalArgumentException(path + " is not a valid path for " + type); throw new IllegalArgumentException(
path + " is not a valid path for " + descriptor.get().getFullName());
} }
builder.addPaths(path); builder.addPaths(path);
} }

@ -233,7 +233,7 @@ public class JsonFormat {
registry, registry,
oldRegistry, oldRegistry,
alwaysOutputDefaultValueFields, alwaysOutputDefaultValueFields,
Collections.<FieldDescriptor>emptySet(), includingDefaultValueFields,
preservingProtoFieldNames, preservingProtoFieldNames,
omittingInsignificantWhitespace, omittingInsignificantWhitespace,
true, true,

@ -71,8 +71,8 @@ public final class Values {
} }
/** /**
* Returns a Value with ListValue set to the appending the result of calling {@link #of(Object)} * Returns a Value with ListValue set to the appending the result of calling {@link #of} on each
* on each element in the iterable. * element in the iterable.
*/ */
public static Value of(Iterable<Value> values) { public static Value of(Iterable<Value> values) {
Value.Builder valueBuilder = Value.newBuilder(); Value.Builder valueBuilder = Value.newBuilder();

@ -30,10 +30,12 @@
package com.google.protobuf.util; package com.google.protobuf.util;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.FieldMask; import com.google.protobuf.FieldMask;
import protobuf_unittest.UnittestProto.NestedTestAllTypes; import protobuf_unittest.UnittestProto.NestedTestAllTypes;
import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestAllTypes;
import junit.framework.TestCase; import junit.framework.TestCase;
/** Unit tests for {@link FieldMaskUtil}. */ /** Unit tests for {@link FieldMaskUtil}. */
@ -172,6 +174,38 @@ public class FieldMaskUtilTest extends TestCase {
assertEquals("bar_baz", mask.getPaths(1)); assertEquals("bar_baz", mask.getPaths(1));
} }
public void testFromStringList() throws Exception {
FieldMask mask =
FieldMaskUtil.fromStringList(
NestedTestAllTypes.class, ImmutableList.of("payload.repeated_nested_message", "child"));
assertThat(mask)
.isEqualTo(
FieldMask.newBuilder()
.addPaths("payload.repeated_nested_message")
.addPaths("child")
.build());
mask =
FieldMaskUtil.fromStringList(
NestedTestAllTypes.getDescriptor(),
ImmutableList.of("payload.repeated_nested_message", "child"));
assertThat(mask)
.isEqualTo(
FieldMask.newBuilder()
.addPaths("payload.repeated_nested_message")
.addPaths("child")
.build());
mask =
FieldMaskUtil.fromStringList(ImmutableList.of("payload.repeated_nested_message", "child"));
assertThat(mask)
.isEqualTo(
FieldMask.newBuilder()
.addPaths("payload.repeated_nested_message")
.addPaths("child")
.build());
}
public void testUnion() throws Exception { public void testUnion() throws Exception {
// Only test a simple case here and expect // Only test a simple case here and expect
// {@link FieldMaskTreeTest#testAddFieldPath} to cover all scenarios. // {@link FieldMaskTreeTest#testAddFieldPath} to cover all scenarios.

@ -30,6 +30,7 @@
package com.google.protobuf.util; package com.google.protobuf.util;
import com.google.common.collect.ImmutableSet;
import com.google.protobuf.Any; import com.google.protobuf.Any;
import com.google.protobuf.BoolValue; import com.google.protobuf.BoolValue;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
@ -1784,4 +1785,16 @@ public class JsonFormatTest extends TestCase {
TestMap emptyMap = TestMap.getDefaultInstance(); TestMap emptyMap = TestMap.getDefaultInstance();
assertEquals("{\n}", toSortedJsonString(emptyMap)); assertEquals("{\n}", toSortedJsonString(emptyMap));
} }
public void testPrintingEnumsAsIntsChainedAfterIncludingDefaultValueFields() throws Exception {
TestAllTypes message = TestAllTypes.newBuilder().setOptionalBool(false).build();
assertEquals(
"{\n" + " \"optionalBool\": false\n" + "}",
JsonFormat.printer()
.includingDefaultValueFields(
ImmutableSet.of(message.getDescriptorForType().findFieldByName("optional_bool")))
.printingEnumsAsInts()
.print(message));
}
} }

@ -1080,7 +1080,7 @@ describe('Message test suite', function() {
it('testMessageWithLargeFieldNumbers', function() { it('testMessageWithLargeFieldNumbers', function() {
var message = new proto.jspb.test.MessageWithLargeFieldNumbers; var message = new proto.jspb.test.MessageWithLargeFieldNumbers;
message.setAString('string'); message.setAString('string');
assertEquals('string', message.getAString()); assertEquals('string', message.getAString());

@ -72,6 +72,7 @@ class Descriptor
->optional('oneof_index', \Google\Protobuf\Internal\GPBType::INT32, 9) ->optional('oneof_index', \Google\Protobuf\Internal\GPBType::INT32, 9)
->optional('json_name', \Google\Protobuf\Internal\GPBType::STRING, 10) ->optional('json_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FieldOptions') ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FieldOptions')
->optional('proto3_optional', \Google\Protobuf\Internal\GPBType::BOOL, 17)
->finalizeToPool(); ->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Type', \Google\Protobuf\Internal\Type::class) $pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Type', \Google\Protobuf\Internal\Type::class)

@ -93,6 +93,20 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
protected $options = null; protected $options = null;
private $has_options = false; private $has_options = false;
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* For message fields this doesn't create any semantic change, since
* non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
*/
protected $proto3_optional = false;
private $has_proto3_optional = false;
/** /**
* Constructor. * Constructor.
@ -130,6 +144,15 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
* will be used. Otherwise, it's deduced from the field's name by converting * will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase. * it to camelCase.
* @type \Google\Protobuf\Internal\FieldOptions $options * @type \Google\Protobuf\Internal\FieldOptions $options
* @type bool $proto3_optional
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* For message fields this doesn't create any semantic change, since
* non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -469,5 +492,51 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
return $this->has_options; return $this->has_options;
} }
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* For message fields this doesn't create any semantic change, since
* non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @return bool
*/
public function getProto3Optional()
{
return $this->proto3_optional;
}
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* For message fields this doesn't create any semantic change, since
* non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @param bool $var
* @return $this
*/
public function setProto3Optional($var)
{
GPBUtil::checkBool($var);
$this->proto3_optional = $var;
$this->has_proto3_optional = true;
return $this;
}
public function hasProto3Optional()
{
return $this->has_proto3_optional;
}
} }

@ -127,7 +127,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies * Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++. * only to generated classes for C++.
* *
* Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = true];</code>
*/ */
protected $cc_enable_arenas = false; protected $cc_enable_arenas = false;
private $has_cc_enable_arenas = false; private $has_cc_enable_arenas = false;
@ -732,7 +732,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies * Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++. * only to generated classes for C++.
* *
* Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = true];</code>
* @return bool * @return bool
*/ */
public function getCcEnableArenas() public function getCcEnableArenas()
@ -744,7 +744,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies * Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++. * only to generated classes for C++.
* *
* Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = true];</code>
* @param bool $var * @param bool $var
* @return $this * @return $this
*/ */

@ -35,6 +35,7 @@ file, in types that make this information accessible in Python.
__author__ = 'robinson@google.com (Will Robinson)' __author__ = 'robinson@google.com (Will Robinson)'
import threading import threading
import warnings
import six import six
from google.protobuf.internal import api_implementation from google.protobuf.internal import api_implementation
@ -91,6 +92,25 @@ class _Lock(object):
_lock = threading.Lock() _lock = threading.Lock()
def _Deprecated(name):
if _Deprecated.count > 0:
_Deprecated.count -= 1
warnings.warn(
'Call to deprecated create function %s(). Note: Create unlinked '
'descriptors is going to go away. Please use get/find descriptors from '
'generated code or query the descriptor_pool.'
% name,
category=DeprecationWarning, stacklevel=3)
# Deprecated warnings will print 100 times at most which should be enough for
# users to notice and do not cause timeout.
_Deprecated.count = 100
_internal_create_key = object()
class DescriptorBase(six.with_metaclass(DescriptorMetaclass)): class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""Descriptors base class. """Descriptors base class.
@ -271,7 +291,7 @@ class Descriptor(_NestedDescriptorBase):
serialized_options=None, serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None, is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
syntax=None): syntax=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() _message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindMessageTypeByName(full_name) return _message.default_pool.FindMessageTypeByName(full_name)
@ -283,13 +303,16 @@ class Descriptor(_NestedDescriptorBase):
serialized_options=None, serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None, is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
syntax=None): syntax=None, create_key=None):
"""Arguments to __init__() are as described in the description """Arguments to __init__() are as described in the description
of Descriptor fields above. of Descriptor fields above.
Note that filename is an obsolete argument, that is not used anymore. Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute. Please use file.name to access this as an attribute.
""" """
if create_key is not _internal_create_key:
_Deprecated('Descriptor')
super(Descriptor, self).__init__( super(Descriptor, self).__init__(
options, 'MessageOptions', name, full_name, file, options, 'MessageOptions', name, full_name, file,
containing_type, serialized_start=serialized_start, containing_type, serialized_start=serialized_start,
@ -515,7 +538,7 @@ class FieldDescriptor(DescriptorBase):
is_extension, extension_scope, options=None, is_extension, extension_scope, options=None,
serialized_options=None, serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None, has_default_value=True, containing_oneof=None, json_name=None,
file=None): # pylint: disable=redefined-builtin file=None, create_key=None): # pylint: disable=redefined-builtin
_message.Message._CheckCalledFromGeneratedFile() _message.Message._CheckCalledFromGeneratedFile()
if is_extension: if is_extension:
return _message.default_pool.FindExtensionByName(full_name) return _message.default_pool.FindExtensionByName(full_name)
@ -527,7 +550,7 @@ class FieldDescriptor(DescriptorBase):
is_extension, extension_scope, options=None, is_extension, extension_scope, options=None,
serialized_options=None, serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None, has_default_value=True, containing_oneof=None, json_name=None,
file=None): # pylint: disable=redefined-builtin file=None, create_key=None): # pylint: disable=redefined-builtin
"""The arguments are as described in the description of FieldDescriptor """The arguments are as described in the description of FieldDescriptor
attributes above. attributes above.
@ -535,6 +558,9 @@ class FieldDescriptor(DescriptorBase):
(to deal with circular references between message types, for example). (to deal with circular references between message types, for example).
Likewise for extension_scope. Likewise for extension_scope.
""" """
if create_key is not _internal_create_key:
_Deprecated('FieldDescriptor')
super(FieldDescriptor, self).__init__( super(FieldDescriptor, self).__init__(
options, serialized_options, 'FieldOptions') options, serialized_options, 'FieldOptions')
self.name = name self.name = name
@ -628,19 +654,22 @@ class EnumDescriptor(_NestedDescriptorBase):
def __new__(cls, name, full_name, filename, values, def __new__(cls, name, full_name, filename, values,
containing_type=None, options=None, containing_type=None, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin serialized_options=None, file=None, # pylint: disable=redefined-builtin
serialized_start=None, serialized_end=None): serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() _message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindEnumTypeByName(full_name) return _message.default_pool.FindEnumTypeByName(full_name)
def __init__(self, name, full_name, filename, values, def __init__(self, name, full_name, filename, values,
containing_type=None, options=None, containing_type=None, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin serialized_options=None, file=None, # pylint: disable=redefined-builtin
serialized_start=None, serialized_end=None): serialized_start=None, serialized_end=None, create_key=None):
"""Arguments are as described in the attribute description above. """Arguments are as described in the attribute description above.
Note that filename is an obsolete argument, that is not used anymore. Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute. Please use file.name to access this as an attribute.
""" """
if create_key is not _internal_create_key:
_Deprecated('EnumDescriptor')
super(EnumDescriptor, self).__init__( super(EnumDescriptor, self).__init__(
options, 'EnumOptions', name, full_name, file, options, 'EnumOptions', name, full_name, file,
containing_type, serialized_start=serialized_start, containing_type, serialized_start=serialized_start,
@ -684,7 +713,7 @@ class EnumValueDescriptor(DescriptorBase):
def __new__(cls, name, index, number, def __new__(cls, name, index, number,
type=None, # pylint: disable=redefined-builtin type=None, # pylint: disable=redefined-builtin
options=None, serialized_options=None): options=None, serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() _message.Message._CheckCalledFromGeneratedFile()
# There is no way we can build a complete EnumValueDescriptor with the # There is no way we can build a complete EnumValueDescriptor with the
# given parameters (the name of the Enum is not known, for example). # given parameters (the name of the Enum is not known, for example).
@ -694,8 +723,11 @@ class EnumValueDescriptor(DescriptorBase):
def __init__(self, name, index, number, def __init__(self, name, index, number,
type=None, # pylint: disable=redefined-builtin type=None, # pylint: disable=redefined-builtin
options=None, serialized_options=None): options=None, serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above.""" """Arguments are as described in the attribute description above."""
if create_key is not _internal_create_key:
_Deprecated('EnumValueDescriptor')
super(EnumValueDescriptor, self).__init__( super(EnumValueDescriptor, self).__init__(
options, serialized_options, 'EnumValueOptions') options, serialized_options, 'EnumValueOptions')
self.name = name self.name = name
@ -724,14 +756,17 @@ class OneofDescriptor(DescriptorBase):
def __new__( def __new__(
cls, name, full_name, index, containing_type, fields, options=None, cls, name, full_name, index, containing_type, fields, options=None,
serialized_options=None): serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() _message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindOneofByName(full_name) return _message.default_pool.FindOneofByName(full_name)
def __init__( def __init__(
self, name, full_name, index, containing_type, fields, options=None, self, name, full_name, index, containing_type, fields, options=None,
serialized_options=None): serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above.""" """Arguments are as described in the attribute description above."""
if create_key is not _internal_create_key:
_Deprecated('OneofDescriptor')
super(OneofDescriptor, self).__init__( super(OneofDescriptor, self).__init__(
options, serialized_options, 'OneofOptions') options, serialized_options, 'OneofOptions')
self.name = name self.name = name
@ -765,13 +800,16 @@ class ServiceDescriptor(_NestedDescriptorBase):
def __new__(cls, name, full_name, index, methods, options=None, def __new__(cls, name, full_name, index, methods, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin serialized_options=None, file=None, # pylint: disable=redefined-builtin
serialized_start=None, serialized_end=None): serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindServiceByName(full_name) return _message.default_pool.FindServiceByName(full_name)
def __init__(self, name, full_name, index, methods, options=None, def __init__(self, name, full_name, index, methods, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin serialized_options=None, file=None, # pylint: disable=redefined-builtin
serialized_start=None, serialized_end=None): serialized_start=None, serialized_end=None, create_key=None):
if create_key is not _internal_create_key:
_Deprecated('ServiceDescriptor')
super(ServiceDescriptor, self).__init__( super(ServiceDescriptor, self).__init__(
options, 'ServiceOptions', name, full_name, file, options, 'ServiceOptions', name, full_name, file,
None, serialized_start=serialized_start, None, serialized_start=serialized_start,
@ -826,17 +864,22 @@ class MethodDescriptor(DescriptorBase):
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor _C_DESCRIPTOR_CLASS = _message.MethodDescriptor
def __new__(cls, name, full_name, index, containing_service, def __new__(cls, name, full_name, index, containing_service,
input_type, output_type, options=None, serialized_options=None): input_type, output_type, options=None, serialized_options=None,
create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindMethodByName(full_name) return _message.default_pool.FindMethodByName(full_name)
def __init__(self, name, full_name, index, containing_service, def __init__(self, name, full_name, index, containing_service,
input_type, output_type, options=None, serialized_options=None): input_type, output_type, options=None, serialized_options=None,
create_key=None):
"""The arguments are as described in the description of MethodDescriptor """The arguments are as described in the description of MethodDescriptor
attributes above. attributes above.
Note that containing_service may be None, and may be set later if necessary. Note that containing_service may be None, and may be set later if necessary.
""" """
if create_key is not _internal_create_key:
_Deprecated('MethodDescriptor')
super(MethodDescriptor, self).__init__( super(MethodDescriptor, self).__init__(
options, serialized_options, 'MethodOptions') options, serialized_options, 'MethodOptions')
self.name = name self.name = name
@ -884,11 +927,11 @@ class FileDescriptor(DescriptorBase):
def __new__(cls, name, package, options=None, def __new__(cls, name, package, options=None,
serialized_options=None, serialized_pb=None, serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None, dependencies=None, public_dependencies=None,
syntax=None, pool=None): syntax=None, pool=None, create_key=None):
# FileDescriptor() is called from various places, not only from generated # FileDescriptor() is called from various places, not only from generated
# files, to register dynamic proto files and messages. # files, to register dynamic proto files and messages.
# pylint: disable=g-explicit-bool-comparison # pylint: disable=g-explicit-bool-comparison
if serialized_pb == '': if serialized_pb == b'':
# Cpp generated code must be linked in if serialized_pb is '' # Cpp generated code must be linked in if serialized_pb is ''
try: try:
return _message.default_pool.FindFileByName(name) return _message.default_pool.FindFileByName(name)
@ -902,8 +945,11 @@ class FileDescriptor(DescriptorBase):
def __init__(self, name, package, options=None, def __init__(self, name, package, options=None,
serialized_options=None, serialized_pb=None, serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None, dependencies=None, public_dependencies=None,
syntax=None, pool=None): syntax=None, pool=None, create_key=None):
"""Constructor.""" """Constructor."""
if create_key is not _internal_create_key:
_Deprecated('FileDescriptor')
super(FileDescriptor, self).__init__( super(FileDescriptor, self).__init__(
options, serialized_options, 'FileOptions') options, serialized_options, 'FileOptions')
@ -1042,9 +1088,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
for enum_proto in desc_proto.enum_type: for enum_proto in desc_proto.enum_type:
full_name = '.'.join(full_message_name + [enum_proto.name]) full_name = '.'.join(full_message_name + [enum_proto.name])
enum_desc = EnumDescriptor( enum_desc = EnumDescriptor(
enum_proto.name, full_name, None, [ enum_proto.name, full_name, None, [
EnumValueDescriptor(enum_val.name, ii, enum_val.number) EnumValueDescriptor(enum_val.name, ii, enum_val.number,
for ii, enum_val in enumerate(enum_proto.value)]) create_key=_internal_create_key)
for ii, enum_val in enumerate(enum_proto.value)],
create_key=_internal_create_key)
enum_types[full_name] = enum_desc enum_types[full_name] = enum_desc
# Create Descriptors for nested types # Create Descriptors for nested types
@ -1083,10 +1131,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
field_proto.label, None, nested_desc, enum_desc, None, False, None, field_proto.label, None, nested_desc, enum_desc, None, False, None,
options=_OptionsOrNone(field_proto), has_default_value=False, options=_OptionsOrNone(field_proto), has_default_value=False,
json_name=json_name) json_name=json_name, create_key=_internal_create_key)
fields.append(field) fields.append(field)
desc_name = '.'.join(full_message_name) desc_name = '.'.join(full_message_name)
return Descriptor(desc_proto.name, desc_name, None, None, fields, return Descriptor(desc_proto.name, desc_name, None, None, fields,
list(nested_types.values()), list(enum_types.values()), [], list(nested_types.values()), list(enum_types.values()), [],
options=_OptionsOrNone(desc_proto)) options=_OptionsOrNone(desc_proto),
create_key=_internal_create_key)

@ -619,7 +619,7 @@ class DescriptorPool(object):
def FindAllExtensions(self, message_descriptor): def FindAllExtensions(self, message_descriptor):
"""Gets all the known extensions of a given message. """Gets all the known extensions of a given message.
Extensions have to be registered to this pool by calling Extensions have to be registered to this pool by build related
:func:`Add` or :func:`AddExtensionDescriptor`. :func:`Add` or :func:`AddExtensionDescriptor`.
Args: Args:
@ -662,18 +662,7 @@ class DescriptorPool(object):
return return
try: try:
file_desc = self._ConvertFileProtoToFileDescriptor(file_proto) self._ConvertFileProtoToFileDescriptor(file_proto)
for extension in file_desc.extensions_by_name.values():
self._extensions_by_number[extension.containing_type][
extension.number] = extension
self._extensions_by_name[extension.containing_type][
extension.full_name] = extension
for message_type in file_desc.message_types_by_name.values():
for extension in message_type.extensions:
self._extensions_by_number[extension.containing_type][
extension.number] = extension
self._extensions_by_name[extension.containing_type][
extension.full_name] = extension
except: except:
warn_msg = ('Unable to load proto file %s for extension number %d.' % warn_msg = ('Unable to load proto file %s for extension number %d.' %
(file_proto.name, number)) (file_proto.name, number))
@ -761,7 +750,9 @@ class DescriptorPool(object):
options=_OptionsOrNone(file_proto), options=_OptionsOrNone(file_proto),
serialized_pb=file_proto.SerializeToString(), serialized_pb=file_proto.SerializeToString(),
dependencies=direct_deps, dependencies=direct_deps,
public_dependencies=public_deps) public_dependencies=public_deps,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
scope = {} scope = {}
# This loop extracts all the message and enum types from all the # This loop extracts all the message and enum types from all the
@ -820,7 +811,15 @@ class DescriptorPool(object):
self.Add(file_proto) self.Add(file_proto)
self._file_descriptors[file_proto.name] = file_descriptor self._file_descriptors[file_proto.name] = file_descriptor
return self._file_descriptors[file_proto.name] # Add extensions to the pool
file_desc = self._file_descriptors[file_proto.name]
for extension in file_desc.extensions_by_name.values():
self._AddExtensionDescriptor(extension)
for message_type in file_desc.message_types_by_name.values():
for extension in message_type.extensions:
self._AddExtensionDescriptor(extension)
return file_desc
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None, def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
scope=None, syntax=None): scope=None, syntax=None):
@ -865,8 +864,11 @@ class DescriptorPool(object):
is_extension=True) is_extension=True)
for index, extension in enumerate(desc_proto.extension)] for index, extension in enumerate(desc_proto.extension)]
oneofs = [ oneofs = [
# pylint: disable=g-complex-comprehension
descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)), descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
index, None, [], desc.options) index, None, [], desc.options,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
for index, desc in enumerate(desc_proto.oneof_decl)] for index, desc in enumerate(desc_proto.oneof_decl)]
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range] extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
if extension_ranges: if extension_ranges:
@ -889,7 +891,9 @@ class DescriptorPool(object):
file=file_desc, file=file_desc,
serialized_start=None, serialized_start=None,
serialized_end=None, serialized_end=None,
syntax=syntax) syntax=syntax,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
for nested in desc.nested_types: for nested in desc.nested_types:
nested.containing_type = desc nested.containing_type = desc
for enum in desc.enum_types: for enum in desc.enum_types:
@ -940,7 +944,9 @@ class DescriptorPool(object):
file=file_desc, file=file_desc,
values=values, values=values,
containing_type=containing_type, containing_type=containing_type,
options=_OptionsOrNone(enum_proto)) options=_OptionsOrNone(enum_proto),
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
scope['.%s' % enum_name] = desc scope['.%s' % enum_name] = desc
self._CheckConflictRegister(desc, desc.full_name, desc.file.name) self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._enum_descriptors[enum_name] = desc self._enum_descriptors[enum_name] = desc
@ -997,7 +1003,9 @@ class DescriptorPool(object):
is_extension=is_extension, is_extension=is_extension,
extension_scope=None, extension_scope=None,
options=_OptionsOrNone(field_proto), options=_OptionsOrNone(field_proto),
file=file_desc) file=file_desc,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
def _SetAllFieldTypes(self, package, desc_proto, scope): def _SetAllFieldTypes(self, package, desc_proto, scope):
"""Sets all the descriptor's fields's types. """Sets all the descriptor's fields's types.
@ -1121,7 +1129,9 @@ class DescriptorPool(object):
index=index, index=index,
number=value_proto.number, number=value_proto.number,
options=_OptionsOrNone(value_proto), options=_OptionsOrNone(value_proto),
type=None) type=None,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
def _MakeServiceDescriptor(self, service_proto, service_index, scope, def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc): package, file_desc):
@ -1146,12 +1156,15 @@ class DescriptorPool(object):
methods = [self._MakeMethodDescriptor(method_proto, service_name, package, methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index) scope, index)
for index, method_proto in enumerate(service_proto.method)] for index, method_proto in enumerate(service_proto.method)]
desc = descriptor.ServiceDescriptor(name=service_proto.name, desc = descriptor.ServiceDescriptor(
full_name=service_name, name=service_proto.name,
index=service_index, full_name=service_name,
methods=methods, index=service_index,
options=_OptionsOrNone(service_proto), methods=methods,
file=file_desc) options=_OptionsOrNone(service_proto),
file=file_desc,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
self._CheckConflictRegister(desc, desc.full_name, desc.file.name) self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._service_descriptors[service_name] = desc self._service_descriptors[service_name] = desc
return desc return desc
@ -1175,13 +1188,16 @@ class DescriptorPool(object):
package, method_proto.input_type, scope) package, method_proto.input_type, scope)
output_type = self._GetTypeFromScope( output_type = self._GetTypeFromScope(
package, method_proto.output_type, scope) package, method_proto.output_type, scope)
return descriptor.MethodDescriptor(name=method_proto.name, return descriptor.MethodDescriptor(
full_name=full_name, name=method_proto.name,
index=index, full_name=full_name,
containing_service=None, index=index,
input_type=input_type, containing_service=None,
output_type=output_type, input_type=input_type,
options=_OptionsOrNone(method_proto)) output_type=output_type,
options=_OptionsOrNone(method_proto),
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
def _ExtractSymbols(self, descriptors): def _ExtractSymbols(self, descriptors):
"""Pulls out all the symbols from descriptor protos. """Pulls out all the symbols from descriptor protos.

@ -816,8 +816,12 @@ def MessageSetItemDecoder(descriptor):
if extension is not None: if extension is not None:
value = field_dict.get(extension) value = field_dict.get(extension)
if value is None: if value is None:
message_type = extension.message_type
if not hasattr(message_type, '_concrete_class'):
# pylint: disable=protected-access
message._FACTORY.GetPrototype(message_type)
value = field_dict.setdefault( value = field_dict.setdefault(
extension, extension.message_type._concrete_class()) extension, message_type._concrete_class())
if value._InternalParse(buffer, message_start,message_end) != message_end: if value._InternalParse(buffer, message_start,message_end) != message_end:
# The only reason _InternalParse would return early is if it encountered # The only reason _InternalParse would return early is if it encountered
# an end-group tag. # an end-group tag.

@ -36,6 +36,7 @@ __author__ = 'matthewtoia@google.com (Matt Toia)'
import copy import copy
import os import os
import warnings
try: try:
import unittest2 as unittest #PY26 import unittest2 as unittest #PY26
@ -63,6 +64,9 @@ from google.protobuf import symbol_database
warnings.simplefilter('error', DeprecationWarning)
class DescriptorPoolTestBase(object): class DescriptorPoolTestBase(object):
def testFindFileByName(self): def testFindFileByName(self):
@ -336,12 +340,10 @@ class DescriptorPoolTestBase(object):
'google.protobuf.python.internal.Factory2Message') 'google.protobuf.python.internal.Factory2Message')
# An extension defined in a message. # An extension defined in a message.
one_more_field = factory2_message.extensions_by_name['one_more_field'] one_more_field = factory2_message.extensions_by_name['one_more_field']
self.pool.AddExtensionDescriptor(one_more_field)
# An extension defined at file scope. # An extension defined at file scope.
factory_test2 = self.pool.FindFileByName( factory_test2 = self.pool.FindFileByName(
'google/protobuf/internal/factory_test2.proto') 'google/protobuf/internal/factory_test2.proto')
another_field = factory_test2.extensions_by_name['another_field'] another_field = factory_test2.extensions_by_name['another_field']
self.pool.AddExtensionDescriptor(another_field)
extensions = self.pool.FindAllExtensions(factory1_message) extensions = self.pool.FindAllExtensions(factory1_message)
expected_extension_numbers = set([one_more_field, another_field]) expected_extension_numbers = set([one_more_field, another_field])
@ -356,16 +358,9 @@ class DescriptorPoolTestBase(object):
def testFindExtensionByNumber(self): def testFindExtensionByNumber(self):
factory1_message = self.pool.FindMessageTypeByName( factory1_message = self.pool.FindMessageTypeByName(
'google.protobuf.python.internal.Factory1Message') 'google.protobuf.python.internal.Factory1Message')
factory2_message = self.pool.FindMessageTypeByName( # Build factory_test2.proto which will put extensions to the pool
'google.protobuf.python.internal.Factory2Message') self.pool.FindFileByName(
# An extension defined in a message.
one_more_field = factory2_message.extensions_by_name['one_more_field']
self.pool.AddExtensionDescriptor(one_more_field)
# An extension defined at file scope.
factory_test2 = self.pool.FindFileByName(
'google/protobuf/internal/factory_test2.proto') 'google/protobuf/internal/factory_test2.proto')
another_field = factory_test2.extensions_by_name['another_field']
self.pool.AddExtensionDescriptor(another_field)
# An extension defined in a message. # An extension defined in a message.
extension = self.pool.FindExtensionByNumber(factory1_message, 1001) extension = self.pool.FindExtensionByNumber(factory1_message, 1001)
@ -533,13 +528,13 @@ class DescriptorPoolTestBase(object):
else: else:
pool = copy.deepcopy(self.pool) pool = copy.deepcopy(self.pool)
file_descriptor = unittest_pb2.DESCRIPTOR file_descriptor = unittest_pb2.DESCRIPTOR
pool.AddDescriptor( pool._AddDescriptor(
file_descriptor.message_types_by_name['TestAllTypes']) file_descriptor.message_types_by_name['TestAllTypes'])
pool.AddEnumDescriptor( pool._AddEnumDescriptor(
file_descriptor.enum_types_by_name['ForeignEnum']) file_descriptor.enum_types_by_name['ForeignEnum'])
pool.AddServiceDescriptor( pool._AddServiceDescriptor(
file_descriptor.services_by_name['TestService']) file_descriptor.services_by_name['TestService'])
pool.AddExtensionDescriptor( pool._AddExtensionDescriptor(
file_descriptor.extensions_by_name['optional_int32_extension']) file_descriptor.extensions_by_name['optional_int32_extension'])
pool.Add(unittest_fd) pool.Add(unittest_fd)
pool.Add(conflict_fd) pool.Add(conflict_fd)
@ -873,7 +868,7 @@ class AddDescriptorTest(unittest.TestCase):
def _TestMessage(self, prefix): def _TestMessage(self, prefix):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
pool.AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR) pool._AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR)
self.assertEqual( self.assertEqual(
'protobuf_unittest.TestAllTypes', 'protobuf_unittest.TestAllTypes',
pool.FindMessageTypeByName( pool.FindMessageTypeByName(
@ -884,7 +879,7 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindMessageTypeByName( pool.FindMessageTypeByName(
prefix + 'protobuf_unittest.TestAllTypes.NestedMessage') prefix + 'protobuf_unittest.TestAllTypes.NestedMessage')
pool.AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR) pool._AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR)
self.assertEqual( self.assertEqual(
'protobuf_unittest.TestAllTypes.NestedMessage', 'protobuf_unittest.TestAllTypes.NestedMessage',
pool.FindMessageTypeByName( pool.FindMessageTypeByName(
@ -909,7 +904,10 @@ class AddDescriptorTest(unittest.TestCase):
def _TestEnum(self, prefix): def _TestEnum(self, prefix):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) if api_implementation.Type() == 'cpp':
pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
else:
pool._AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
self.assertEqual( self.assertEqual(
'protobuf_unittest.ForeignEnum', 'protobuf_unittest.ForeignEnum',
pool.FindEnumTypeByName( pool.FindEnumTypeByName(
@ -920,7 +918,10 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindEnumTypeByName( pool.FindEnumTypeByName(
prefix + 'protobuf_unittest.ForeignEnum.NestedEnum') prefix + 'protobuf_unittest.ForeignEnum.NestedEnum')
pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) if api_implementation.Type() == 'cpp':
pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
else:
pool._AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
self.assertEqual( self.assertEqual(
'protobuf_unittest.TestAllTypes.NestedEnum', 'protobuf_unittest.TestAllTypes.NestedEnum',
pool.FindEnumTypeByName( pool.FindEnumTypeByName(
@ -949,7 +950,7 @@ class AddDescriptorTest(unittest.TestCase):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
pool.FindServiceByName('protobuf_unittest.TestService') pool.FindServiceByName('protobuf_unittest.TestService')
pool.AddServiceDescriptor(unittest_pb2._TESTSERVICE) pool._AddServiceDescriptor(unittest_pb2._TESTSERVICE)
self.assertEqual( self.assertEqual(
'protobuf_unittest.TestService', 'protobuf_unittest.TestService',
pool.FindServiceByName('protobuf_unittest.TestService').full_name) pool.FindServiceByName('protobuf_unittest.TestService').full_name)
@ -958,7 +959,7 @@ class AddDescriptorTest(unittest.TestCase):
'With the cpp implementation, Add() must be called first') 'With the cpp implementation, Add() must be called first')
def testFile(self): def testFile(self):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
pool.AddFileDescriptor(unittest_pb2.DESCRIPTOR) pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR)
self.assertEqual( self.assertEqual(
'google/protobuf/unittest.proto', 'google/protobuf/unittest.proto',
pool.FindFileByName( pool.FindFileByName(
@ -1032,16 +1033,28 @@ class AddDescriptorTest(unittest.TestCase):
def testAddTypeError(self): def testAddTypeError(self):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
with self.assertRaises(TypeError): if api_implementation.Type() == 'cpp':
pool.AddDescriptor(0) with self.assertRaises(TypeError):
with self.assertRaises(TypeError): pool.AddDescriptor(0)
pool.AddEnumDescriptor(0) with self.assertRaises(TypeError):
with self.assertRaises(TypeError): pool.AddEnumDescriptor(0)
pool.AddServiceDescriptor(0) with self.assertRaises(TypeError):
with self.assertRaises(TypeError): pool.AddServiceDescriptor(0)
pool.AddExtensionDescriptor(0) with self.assertRaises(TypeError):
with self.assertRaises(TypeError): pool.AddExtensionDescriptor(0)
pool.AddFileDescriptor(0) with self.assertRaises(TypeError):
pool.AddFileDescriptor(0)
else:
with self.assertRaises(TypeError):
pool._AddDescriptor(0)
with self.assertRaises(TypeError):
pool._AddEnumDescriptor(0)
with self.assertRaises(TypeError):
pool._AddServiceDescriptor(0)
with self.assertRaises(TypeError):
pool._AddExtensionDescriptor(0)
with self.assertRaises(TypeError):
pool._AddFileDescriptor(0)
TEST1_FILE = ProtoFile( TEST1_FILE = ProtoFile(

@ -35,6 +35,7 @@
__author__ = 'robinson@google.com (Will Robinson)' __author__ = 'robinson@google.com (Will Robinson)'
import sys import sys
import warnings
try: try:
import unittest2 as unittest #PY26 import unittest2 as unittest #PY26
@ -58,6 +59,9 @@ name: 'TestEmptyMessage'
""" """
warnings.simplefilter('error', DeprecationWarning)
class DescriptorTest(unittest.TestCase): class DescriptorTest(unittest.TestCase):
def setUp(self): def setUp(self):

@ -87,6 +87,10 @@ class _ExtensionDict(object):
if extension_handle.label == FieldDescriptor.LABEL_REPEATED: if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
result = extension_handle._default_constructor(self._extended_message) result = extension_handle._default_constructor(self._extended_message)
elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE: elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
message_type = extension_handle.message_type
if not hasattr(message_type, '_concrete_class'):
# pylint: disable=protected-access
self._extended_message._FACTORY.GetPrototype(message_type)
assert getattr(extension_handle.message_type, '_concrete_class', None), ( assert getattr(extension_handle.message_type, '_concrete_class', None), (
'Uninitialized concrete class found for field %r (message type %r)' 'Uninitialized concrete class found for field %r (message type %r)'
% (extension_handle.full_name, % (extension_handle.full_name,

@ -821,6 +821,10 @@ class JsonFormatTest(JsonFormatBase):
def testFloatPrecision(self): def testFloatPrecision(self):
message = json_format_proto3_pb2.TestMessage() message = json_format_proto3_pb2.TestMessage()
message.float_value = 1.123456789 message.float_value = 1.123456789
# Default to 8 valid digits.
text = '{\n "floatValue": 1.1234568\n}'
self.assertEqual(
json_format.MessageToJson(message), text)
# Set to 7 valid digits. # Set to 7 valid digits.
text = '{\n "floatValue": 1.123457\n}' text = '{\n "floatValue": 1.123457\n}'
self.assertEqual( self.assertEqual(

@ -106,6 +106,9 @@ def IsNegInf(val):
return isinf(val) and (val < 0) return isinf(val) and (val < 0)
warnings.simplefilter('error', DeprecationWarning)
@_parameterized.named_parameters( @_parameterized.named_parameters(
('_proto2', unittest_pb2), ('_proto2', unittest_pb2),
('_proto3', unittest_proto3_arena_pb2)) ('_proto3', unittest_proto3_arena_pb2))
@ -438,12 +441,19 @@ class MessageTest(unittest.TestCase):
self.assertEqual(str(message), 'optional_float: 2.0\n') self.assertEqual(str(message), 'optional_float: 2.0\n')
def testHighPrecisionFloatPrinting(self, message_module): def testHighPrecisionFloatPrinting(self, message_module):
message = message_module.TestAllTypes() msg = message_module.TestAllTypes()
message.optional_double = 0.12345678912345678 msg.optional_float = 0.12345678912345678
old_float = msg.optional_float
msg.ParseFromString(msg.SerializeToString())
self.assertEqual(old_float, msg.optional_float)
def testHighPrecisionDoublePrinting(self, message_module):
msg = message_module.TestAllTypes()
msg.optional_double = 0.12345678912345678
if sys.version_info >= (3,): if sys.version_info >= (3,):
self.assertEqual(str(message), 'optional_double: 0.12345678912345678\n') self.assertEqual(str(msg), 'optional_double: 0.12345678912345678\n')
else: else:
self.assertEqual(str(message), 'optional_double: 0.123456789123\n') self.assertEqual(str(msg), 'optional_double: 0.123456789123\n')
def testUnknownFieldPrinting(self, message_module): def testUnknownFieldPrinting(self, message_module):
populated = message_module.TestAllTypes() populated = message_module.TestAllTypes()
@ -885,11 +895,13 @@ class MessageTest(unittest.TestCase):
def testOneofDefaultValues(self, message_module): def testOneofDefaultValues(self, message_module):
m = message_module.TestAllTypes() m = message_module.TestAllTypes()
self.assertIs(None, m.WhichOneof('oneof_field')) self.assertIs(None, m.WhichOneof('oneof_field'))
self.assertFalse(m.HasField('oneof_field'))
self.assertFalse(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_uint32'))
# Oneof is set even when setting it to a default value. # Oneof is set even when setting it to a default value.
m.oneof_uint32 = 0 m.oneof_uint32 = 0
self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field'))
self.assertTrue(m.HasField('oneof_field'))
self.assertTrue(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_uint32'))
self.assertFalse(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_string'))

@ -124,9 +124,16 @@ class GeneratedProtocolMessageType(type):
Returns: Returns:
Newly-allocated class. Newly-allocated class.
Raises:
RuntimeError: Generated code only work with python cpp extension.
""" """
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY] descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
if isinstance(descriptor, str):
raise RuntimeError('The generated code only work with python cpp '
'extension, but it is using pure python runtime.')
# If a concrete class already exists for this descriptor, don't try to # If a concrete class already exists for this descriptor, don't try to
# create another. Doing so will break any messages that already exist with # create another. Doing so will break any messages that already exist with
# the existing class. # the existing class.
@ -838,10 +845,9 @@ def _AddHasFieldMethod(message_descriptor, cls):
continue continue
hassable_fields[field.name] = field hassable_fields[field.name] = field
if not is_proto3: # Has methods are supported for oneof descriptors.
# Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs:
for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof
hassable_fields[oneof.name] = oneof
def HasField(self, field_name): def HasField(self, field_name):
try: try:

@ -40,6 +40,7 @@ import gc
import operator import operator
import six import six
import struct import struct
import warnings
try: try:
import unittest2 as unittest #PY26 import unittest2 as unittest #PY26
@ -70,6 +71,9 @@ if six.PY3:
long = int # pylint: disable=redefined-builtin,invalid-name long = int # pylint: disable=redefined-builtin,invalid-name
warnings.simplefilter('error', DeprecationWarning)
class _MiniDecoder(object): class _MiniDecoder(object):
"""Decodes a stream of values from a string. """Decodes a stream of values from a string.
@ -1433,12 +1437,16 @@ class Proto2ReflectionTest(unittest.TestCase):
label=FieldDescriptor.LABEL_OPTIONAL, default_value=0, label=FieldDescriptor.LABEL_OPTIONAL, default_value=0,
containing_type=None, message_type=None, enum_type=None, containing_type=None, message_type=None, enum_type=None,
is_extension=False, extension_scope=None, is_extension=False, extension_scope=None,
options=descriptor_pb2.FieldOptions()) options=descriptor_pb2.FieldOptions(),
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
mydescriptor = descriptor.Descriptor( mydescriptor = descriptor.Descriptor(
name='MyProto', full_name='MyProto', filename='ignored', name='MyProto', full_name='MyProto', filename='ignored',
containing_type=None, nested_types=[], enum_types=[], containing_type=None, nested_types=[], enum_types=[],
fields=[foo_field_descriptor], extensions=[], fields=[foo_field_descriptor], extensions=[],
options=descriptor_pb2.MessageOptions()) options=descriptor_pb2.MessageOptions(),
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
class MyProtoClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): class MyProtoClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)):
DESCRIPTOR = mydescriptor DESCRIPTOR = mydescriptor
myproto_instance = MyProtoClass() myproto_instance = MyProtoClass()
@ -3168,22 +3176,34 @@ class ClassAPITest(unittest.TestCase):
'C++ implementation requires a call to MakeDescriptor()') 'C++ implementation requires a call to MakeDescriptor()')
@testing_refleaks.SkipReferenceLeakChecker('MakeClass is not repeatable') @testing_refleaks.SkipReferenceLeakChecker('MakeClass is not repeatable')
def testMakeClassWithNestedDescriptor(self): def testMakeClassWithNestedDescriptor(self):
leaf_desc = descriptor.Descriptor('leaf', 'package.parent.child.leaf', '', leaf_desc = descriptor.Descriptor(
containing_type=None, fields=[], 'leaf', 'package.parent.child.leaf', '',
nested_types=[], enum_types=[], containing_type=None, fields=[],
extensions=[]) nested_types=[], enum_types=[],
child_desc = descriptor.Descriptor('child', 'package.parent.child', '', extensions=[],
containing_type=None, fields=[], # pylint: disable=protected-access
nested_types=[leaf_desc], enum_types=[], create_key=descriptor._internal_create_key)
extensions=[]) child_desc = descriptor.Descriptor(
sibling_desc = descriptor.Descriptor('sibling', 'package.parent.sibling', 'child', 'package.parent.child', '',
'', containing_type=None, fields=[], containing_type=None, fields=[],
nested_types=[], enum_types=[], nested_types=[leaf_desc], enum_types=[],
extensions=[]) extensions=[],
parent_desc = descriptor.Descriptor('parent', 'package.parent', '', # pylint: disable=protected-access
containing_type=None, fields=[], create_key=descriptor._internal_create_key)
nested_types=[child_desc, sibling_desc], sibling_desc = descriptor.Descriptor(
enum_types=[], extensions=[]) 'sibling', 'package.parent.sibling',
'', containing_type=None, fields=[],
nested_types=[], enum_types=[],
extensions=[],
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
parent_desc = descriptor.Descriptor(
'parent', 'package.parent', '',
containing_type=None, fields=[],
nested_types=[child_desc, sibling_desc],
enum_types=[], extensions=[],
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
reflection.MakeClass(parent_desc) reflection.MakeClass(parent_desc)
def _GetSerializedFileDescriptor(self, name): def _GetSerializedFileDescriptor(self, name):
@ -3305,4 +3325,3 @@ class ClassAPITest(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

@ -2194,5 +2194,23 @@ class WhitespaceTest(TextFormatBase):
}""")) }"""))
class OptionalColonMessageToStringTest(unittest.TestCase):
def testForcePrintOptionalColon(self):
packed_message = unittest_pb2.OneString()
packed_message.data = 'string'
message = any_test_pb2.TestAny()
message.any_value.Pack(packed_message)
output = text_format.MessageToString(
message,
force_colon=True)
expected = ('any_value: {\n'
' [type.googleapis.com/protobuf_unittest.OneString]: {\n'
' data: "string"\n'
' }\n'
'}\n')
self.assertEqual(expected, output)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

@ -45,6 +45,11 @@ TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
__author__ = 'robinson@google.com (Will Robinson)' __author__ = 'robinson@google.com (Will Robinson)'
try:
import ctypes
except Exception: # pylint: disable=broad-except
ctypes = None
import struct
import numbers import numbers
import six import six
@ -257,9 +262,10 @@ class FloatValueChecker(object):
if converted_value < _FLOAT_MIN: if converted_value < _FLOAT_MIN:
return _NEG_INF return _NEG_INF
return converted_value if ctypes:
# TODO(jieluo): convert to 4 bytes float (c style float) at setters: return ctypes.c_float(converted_value).value
# return struct.unpack('f', struct.pack('f', converted_value)) else:
return struct.unpack('<f', struct.pack('<f', converted_value))[0]
def DefaultValue(self): def DefaultValue(self):
return 0.0 return 0.0

@ -104,7 +104,7 @@ def MessageToJson(
sort_keys=False, sort_keys=False,
use_integers_for_enums=False, use_integers_for_enums=False,
descriptor_pool=None, descriptor_pool=None,
float_precision=None): float_precision=8):
"""Converts protobuf message to JSON format. """Converts protobuf message to JSON format.
Args: Args:
@ -123,6 +123,7 @@ def MessageToJson(
descriptor_pool: A Descriptor Pool for resolving types. If None use the descriptor_pool: A Descriptor Pool for resolving types. If None use the
default. default.
float_precision: If set, use this to specify float field valid digits. float_precision: If set, use this to specify float field valid digits.
Otherwise, 8 valid digits is used (default '.8g').
Returns: Returns:
A string containing the JSON formatted protocol buffer message. A string containing the JSON formatted protocol buffer message.
@ -142,7 +143,7 @@ def MessageToDict(
preserving_proto_field_name=False, preserving_proto_field_name=False,
use_integers_for_enums=False, use_integers_for_enums=False,
descriptor_pool=None, descriptor_pool=None,
float_precision=None): float_precision=8):
"""Converts protobuf message to a dictionary. """Converts protobuf message to a dictionary.
When the dictionary is encoded to JSON, it conforms to proto3 JSON spec. When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.
@ -160,6 +161,7 @@ def MessageToDict(
descriptor_pool: A Descriptor Pool for resolving types. If None use the descriptor_pool: A Descriptor Pool for resolving types. If None use the
default. default.
float_precision: If set, use this to specify float field valid digits. float_precision: If set, use this to specify float field valid digits.
Otherwise, 8 valid digits is used (default '.8g').
Returns: Returns:
A dict representation of the protocol buffer message. A dict representation of the protocol buffer message.

@ -83,6 +83,8 @@ class MessageFactory(object):
descriptor_name, descriptor_name,
(message.Message,), (message.Message,),
{'DESCRIPTOR': descriptor, '__module__': None}) {'DESCRIPTOR': descriptor, '__module__': None})
# pylint: disable=protected-access
result_class._FACTORY = self
# If module not set, it wrongly points to message_factory module. # If module not set, it wrongly points to message_factory module.
self._classes[descriptor] = result_class self._classes[descriptor] = result_class
for field in descriptor.fields: for field in descriptor.fields:

@ -1425,16 +1425,7 @@ bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) {
} }
if (field_descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { if (field_descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) {
// HasField() for a oneof *itself* isn't supported. // HasField() is supported for oneof fields.
if (in_oneof) {
PyErr_Format(PyExc_ValueError,
"Can't test oneof field \"%s.%s\" for presence in proto3, "
"use WhichOneof instead.", message_name.c_str(),
field_descriptor->containing_oneof()->name().c_str());
return false;
}
// ...but HasField() for fields *in* a oneof is supported.
if (field_descriptor->containing_oneof() != NULL) { if (field_descriptor->containing_oneof() != NULL) {
return true; return true;
} }

@ -107,9 +107,12 @@ PyMODINIT_FUNC INITFUNC() {
} }
// Adds the C++ API // Adds the C++ API
if (PyObject* api = if (PyObject* api = PyCapsule_New(
PyCapsule_New(new ApiImplementation(), new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
google::protobuf::python::PyProtoAPICapsuleName(), NULL)) { [](PyObject* o) {
delete (ApiImplementation*)PyCapsule_GetPointer(
o, google::protobuf::python::PyProtoAPICapsuleName());
})) {
PyModule_AddObject(m, "proto_API", api); PyModule_AddObject(m, "proto_API", api);
} else { } else {
return INITFUNC_ERRORVAL; return INITFUNC_ERRORVAL;

@ -132,7 +132,8 @@ def MessageToString(message,
descriptor_pool=None, descriptor_pool=None,
indent=0, indent=0,
message_formatter=None, message_formatter=None,
print_unknown_fields=False): print_unknown_fields=False,
force_colon=False):
# type: (...) -> str # type: (...) -> str
"""Convert protobuf message to text format. """Convert protobuf message to text format.
@ -170,17 +171,28 @@ def MessageToString(message,
Custom formatter for selected sub-messages (usually based on message Custom formatter for selected sub-messages (usually based on message
type). Use to pretty print parts of the protobuf for easier diffing. type). Use to pretty print parts of the protobuf for easier diffing.
print_unknown_fields: If True, unknown fields will be printed. print_unknown_fields: If True, unknown fields will be printed.
force_colon: If set, a colon will be added after the field name even if the
field is a proto message.
Returns: Returns:
str: A string of the text formatted protocol buffer message. str: A string of the text formatted protocol buffer message.
""" """
out = TextWriter(as_utf8) out = TextWriter(as_utf8)
printer = _Printer(out, indent, as_utf8, as_one_line, printer = _Printer(
use_short_repeated_primitives, pointy_brackets, out,
use_index_order, float_format, double_format, indent,
use_field_number, as_utf8,
descriptor_pool, message_formatter, as_one_line,
print_unknown_fields=print_unknown_fields) use_short_repeated_primitives,
pointy_brackets,
use_index_order,
float_format,
double_format,
use_field_number,
descriptor_pool,
message_formatter,
print_unknown_fields=print_unknown_fields,
force_colon=force_colon)
printer.PrintMessage(message) printer.PrintMessage(message)
result = out.getvalue() result = out.getvalue()
out.close() out.close()
@ -218,7 +230,8 @@ def PrintMessage(message,
use_field_number=False, use_field_number=False,
descriptor_pool=None, descriptor_pool=None,
message_formatter=None, message_formatter=None,
print_unknown_fields=False): print_unknown_fields=False,
force_colon=False):
printer = _Printer( printer = _Printer(
out=out, indent=indent, as_utf8=as_utf8, out=out, indent=indent, as_utf8=as_utf8,
as_one_line=as_one_line, as_one_line=as_one_line,
@ -230,7 +243,8 @@ def PrintMessage(message,
use_field_number=use_field_number, use_field_number=use_field_number,
descriptor_pool=descriptor_pool, descriptor_pool=descriptor_pool,
message_formatter=message_formatter, message_formatter=message_formatter,
print_unknown_fields=print_unknown_fields) print_unknown_fields=print_unknown_fields,
force_colon=force_colon)
printer.PrintMessage(message) printer.PrintMessage(message)
@ -246,13 +260,15 @@ def PrintField(field,
float_format=None, float_format=None,
double_format=None, double_format=None,
message_formatter=None, message_formatter=None,
print_unknown_fields=False): print_unknown_fields=False,
force_colon=False):
"""Print a single field name/value pair.""" """Print a single field name/value pair."""
printer = _Printer(out, indent, as_utf8, as_one_line, printer = _Printer(out, indent, as_utf8, as_one_line,
use_short_repeated_primitives, pointy_brackets, use_short_repeated_primitives, pointy_brackets,
use_index_order, float_format, double_format, use_index_order, float_format, double_format,
message_formatter=message_formatter, message_formatter=message_formatter,
print_unknown_fields=print_unknown_fields) print_unknown_fields=print_unknown_fields,
force_colon=force_colon)
printer.PrintField(field, value) printer.PrintField(field, value)
@ -268,13 +284,15 @@ def PrintFieldValue(field,
float_format=None, float_format=None,
double_format=None, double_format=None,
message_formatter=None, message_formatter=None,
print_unknown_fields=False): print_unknown_fields=False,
force_colon=False):
"""Print a single field value (not including name).""" """Print a single field value (not including name)."""
printer = _Printer(out, indent, as_utf8, as_one_line, printer = _Printer(out, indent, as_utf8, as_one_line,
use_short_repeated_primitives, pointy_brackets, use_short_repeated_primitives, pointy_brackets,
use_index_order, float_format, double_format, use_index_order, float_format, double_format,
message_formatter=message_formatter, message_formatter=message_formatter,
print_unknown_fields=print_unknown_fields) print_unknown_fields=print_unknown_fields,
force_colon=force_colon)
printer.PrintFieldValue(field, value) printer.PrintFieldValue(field, value)
@ -324,7 +342,8 @@ class _Printer(object):
use_field_number=False, use_field_number=False,
descriptor_pool=None, descriptor_pool=None,
message_formatter=None, message_formatter=None,
print_unknown_fields=False): print_unknown_fields=False,
force_colon=False):
"""Initialize the Printer. """Initialize the Printer.
Double values can be formatted compactly with 15 digits of precision Double values can be formatted compactly with 15 digits of precision
@ -358,6 +377,8 @@ class _Printer(object):
to custom format selected sub-messages (usually based on message type). to custom format selected sub-messages (usually based on message type).
Use to pretty print parts of the protobuf for easier diffing. Use to pretty print parts of the protobuf for easier diffing.
print_unknown_fields: If True, unknown fields will be printed. print_unknown_fields: If True, unknown fields will be printed.
force_colon: If set, a colon will be added after the field name even if
the field is a proto message.
""" """
self.out = out self.out = out
self.indent = indent self.indent = indent
@ -375,6 +396,7 @@ class _Printer(object):
self.descriptor_pool = descriptor_pool self.descriptor_pool = descriptor_pool
self.message_formatter = message_formatter self.message_formatter = message_formatter
self.print_unknown_fields = print_unknown_fields self.print_unknown_fields = print_unknown_fields
self.force_colon = force_colon
def _TryPrintAsAnyMessage(self, message): def _TryPrintAsAnyMessage(self, message):
"""Serializes if message is a google.protobuf.Any field.""" """Serializes if message is a google.protobuf.Any field."""
@ -384,7 +406,8 @@ class _Printer(object):
self.descriptor_pool) self.descriptor_pool)
if packed_message: if packed_message:
packed_message.MergeFromString(message.value) packed_message.MergeFromString(message.value)
self.out.write('%s[%s] ' % (self.indent * ' ', message.type_url)) colon = ':' if self.force_colon else ''
self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
self._PrintMessageFieldValue(packed_message) self._PrintMessageFieldValue(packed_message)
self.out.write(' ' if self.as_one_line else '\n') self.out.write(' ' if self.as_one_line else '\n')
return True return True
@ -518,9 +541,11 @@ class _Printer(object):
else: else:
out.write(field.name) out.write(field.name)
if field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE: if (self.force_colon or
field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
# The colon is optional in this case, but our cross-language golden files # The colon is optional in this case, but our cross-language golden files
# don't include it. # don't include it. Here, the colon is only included if force_colon is
# set to True
out.write(':') out.write(':')
def PrintField(self, field, value): def PrintField(self, field, value):
@ -531,6 +556,7 @@ class _Printer(object):
self.out.write(' ' if self.as_one_line else '\n') self.out.write(' ' if self.as_one_line else '\n')
def _PrintShortRepeatedPrimitivesValue(self, field, value): def _PrintShortRepeatedPrimitivesValue(self, field, value):
""""Prints short repeated primitives value."""
# Note: this is called only when value has at least one element. # Note: this is called only when value has at least one element.
self._PrintFieldName(field) self._PrintFieldName(field)
self.out.write(' [') self.out.write(' [')
@ -539,6 +565,8 @@ class _Printer(object):
self.out.write(', ') self.out.write(', ')
self.PrintFieldValue(field, value[-1]) self.PrintFieldValue(field, value[-1])
self.out.write(']') self.out.write(']')
if self.force_colon:
self.out.write(':')
self.out.write(' ' if self.as_one_line else '\n') self.out.write(' ' if self.as_one_line else '\n')
def _PrintMessageFieldValue(self, value): def _PrintMessageFieldValue(self, value):

@ -19,23 +19,17 @@ from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean from distutils.command.clean import clean as _clean
from distutils.spawn import find_executable from distutils.spawn import find_executable
current_dir = (os.path.dirname(__file__) or os.curdir)
current_dir_relative = os.path.relpath(current_dir)
src_dir = os.path.abspath(os.path.join(current_dir, "..", "src"))
vsprojects_dir = os.path.abspath(os.path.join(current_dir, "..", "vsprojects"))
# Find the Protocol Compiler. # Find the Protocol Compiler.
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
protoc = os.environ['PROTOC'] protoc = os.environ['PROTOC']
elif os.path.exists(os.path.join(src_dir, "protoc")): elif os.path.exists("../src/protoc"):
protoc = os.path.join(src_dir, "protoc") protoc = "../src/protoc"
elif os.path.exists(os.path.join(src_dir, "protoc.exe")): elif os.path.exists("../src/protoc.exe"):
protoc = os.path.join(src_dir, "protoc.exe") protoc = "../src/protoc.exe"
elif os.path.exists(os.path.join(vsprojects_dir, "Debug", "protoc.exe")): elif os.path.exists("../vsprojects/Debug/protoc.exe"):
protoc = os.path.join(vsprojects_dir, "Debug", "protoc.exe") protoc = "../vsprojects/Debug/protoc.exe"
elif os.path.exists(os.path.join(vsprojects_dir, "Release", "protoc.exe")): elif os.path.exists("../vsprojects/Release/protoc.exe"):
protoc = os.path.join(vsprojects_dir, "Release", "protoc.exe") protoc = "../vsprojects/Release/protoc.exe"
else: else:
protoc = find_executable("protoc") protoc = find_executable("protoc")
@ -46,7 +40,7 @@ def GetVersion():
Do not import google.protobuf.__init__ directly, because an installed Do not import google.protobuf.__init__ directly, because an installed
protobuf library may be loaded instead.""" protobuf library may be loaded instead."""
with open(os.path.join(current_dir, 'google', 'protobuf', '__init__.py')) as version_file: with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals()) exec(version_file.read(), globals())
global __version__ global __version__
return __version__ return __version__
@ -57,21 +51,15 @@ def generate_proto(source, require = True):
.proto file. Does nothing if the output already exists and is newer than .proto file. Does nothing if the output already exists and is newer than
the input.""" the input."""
original_source = source
source = source.replace("../src", src_dir)
if not require and not os.path.exists(source): if not require and not os.path.exists(source):
return return
output = os.path.join( output = source.replace(".proto", "_pb2.py").replace("../src/", "")
current_dir,
original_source.replace(".proto", "_pb2.py").replace("../src/", "")
)
if (not os.path.exists(output) or if (not os.path.exists(output) or
(os.path.exists(source) and (os.path.exists(source) and
os.path.getmtime(source) > os.path.getmtime(output))): os.path.getmtime(source) > os.path.getmtime(output))):
print("Generating %s..." % os.path.relpath(output)) print("Generating %s..." % output)
if not os.path.exists(source): if not os.path.exists(source):
sys.stderr.write("Can't find required file: %s\n" % source) sys.stderr.write("Can't find required file: %s\n" % source)
@ -83,13 +71,7 @@ def generate_proto(source, require = True):
"or install the binary package.\n") "or install the binary package.\n")
sys.exit(-1) sys.exit(-1)
protoc_command = [ protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
protoc,
"-I{}".format(src_dir),
"-I{}".format(current_dir),
"--python_out={}".format(current_dir),
source,
]
if subprocess.call(protoc_command) != 0: if subprocess.call(protoc_command) != 0:
sys.exit(-1) sys.exit(-1)
@ -134,7 +116,7 @@ def GenerateUnittestProtos():
class clean(_clean): class clean(_clean):
def run(self): def run(self):
# Delete generated files in the code tree. # Delete generated files in the code tree.
for (dirpath, dirnames, filenames) in os.walk(current_dir): for (dirpath, dirnames, filenames) in os.walk("."):
for filename in filenames: for filename in filenames:
filepath = os.path.join(dirpath, filename) filepath = os.path.join(dirpath, filename)
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
@ -287,14 +269,7 @@ if __name__ == '__main__':
"Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.7",
], ],
namespace_packages=['google'], namespace_packages=['google'],
# package_dir is required when setup.py is not run from the python/
# directory (such as from the ReadTheDocs build). See
# https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
# package_dir must be a relative path. See:
# https://stackoverflow.com/a/53547931/101923
package_dir={"": current_dir_relative},
packages=find_packages( packages=find_packages(
where=current_dir,
exclude=[ exclude=[
'import_test_package', 'import_test_package',
], ],

@ -510,6 +510,7 @@ protoc_inputs = \
google/protobuf/unittest_proto3_arena.proto \ google/protobuf/unittest_proto3_arena.proto \
google/protobuf/unittest_proto3_arena_lite.proto \ google/protobuf/unittest_proto3_arena_lite.proto \
google/protobuf/unittest_proto3_lite.proto \ google/protobuf/unittest_proto3_lite.proto \
google/protobuf/unittest_proto3_optional.proto \
google/protobuf/unittest_well_known_types.proto \ google/protobuf/unittest_well_known_types.proto \
google/protobuf/util/internal/testdata/anys.proto \ google/protobuf/util/internal/testdata/anys.proto \
google/protobuf/util/internal/testdata/books.proto \ google/protobuf/util/internal/testdata/books.proto \
@ -643,6 +644,8 @@ protoc_outputs = \
google/protobuf/unittest_proto3_arena_lite.pb.h \ google/protobuf/unittest_proto3_arena_lite.pb.h \
google/protobuf/unittest_proto3_lite.pb.cc \ google/protobuf/unittest_proto3_lite.pb.cc \
google/protobuf/unittest_proto3_lite.pb.h \ google/protobuf/unittest_proto3_lite.pb.h \
google/protobuf/unittest_proto3_optional.pb.cc \
google/protobuf/unittest_proto3_optional.pb.h \
google/protobuf/unittest_well_known_types.pb.cc \ google/protobuf/unittest_well_known_types.pb.cc \
google/protobuf/unittest_well_known_types.pb.h \ google/protobuf/unittest_well_known_types.pb.h \
google/protobuf/util/internal/testdata/anys.pb.cc \ google/protobuf/util/internal/testdata/anys.pb.cc \
@ -686,7 +689,7 @@ else
# relative to srcdir, which may not be the same as the current directory when # relative to srcdir, which may not be the same as the current directory when
# building out-of-tree. # building out-of-tree.
unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs) unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs)
oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) ) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) --experimental_allow_proto3_optional )
touch unittest_proto_middleman touch unittest_proto_middleman
endif endif

@ -69,9 +69,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
&scc_info_Any_google_2fprotobuf_2fany_2eproto.base, &scc_info_Any_google_2fprotobuf_2fany_2eproto.base,
}; };
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once;
static bool descriptor_table_google_2fprotobuf_2fany_2eproto_initialized = false;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = { const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = {
&descriptor_table_google_2fprotobuf_2fany_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205, false, false, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205,
&descriptor_table_google_2fprotobuf_2fany_2eproto_once, descriptor_table_google_2fprotobuf_2fany_2eproto_sccs, descriptor_table_google_2fprotobuf_2fany_2eproto_deps, 1, 0, &descriptor_table_google_2fprotobuf_2fany_2eproto_once, descriptor_table_google_2fprotobuf_2fany_2eproto_sccs, descriptor_table_google_2fprotobuf_2fany_2eproto_deps, 1, 0,
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fany_2eproto::offsets, schemas, file_default_instances, TableStruct_google_2fprotobuf_2fany_2eproto::offsets,
file_level_metadata_google_2fprotobuf_2fany_2eproto, 1, file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, file_level_service_descriptors_google_2fprotobuf_2fany_2eproto, file_level_metadata_google_2fprotobuf_2fany_2eproto, 1, file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, file_level_service_descriptors_google_2fprotobuf_2fany_2eproto,
@ -102,23 +101,26 @@ class Any::_Internal {
public: public:
}; };
Any::Any() Any::Any(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr), _any_metadata_(&type_url_, &value_) { : ::PROTOBUF_NAMESPACE_ID::Message(arena),
_any_metadata_(&type_url_, &value_) {
SharedCtor(); SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Any) RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Any)
} }
Any::Any(const Any& from) Any::Any(const Any& from)
: ::PROTOBUF_NAMESPACE_ID::Message(), : ::PROTOBUF_NAMESPACE_ID::Message(),
_internal_metadata_(nullptr),
_any_metadata_(&type_url_, &value_) { _any_metadata_(&type_url_, &value_) {
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_type_url().empty()) { if (!from._internal_type_url().empty()) {
type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_); type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_type_url(),
GetArena());
} }
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_value().empty()) { if (!from._internal_value().empty()) {
value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_); value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_value(),
GetArena());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any) // @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
} }
@ -132,13 +134,21 @@ void Any::SharedCtor() {
Any::~Any() { Any::~Any() {
// @@protoc_insertion_point(destructor:google.protobuf.Any) // @@protoc_insertion_point(destructor:google.protobuf.Any)
SharedDtor(); SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
void Any::SharedDtor() { void Any::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
} }
void Any::ArenaDtor(void* object) {
Any* _this = reinterpret_cast< Any* >(object);
(void)_this;
}
void Any::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void Any::SetCachedSize(int size) const { void Any::SetCachedSize(int size) const {
_cached_size_.Set(size); _cached_size_.Set(size);
} }
@ -154,13 +164,14 @@ void Any::Clear() {
// Prevent compiler warnings about cached_has_bits being unused // Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits; (void) cached_has_bits;
type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
_internal_metadata_.Clear(); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) { while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag; ::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@ -189,7 +200,9 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
ctx->SetLastTag(tag); ctx->SetLastTag(tag);
goto success; goto success;
} }
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr); CHK_(ptr != nullptr);
continue; continue;
} }
@ -227,7 +240,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields(), target, stream); _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
} }
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any) // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any)
return target; return target;
@ -282,17 +295,15 @@ void Any::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Any::MergeFrom(const Any& from) { void Any::MergeFrom(const Any& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any)
GOOGLE_DCHECK_NE(&from, this); GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits; (void) cached_has_bits;
if (from.type_url().size() > 0) { if (from.type_url().size() > 0) {
_internal_set_type_url(from._internal_type_url());
type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_);
} }
if (from.value().size() > 0) { if (from.value().size() > 0) {
_internal_set_value(from._internal_value());
value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_);
} }
} }
@ -316,11 +327,9 @@ bool Any::IsInitialized() const {
void Any::InternalSwap(Any* other) { void Any::InternalSwap(Any* other) {
using std::swap; using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_); _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
GetArenaNoVirtual()); value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArenaNoVirtual());
} }
::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const { ::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const {
@ -332,7 +341,7 @@ void Any::InternalSwap(Any* other) {
PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_CLOSE
PROTOBUF_NAMESPACE_OPEN PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Any >(Arena* arena) { template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Any >(Arena* arena) {
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Any >(arena); return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Any >(arena);
} }
PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_CLOSE

@ -26,7 +26,7 @@
#include <google/protobuf/generated_message_table_driven.h> #include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/generated_message_util.h> #include <google/protobuf/generated_message_util.h>
#include <google/protobuf/inlined_string_field.h> #include <google/protobuf/inlined_string_field.h>
#include <google/protobuf/metadata.h> #include <google/protobuf/metadata_lite.h>
#include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/repeated_field.h> // IWYU pragma: export
@ -66,10 +66,10 @@ PROTOBUF_NAMESPACE_OPEN
// =================================================================== // ===================================================================
class PROTOBUF_EXPORT Any : class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ {
public: public:
Any(); inline Any() : Any(nullptr) {};
virtual ~Any(); virtual ~Any();
Any(const Any& from); Any(const Any& from);
@ -83,7 +83,7 @@ class PROTOBUF_EXPORT Any :
return *this; return *this;
} }
inline Any& operator=(Any&& from) noexcept { inline Any& operator=(Any&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from); if (this != &from) InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -148,6 +148,15 @@ class PROTOBUF_EXPORT Any :
} }
inline void Swap(Any* other) { inline void Swap(Any* other) {
if (other == this) return; if (other == this) return;
if (GetArena() == other->GetArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
}
}
void UnsafeArenaSwap(Any* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other); InternalSwap(other);
} }
@ -182,13 +191,11 @@ class PROTOBUF_EXPORT Any :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Any"; return "google.protobuf.Any";
} }
protected:
explicit Any(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private: private:
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { static void ArenaDtor(void* object);
return nullptr; inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
}
inline void* MaybeArenaPtr() const {
return nullptr;
}
public: public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@ -218,6 +225,15 @@ class PROTOBUF_EXPORT Any :
std::string* mutable_type_url(); std::string* mutable_type_url();
std::string* release_type_url(); std::string* release_type_url();
void set_allocated_type_url(std::string* type_url); void set_allocated_type_url(std::string* type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_type_url(
std::string* type_url);
private: private:
const std::string& _internal_type_url() const; const std::string& _internal_type_url() const;
void _internal_set_type_url(const std::string& value); void _internal_set_type_url(const std::string& value);
@ -234,6 +250,15 @@ class PROTOBUF_EXPORT Any :
std::string* mutable_value(); std::string* mutable_value();
std::string* release_value(); std::string* release_value();
void set_allocated_value(std::string* value); void set_allocated_value(std::string* value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_value(
std::string* value);
private: private:
const std::string& _internal_value() const; const std::string& _internal_value() const;
void _internal_set_value(const std::string& value); void _internal_set_value(const std::string& value);
@ -244,7 +269,9 @@ class PROTOBUF_EXPORT Any :
private: private:
class _Internal; class _Internal;
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
@ -264,7 +291,7 @@ class PROTOBUF_EXPORT Any :
// string type_url = 1; // string type_url = 1;
inline void Any::clear_type_url() { inline void Any::clear_type_url() {
type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Any::type_url() const { inline const std::string& Any::type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
@ -279,38 +306,40 @@ inline std::string* Any::mutable_type_url() {
return _internal_mutable_type_url(); return _internal_mutable_type_url();
} }
inline const std::string& Any::_internal_type_url() const { inline const std::string& Any::_internal_type_url() const {
return type_url_.GetNoArena(); return type_url_.Get();
} }
inline void Any::_internal_set_type_url(const std::string& value) { inline void Any::_internal_set_type_url(const std::string& value) {
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Any::set_type_url(std::string&& value) { inline void Any::set_type_url(std::string&& value) {
type_url_.SetNoArena( type_url_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
} }
inline void Any::set_type_url(const char* value) { inline void Any::set_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
} }
inline void Any::set_type_url(const char* value, size_t size) { inline void Any::set_type_url(const char* value,
size_t size) {
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url)
} }
inline std::string* Any::_internal_mutable_type_url() { inline std::string* Any::_internal_mutable_type_url() {
return type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Any::release_type_url() { inline std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
return type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Any::set_allocated_type_url(std::string* type_url) { inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) { if (type_url != nullptr) {
@ -318,13 +347,33 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
} else { } else {
} }
type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url); type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
} }
inline std::string* Any::unsafe_arena_release_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Any::unsafe_arena_set_allocated_type_url(
std::string* type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (type_url != nullptr) {
} else {
}
type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.type_url)
}
// bytes value = 2; // bytes value = 2;
inline void Any::clear_value() { inline void Any::clear_value() {
value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Any::value() const { inline const std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value) // @@protoc_insertion_point(field_get:google.protobuf.Any.value)
@ -339,38 +388,40 @@ inline std::string* Any::mutable_value() {
return _internal_mutable_value(); return _internal_mutable_value();
} }
inline const std::string& Any::_internal_value() const { inline const std::string& Any::_internal_value() const {
return value_.GetNoArena(); return value_.Get();
} }
inline void Any::_internal_set_value(const std::string& value) { inline void Any::_internal_set_value(const std::string& value) {
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Any::set_value(std::string&& value) { inline void Any::set_value(std::string&& value) {
value_.SetNoArena( value_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
} }
inline void Any::set_value(const char* value) { inline void Any::set_value(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value) // @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
} }
inline void Any::set_value(const void* value, size_t size) { inline void Any::set_value(const void* value,
size_t size) {
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value)
} }
inline std::string* Any::_internal_mutable_value() { inline std::string* Any::_internal_mutable_value() {
return value_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return value_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Any::release_value() { inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value) // @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Any::set_allocated_value(std::string* value) { inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) { if (value != nullptr) {
@ -378,9 +429,29 @@ inline void Any::set_allocated_value(std::string* value) {
} else { } else {
} }
value_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
} }
inline std::string* Any::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.value)
GOOGLE_DCHECK(GetArena() != nullptr);
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Any::unsafe_arena_set_allocated_value(
std::string* value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (value != nullptr) {
} else {
}
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
value, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.value)
}
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

@ -159,9 +159,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
&scc_info_Mixin_google_2fprotobuf_2fapi_2eproto.base, &scc_info_Mixin_google_2fprotobuf_2fapi_2eproto.base,
}; };
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once;
static bool descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized = false;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = { const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = {
&descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750, false, false, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750,
&descriptor_table_google_2fprotobuf_2fapi_2eproto_once, descriptor_table_google_2fprotobuf_2fapi_2eproto_sccs, descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, 3, 2, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, descriptor_table_google_2fprotobuf_2fapi_2eproto_sccs, descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, 3, 2,
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fapi_2eproto::offsets, schemas, file_default_instances, TableStruct_google_2fprotobuf_2fapi_2eproto::offsets,
file_level_metadata_google_2fprotobuf_2fapi_2eproto, 3, file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto, file_level_metadata_google_2fprotobuf_2fapi_2eproto, 3, file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto,
@ -190,30 +189,35 @@ void Api::clear_options() {
options_.Clear(); options_.Clear();
} }
void Api::clear_source_context() { void Api::clear_source_context() {
if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) { if (GetArena() == nullptr && source_context_ != nullptr) {
delete source_context_; delete source_context_;
} }
source_context_ = nullptr; source_context_ = nullptr;
} }
Api::Api() Api::Api(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { : ::PROTOBUF_NAMESPACE_ID::Message(arena),
methods_(arena),
options_(arena),
mixins_(arena) {
SharedCtor(); SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Api) RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Api)
} }
Api::Api(const Api& from) Api::Api(const Api& from)
: ::PROTOBUF_NAMESPACE_ID::Message(), : ::PROTOBUF_NAMESPACE_ID::Message(),
_internal_metadata_(nullptr),
methods_(from.methods_), methods_(from.methods_),
options_(from.options_), options_(from.options_),
mixins_(from.mixins_) { mixins_(from.mixins_) {
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
GetArena());
} }
version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_version().empty()) { if (!from._internal_version().empty()) {
version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_); version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_version(),
GetArena());
} }
if (from._internal_has_source_context()) { if (from._internal_has_source_context()) {
source_context_ = new PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_); source_context_ = new PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_);
@ -236,14 +240,22 @@ void Api::SharedCtor() {
Api::~Api() { Api::~Api() {
// @@protoc_insertion_point(destructor:google.protobuf.Api) // @@protoc_insertion_point(destructor:google.protobuf.Api)
SharedDtor(); SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
void Api::SharedDtor() { void Api::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (this != internal_default_instance()) delete source_context_; if (this != internal_default_instance()) delete source_context_;
} }
void Api::ArenaDtor(void* object) {
Api* _this = reinterpret_cast< Api* >(object);
(void)_this;
}
void Api::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void Api::SetCachedSize(int size) const { void Api::SetCachedSize(int size) const {
_cached_size_.Set(size); _cached_size_.Set(size);
} }
@ -262,18 +274,19 @@ void Api::Clear() {
methods_.Clear(); methods_.Clear();
options_.Clear(); options_.Clear();
mixins_.Clear(); mixins_.Clear();
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) { if (GetArena() == nullptr && source_context_ != nullptr) {
delete source_context_; delete source_context_;
} }
source_context_ = nullptr; source_context_ = nullptr;
syntax_ = 0; syntax_ = 0;
_internal_metadata_.Clear(); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) { while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag; ::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@ -354,7 +367,9 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
ctx->SetLastTag(tag); ctx->SetLastTag(tag);
goto success; goto success;
} }
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr); CHK_(ptr != nullptr);
continue; continue;
} }
@ -435,7 +450,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields(), target, stream); _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
} }
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Api) // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Api)
return target; return target;
@ -524,7 +539,7 @@ void Api::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Api::MergeFrom(const Api& from) { void Api::MergeFrom(const Api& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api)
GOOGLE_DCHECK_NE(&from, this); GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits; (void) cached_has_bits;
@ -532,12 +547,10 @@ void Api::MergeFrom(const Api& from) {
options_.MergeFrom(from.options_); options_.MergeFrom(from.options_);
mixins_.MergeFrom(from.mixins_); mixins_.MergeFrom(from.mixins_);
if (from.name().size() > 0) { if (from.name().size() > 0) {
_internal_set_name(from._internal_name());
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
} }
if (from.version().size() > 0) { if (from.version().size() > 0) {
_internal_set_version(from._internal_version());
version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_);
} }
if (from.has_source_context()) { if (from.has_source_context()) {
_internal_mutable_source_context()->PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context()); _internal_mutable_source_context()->PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context());
@ -567,16 +580,18 @@ bool Api::IsInitialized() const {
void Api::InternalSwap(Api* other) { void Api::InternalSwap(Api* other) {
using std::swap; using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_); _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
methods_.InternalSwap(&other->methods_); methods_.InternalSwap(&other->methods_);
options_.InternalSwap(&other->options_); options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_); mixins_.InternalSwap(&other->mixins_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
GetArenaNoVirtual()); version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::PROTOBUF_NAMESPACE_ID::internal::memswap<
GetArenaNoVirtual()); PROTOBUF_FIELD_OFFSET(Api, syntax_)
swap(source_context_, other->source_context_); + sizeof(Api::syntax_)
swap(syntax_, other->syntax_); - PROTOBUF_FIELD_OFFSET(Api, source_context_)>(
reinterpret_cast<char*>(&source_context_),
reinterpret_cast<char*>(&other->source_context_));
} }
::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const { ::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const {
@ -595,27 +610,31 @@ class Method::_Internal {
void Method::clear_options() { void Method::clear_options() {
options_.Clear(); options_.Clear();
} }
Method::Method() Method::Method(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { : ::PROTOBUF_NAMESPACE_ID::Message(arena),
options_(arena) {
SharedCtor(); SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Method) RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Method)
} }
Method::Method(const Method& from) Method::Method(const Method& from)
: ::PROTOBUF_NAMESPACE_ID::Message(), : ::PROTOBUF_NAMESPACE_ID::Message(),
_internal_metadata_(nullptr),
options_(from.options_) { options_(from.options_) {
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
GetArena());
} }
request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_request_type_url().empty()) { if (!from._internal_request_type_url().empty()) {
request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_); request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_request_type_url(),
GetArena());
} }
response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_response_type_url().empty()) { if (!from._internal_response_type_url().empty()) {
response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_); response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_response_type_url(),
GetArena());
} }
::memcpy(&request_streaming_, &from.request_streaming_, ::memcpy(&request_streaming_, &from.request_streaming_,
static_cast<size_t>(reinterpret_cast<char*>(&syntax_) - static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
@ -636,14 +655,22 @@ void Method::SharedCtor() {
Method::~Method() { Method::~Method() {
// @@protoc_insertion_point(destructor:google.protobuf.Method) // @@protoc_insertion_point(destructor:google.protobuf.Method)
SharedDtor(); SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
void Method::SharedDtor() { void Method::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
} }
void Method::ArenaDtor(void* object) {
Method* _this = reinterpret_cast< Method* >(object);
(void)_this;
}
void Method::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void Method::SetCachedSize(int size) const { void Method::SetCachedSize(int size) const {
_cached_size_.Set(size); _cached_size_.Set(size);
} }
@ -660,17 +687,18 @@ void Method::Clear() {
(void) cached_has_bits; (void) cached_has_bits;
options_.Clear(); options_.Clear();
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::memset(&request_streaming_, 0, static_cast<size_t>( ::memset(&request_streaming_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&syntax_) - reinterpret_cast<char*>(&syntax_) -
reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_)); reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_));
_internal_metadata_.Clear(); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) { while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag; ::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@ -743,7 +771,9 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int
ctx->SetLastTag(tag); ctx->SetLastTag(tag);
goto success; goto success;
} }
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr); CHK_(ptr != nullptr);
continue; continue;
} }
@ -822,7 +852,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields(), target, stream); _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
} }
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Method) // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Method)
return target; return target;
@ -907,22 +937,19 @@ void Method::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Method::MergeFrom(const Method& from) { void Method::MergeFrom(const Method& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method)
GOOGLE_DCHECK_NE(&from, this); GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits; (void) cached_has_bits;
options_.MergeFrom(from.options_); options_.MergeFrom(from.options_);
if (from.name().size() > 0) { if (from.name().size() > 0) {
_internal_set_name(from._internal_name());
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
} }
if (from.request_type_url().size() > 0) { if (from.request_type_url().size() > 0) {
_internal_set_request_type_url(from._internal_request_type_url());
request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
} }
if (from.response_type_url().size() > 0) { if (from.response_type_url().size() > 0) {
_internal_set_response_type_url(from._internal_response_type_url());
response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
} }
if (from.request_streaming() != 0) { if (from.request_streaming() != 0) {
_internal_set_request_streaming(from._internal_request_streaming()); _internal_set_request_streaming(from._internal_request_streaming());
@ -955,17 +982,17 @@ bool Method::IsInitialized() const {
void Method::InternalSwap(Method* other) { void Method::InternalSwap(Method* other) {
using std::swap; using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_); _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
options_.InternalSwap(&other->options_); options_.InternalSwap(&other->options_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
GetArenaNoVirtual()); request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
GetArenaNoVirtual()); ::PROTOBUF_NAMESPACE_ID::internal::memswap<
response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), PROTOBUF_FIELD_OFFSET(Method, syntax_)
GetArenaNoVirtual()); + sizeof(Method::syntax_)
swap(request_streaming_, other->request_streaming_); - PROTOBUF_FIELD_OFFSET(Method, request_streaming_)>(
swap(response_streaming_, other->response_streaming_); reinterpret_cast<char*>(&request_streaming_),
swap(syntax_, other->syntax_); reinterpret_cast<char*>(&other->request_streaming_));
} }
::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const { ::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const {
@ -981,22 +1008,24 @@ class Mixin::_Internal {
public: public:
}; };
Mixin::Mixin() Mixin::Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { : ::PROTOBUF_NAMESPACE_ID::Message(arena) {
SharedCtor(); SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Mixin) RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Mixin)
} }
Mixin::Mixin(const Mixin& from) Mixin::Mixin(const Mixin& from)
: ::PROTOBUF_NAMESPACE_ID::Message(), : ::PROTOBUF_NAMESPACE_ID::Message() {
_internal_metadata_(nullptr) { _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_internal_metadata_.MergeFrom(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) { if (!from._internal_name().empty()) {
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
GetArena());
} }
root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_root().empty()) { if (!from._internal_root().empty()) {
root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_); root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_root(),
GetArena());
} }
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin) // @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
} }
@ -1010,13 +1039,21 @@ void Mixin::SharedCtor() {
Mixin::~Mixin() { Mixin::~Mixin() {
// @@protoc_insertion_point(destructor:google.protobuf.Mixin) // @@protoc_insertion_point(destructor:google.protobuf.Mixin)
SharedDtor(); SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
void Mixin::SharedDtor() { void Mixin::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
} }
void Mixin::ArenaDtor(void* object) {
Mixin* _this = reinterpret_cast< Mixin* >(object);
(void)_this;
}
void Mixin::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void Mixin::SetCachedSize(int size) const { void Mixin::SetCachedSize(int size) const {
_cached_size_.Set(size); _cached_size_.Set(size);
} }
@ -1032,13 +1069,14 @@ void Mixin::Clear() {
// Prevent compiler warnings about cached_has_bits being unused // Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits; (void) cached_has_bits;
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
_internal_metadata_.Clear(); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
} }
const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) { while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag; ::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@ -1068,7 +1106,9 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte
ctx->SetLastTag(tag); ctx->SetLastTag(tag);
goto success; goto success;
} }
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr); CHK_(ptr != nullptr);
continue; continue;
} }
@ -1110,7 +1150,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields(), target, stream); _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
} }
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Mixin) // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Mixin)
return target; return target;
@ -1165,17 +1205,15 @@ void Mixin::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Mixin::MergeFrom(const Mixin& from) { void Mixin::MergeFrom(const Mixin& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin)
GOOGLE_DCHECK_NE(&from, this); GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_); _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits; (void) cached_has_bits;
if (from.name().size() > 0) { if (from.name().size() > 0) {
_internal_set_name(from._internal_name());
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
} }
if (from.root().size() > 0) { if (from.root().size() > 0) {
_internal_set_root(from._internal_root());
root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_);
} }
} }
@ -1199,11 +1237,9 @@ bool Mixin::IsInitialized() const {
void Mixin::InternalSwap(Mixin* other) { void Mixin::InternalSwap(Mixin* other) {
using std::swap; using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_); _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
GetArenaNoVirtual()); root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArenaNoVirtual());
} }
::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const { ::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const {
@ -1215,13 +1251,13 @@ void Mixin::InternalSwap(Mixin* other) {
PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_CLOSE
PROTOBUF_NAMESPACE_OPEN PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Api >(Arena* arena) { template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Api >(Arena* arena) {
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Api >(arena); return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Api >(arena);
} }
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Method >(Arena* arena) { template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Method >(Arena* arena) {
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Method >(arena); return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Method >(arena);
} }
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) { template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) {
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena); return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena);
} }
PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_CLOSE

@ -26,7 +26,7 @@
#include <google/protobuf/generated_message_table_driven.h> #include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/generated_message_util.h> #include <google/protobuf/generated_message_util.h>
#include <google/protobuf/inlined_string_field.h> #include <google/protobuf/inlined_string_field.h>
#include <google/protobuf/metadata.h> #include <google/protobuf/metadata_lite.h>
#include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/repeated_field.h> // IWYU pragma: export
@ -76,10 +76,10 @@ PROTOBUF_NAMESPACE_OPEN
// =================================================================== // ===================================================================
class PROTOBUF_EXPORT Api : class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ {
public: public:
Api(); inline Api() : Api(nullptr) {};
virtual ~Api(); virtual ~Api();
Api(const Api& from); Api(const Api& from);
@ -93,7 +93,7 @@ class PROTOBUF_EXPORT Api :
return *this; return *this;
} }
inline Api& operator=(Api&& from) noexcept { inline Api& operator=(Api&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from); if (this != &from) InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -125,6 +125,15 @@ class PROTOBUF_EXPORT Api :
} }
inline void Swap(Api* other) { inline void Swap(Api* other) {
if (other == this) return; if (other == this) return;
if (GetArena() == other->GetArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
}
}
void UnsafeArenaSwap(Api* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other); InternalSwap(other);
} }
@ -159,13 +168,11 @@ class PROTOBUF_EXPORT Api :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Api"; return "google.protobuf.Api";
} }
protected:
explicit Api(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private: private:
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { static void ArenaDtor(void* object);
return nullptr; inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
}
inline void* MaybeArenaPtr() const {
return nullptr;
}
public: public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@ -254,6 +261,15 @@ class PROTOBUF_EXPORT Api :
std::string* mutable_name(); std::string* mutable_name();
std::string* release_name(); std::string* release_name();
void set_allocated_name(std::string* name); void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private: private:
const std::string& _internal_name() const; const std::string& _internal_name() const;
void _internal_set_name(const std::string& value); void _internal_set_name(const std::string& value);
@ -270,6 +286,15 @@ class PROTOBUF_EXPORT Api :
std::string* mutable_version(); std::string* mutable_version();
std::string* release_version(); std::string* release_version();
void set_allocated_version(std::string* version); void set_allocated_version(std::string* version);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_version();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_version(
std::string* version);
private: private:
const std::string& _internal_version() const; const std::string& _internal_version() const;
void _internal_set_version(const std::string& value); void _internal_set_version(const std::string& value);
@ -290,6 +315,9 @@ class PROTOBUF_EXPORT Api :
const PROTOBUF_NAMESPACE_ID::SourceContext& _internal_source_context() const; const PROTOBUF_NAMESPACE_ID::SourceContext& _internal_source_context() const;
PROTOBUF_NAMESPACE_ID::SourceContext* _internal_mutable_source_context(); PROTOBUF_NAMESPACE_ID::SourceContext* _internal_mutable_source_context();
public: public:
void unsafe_arena_set_allocated_source_context(
PROTOBUF_NAMESPACE_ID::SourceContext* source_context);
PROTOBUF_NAMESPACE_ID::SourceContext* unsafe_arena_release_source_context();
// .google.protobuf.Syntax syntax = 7; // .google.protobuf.Syntax syntax = 7;
void clear_syntax(); void clear_syntax();
@ -304,7 +332,9 @@ class PROTOBUF_EXPORT Api :
private: private:
class _Internal; class _Internal;
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method > methods_; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method > methods_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin > mixins_; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin > mixins_;
@ -317,10 +347,10 @@ class PROTOBUF_EXPORT Api :
}; };
// ------------------------------------------------------------------- // -------------------------------------------------------------------
class PROTOBUF_EXPORT Method : class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ {
public: public:
Method(); inline Method() : Method(nullptr) {};
virtual ~Method(); virtual ~Method();
Method(const Method& from); Method(const Method& from);
@ -334,7 +364,7 @@ class PROTOBUF_EXPORT Method :
return *this; return *this;
} }
inline Method& operator=(Method&& from) noexcept { inline Method& operator=(Method&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from); if (this != &from) InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -366,6 +396,15 @@ class PROTOBUF_EXPORT Method :
} }
inline void Swap(Method* other) { inline void Swap(Method* other) {
if (other == this) return; if (other == this) return;
if (GetArena() == other->GetArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
}
}
void UnsafeArenaSwap(Method* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other); InternalSwap(other);
} }
@ -400,13 +439,11 @@ class PROTOBUF_EXPORT Method :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Method"; return "google.protobuf.Method";
} }
protected:
explicit Method(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private: private:
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { static void ArenaDtor(void* object);
return nullptr; inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
}
inline void* MaybeArenaPtr() const {
return nullptr;
}
public: public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@ -459,6 +496,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_name(); std::string* mutable_name();
std::string* release_name(); std::string* release_name();
void set_allocated_name(std::string* name); void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private: private:
const std::string& _internal_name() const; const std::string& _internal_name() const;
void _internal_set_name(const std::string& value); void _internal_set_name(const std::string& value);
@ -475,6 +521,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_request_type_url(); std::string* mutable_request_type_url();
std::string* release_request_type_url(); std::string* release_request_type_url();
void set_allocated_request_type_url(std::string* request_type_url); void set_allocated_request_type_url(std::string* request_type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_request_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_request_type_url(
std::string* request_type_url);
private: private:
const std::string& _internal_request_type_url() const; const std::string& _internal_request_type_url() const;
void _internal_set_request_type_url(const std::string& value); void _internal_set_request_type_url(const std::string& value);
@ -491,6 +546,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_response_type_url(); std::string* mutable_response_type_url();
std::string* release_response_type_url(); std::string* release_response_type_url();
void set_allocated_response_type_url(std::string* response_type_url); void set_allocated_response_type_url(std::string* response_type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_response_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_response_type_url(
std::string* response_type_url);
private: private:
const std::string& _internal_response_type_url() const; const std::string& _internal_response_type_url() const;
void _internal_set_response_type_url(const std::string& value); void _internal_set_response_type_url(const std::string& value);
@ -528,7 +592,9 @@ class PROTOBUF_EXPORT Method :
private: private:
class _Internal; class _Internal;
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_;
@ -541,10 +607,10 @@ class PROTOBUF_EXPORT Method :
}; };
// ------------------------------------------------------------------- // -------------------------------------------------------------------
class PROTOBUF_EXPORT Mixin : class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ {
public: public:
Mixin(); inline Mixin() : Mixin(nullptr) {};
virtual ~Mixin(); virtual ~Mixin();
Mixin(const Mixin& from); Mixin(const Mixin& from);
@ -558,7 +624,7 @@ class PROTOBUF_EXPORT Mixin :
return *this; return *this;
} }
inline Mixin& operator=(Mixin&& from) noexcept { inline Mixin& operator=(Mixin&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from); if (this != &from) InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -590,6 +656,15 @@ class PROTOBUF_EXPORT Mixin :
} }
inline void Swap(Mixin* other) { inline void Swap(Mixin* other) {
if (other == this) return; if (other == this) return;
if (GetArena() == other->GetArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
}
}
void UnsafeArenaSwap(Mixin* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other); InternalSwap(other);
} }
@ -624,13 +699,11 @@ class PROTOBUF_EXPORT Mixin :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Mixin"; return "google.protobuf.Mixin";
} }
protected:
explicit Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private: private:
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { static void ArenaDtor(void* object);
return nullptr; inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
}
inline void* MaybeArenaPtr() const {
return nullptr;
}
public: public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@ -660,6 +733,15 @@ class PROTOBUF_EXPORT Mixin :
std::string* mutable_name(); std::string* mutable_name();
std::string* release_name(); std::string* release_name();
void set_allocated_name(std::string* name); void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private: private:
const std::string& _internal_name() const; const std::string& _internal_name() const;
void _internal_set_name(const std::string& value); void _internal_set_name(const std::string& value);
@ -676,6 +758,15 @@ class PROTOBUF_EXPORT Mixin :
std::string* mutable_root(); std::string* mutable_root();
std::string* release_root(); std::string* release_root();
void set_allocated_root(std::string* root); void set_allocated_root(std::string* root);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_root();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_root(
std::string* root);
private: private:
const std::string& _internal_root() const; const std::string& _internal_root() const;
void _internal_set_root(const std::string& value); void _internal_set_root(const std::string& value);
@ -686,7 +777,9 @@ class PROTOBUF_EXPORT Mixin :
private: private:
class _Internal; class _Internal;
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
@ -705,7 +798,7 @@ class PROTOBUF_EXPORT Mixin :
// string name = 1; // string name = 1;
inline void Api::clear_name() { inline void Api::clear_name() {
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Api::name() const { inline const std::string& Api::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.name) // @@protoc_insertion_point(field_get:google.protobuf.Api.name)
@ -720,38 +813,40 @@ inline std::string* Api::mutable_name() {
return _internal_mutable_name(); return _internal_mutable_name();
} }
inline const std::string& Api::_internal_name() const { inline const std::string& Api::_internal_name() const {
return name_.GetNoArena(); return name_.Get();
} }
inline void Api::_internal_set_name(const std::string& value) { inline void Api::_internal_set_name(const std::string& value) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Api::set_name(std::string&& value) { inline void Api::set_name(std::string&& value) {
name_.SetNoArena( name_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
} }
inline void Api::set_name(const char* value) { inline void Api::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.name) // @@protoc_insertion_point(field_set_char:google.protobuf.Api.name)
} }
inline void Api::set_name(const char* value, size_t size) { inline void Api::set_name(const char* value,
size_t size) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name)
} }
inline std::string* Api::_internal_mutable_name() { inline std::string* Api::_internal_mutable_name() {
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Api::release_name() { inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name) // @@protoc_insertion_point(field_release:google.protobuf.Api.name)
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Api::set_allocated_name(std::string* name) { inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -759,9 +854,29 @@ inline void Api::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name); name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
} }
inline std::string* Api::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Api::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.name)
}
// repeated .google.protobuf.Method methods = 2; // repeated .google.protobuf.Method methods = 2;
inline int Api::_internal_methods_size() const { inline int Api::_internal_methods_size() const {
@ -840,7 +955,7 @@ Api::options() const {
// string version = 4; // string version = 4;
inline void Api::clear_version() { inline void Api::clear_version() {
version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Api::version() const { inline const std::string& Api::version() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.version) // @@protoc_insertion_point(field_get:google.protobuf.Api.version)
@ -855,38 +970,40 @@ inline std::string* Api::mutable_version() {
return _internal_mutable_version(); return _internal_mutable_version();
} }
inline const std::string& Api::_internal_version() const { inline const std::string& Api::_internal_version() const {
return version_.GetNoArena(); return version_.Get();
} }
inline void Api::_internal_set_version(const std::string& value) { inline void Api::_internal_set_version(const std::string& value) {
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Api::set_version(std::string&& value) { inline void Api::set_version(std::string&& value) {
version_.SetNoArena( version_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
} }
inline void Api::set_version(const char* value) { inline void Api::set_version(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.version) // @@protoc_insertion_point(field_set_char:google.protobuf.Api.version)
} }
inline void Api::set_version(const char* value, size_t size) { inline void Api::set_version(const char* value,
size_t size) {
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version)
} }
inline std::string* Api::_internal_mutable_version() { inline std::string* Api::_internal_mutable_version() {
return version_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return version_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Api::release_version() { inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version) // @@protoc_insertion_point(field_release:google.protobuf.Api.version)
return version_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Api::set_allocated_version(std::string* version) { inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) { if (version != nullptr) {
@ -894,9 +1011,29 @@ inline void Api::set_allocated_version(std::string* version) {
} else { } else {
} }
version_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version); version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
} }
inline std::string* Api::unsafe_arena_release_version() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.version)
GOOGLE_DCHECK(GetArena() != nullptr);
return version_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Api::unsafe_arena_set_allocated_version(
std::string* version) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (version != nullptr) {
} else {
}
version_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
version, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.version)
}
// .google.protobuf.SourceContext source_context = 5; // .google.protobuf.SourceContext source_context = 5;
inline bool Api::_internal_has_source_context() const { inline bool Api::_internal_has_source_context() const {
@ -914,7 +1051,27 @@ inline const PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context)
return _internal_source_context(); return _internal_source_context();
} }
inline void Api::unsafe_arena_set_allocated_source_context(
PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
if (GetArena() == nullptr) {
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
}
source_context_ = source_context;
if (source_context) {
} else {
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context)
}
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() { inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
auto temp = unsafe_arena_release_source_context();
if (GetArena() != nullptr) {
temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp);
}
return temp;
}
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_context() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context) // @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_; PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
@ -924,7 +1081,7 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() { inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() {
if (source_context_ == nullptr) { if (source_context_ == nullptr) {
auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArenaNoVirtual()); auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArena());
source_context_ = p; source_context_ = p;
} }
return source_context_; return source_context_;
@ -934,12 +1091,13 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
return _internal_mutable_source_context(); return _internal_mutable_source_context();
} }
inline void Api::set_allocated_source_context(PROTOBUF_NAMESPACE_ID::SourceContext* source_context) { inline void Api::set_allocated_source_context(PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual(); ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArena();
if (message_arena == nullptr) { if (message_arena == nullptr) {
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_); delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
} }
if (source_context) { if (source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = nullptr; ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)->GetArena();
if (message_arena != submessage_arena) { if (message_arena != submessage_arena) {
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, source_context, submessage_arena); message_arena, source_context, submessage_arena);
@ -1017,7 +1175,7 @@ inline void Api::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1; // string name = 1;
inline void Method::clear_name() { inline void Method::clear_name() {
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Method::name() const { inline const std::string& Method::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.name) // @@protoc_insertion_point(field_get:google.protobuf.Method.name)
@ -1032,38 +1190,40 @@ inline std::string* Method::mutable_name() {
return _internal_mutable_name(); return _internal_mutable_name();
} }
inline const std::string& Method::_internal_name() const { inline const std::string& Method::_internal_name() const {
return name_.GetNoArena(); return name_.Get();
} }
inline void Method::_internal_set_name(const std::string& value) { inline void Method::_internal_set_name(const std::string& value) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Method::set_name(std::string&& value) { inline void Method::set_name(std::string&& value) {
name_.SetNoArena( name_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
} }
inline void Method::set_name(const char* value) { inline void Method::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.name) // @@protoc_insertion_point(field_set_char:google.protobuf.Method.name)
} }
inline void Method::set_name(const char* value, size_t size) { inline void Method::set_name(const char* value,
size_t size) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name)
} }
inline std::string* Method::_internal_mutable_name() { inline std::string* Method::_internal_mutable_name() {
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Method::release_name() { inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name) // @@protoc_insertion_point(field_release:google.protobuf.Method.name)
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Method::set_allocated_name(std::string* name) { inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -1071,13 +1231,33 @@ inline void Method::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name); name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
} }
inline std::string* Method::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.name)
}
// string request_type_url = 2; // string request_type_url = 2;
inline void Method::clear_request_type_url() { inline void Method::clear_request_type_url() {
request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Method::request_type_url() const { inline const std::string& Method::request_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url)
@ -1092,38 +1272,40 @@ inline std::string* Method::mutable_request_type_url() {
return _internal_mutable_request_type_url(); return _internal_mutable_request_type_url();
} }
inline const std::string& Method::_internal_request_type_url() const { inline const std::string& Method::_internal_request_type_url() const {
return request_type_url_.GetNoArena(); return request_type_url_.Get();
} }
inline void Method::_internal_set_request_type_url(const std::string& value) { inline void Method::_internal_set_request_type_url(const std::string& value) {
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Method::set_request_type_url(std::string&& value) { inline void Method::set_request_type_url(std::string&& value) {
request_type_url_.SetNoArena( request_type_url_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
} }
inline void Method::set_request_type_url(const char* value) { inline void Method::set_request_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url)
} }
inline void Method::set_request_type_url(const char* value, size_t size) { inline void Method::set_request_type_url(const char* value,
size_t size) {
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url)
} }
inline std::string* Method::_internal_mutable_request_type_url() { inline std::string* Method::_internal_mutable_request_type_url() {
return request_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return request_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Method::release_request_type_url() { inline std::string* Method::release_request_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
return request_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Method::set_allocated_request_type_url(std::string* request_type_url) { inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) { if (request_type_url != nullptr) {
@ -1131,9 +1313,29 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
} else { } else {
} }
request_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url); request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
} }
inline std::string* Method::unsafe_arena_release_request_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.request_type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return request_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_request_type_url(
std::string* request_type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (request_type_url != nullptr) {
} else {
}
request_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
request_type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.request_type_url)
}
// bool request_streaming = 3; // bool request_streaming = 3;
inline void Method::clear_request_streaming() { inline void Method::clear_request_streaming() {
@ -1157,7 +1359,7 @@ inline void Method::set_request_streaming(bool value) {
// string response_type_url = 4; // string response_type_url = 4;
inline void Method::clear_response_type_url() { inline void Method::clear_response_type_url() {
response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Method::response_type_url() const { inline const std::string& Method::response_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url)
@ -1172,38 +1374,40 @@ inline std::string* Method::mutable_response_type_url() {
return _internal_mutable_response_type_url(); return _internal_mutable_response_type_url();
} }
inline const std::string& Method::_internal_response_type_url() const { inline const std::string& Method::_internal_response_type_url() const {
return response_type_url_.GetNoArena(); return response_type_url_.Get();
} }
inline void Method::_internal_set_response_type_url(const std::string& value) { inline void Method::_internal_set_response_type_url(const std::string& value) {
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Method::set_response_type_url(std::string&& value) { inline void Method::set_response_type_url(std::string&& value) {
response_type_url_.SetNoArena( response_type_url_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
} }
inline void Method::set_response_type_url(const char* value) { inline void Method::set_response_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url)
} }
inline void Method::set_response_type_url(const char* value, size_t size) { inline void Method::set_response_type_url(const char* value,
size_t size) {
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url)
} }
inline std::string* Method::_internal_mutable_response_type_url() { inline std::string* Method::_internal_mutable_response_type_url() {
return response_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return response_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Method::release_response_type_url() { inline std::string* Method::release_response_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
return response_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Method::set_allocated_response_type_url(std::string* response_type_url) { inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) { if (response_type_url != nullptr) {
@ -1211,9 +1415,29 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
} else { } else {
} }
response_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url); response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
} }
inline std::string* Method::unsafe_arena_release_response_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.response_type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return response_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_response_type_url(
std::string* response_type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (response_type_url != nullptr) {
} else {
}
response_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
response_type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.response_type_url)
}
// bool response_streaming = 5; // bool response_streaming = 5;
inline void Method::clear_response_streaming() { inline void Method::clear_response_streaming() {
@ -1297,7 +1521,7 @@ inline void Method::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1; // string name = 1;
inline void Mixin::clear_name() { inline void Mixin::clear_name() {
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Mixin::name() const { inline const std::string& Mixin::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
@ -1312,38 +1536,40 @@ inline std::string* Mixin::mutable_name() {
return _internal_mutable_name(); return _internal_mutable_name();
} }
inline const std::string& Mixin::_internal_name() const { inline const std::string& Mixin::_internal_name() const {
return name_.GetNoArena(); return name_.Get();
} }
inline void Mixin::_internal_set_name(const std::string& value) { inline void Mixin::_internal_set_name(const std::string& value) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Mixin::set_name(std::string&& value) { inline void Mixin::set_name(std::string&& value) {
name_.SetNoArena( name_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
} }
inline void Mixin::set_name(const char* value) { inline void Mixin::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name)
} }
inline void Mixin::set_name(const char* value, size_t size) { inline void Mixin::set_name(const char* value,
size_t size) {
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name)
} }
inline std::string* Mixin::_internal_mutable_name() { inline std::string* Mixin::_internal_mutable_name() {
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Mixin::release_name() { inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Mixin::set_allocated_name(std::string* name) { inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) { if (name != nullptr) {
@ -1351,13 +1577,33 @@ inline void Mixin::set_allocated_name(std::string* name) {
} else { } else {
} }
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name); name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
} }
inline std::string* Mixin::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Mixin::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.name)
}
// string root = 2; // string root = 2;
inline void Mixin::clear_root() { inline void Mixin::clear_root() {
root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline const std::string& Mixin::root() const { inline const std::string& Mixin::root() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
@ -1372,38 +1618,40 @@ inline std::string* Mixin::mutable_root() {
return _internal_mutable_root(); return _internal_mutable_root();
} }
inline const std::string& Mixin::_internal_root() const { inline const std::string& Mixin::_internal_root() const {
return root_.GetNoArena(); return root_.Get();
} }
inline void Mixin::_internal_set_root(const std::string& value) { inline void Mixin::_internal_set_root(const std::string& value) {
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
} }
inline void Mixin::set_root(std::string&& value) { inline void Mixin::set_root(std::string&& value) {
root_.SetNoArena( root_.Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
} }
inline void Mixin::set_root(const char* value) { inline void Mixin::set_root(const char* value) {
GOOGLE_DCHECK(value != nullptr); GOOGLE_DCHECK(value != nullptr);
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root)
} }
inline void Mixin::set_root(const char* value, size_t size) { inline void Mixin::set_root(const char* value,
size_t size) {
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
::std::string(reinterpret_cast<const char*>(value), size)); reinterpret_cast<const char*>(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root)
} }
inline std::string* Mixin::_internal_mutable_root() { inline std::string* Mixin::_internal_mutable_root() {
return root_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return root_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline std::string* Mixin::release_root() { inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
return root_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} }
inline void Mixin::set_allocated_root(std::string* root) { inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) { if (root != nullptr) {
@ -1411,9 +1659,29 @@ inline void Mixin::set_allocated_root(std::string* root) {
} else { } else {
} }
root_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root); root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root,
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root) // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
} }
inline std::string* Mixin::unsafe_arena_release_root() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.root)
GOOGLE_DCHECK(GetArena() != nullptr);
return root_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Mixin::unsafe_arena_set_allocated_root(
std::string* root) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (root != nullptr) {
} else {
}
root_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
root, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.root)
}
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

@ -338,10 +338,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename T> template <typename T>
PROTOBUF_ALWAYS_INLINE static T* CreateArray(Arena* arena, PROTOBUF_ALWAYS_INLINE static T* CreateArray(Arena* arena,
size_t num_elements) { size_t num_elements) {
#ifndef __INTEL_COMPILER // icc mis-evaluates some types as non-pod
static_assert(std::is_pod<T>::value, static_assert(std::is_pod<T>::value,
"CreateArray requires a trivially constructible type"); "CreateArray requires a trivially constructible type");
#endif
static_assert(std::is_trivially_destructible<T>::value, static_assert(std::is_trivially_destructible<T>::value,
"CreateArray requires a trivially destructible type"); "CreateArray requires a trivially destructible type");
GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T)) GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
@ -455,7 +453,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return new (ptr) T(std::forward<Args>(args)...); return new (ptr) T(std::forward<Args>(args)...);
} }
static Arena* GetArena(const T* p) { return p->GetArenaNoVirtual(); } static Arena* GetArena(const T* p) { return p->GetArena(); }
friend class Arena; friend class Arena;
}; };
@ -534,6 +532,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// the cookie is not null. // the cookie is not null.
template <typename T> template <typename T>
PROTOBUF_ALWAYS_INLINE void* AllocateInternal(bool skip_explicit_ownership) { PROTOBUF_ALWAYS_INLINE void* AllocateInternal(bool skip_explicit_ownership) {
static_assert(alignof(T) <= 8, "T is overaligned, see b/151247138");
const size_t n = internal::AlignUpTo8(sizeof(T)); const size_t n = internal::AlignUpTo8(sizeof(T));
AllocHook(RTTI_TYPE_ID(T), n); AllocHook(RTTI_TYPE_ID(T), n);
// Monitor allocation if needed. // Monitor allocation if needed.
@ -618,24 +617,25 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// CreateInArenaStorage is used to implement map field. Without it, // CreateInArenaStorage is used to implement map field. Without it,
// Map need to call generated message's protected arena constructor, // Map need to call generated message's protected arena constructor,
// which needs to declare Map as friend of generated message. // which needs to declare Map as friend of generated message.
template <typename T> template <typename T, typename... Args>
static void CreateInArenaStorage(T* ptr, Arena* arena) { static void CreateInArenaStorage(T* ptr, Arena* arena, Args&&... args) {
CreateInArenaStorageInternal(ptr, arena, CreateInArenaStorageInternal(ptr, arena,
typename is_arena_constructable<T>::type()); typename is_arena_constructable<T>::type(),
std::forward<Args>(args)...);
RegisterDestructorInternal( RegisterDestructorInternal(
ptr, arena, ptr, arena,
typename InternalHelper<T>::is_destructor_skippable::type()); typename InternalHelper<T>::is_destructor_skippable::type());
} }
template <typename T> template <typename T, typename... Args>
static void CreateInArenaStorageInternal(T* ptr, Arena* arena, static void CreateInArenaStorageInternal(T* ptr, Arena* arena,
std::true_type) { std::true_type, Args&&... args) {
InternalHelper<T>::Construct(ptr, arena); InternalHelper<T>::Construct(ptr, arena, std::forward<Args>(args)...);
} }
template <typename T> template <typename T, typename... Args>
static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */, static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */,
std::false_type) { std::false_type, Args&&... args) {
new (ptr) T(); new (ptr) T(std::forward<Args>(args)...);
} }
template <typename T> template <typename T>
@ -667,7 +667,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// Implementation for GetArena(). Only message objects with // Implementation for GetArena(). Only message objects with
// InternalArenaConstructable_ tags can be associated with an arena, and such // InternalArenaConstructable_ tags can be associated with an arena, and such
// objects must implement a GetArenaNoVirtual() method. // objects must implement a GetArena() method.
template <typename T, typename std::enable_if< template <typename T, typename std::enable_if<
is_arena_constructable<T>::value, int>::type = 0> is_arena_constructable<T>::value, int>::type = 0>
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
@ -694,6 +694,17 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
AllocHook(NULL, n); AllocHook(NULL, n);
return AllocateAlignedNoHook(internal::AlignUpTo8(n)); return AllocateAlignedNoHook(internal::AlignUpTo8(n));
} }
template<size_t Align>
void* AllocateAlignedTo(size_t n) {
static_assert(Align > 0, "Alignment must be greater than 0");
static_assert((Align & (Align - 1)) == 0, "Alignment must be power of two");
if (Align <= 8) return AllocateAligned(n);
// TODO(b/151247138): if the pointer would have been aligned already,
// this is wasting space. We should pass the alignment down.
uintptr_t ptr = reinterpret_cast<uintptr_t>(AllocateAligned(n + Align - 8));
ptr = (ptr + Align - 1) & -Align;
return reinterpret_cast<void*>(ptr);
}
void* AllocateAlignedNoHook(size_t n); void* AllocateAlignedNoHook(size_t n);

@ -102,6 +102,16 @@ class PROTOC_EXPORT CodeGenerator {
GeneratorContext* generator_context, GeneratorContext* generator_context,
std::string* error) const; std::string* error) const;
// Sync with plugin.proto.
enum Feature {
FEATURE_PROTO3_OPTIONAL = 1,
};
// Implement this to indicate what features this code generator supports.
// This should be a bitwise OR of features from the Features enum in
// plugin.proto.
virtual uint64 GetSupportedFeatures() const { return 0; }
// This is no longer used, but this class is part of the opensource protobuf // This is no longer used, but this class is part of the opensource protobuf
// library, so it has to remain to keep vtables the same for the current // library, so it has to remain to keep vtables the same for the current
// version of the library. When protobufs does a api breaking change, the // version of the library. When protobufs does a api breaking change, the

@ -773,16 +773,9 @@ const char* const CommandLineInterface::kPathSeparator = ":";
#endif #endif
CommandLineInterface::CommandLineInterface() CommandLineInterface::CommandLineInterface()
: mode_(MODE_COMPILE), : direct_dependencies_violation_msg_(
print_mode_(PRINT_NONE), kDefaultDirectDependenciesViolationMsg) {}
error_format_(ERROR_FORMAT_GCC),
direct_dependencies_explicitly_set_(false),
direct_dependencies_violation_msg_(
kDefaultDirectDependenciesViolationMsg),
imports_in_descriptor_set_(false),
source_info_in_descriptor_set_(false),
disallow_services_(false) {
}
CommandLineInterface::~CommandLineInterface() {} CommandLineInterface::~CommandLineInterface() {}
void CommandLineInterface::RegisterGenerator(const std::string& flag_name, void CommandLineInterface::RegisterGenerator(const std::string& flag_name,
@ -811,6 +804,39 @@ void CommandLineInterface::AllowPlugins(const std::string& exe_name_prefix) {
plugin_prefix_ = exe_name_prefix; plugin_prefix_ = exe_name_prefix;
} }
namespace {
bool ContainsProto3Optional(const Descriptor* desc) {
for (int i = 0; i < desc->field_count(); i++) {
if (desc->field(i)->has_optional_keyword()) {
return true;
}
}
for (int i = 0; i < desc->nested_type_count(); i++) {
if (ContainsProto3Optional(desc->nested_type(i))) {
return true;
}
}
return false;
}
bool ContainsProto3Optional(const FileDescriptor* file) {
if (file->syntax() == FileDescriptor::SYNTAX_PROTO3) {
for (int i = 0; i < file->message_type_count(); i++) {
if (ContainsProto3Optional(file->message_type(i))) {
return true;
}
}
}
return false;
}
} // namespace
namespace {
std::unique_ptr<SimpleDescriptorDatabase>
PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name);
}
int CommandLineInterface::Run(int argc, const char* const argv[]) { int CommandLineInterface::Run(int argc, const char* const argv[]) {
Clear(); Clear();
@ -827,16 +853,38 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
std::unique_ptr<DiskSourceTree> disk_source_tree; std::unique_ptr<DiskSourceTree> disk_source_tree;
std::unique_ptr<ErrorPrinter> error_collector; std::unique_ptr<ErrorPrinter> error_collector;
std::unique_ptr<DescriptorPool> descriptor_pool; std::unique_ptr<DescriptorPool> descriptor_pool;
std::unique_ptr<SimpleDescriptorDatabase> descriptor_set_in_database;
// The SimpleDescriptorDatabases here are the constituents of the
// MergedDescriptorDatabase descriptor_set_in_database, so this vector is for
// managing their lifetimes. Its scope should match descriptor_set_in_database
std::vector<std::unique_ptr<SimpleDescriptorDatabase>>
databases_per_descriptor_set;
std::unique_ptr<MergedDescriptorDatabase> descriptor_set_in_database;
std::unique_ptr<SourceTreeDescriptorDatabase> source_tree_database; std::unique_ptr<SourceTreeDescriptorDatabase> source_tree_database;
// Any --descriptor_set_in FileDescriptorSet objects will be used as a // Any --descriptor_set_in FileDescriptorSet objects will be used as a
// fallback to input_files on command line, so create that db first. // fallback to input_files on command line, so create that db first.
if (!descriptor_set_in_names_.empty()) { if (!descriptor_set_in_names_.empty()) {
descriptor_set_in_database.reset(new SimpleDescriptorDatabase()); for (const std::string& name : descriptor_set_in_names_) {
if (!PopulateSimpleDescriptorDatabase(descriptor_set_in_database.get())) { std::unique_ptr<SimpleDescriptorDatabase> database_for_descriptor_set =
return 1; PopulateSingleSimpleDescriptorDatabase(name);
if (!database_for_descriptor_set) {
return EXIT_FAILURE;
}
databases_per_descriptor_set.push_back(
std::move(database_for_descriptor_set));
}
std::vector<DescriptorDatabase*> raw_databases_per_descriptor_set;
raw_databases_per_descriptor_set.reserve(
databases_per_descriptor_set.size());
for (const std::unique_ptr<SimpleDescriptorDatabase>& db :
databases_per_descriptor_set) {
raw_databases_per_descriptor_set.push_back(db.get());
} }
descriptor_set_in_database.reset(
new MergedDescriptorDatabase(raw_databases_per_descriptor_set));
} }
if (proto_path_.empty()) { if (proto_path_.empty()) {
@ -876,6 +924,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
} }
for (auto fd : parsed_files) {
if (!AllowProto3Optional(*fd) && ContainsProto3Optional(fd)) {
std::cerr << fd->name()
<< ": This file contains proto3 optional fields, but "
"--experimental_allow_proto3_optional was not set."
<< std::endl;
return 1;
}
}
// We construct a separate GeneratorContext for each output location. Note // We construct a separate GeneratorContext for each output location. Note
// that two code generators may output to the same location, in which case // that two code generators may output to the same location, in which case
// they should share a single GeneratorContext so that OpenForInsert() works. // they should share a single GeneratorContext so that OpenForInsert() works.
@ -1000,46 +1058,57 @@ bool CommandLineInterface::InitializeDiskSourceTree(
return true; return true;
} }
bool CommandLineInterface::PopulateSimpleDescriptorDatabase( namespace {
SimpleDescriptorDatabase* database) { std::unique_ptr<SimpleDescriptorDatabase>
for (int i = 0; i < descriptor_set_in_names_.size(); i++) { PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name) {
int fd; int fd;
do { do {
fd = open(descriptor_set_in_names_[i].c_str(), O_RDONLY | O_BINARY); fd = open(descriptor_set_name.c_str(), O_RDONLY | O_BINARY);
} while (fd < 0 && errno == EINTR); } while (fd < 0 && errno == EINTR);
if (fd < 0) { if (fd < 0) {
std::cerr << descriptor_set_in_names_[i] << ": " << strerror(ENOENT) std::cerr << descriptor_set_name << ": " << strerror(ENOENT) << std::endl;
<< std::endl; return nullptr;
return false; }
}
FileDescriptorSet file_descriptor_set; FileDescriptorSet file_descriptor_set;
bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd); bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
if (close(fd) != 0) { if (close(fd) != 0) {
std::cerr << descriptor_set_in_names_[i] << ": close: " << strerror(errno) std::cerr << descriptor_set_name << ": close: " << strerror(errno)
<< std::endl; << std::endl;
return false; return nullptr;
} }
if (!parsed) { if (!parsed) {
std::cerr << descriptor_set_in_names_[i] << ": Unable to parse." std::cerr << descriptor_set_name << ": Unable to parse." << std::endl;
<< std::endl; return nullptr;
return false; }
}
for (int j = 0; j < file_descriptor_set.file_size(); j++) { std::unique_ptr<SimpleDescriptorDatabase> database{
FileDescriptorProto previously_added_file_descriptor_proto; new SimpleDescriptorDatabase()};
if (database->FindFileByName(file_descriptor_set.file(j).name(),
&previously_added_file_descriptor_proto)) { for (int j = 0; j < file_descriptor_set.file_size(); j++) {
// already present - skip FileDescriptorProto previously_added_file_descriptor_proto;
continue; if (database->FindFileByName(file_descriptor_set.file(j).name(),
} &previously_added_file_descriptor_proto)) {
if (!database->Add(file_descriptor_set.file(j))) { // already present - skip
return false; continue;
} }
if (!database->Add(file_descriptor_set.file(j))) {
return nullptr;
} }
} }
return true; return database;
}
} // namespace
bool CommandLineInterface::AllowProto3Optional(
const FileDescriptor& file) const {
if (allow_proto3_optional_) return true;
if (file.name() == "google/protobuf/unittest_proto3_optional.proto") {
return true;
}
return false;
} }
bool CommandLineInterface::VerifyInputFilesInDescriptors( bool CommandLineInterface::VerifyInputFilesInDescriptors(
@ -1068,10 +1137,26 @@ bool CommandLineInterface::ParseInputFiles(
DescriptorPool* descriptor_pool, DiskSourceTree* source_tree, DescriptorPool* descriptor_pool, DiskSourceTree* source_tree,
std::vector<const FileDescriptor*>* parsed_files) { std::vector<const FileDescriptor*>* parsed_files) {
// Track unused imports in all source files if (!proto_path_.empty()) {
for (const auto& input_file : input_files_) { // Track unused imports in all source files that were loaded from the
descriptor_pool->AddUnusedImportTrackFile(input_file); // filesystem. We do not track unused imports for files loaded from
// descriptor sets as they may be programmatically generated in which case
// exerting this level of rigor is less desirable. We're also making the
// assumption that the initial parse of the proto from the filesystem
// was rigorous in checking unused imports and that the descriptor set
// being parsed was produced then and that it was subsequent mutations
// of that descriptor set that left unused imports.
//
// Note that relying on proto_path exclusively is limited in that we may
// be loading descriptors from both the filesystem and descriptor sets
// depending on the invocation. At least for invocations that are
// exclusively reading from descriptor sets, we can eliminate this failure
// condition.
for (const auto& input_file : input_files_) {
descriptor_pool->AddUnusedImportTrackFile(input_file);
}
} }
bool result = true; bool result = true;
// Parse each file. // Parse each file.
for (const auto& input_file : input_files_) { for (const auto& input_file : input_files_) {
@ -1139,6 +1224,7 @@ void CommandLineInterface::Clear() {
source_info_in_descriptor_set_ = false; source_info_in_descriptor_set_ = false;
disallow_services_ = false; disallow_services_ = false;
direct_dependencies_explicitly_set_ = false; direct_dependencies_explicitly_set_ = false;
allow_proto3_optional_ = false;
} }
bool CommandLineInterface::MakeProtoProtoPathRelative( bool CommandLineInterface::MakeProtoProtoPathRelative(
@ -1414,7 +1500,8 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name,
if (*name == "-h" || *name == "--help" || *name == "--disallow_services" || if (*name == "-h" || *name == "--help" || *name == "--disallow_services" ||
*name == "--include_imports" || *name == "--include_source_info" || *name == "--include_imports" || *name == "--include_source_info" ||
*name == "--version" || *name == "--decode_raw" || *name == "--version" || *name == "--decode_raw" ||
*name == "--print_free_field_numbers") { *name == "--print_free_field_numbers" ||
*name == "--experimental_allow_proto3_optional") {
// HACK: These are the only flags that don't take a value. // HACK: These are the only flags that don't take a value.
// They probably should not be hard-coded like this but for now it's // They probably should not be hard-coded like this but for now it's
// not worth doing better. // not worth doing better.
@ -1621,6 +1708,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
} else if (name == "--disallow_services") { } else if (name == "--disallow_services") {
disallow_services_ = true; disallow_services_ = true;
} else if (name == "--experimental_allow_proto3_optional") {
allow_proto3_optional_ = true;
} else if (name == "--encode" || name == "--decode" || } else if (name == "--encode" || name == "--decode" ||
name == "--decode_raw") { name == "--decode_raw") {
if (mode_ != MODE_COMPILE) { if (mode_ != MODE_COMPILE) {
@ -1921,6 +2011,28 @@ void CommandLineInterface::PrintHelpText() {
<< std::endl; << std::endl;
} }
bool CommandLineInterface::EnforceProto3OptionalSupport(
const std::string& codegen_name, uint64 supported_features,
const std::vector<const FileDescriptor*>& parsed_files) const {
bool supports_proto3_optional =
supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL;
if (!supports_proto3_optional) {
for (const auto fd : parsed_files) {
if (ContainsProto3Optional(fd)) {
std::cerr << fd->name()
<< ": is a proto3 file that contains optional fields, but "
"code generator "
<< codegen_name
<< " hasn't been updated to support optional fields in "
"proto3. Please ask the owner of this code generator to "
"support proto3 optional.";
return false;
}
}
}
return true;
}
bool CommandLineInterface::GenerateOutput( bool CommandLineInterface::GenerateOutput(
const std::vector<const FileDescriptor*>& parsed_files, const std::vector<const FileDescriptor*>& parsed_files,
const OutputDirective& output_directive, const OutputDirective& output_directive,
@ -1955,6 +2067,12 @@ bool CommandLineInterface::GenerateOutput(
} }
parameters.append(generator_parameters_[output_directive.name]); parameters.append(generator_parameters_[output_directive.name]);
} }
if (!EnforceProto3OptionalSupport(
output_directive.name,
output_directive.generator->GetSupportedFeatures(), parsed_files)) {
return false;
}
if (!output_directive.generator->GenerateAll(parsed_files, parameters, if (!output_directive.generator->GenerateAll(parsed_files, parameters,
generator_context, &error)) { generator_context, &error)) {
// Generator returned an error. // Generator returned an error.
@ -2119,6 +2237,9 @@ bool CommandLineInterface::GeneratePluginOutput(
// Generator returned an error. // Generator returned an error.
*error = response.error(); *error = response.error();
return false; return false;
} else if (!EnforceProto3OptionalSupport(
plugin_name, response.supported_features(), parsed_files)) {
return false;
} }
return true; return true;

@ -226,6 +226,17 @@ class PROTOC_EXPORT CommandLineInterface {
bool MakeInputsBeProtoPathRelative(DiskSourceTree* source_tree, bool MakeInputsBeProtoPathRelative(DiskSourceTree* source_tree,
DescriptorDatabase* fallback_database); DescriptorDatabase* fallback_database);
// Is this .proto file whitelisted, or do we have a command-line flag allowing
// us to use proto3 optional? This is a temporary control to avoid people from
// using proto3 optional until code generators have implemented it.
bool AllowProto3Optional(const FileDescriptor& file) const;
// Fails if these files use proto3 optional and the code generator doesn't
// support it. This is a permanent check.
bool EnforceProto3OptionalSupport(
const std::string& codegen_name, uint64 supported_features,
const std::vector<const FileDescriptor*>& parsed_files) const;
// Return status for ParseArguments() and InterpretArgument(). // Return status for ParseArguments() and InterpretArgument().
enum ParseArgumentStatus { enum ParseArgumentStatus {
@ -269,9 +280,6 @@ class PROTOC_EXPORT CommandLineInterface {
// Verify that all the input files exist in the given database. // Verify that all the input files exist in the given database.
bool VerifyInputFilesInDescriptors(DescriptorDatabase* fallback_database); bool VerifyInputFilesInDescriptors(DescriptorDatabase* fallback_database);
// Loads descriptor_set_in into the provided database
bool PopulateSimpleDescriptorDatabase(SimpleDescriptorDatabase* database);
// Parses input_files_ into parsed_files // Parses input_files_ into parsed_files
bool ParseInputFiles(DescriptorPool* descriptor_pool, bool ParseInputFiles(DescriptorPool* descriptor_pool,
DiskSourceTree* source_tree, DiskSourceTree* source_tree,
@ -373,21 +381,21 @@ class PROTOC_EXPORT CommandLineInterface {
MODE_PRINT, // Print mode: print info of the given .proto files and exit. MODE_PRINT, // Print mode: print info of the given .proto files and exit.
}; };
Mode mode_; Mode mode_ = MODE_COMPILE;
enum PrintMode { enum PrintMode {
PRINT_NONE, // Not in MODE_PRINT PRINT_NONE, // Not in MODE_PRINT
PRINT_FREE_FIELDS, // --print_free_fields PRINT_FREE_FIELDS, // --print_free_fields
}; };
PrintMode print_mode_; PrintMode print_mode_ = PRINT_NONE;
enum ErrorFormat { enum ErrorFormat {
ERROR_FORMAT_GCC, // GCC error output format (default). ERROR_FORMAT_GCC, // GCC error output format (default).
ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs). ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs).
}; };
ErrorFormat error_format_; ErrorFormat error_format_ = ERROR_FORMAT_GCC;
std::vector<std::pair<std::string, std::string> > std::vector<std::pair<std::string, std::string> >
proto_path_; // Search path for proto files. proto_path_; // Search path for proto files.
@ -396,7 +404,7 @@ class PROTOC_EXPORT CommandLineInterface {
// Names of proto files which are allowed to be imported. Used by build // Names of proto files which are allowed to be imported. Used by build
// systems to enforce depend-on-what-you-import. // systems to enforce depend-on-what-you-import.
std::set<std::string> direct_dependencies_; std::set<std::string> direct_dependencies_;
bool direct_dependencies_explicitly_set_; bool direct_dependencies_explicitly_set_ = false;
// If there's a violation of depend-on-what-you-import, this string will be // If there's a violation of depend-on-what-you-import, this string will be
// presented to the user. "%s" will be replaced with the violating import. // presented to the user. "%s" will be replaced with the violating import.
@ -435,10 +443,13 @@ class PROTOC_EXPORT CommandLineInterface {
// True if --include_source_info was given, meaning that we should not strip // True if --include_source_info was given, meaning that we should not strip
// SourceCodeInfo from the DescriptorSet. // SourceCodeInfo from the DescriptorSet.
bool source_info_in_descriptor_set_; bool source_info_in_descriptor_set_ = false;
// Was the --disallow_services flag used? // Was the --disallow_services flag used?
bool disallow_services_; bool disallow_services_ = false;
// Was the --experimental_allow_proto3_optional flag used?
bool allow_proto3_optional_ = false;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
}; };

@ -205,6 +205,17 @@ class CommandLineInterfaceTest : public testing::Test {
void ExpectFileContent(const std::string& filename, void ExpectFileContent(const std::string& filename,
const std::string& content); const std::string& content);
// The default code generators support all features. Use this to create a
// code generator that omits the given feature(s).
void CreateGeneratorWithMissingFeatures(const std::string& name,
const std::string& description,
uint64 features) {
MockCodeGenerator* generator = new MockCodeGenerator(name);
generator->SuppressFeatures(features);
mock_generators_to_delete_.push_back(generator);
cli_.RegisterGenerator(name, generator, description);
}
private: private:
// The object we are testing. // The object we are testing.
CommandLineInterface cli_; CommandLineInterface cli_;
@ -913,6 +924,58 @@ TEST_F(CommandLineInterfaceTest,
ExpectErrorSubstring("bar.proto: \"Baz\" is not defined."); ExpectErrorSubstring("bar.proto: \"Baz\" is not defined.");
} }
TEST_F(CommandLineInterfaceTest,
InputsOnlyFromDescriptorSetIn_UnusedImportIsNotReported) {
FileDescriptorSet file_descriptor_set;
FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
file_descriptor_proto->set_name("unused.proto");
file_descriptor_proto->add_message_type()->set_name("Unused");
file_descriptor_proto = file_descriptor_set.add_file();
file_descriptor_proto->set_name("bar.proto");
file_descriptor_proto->add_dependency("unused.proto");
file_descriptor_proto->add_message_type()->set_name("Bar");
WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
"--descriptor_set_in=$tmpdir/unused_and_bar.bin unused.proto bar.proto");
ExpectNoErrors();
}
TEST_F(CommandLineInterfaceTest,
InputsFromDescriptorSetInAndFileSystem_UnusedImportIsReported) {
FileDescriptorSet file_descriptor_set;
FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
file_descriptor_proto->set_name("unused.proto");
file_descriptor_proto->add_message_type()->set_name("Unused");
file_descriptor_proto = file_descriptor_set.add_file();
file_descriptor_proto->set_name("bar.proto");
file_descriptor_proto->add_dependency("unused.proto");
file_descriptor_proto->add_message_type()->set_name("Bar");
WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
"import \"bar.proto\";\n"
"message Foo {\n"
" optional Bar bar = 1;\n"
"}\n");
Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
"--descriptor_set_in=$tmpdir/unused_and_bar.bin "
"--proto_path=$tmpdir unused.proto bar.proto foo.proto");
// Reporting unused imports here is unfair, since it's unactionable. Notice
// the lack of a line number.
// TODO(b/144853061): If the file with unused import is from the descriptor
// set and not from the file system, suppress the warning.
ExpectWarningSubstring("bar.proto: warning: Import unused.proto is unused.");
}
TEST_F(CommandLineInterfaceTest, TEST_F(CommandLineInterfaceTest,
OnlyReportsUnusedImportsForFilesBeingGenerated) { OnlyReportsUnusedImportsForFilesBeingGenerated) {
CreateTempFile("unused.proto", CreateTempFile("unused.proto",
@ -975,7 +1038,6 @@ TEST_F(CommandLineInterfaceTest, ReportsTransitiveMisingImports_LeafLast) {
ExpectWarningSubstring( ExpectWarningSubstring(
"bar.proto:2:1: warning: Import unused.proto is unused."); "bar.proto:2:1: warning: Import unused.proto is unused.");
} }
TEST_F(CommandLineInterfaceTest, CreateDirectory) { TEST_F(CommandLineInterfaceTest, CreateDirectory) {
// Test that when we output to a sub-directory, it is created. // Test that when we output to a sub-directory, it is created.
@ -2310,6 +2372,78 @@ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
ExpectErrorText("Missing value for flag: --test_out\n"); ExpectErrorText("Missing value for flag: --test_out\n");
} }
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowed) {
CreateTempFile("foo.proto",
"syntax = \"proto3\";\n"
"message Foo {\n"
" optional int32 i = 1;\n"
"}\n");
Run("protocol_compiler --proto_path=$tmpdir foo.proto -odescriptor.pb");
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
}
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedDescriptor) {
CreateTempFile("foo.proto",
"syntax = \"proto3\";\n"
"message Foo {\n"
" optional int32 i = 1;\n"
"}\n");
Run("protocol_compiler --experimental_allow_proto3_optional "
"--proto_path=$tmpdir foo.proto "
" -o$tmpdir/descriptor.pb");
ExpectNoErrors();
Run("protocol_compiler --descriptor_set_in=$tmpdir/descriptor.pb foo.proto "
"--test_out=$tmpdir");
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
}
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedGenCode) {
CreateTempFile("foo.proto",
"syntax = \"proto3\";\n"
"message Foo {\n"
" optional int32 i = 1;\n"
"}\n");
Run("protocol_compiler --proto_path=$tmpdir foo.proto --test_out=$tmpdir");
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
}
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedNoCodegenSupport) {
CreateTempFile("foo.proto",
"syntax = \"proto3\";\n"
"message Foo {\n"
" optional int32 i = 1;\n"
"}\n");
CreateGeneratorWithMissingFeatures("--no_proto3_optional_out",
"Doesn't support proto3 optional",
CodeGenerator::FEATURE_PROTO3_OPTIONAL);
Run("protocol_compiler --experimental_allow_proto3_optional "
"--proto_path=$tmpdir foo.proto --no_proto3_optional_out=$tmpdir");
ExpectErrorSubstring(
"code generator --no_proto3_optional_out hasn't been updated to support "
"optional fields in proto3");
}
TEST_F(CommandLineInterfaceTest, Proto3OptionalAllowWithFlag) {
CreateTempFile("foo.proto",
"syntax = \"proto3\";\n"
"message Foo {\n"
" optional int32 i = 1;\n"
"}\n");
Run("protocol_compiler --experimental_allow_proto3_optional "
"--proto_path=$tmpdir foo.proto --test_out=$tmpdir");
ExpectNoErrors();
}
TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) { TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
CreateTempFile("foo.proto", CreateTempFile("foo.proto",
"syntax = \"proto2\";\n" "syntax = \"proto2\";\n"

@ -76,8 +76,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector --------------------------------------- // implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column, void AddError(const std::string& filename, int line, int column,
const std::string& message) { const std::string& message) {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
column, message); message);
} }
}; };

@ -94,7 +94,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
variables_["constant_name"] = FieldConstantName(descriptor_); variables_["constant_name"] = FieldConstantName(descriptor_);
variables_["field_type"] = variables_["field_type"] =
StrCat(static_cast<int>(descriptor_->type())); StrCat(static_cast<int>(descriptor_->type()));
variables_["packed"] = descriptor_->options().packed() ? "true" : "false"; variables_["packed"] = descriptor_->is_packed() ? "true" : "false";
std::string scope = std::string scope =
IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : ""; IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : "";
@ -157,6 +157,11 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
StringReplace(variables_["scoped_name"], "::", "_", true) + "_default"; StringReplace(variables_["scoped_name"], "::", "_", true) + "_default";
format("const std::string $1$($2$);\n", default_str, format("const std::string $1$($2$);\n", default_str,
DefaultValue(options_, descriptor_)); DefaultValue(options_, descriptor_));
} else if (descriptor_->message_type()) {
// We have to initialize the default instance for extensions at registration
// time.
default_str =
FieldMessageTypeName(descriptor_, options_) + "::default_instance()";
} else { } else {
default_str = DefaultValue(options_, descriptor_); default_str = DefaultValue(options_, descriptor_);
} }

@ -411,11 +411,6 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* printer) {
IncludeFile("net/proto2/public/reflection_ops.h", printer); IncludeFile("net/proto2/public/reflection_ops.h", printer);
IncludeFile("net/proto2/public/wire_format.h", printer); IncludeFile("net/proto2/public/wire_format.h", printer);
} }
if (IsProto2MessageSetFile(file_, options_)) {
format(
// Implementation of proto1 MessageSet API methods.
"#include \"net/proto2/internal/message_set_util.h\"\n");
}
if (options_.proto_h) { if (options_.proto_h) {
// Use the smaller .proto.h files. // Use the smaller .proto.h files.
@ -898,18 +893,21 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
format("};\n"); format("};\n");
// The DescriptorTable itself. // The DescriptorTable itself.
// Should be "bool eager = NeedsEagerDescriptorAssignment(file_, options_);"
// however this might cause a tsan failure in superroot b/148382879,
// so disable for now.
bool eager = false;
format( format(
"static ::$proto_ns$::internal::once_flag $desc_table$_once;\n" "static ::$proto_ns$::internal::once_flag $desc_table$_once;\n"
"static bool $desc_table$_initialized = false;\n"
"const ::$proto_ns$::internal::DescriptorTable $desc_table$ = {\n" "const ::$proto_ns$::internal::DescriptorTable $desc_table$ = {\n"
" &$desc_table$_initialized, $1$, \"$filename$\", $2$,\n" " false, $1$, $2$, \"$filename$\", $3$,\n"
" &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $3$, $4$,\n" " &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $4$, $5$,\n"
" schemas, file_default_instances, $tablename$::offsets,\n" " schemas, file_default_instances, $tablename$::offsets,\n"
" $file_level_metadata$, $5$, $file_level_enum_descriptors$, " " $file_level_metadata$, $6$, $file_level_enum_descriptors$, "
"$file_level_service_descriptors$,\n" "$file_level_service_descriptors$,\n"
"};\n\n", "};\n\n",
protodef_name, file_data.size(), sccs_.size(), num_deps, eager ? "true" : "false", protodef_name, file_data.size(), sccs_.size(),
message_generators_.size()); num_deps, message_generators_.size());
// For descriptor.proto we want to avoid doing any dynamic initialization, // For descriptor.proto we want to avoid doing any dynamic initialization,
// because in some situations that would otherwise pull in a lot of // because in some situations that would otherwise pull in a lot of
@ -1297,12 +1295,10 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
IncludeFile("net/proto2/public/generated_message_table_driven.h", printer); IncludeFile("net/proto2/public/generated_message_table_driven.h", printer);
IncludeFile("net/proto2/public/generated_message_util.h", printer); IncludeFile("net/proto2/public/generated_message_util.h", printer);
IncludeFile("net/proto2/public/inlined_string_field.h", printer); IncludeFile("net/proto2/public/inlined_string_field.h", printer);
IncludeFile("net/proto2/public/metadata_lite.h", printer);
if (HasDescriptorMethods(file_, options_)) { if (HasDescriptorMethods(file_, options_)) {
IncludeFile("net/proto2/public/metadata.h", printer);
IncludeFile("net/proto2/public/generated_message_reflection.h", printer); IncludeFile("net/proto2/public/generated_message_reflection.h", printer);
} else {
IncludeFile("net/proto2/public/metadata_lite.h", printer);
} }
if (!message_generators_.empty()) { if (!message_generators_.empty()) {

@ -93,6 +93,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.annotation_guard_name = options[i].second; file_options.annotation_guard_name = options[i].second;
} else if (options[i].first == "speed") { } else if (options[i].first == "speed") {
file_options.enforce_mode = EnforceOptimizeMode::kSpeed; file_options.enforce_mode = EnforceOptimizeMode::kSpeed;
} else if (options[i].first == "code_size") {
file_options.enforce_mode = EnforceOptimizeMode::kCodeSize;
} else if (options[i].first == "lite") { } else if (options[i].first == "lite") {
file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime; file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime;
} else if (options[i].first == "lite_implicit_weak_fields") { } else if (options[i].first == "lite_implicit_weak_fields") {

@ -81,7 +81,14 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
// implements CodeGenerator ---------------------------------------- // implements CodeGenerator ----------------------------------------
bool Generate(const FileDescriptor* file, const std::string& parameter, bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* generator_context, std::string* error) const; GeneratorContext* generator_context,
std::string* error) const override;
uint64 GetSupportedFeatures() const override {
// We don't fully support this yet, but this is needed to unblock the tests,
// and we will have full support before the experimental flag is removed.
return FEATURE_PROTO3_OPTIONAL;
}
private: private:
bool opensource_runtime_ = true; bool opensource_runtime_ = true;

@ -43,10 +43,13 @@
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/logging.h>
#include <google/protobuf/compiler/cpp/cpp_options.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/scc.h> #include <google/protobuf/compiler/scc.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h> #include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
@ -244,6 +247,31 @@ void SetCommonVars(const Options& options,
(*variables)["string"] = "std::string"; (*variables)["string"] = "std::string";
} }
void SetUnknkownFieldsVariable(const Descriptor* descriptor,
const Options& options,
std::map<std::string, std::string>* variables) {
std::string proto_ns = ProtobufNamespace(options);
std::string unknown_fields_type;
if (UseUnknownFieldSet(descriptor->file(), options)) {
unknown_fields_type = "::" + proto_ns + "::UnknownFieldSet";
(*variables)["unknown_fields"] =
"_internal_metadata_.unknown_fields<" + unknown_fields_type + ">(" +
unknown_fields_type + "::default_instance)";
} else {
unknown_fields_type =
PrimitiveTypeName(options, FieldDescriptor::CPPTYPE_STRING);
(*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields<" +
unknown_fields_type + ">(::" + proto_ns +
"::internal::GetEmptyString)";
}
(*variables)["unknown_fields_type"] = unknown_fields_type;
(*variables)["have_unknown_fields"] =
"_internal_metadata_.have_unknown_fields()";
(*variables)["mutable_unknown_fields"] =
"_internal_metadata_.mutable_unknown_fields<" + unknown_fields_type +
">()";
}
std::string UnderscoresToCamelCase(const std::string& input, std::string UnderscoresToCamelCase(const std::string& input,
bool cap_next_letter) { bool cap_next_letter) {
std::string result; std::string result;
@ -334,6 +362,16 @@ std::string QualifiedClassName(const EnumDescriptor* d) {
return QualifiedClassName(d, Options()); return QualifiedClassName(d, Options());
} }
std::string QualifiedExtensionName(const FieldDescriptor* d,
const Options& options) {
GOOGLE_DCHECK(d->is_extension());
return QualifiedFileLevelSymbol(d->file(), FieldName(d), options);
}
std::string QualifiedExtensionName(const FieldDescriptor* d) {
return QualifiedExtensionName(d, Options());
}
std::string Namespace(const std::string& package) { std::string Namespace(const std::string& package) {
if (package.empty()) return ""; if (package.empty()) return "";
return "::" + DotsToColons(package); return "::" + DotsToColons(package);
@ -1345,11 +1383,14 @@ class ParseLoopGenerator {
format_.Set("GOOGLE_PROTOBUF", MacroPrefix(options_)); format_.Set("GOOGLE_PROTOBUF", MacroPrefix(options_));
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
SetCommonVars(options_, &vars); SetCommonVars(options_, &vars);
SetUnknkownFieldsVariable(descriptor, options_, &vars);
format_.AddMap(vars); format_.AddMap(vars);
std::vector<const FieldDescriptor*> ordered_fields; std::vector<const FieldDescriptor*> ordered_fields;
for (auto field : FieldRange(descriptor)) { for (auto field : FieldRange(descriptor)) {
ordered_fields.push_back(field); if (IsFieldUsed(field, options_)) {
ordered_fields.push_back(field);
}
} }
std::sort(ordered_fields.begin(), ordered_fields.end(), std::sort(ordered_fields.begin(), ordered_fields.end(),
[](const FieldDescriptor* a, const FieldDescriptor* b) { [](const FieldDescriptor* a, const FieldDescriptor* b) {
@ -1375,12 +1416,13 @@ class ParseLoopGenerator {
} }
if (descriptor->file()->options().cc_enable_arenas()) { if (descriptor->file()->options().cc_enable_arenas()) {
format_("$p_ns$::Arena* arena = GetArenaNoVirtual(); (void)arena;\n"); format_("$p_ns$::Arena* arena = GetArena(); (void)arena;\n");
} }
GenerateParseLoop(descriptor, ordered_fields); GenerateParseLoop(descriptor, ordered_fields);
format_.Outdent(); format_.Outdent();
format_("success:\n"); format_("success:\n");
if (hasbits_size) format_(" _has_bits_.Or(has_bits);\n"); if (hasbits_size) format_(" _has_bits_.Or(has_bits);\n");
format_( format_(
" return ptr;\n" " return ptr;\n"
"failure:\n" "failure:\n"
@ -1495,12 +1537,20 @@ class ParseLoopGenerator {
enum_validator = enum_validator =
StrCat(", ", QualifiedClassName(field->enum_type(), options_), StrCat(", ", QualifiedClassName(field->enum_type(), options_),
"_IsValid, &_internal_metadata_, ", field->number()); "_IsValid, &_internal_metadata_, ", field->number());
format_(
"ptr = "
"$pi_ns$::Packed$1$Parser<$unknown_fields_type$>(_internal_mutable_"
"$2$(), ptr, "
"ctx$3$);\n",
DeclaredTypeMethodName(field->type()), FieldName(field),
enum_validator);
} else {
format_(
"ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
"ctx$3$);\n",
DeclaredTypeMethodName(field->type()), FieldName(field),
enum_validator);
} }
format_(
"ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
"ctx$3$);\n",
DeclaredTypeMethodName(field->type()), FieldName(field),
enum_validator);
} else { } else {
auto field_type = field->type(); auto field_type = field->type();
switch (field_type) { switch (field_type) {
@ -1518,7 +1568,9 @@ class ParseLoopGenerator {
if (HasFieldPresence(field->file()) && if (HasFieldPresence(field->file()) &&
val->type() == FieldDescriptor::TYPE_ENUM) { val->type() == FieldDescriptor::TYPE_ENUM) {
format_( format_(
"auto object = ::$proto_ns$::internal::InitEnumParseWrapper(" "auto object = "
"::$proto_ns$::internal::InitEnumParseWrapper<$unknown_"
"fields_type$>("
"&$1$_, $2$_IsValid, $3$, &_internal_metadata_);\n" "&$1$_, $2$_IsValid, $3$, &_internal_metadata_);\n"
"ptr = ctx->ParseMessage(&object, ptr);\n", "ptr = ctx->ParseMessage(&object, ptr);\n",
FieldName(field), QualifiedClassName(val->enum_type()), FieldName(field), QualifiedClassName(val->enum_type()),
@ -1533,8 +1585,7 @@ class ParseLoopGenerator {
"if (!_internal_has_$1$()) {\n" "if (!_internal_has_$1$()) {\n"
" clear_$2$();\n" " clear_$2$();\n"
" $2$_.$1$_ = ::$proto_ns$::Arena::CreateMessage<\n" " $2$_.$1$_ = ::$proto_ns$::Arena::CreateMessage<\n"
" $pi_ns$::LazyField>(" " $pi_ns$::LazyField>(GetArena());\n"
"GetArenaNoVirtual());\n"
" set_has_$1$();\n" " set_has_$1$();\n"
"}\n" "}\n"
"ptr = ctx->ParseMessage($2$_.$1$_, ptr);\n", "ptr = ctx->ParseMessage($2$_.$1$_, ptr);\n",
@ -1624,7 +1675,10 @@ class ParseLoopGenerator {
field->number()); field->number());
} }
} else { } else {
std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 || field->type() == FieldDescriptor::TYPE_UINT32) ? "32" : "64"; std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 ||
field->type() == FieldDescriptor::TYPE_UINT32)
? "32"
: "64";
std::string zigzag; std::string zigzag;
if ((field->type() == FieldDescriptor::TYPE_SINT32 || if ((field->type() == FieldDescriptor::TYPE_SINT32 ||
field->type() == FieldDescriptor::TYPE_SINT64)) { field->type() == FieldDescriptor::TYPE_SINT64)) {
@ -1807,7 +1861,10 @@ class ParseLoopGenerator {
"}\n"); "}\n");
} }
format_( format_(
" ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);\n" " ptr = UnknownFieldParse(tag,\n"
" _internal_metadata_.mutable_unknown_fields<$unknown_"
"fields_type$>(),\n"
" ptr, ctx);\n"
" CHK_(ptr != nullptr);\n" " CHK_(ptr != nullptr);\n"
" continue;\n"); " continue;\n");
} }
@ -1827,6 +1884,130 @@ void GenerateParserLoop(const Descriptor* descriptor, int num_hasbits,
generator.GenerateParserLoop(descriptor); generator.GenerateParserLoop(descriptor);
} }
static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file,
const Options& options,
bool* has_opt_codesize_extension) {
std::vector<const FieldDescriptor*> fields;
auto reflection = msg.GetReflection();
reflection->ListFields(msg, &fields);
for (auto field : fields) {
const auto* field_msg = field->message_type();
if (field_msg == nullptr) {
// It so happens that enums Is_Valid are still generated so enums work.
// Only messages have potential problems.
continue;
}
// If this option has an extension set AND that extension is defined in the
// same file we have bootstrap problem.
if (field->is_extension()) {
const auto* msg_extension_file = field->message_type()->file();
if (msg_extension_file == file) return true;
if (has_opt_codesize_extension &&
GetOptimizeFor(msg_extension_file, options) ==
FileOptions::CODE_SIZE) {
*has_opt_codesize_extension = true;
}
}
// Recurse in this field to see if there is a problem in there
if (field->is_repeated()) {
for (int i = 0; i < reflection->FieldSize(msg, field); i++) {
if (HasExtensionFromFile(reflection->GetRepeatedMessage(msg, field, i),
file, options, has_opt_codesize_extension)) {
return true;
}
}
} else {
if (HasExtensionFromFile(reflection->GetMessage(msg, field), file,
options, has_opt_codesize_extension)) {
return true;
}
}
}
return false;
}
static bool HasBootstrapProblem(const FileDescriptor* file,
const Options& options,
bool* has_opt_codesize_extension) {
static auto& cache = *new std::unordered_map<const FileDescriptor*, bool>;
auto it = cache.find(file);
if (it != cache.end()) return it->second;
// In order to build the data structures for the reflective parse, it needs
// to parse the serialized descriptor describing all the messages defined in
// this file. Obviously this presents a bootstrap problem for descriptor
// messages.
if (file->name() == "net/proto2/proto/descriptor.proto" ||
file->name() == "google/protobuf/descriptor.proto") {
return true;
}
// Unfortunately we're not done yet. The descriptor option messages allow
// for extensions. So we need to be able to parse these extensions in order
// to parse the file descriptor for a file that has custom options. This is a
// problem when these custom options extensions are defined in the same file.
FileDescriptorProto linkedin_fd_proto;
const DescriptorPool* pool = file->pool();
const Descriptor* fd_proto_descriptor =
pool->FindMessageTypeByName(linkedin_fd_proto.GetTypeName());
// Not all pools have descriptor.proto in them. In these cases there for sure
// are no custom options.
if (fd_proto_descriptor == nullptr) return false;
// It's easier to inspect file as a proto, because we can use reflection on
// the proto to iterate over all content.
file->CopyTo(&linkedin_fd_proto);
// linkedin_fd_proto is a generated proto linked in the proto compiler. As
// such it doesn't know the extensions that are potentially present in the
// descriptor pool constructed from the protos that are being compiled. These
// custom options are therefore in the unknown fields.
// By building the corresponding FileDescriptorProto in the pool constructed
// by the protos that are being compiled, ie. file's pool, the unknown fields
// are converted to extensions.
DynamicMessageFactory factory(pool);
Message* fd_proto = factory.GetPrototype(fd_proto_descriptor)->New();
fd_proto->ParseFromString(linkedin_fd_proto.SerializeAsString());
bool& res = cache[file];
res = HasExtensionFromFile(*fd_proto, file, options,
has_opt_codesize_extension);
delete fd_proto;
return res;
}
FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
const Options& options,
bool* has_opt_codesize_extension) {
if (has_opt_codesize_extension) *has_opt_codesize_extension = false;
switch (options.enforce_mode) {
case EnforceOptimizeMode::kSpeed:
return FileOptions::SPEED;
case EnforceOptimizeMode::kLiteRuntime:
return FileOptions::LITE_RUNTIME;
case EnforceOptimizeMode::kCodeSize:
if (file->options().optimize_for() == FileOptions::LITE_RUNTIME) {
return FileOptions::LITE_RUNTIME;
}
if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
return FileOptions::SPEED;
}
return FileOptions::CODE_SIZE;
case EnforceOptimizeMode::kNoEnforcement:
if (file->options().optimize_for() == FileOptions::CODE_SIZE) {
if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
GOOGLE_LOG(WARNING) << "Proto states optimize_for = CODE_SIZE, but we "
"cannot honor that because it contains custom option "
"extensions defined in the same proto.";
return FileOptions::SPEED;
}
}
return file->options().optimize_for();
}
GOOGLE_LOG(FATAL) << "Unknown optimization enforcement requested.";
// The phony return below serves to silence a warning from GCC 8.
return FileOptions::SPEED;
}
} // namespace cpp } // namespace cpp
} // namespace compiler } // namespace compiler
} // namespace protobuf } // namespace protobuf

@ -83,6 +83,10 @@ extern const char kThinSeparator[];
void SetCommonVars(const Options& options, void SetCommonVars(const Options& options,
std::map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
void SetUnknkownFieldsVariable(const Descriptor* descriptor,
const Options& options,
std::map<std::string, std::string>* variables);
bool GetBootstrapBasename(const Options& options, const std::string& basename, bool GetBootstrapBasename(const Options& options, const std::string& basename,
std::string* bootstrap_basename); std::string* bootstrap_basename);
bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
@ -130,6 +134,10 @@ inline std::string ClassName(const EnumDescriptor* descriptor, bool qualified) {
: ClassName(descriptor); : ClassName(descriptor);
} }
std::string QualifiedExtensionName(const FieldDescriptor* d,
const Options& options);
std::string QualifiedExtensionName(const FieldDescriptor* d);
// Type name of default instance. // Type name of default instance.
std::string DefaultInstanceType(const Descriptor* descriptor, std::string DefaultInstanceType(const Descriptor* descriptor,
const Options& options); const Options& options);
@ -339,6 +347,12 @@ inline bool IsLazy(const FieldDescriptor* field, const Options& options) {
!options.opensource_runtime; !options.opensource_runtime;
} }
// Returns true if "field" is used.
inline bool IsFieldUsed(const FieldDescriptor* /*field*/,
const Options& /*options*/) {
return true;
}
// Does the file contain any definitions that need extension_set.h? // Does the file contain any definitions that need extension_set.h?
bool HasExtensionsOrExtendableMessage(const FileDescriptor* file); bool HasExtensionsOrExtendableMessage(const FileDescriptor* file);
@ -414,6 +428,12 @@ inline bool HasFieldPresence(const FileDescriptor* file) {
return file->syntax() != FileDescriptor::SYNTAX_PROTO3; return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
} }
inline bool HasHasbit(const FieldDescriptor* field) {
// TODO(haberman): remove, and give some proto3 fields hasbits.
if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) return false;
return field->is_singular_with_presence();
}
// Returns true if 'enum' semantics are such that unknown values are preserved // Returns true if 'enum' semantics are such that unknown values are preserved
// in the enum field itself, rather than going to the UnknownFieldSet. // in the enum field itself, rather than going to the UnknownFieldSet.
inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) { inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) {
@ -475,16 +495,32 @@ inline std::string IncludeGuard(const FileDescriptor* file, bool pb_h,
} }
} }
// Returns the OptimizeMode for this file, furthermore it updates a status
// bool if has_opt_codesize_extension is non-null. If this status bool is true
// it means this file contains an extension that itself is defined as
// optimized_for = CODE_SIZE.
FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
const Options& options,
bool* has_opt_codesize_extension);
inline FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file, inline FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
const Options& options) { const Options& options) {
switch (options.enforce_mode) { return GetOptimizeFor(file, options, nullptr);
case EnforceOptimizeMode::kSpeed: }
return FileOptions::SPEED; inline bool NeedsEagerDescriptorAssignment(const FileDescriptor* file,
case EnforceOptimizeMode::kLiteRuntime: const Options& options) {
return FileOptions::LITE_RUNTIME; bool has_opt_codesize_extension;
case EnforceOptimizeMode::kNoEnforcement: if (GetOptimizeFor(file, options, &has_opt_codesize_extension) ==
default: FileOptions::CODE_SIZE &&
return file->options().optimize_for(); has_opt_codesize_extension) {
// If this filedescriptor contains an extension from another file which
// is optimized_for = CODE_SIZE. We need to be careful in the ordering so
// we eagerly build the descriptors in the dependencies before building
// the descriptors of this file.
return true;
} else {
// If we have a generated code based parser we never need eager
// initialization of descriptors of our deps.
return false;
} }
} }

File diff suppressed because it is too large Load Diff

@ -144,6 +144,7 @@ class MessageGenerator {
void GenerateSerializeWithCachedSizesBody(io::Printer* printer); void GenerateSerializeWithCachedSizesBody(io::Printer* printer);
void GenerateByteSize(io::Printer* printer); void GenerateByteSize(io::Printer* printer);
void GenerateMergeFrom(io::Printer* printer); void GenerateMergeFrom(io::Printer* printer);
void GenerateClassSpecificMergeFrom(io::Printer* printer);
void GenerateCopyFrom(io::Printer* printer); void GenerateCopyFrom(io::Printer* printer);
void GenerateSwap(io::Printer* printer); void GenerateSwap(io::Printer* printer);
void GenerateIsInitialized(io::Printer* printer); void GenerateIsInitialized(io::Printer* printer);
@ -180,6 +181,10 @@ class MessageGenerator {
bool copy_constructor) const; bool copy_constructor) const;
size_t HasBitsSize() const; size_t HasBitsSize() const;
int HasBitIndex(const FieldDescriptor* a) const;
int HasByteIndex(const FieldDescriptor* a) const;
int HasWordIndex(const FieldDescriptor* a) const;
bool SameHasByte(const FieldDescriptor* a, const FieldDescriptor* b) const;
std::vector<uint32> RequiredFieldsBitMask() const; std::vector<uint32> RequiredFieldsBitMask() const;
const Descriptor* descriptor_; const Descriptor* descriptor_;

@ -66,10 +66,10 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
(*variables)["type_default_instance_ptr"] = (*variables)["type_default_instance_ptr"] =
QualifiedDefaultInstancePtr(descriptor->message_type(), options); QualifiedDefaultInstancePtr(descriptor->message_type(), options);
(*variables)["type_reference_function"] = (*variables)["type_reference_function"] =
implicit_weak implicit_weak ? (" ::" + (*variables)["proto_ns"] +
? (" " + (*variables)["proto_ns"] + "::internal::StrongReference(" + "::internal::StrongReference(" +
(*variables)["type_default_instance"] + ");\n") (*variables)["type_default_instance"] + ");\n")
: ""; : "";
// NOTE: Escaped here to unblock proto1->proto2 migration. // NOTE: Escaped here to unblock proto1->proto2 migration.
// TODO(liujisi): Extend this to apply for other conflicting methods. // TODO(liujisi): Extend this to apply for other conflicting methods.
(*variables)["release_name"] = (*variables)["release_name"] =
@ -104,17 +104,43 @@ void MessageFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
void MessageFieldGenerator::GenerateAccessorDeclarations( void MessageFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!IsFieldUsed(descriptor_, options_)) {
format(
"$deprecated_attr$const $type$& ${1$$name$$}$() const { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$$release_name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$mutable_$name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$void ${1$set_allocated_$name$$}$"
"($type$* $name$) { __builtin_trap(); }\n",
descriptor_);
if (SupportsArenas(descriptor_)) {
format(
"$deprecated_attr$void "
"${1$unsafe_arena_set_allocated_$name$$}$(\n"
" $type$* $name$) { __builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$unsafe_arena_release_$name$$}$() { "
"__builtin_trap(); }\n",
descriptor_);
}
return;
}
format( format(
"$deprecated_attr$const $type$& ${1$$name$$}$() const;\n" "$deprecated_attr$const $type$& ${1$$name$$}$() const;\n"
"$deprecated_attr$$type$* ${1$$release_name$$}$();\n" "$deprecated_attr$$type$* ${1$$release_name$$}$();\n"
"$deprecated_attr$$type$* ${1$mutable_$name$$}$();\n" "$deprecated_attr$$type$* ${1$mutable_$name$$}$();\n"
"$deprecated_attr$void ${1$set_allocated_$name$$}$" "$deprecated_attr$void ${1$set_allocated_$name$$}$"
"($type$* $name$);\n" "($type$* $name$);\n",
"private:\n"
"const $type$& ${1$_internal_$name$$}$() const;\n"
"$type$* ${1$_internal_mutable_$name$$}$();\n"
"public:\n",
descriptor_); descriptor_);
if (IsFieldUsed(descriptor_, options_)) {
format(
"private:\n"
"const $type$& ${1$_internal_$name$$}$() const;\n"
"$type$* ${1$_internal_mutable_$name$$}$();\n"
"public:\n",
descriptor_);
}
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
format( format(
"$deprecated_attr$void " "$deprecated_attr$void "
@ -127,27 +153,6 @@ void MessageFieldGenerator::GenerateAccessorDeclarations(
void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions( void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_);
if (SupportsArenas(descriptor_)) {
format(
"void $classname$::unsafe_arena_set_allocated_$name$(\n"
" $type$* $name$) {\n"
"$annotate_accessor$"
// If we're not on an arena, free whatever we were holding before.
// (If we are on arena, we can just forget the earlier pointer.)
" if (GetArenaNoVirtual() == nullptr) {\n"
" delete $name$_;\n"
" }\n"
" $name$_ = $name$;\n"
" if ($name$) {\n"
" $set_hasbit$\n"
" } else {\n"
" $clear_hasbit$\n"
" }\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated"
":$full_name$)\n"
"}\n");
}
} }
void MessageFieldGenerator::GenerateInlineAccessorDefinitions( void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
@ -167,10 +172,35 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"); "}\n");
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
format(
"inline void $classname$::unsafe_arena_set_allocated_$name$(\n"
" $type$* $name$) {\n"
"$annotate_accessor$"
// If we're not on an arena, free whatever we were holding before.
// (If we are on arena, we can just forget the earlier pointer.)
" if (GetArena() == nullptr) {\n"
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($name$_);\n"
" }\n");
if (implicit_weak_field_) {
format(
" $name$_ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
} else {
format(" $name$_ = $name$;\n");
}
format(
" if ($name$) {\n"
" $set_hasbit$\n"
" } else {\n"
" $clear_hasbit$\n"
" }\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated"
":$full_name$)\n"
"}\n");
format( format(
"inline $type$* $classname$::$release_name$() {\n" "inline $type$* $classname$::$release_name$() {\n"
" auto temp = unsafe_arena_release_$name$();\n" " auto temp = unsafe_arena_release_$name$();\n"
" if (GetArenaNoVirtual() != nullptr) {\n" " if (GetArena() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n" " temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n" " }\n"
" return temp;\n" " return temp;\n"
@ -194,7 +224,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$type_reference_function$" "$type_reference_function$"
" $set_hasbit$\n" " $set_hasbit$\n"
" if ($name$_ == nullptr) {\n" " if ($name$_ == nullptr) {\n"
" auto* p = CreateMaybeMessage<$type$>(GetArenaNoVirtual());\n"); " auto* p = CreateMaybeMessage<$type$>(GetArena());\n");
if (implicit_weak_field_) { if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n"); format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
} else { } else {
@ -215,7 +245,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
format( format(
"inline void $classname$::set_allocated_$name$($type$* $name$) {\n" "inline void $classname$::set_allocated_$name$($type$* $name$) {\n"
"$annotate_accessor$" "$annotate_accessor$"
" ::$proto_ns$::Arena* message_arena = GetArenaNoVirtual();\n"); " ::$proto_ns$::Arena* message_arena = GetArena();\n");
format(" if (message_arena == nullptr) {\n"); format(" if (message_arena == nullptr) {\n");
if (IsCrossFileMessage(descriptor_)) { if (IsCrossFileMessage(descriptor_)) {
format( format(
@ -309,12 +339,11 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
" if ($type_default_instance_ptr$ == nullptr) {\n" " if ($type_default_instance_ptr$ == nullptr) {\n"
" msg->$name$_ = ::$proto_ns$::Arena::CreateMessage<\n" " msg->$name$_ = ::$proto_ns$::Arena::CreateMessage<\n"
" ::$proto_ns$::internal::ImplicitWeakMessage>(\n" " ::$proto_ns$::internal::ImplicitWeakMessage>(\n"
" msg->GetArenaNoVirtual());\n" " msg->GetArena());\n"
" } else {\n" " } else {\n"
" msg->$name$_ = reinterpret_cast<const " " msg->$name$_ = reinterpret_cast<const "
"::$proto_ns$::MessageLite*>(\n" "::$proto_ns$::MessageLite*>(\n"
" $type_default_instance_ptr$)->New(" " $type_default_instance_ptr$)->New(msg->GetArena());\n"
"msg->GetArenaNoVirtual());\n"
" }\n" " }\n"
" }\n" " }\n"
" return msg->$name$_;\n" " return msg->$name$_;\n"
@ -353,12 +382,14 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
} }
void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!HasFieldPresence(descriptor_->file())) { if (!HasFieldPresence(descriptor_->file())) {
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
// NULL. Thus on clear, we need to delete the object. // NULL. Thus on clear, we need to delete the object.
format( format(
"if (GetArenaNoVirtual() == nullptr && $name$_ != nullptr) {\n" "if (GetArena() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n" " delete $name$_;\n"
"}\n" "}\n"
"$name$_ = nullptr;\n"); "$name$_ = nullptr;\n");
@ -369,12 +400,14 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
void MessageFieldGenerator::GenerateMessageClearingCode( void MessageFieldGenerator::GenerateMessageClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!HasFieldPresence(descriptor_->file())) { if (!HasFieldPresence(descriptor_->file())) {
// If we don't have has-bits, message presence is indicated only by ptr != // If we don't have has-bits, message presence is indicated only by ptr !=
// NULL. Thus on clear, we need to delete the object. // NULL. Thus on clear, we need to delete the object.
format( format(
"if (GetArenaNoVirtual() == nullptr && $name$_ != nullptr) {\n" "if (GetArena() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n" " delete $name$_;\n"
"}\n" "}\n"
"$name$_ = nullptr;\n"); "$name$_ = nullptr;\n");
@ -386,6 +419,8 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
} }
void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
@ -399,11 +434,15 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
} }
void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n"); format("swap($name$_, other->$name$_);\n");
} }
void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (options_.opensource_runtime) { if (options_.opensource_runtime) {
// TODO(gerbens) Remove this when we don't need to destruct default // TODO(gerbens) Remove this when we don't need to destruct default
@ -418,12 +457,16 @@ void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
void MessageFieldGenerator::GenerateConstructorCode( void MessageFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_ = nullptr;\n"); format("$name$_ = nullptr;\n");
} }
void MessageFieldGenerator::GenerateCopyConstructorCode( void MessageFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"if (from._internal_has_$name$()) {\n" "if (from._internal_has_$name$()) {\n"
@ -435,6 +478,8 @@ void MessageFieldGenerator::GenerateCopyConstructorCode(
void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"target = stream->EnsureSpace(target);\n" "target = stream->EnsureSpace(target);\n"
@ -444,6 +489,8 @@ void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
} }
void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const { void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$ +\n" "total_size += $tag_size$ +\n"
@ -468,7 +515,7 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
format( format(
"void $classname$::set_allocated_$name$($type$* $name$) {\n" "void $classname$::set_allocated_$name$($type$* $name$) {\n"
"$annotate_accessor$" "$annotate_accessor$"
" ::$proto_ns$::Arena* message_arena = GetArenaNoVirtual();\n" " ::$proto_ns$::Arena* message_arena = GetArena();\n"
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" if ($name$) {\n"); " if ($name$) {\n");
if (SupportsArenas(descriptor_->message_type()) && if (SupportsArenas(descriptor_->message_type()) &&
@ -510,7 +557,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $type$* temp = $field_member$;\n"); " $type$* temp = $field_member$;\n");
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
format( format(
" if (GetArenaNoVirtual() != nullptr) {\n" " if (GetArena() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n" " temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n"); " }\n");
} }
@ -570,8 +617,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n" " if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n" " clear_$oneof_name$();\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$ = CreateMaybeMessage< $type$ >(\n" " $field_member$ = CreateMaybeMessage< $type$ >(GetArena());\n"
" GetArenaNoVirtual());\n"
" }\n" " }\n"
" return $field_member$;\n" " return $field_member$;\n"
"}\n" "}\n"
@ -584,10 +630,12 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void MessageOneofFieldGenerator::GenerateClearingCode( void MessageOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
format( format(
"if (GetArenaNoVirtual() == nullptr) {\n" "if (GetArena() == nullptr) {\n"
" delete $field_member$;\n" " delete $field_member$;\n"
"}\n"); "}\n");
} else { } else {
@ -643,14 +691,35 @@ void RepeatedMessageFieldGenerator::GeneratePrivateMembers(
void RepeatedMessageFieldGenerator::GenerateAccessorDeclarations( void RepeatedMessageFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (!IsFieldUsed(descriptor_, options_)) {
format(
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index) { "
"__builtin_trap(); }\n"
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
" ${1$mutable_$name$$}$() { __builtin_trap(); }\n"
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$add_$name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n"
" ${1$$name$$}$() const { __builtin_trap(); }\n",
descriptor_);
return;
}
format( format(
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index);\n" "$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index);\n"
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n" "$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
" ${1$mutable_$name$$}$();\n" " ${1$mutable_$name$$}$();\n",
"private:\n" descriptor_);
"const $type$& ${1$_internal_$name$$}$(int index) const;\n" if (IsFieldUsed(descriptor_, options_)) {
"$type$* ${1$_internal_add_$name$$}$();\n" format(
"public:\n" "private:\n"
"const $type$& ${1$_internal_$name$$}$(int index) const;\n"
"$type$* ${1$_internal_add_$name$$}$();\n"
"public:\n",
descriptor_);
}
format(
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const;\n" "$deprecated_attr$const $type$& ${1$$name$$}$(int index) const;\n"
"$deprecated_attr$$type$* ${1$add_$name$$}$();\n" "$deprecated_attr$$type$* ${1$add_$name$$}$();\n"
"$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n" "$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n"
@ -722,18 +791,24 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedMessageFieldGenerator::GenerateClearingCode( void RepeatedMessageFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.Clear();\n"); format("$name$_.Clear();\n");
} }
void RepeatedMessageFieldGenerator::GenerateMergingCode( void RepeatedMessageFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n"); format("$name$_.MergeFrom(from.$name$_);\n");
} }
void RepeatedMessageFieldGenerator::GenerateSwappingCode( void RepeatedMessageFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n"); format("$name$_.InternalSwap(&other->$name$_);\n");
} }
@ -745,6 +820,8 @@ void RepeatedMessageFieldGenerator::GenerateConstructorCode(
void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (implicit_weak_field_) { if (implicit_weak_field_) {
format( format(
@ -770,6 +847,8 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
void RepeatedMessageFieldGenerator::GenerateByteSize( void RepeatedMessageFieldGenerator::GenerateByteSize(
io::Printer* printer) const { io::Printer* printer) const {
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
Formatter format(printer, variables_); Formatter format(printer, variables_);
format( format(
"total_size += $tag_size$UL * this->_internal_$name$_size();\n" "total_size += $tag_size$UL * this->_internal_$name$_size();\n"

@ -44,7 +44,8 @@ namespace cpp {
enum class EnforceOptimizeMode { enum class EnforceOptimizeMode {
kNoEnforcement, // Use the runtime specified by the file specific options. kNoEnforcement, // Use the runtime specified by the file specific options.
kSpeed, // This is the full runtime. kSpeed, // Full runtime with a generated code implementation.
kCodeSize, // Full runtime with a reflective implementation.
kLiteRuntime, kLiteRuntime,
}; };
@ -62,6 +63,7 @@ struct Options {
bool bootstrap = false; bool bootstrap = false;
bool opensource_runtime = false; bool opensource_runtime = false;
bool annotate_accessor = false; bool annotate_accessor = false;
bool unused_field_stripping = false;
std::string runtime_include_base; std::string runtime_include_base;
int num_cc_files = 0; int num_cc_files = 0;
std::string annotation_pragma_name; std::string annotation_pragma_name;

@ -237,13 +237,13 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void $classname$::_internal_set_$name$(const std::string& " "inline void $classname$::_internal_set_$name$(const std::string& "
"value) {\n" "value) {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.Set$lite$($default_variable$, value, GetArenaNoVirtual());\n" " $name$_.Set$lite$($default_variable$, value, GetArena());\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(std::string&& value) {\n" "inline void $classname$::set_$name$(std::string&& value) {\n"
"$annotate_accessor$" "$annotate_accessor$"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.Set$lite$(\n" " $name$_.Set$lite$(\n"
" $default_variable$, ::std::move(value), GetArenaNoVirtual());\n" " $default_variable$, ::std::move(value), GetArena());\n"
" // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(const char* value) {\n" "inline void $classname$::set_$name$(const char* value) {\n"
@ -251,7 +251,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $null_check$" " $null_check$"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.Set$lite$($default_variable$, $string_piece$(value),\n" " $name$_.Set$lite$($default_variable$, $string_piece$(value),\n"
" GetArenaNoVirtual());\n" " GetArena());\n"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n"); "}\n");
if (!options_.opensource_runtime) { if (!options_.opensource_runtime) {
@ -259,8 +259,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void $classname$::set_$name$(::StringPiece value) {\n" "inline void $classname$::set_$name$(::StringPiece value) {\n"
"$annotate_accessor$" "$annotate_accessor$"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.Set$lite$($default_variable$, value, " " $name$_.Set$lite$($default_variable$, value,GetArena());\n"
"GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n" " // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n"); "}\n");
} }
@ -271,13 +270,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_accessor$" "$annotate_accessor$"
" $set_hasbit$\n" " $set_hasbit$\n"
" $name$_.Set$lite$($default_variable$, $string_piece$(\n" " $name$_.Set$lite$($default_variable$, $string_piece$(\n"
" reinterpret_cast<const char*>(value), size), " " reinterpret_cast<const char*>(value), size), GetArena());\n"
"GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
"}\n" "}\n"
"inline std::string* $classname$::_internal_mutable_$name$() {\n" "inline std::string* $classname$::_internal_mutable_$name$() {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" " return $name$_.Mutable($default_variable$, GetArena());\n"
"}\n" "}\n"
"inline std::string* $classname$::$release_name$() {\n" "inline std::string* $classname$::$release_name$() {\n"
"$annotate_accessor$" "$annotate_accessor$"
@ -290,12 +288,11 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n" " }\n"
" $clear_hasbit$\n" " $clear_hasbit$\n"
" return $name$_.ReleaseNonDefault(" " return $name$_.ReleaseNonDefault("
"$default_variable$, GetArenaNoVirtual());\n"); "$default_variable$, GetArena());\n");
} else { } else {
format( format(
" $clear_hasbit$\n" " $clear_hasbit$\n"
" return $name$_.Release($default_variable$, " " return $name$_.Release($default_variable$, GetArena());\n");
"GetArenaNoVirtual());\n");
} }
format( format(
@ -308,7 +305,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n" " $clear_hasbit$\n"
" }\n" " }\n"
" $name$_.SetAllocated($default_variable$, $name$,\n" " $name$_.SetAllocated($default_variable$, $name$,\n"
" GetArenaNoVirtual());\n" " GetArena());\n"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n"); "}\n");
if (options_.opensource_runtime) { if (options_.opensource_runtime) {
@ -317,22 +314,22 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_accessor$" "$annotate_accessor$"
" // " " // "
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" $DCHK$(GetArenaNoVirtual() != nullptr);\n" " $DCHK$(GetArena() != nullptr);\n"
" $clear_hasbit$\n" " $clear_hasbit$\n"
" return $name$_.UnsafeArenaRelease($default_variable$,\n" " return $name$_.UnsafeArenaRelease($default_variable$,\n"
" GetArenaNoVirtual());\n" " GetArena());\n"
"}\n" "}\n"
"inline void $classname$::unsafe_arena_set_allocated_$name$(\n" "inline void $classname$::unsafe_arena_set_allocated_$name$(\n"
"$annotate_accessor$" "$annotate_accessor$"
" std::string* $name$) {\n" " std::string* $name$) {\n"
" $DCHK$(GetArenaNoVirtual() != nullptr);\n" " $DCHK$(GetArena() != nullptr);\n"
" if ($name$ != nullptr) {\n" " if ($name$ != nullptr) {\n"
" $set_hasbit$\n" " $set_hasbit$\n"
" } else {\n" " } else {\n"
" $clear_hasbit$\n" " $clear_hasbit$\n"
" }\n" " }\n"
" $name$_.UnsafeArenaSetAllocated($default_variable$,\n" " $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
" $name$, GetArenaNoVirtual());\n" " $name$, GetArena());\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
"$full_name$)\n" "$full_name$)\n"
"}\n"); "}\n");
@ -436,11 +433,9 @@ void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
// below methods are inlined one-liners)! // below methods are inlined one-liners)!
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
format( format("$name$_.ClearToEmpty($default_variable$, GetArena());\n");
"$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
} else { } else {
format( format("$name$_.ClearToDefault($default_variable$, GetArena());\n");
"$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
} }
} else { } else {
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
@ -481,14 +476,12 @@ void StringFieldGenerator::GenerateMessageClearingCode(
if (must_be_present) { if (must_be_present) {
format("$name$_.ClearNonDefaultToEmpty();\n"); format("$name$_.ClearNonDefaultToEmpty();\n");
} else { } else {
format( format("$name$_.ClearToEmpty($default_variable$, GetArena());\n");
"$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
} }
} else { } else {
// Clear to a non-empty default is more involved, as we try to use the // Clear to a non-empty default is more involved, as we try to use the
// Arena if one is present and may need to reallocate the string. // Arena if one is present and may need to reallocate the string.
format( format("$name$_.ClearToDefault($default_variable$, GetArena());\n");
"$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
} }
} else if (must_be_present) { } else if (must_be_present) {
// When Arenas are disabled and field presence has been checked, we can // When Arenas are disabled and field presence has been checked, we can
@ -524,9 +517,7 @@ void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
if (inlined_) { if (inlined_) {
format("$name$_.Swap(&other->$name$_);\n"); format("$name$_.Swap(&other->$name$_);\n");
} else { } else {
format( format("$name$_.Swap(&other->$name$_, $default_variable$, GetArena());\n");
"$name$_.Swap(&other->$name$_, $default_variable$,\n"
" GetArenaNoVirtual());\n");
} }
} }
@ -559,7 +550,7 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
// TODO(gpike): improve this // TODO(gpike): improve this
format( format(
"$name$_.Set$lite$($default_variable$, from._internal_$name$(),\n" "$name$_.Set$lite$($default_variable$, from._internal_$name$(),\n"
" GetArenaNoVirtual());\n"); " GetArena());\n");
} else { } else {
format("$name$_.AssignWithDefault($default_variable$, from.$name$_);\n"); format("$name$_.AssignWithDefault($default_variable$, from.$name$_);\n");
} }
@ -682,8 +673,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
" $field_member$.Set$lite$($default_variable$, value,\n" " $field_member$.Set$lite$($default_variable$, value, GetArena());\n"
" GetArenaNoVirtual());\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(std::string&& value) {\n" "inline void $classname$::set_$name$(std::string&& value) {\n"
"$annotate_accessor$" "$annotate_accessor$"
@ -694,7 +684,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
" $field_member$.Set$lite$(\n" " $field_member$.Set$lite$(\n"
" $default_variable$, ::std::move(value), GetArenaNoVirtual());\n" " $default_variable$, ::std::move(value), GetArena());\n"
" // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
"}\n" "}\n"
"inline void $classname$::set_$name$(const char* value) {\n" "inline void $classname$::set_$name$(const char* value) {\n"
@ -706,7 +696,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
" $field_member$.Set$lite$($default_variable$,\n" " $field_member$.Set$lite$($default_variable$,\n"
" $string_piece$(value), GetArenaNoVirtual());\n" " $string_piece$(value), GetArena());\n"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n"); "}\n");
if (!options_.opensource_runtime) { if (!options_.opensource_runtime) {
@ -719,7 +709,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
" $field_member$.Set$lite$($default_variable$, value,\n" " $field_member$.Set$lite$($default_variable$, value,\n"
" GetArenaNoVirtual());\n" " GetArena());\n"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n" " // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n"); "}\n");
} }
@ -736,7 +726,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.Set$lite$(\n" " $field_member$.Set$lite$(\n"
" $default_variable$, $string_piece$(\n" " $default_variable$, $string_piece$(\n"
" reinterpret_cast<const char*>(value), size),\n" " reinterpret_cast<const char*>(value), size),\n"
" GetArenaNoVirtual());\n" " GetArena());\n"
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
"}\n" "}\n"
"inline std::string* $classname$::_internal_mutable_$name$() {\n" "inline std::string* $classname$::_internal_mutable_$name$() {\n"
@ -745,16 +735,14 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
" return $field_member$.Mutable($default_variable$,\n" " return $field_member$.Mutable($default_variable$, GetArena());\n"
" GetArenaNoVirtual());\n"
"}\n" "}\n"
"inline std::string* $classname$::$release_name$() {\n" "inline std::string* $classname$::$release_name$() {\n"
"$annotate_accessor$" "$annotate_accessor$"
" // @@protoc_insertion_point(field_release:$full_name$)\n" " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n" " clear_has_$oneof_name$();\n"
" return $field_member$.Release($default_variable$,\n" " return $field_member$.Release($default_variable$, GetArena());\n"
" GetArenaNoVirtual());\n"
" } else {\n" " } else {\n"
" return nullptr;\n" " return nullptr;\n"
" }\n" " }\n"
@ -776,11 +764,11 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_accessor$" "$annotate_accessor$"
" // " " // "
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" $DCHK$(GetArenaNoVirtual() != nullptr);\n" " $DCHK$(GetArena() != nullptr);\n"
" if (_internal_has_$name$()) {\n" " if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n" " clear_has_$oneof_name$();\n"
" return $field_member$.UnsafeArenaRelease(\n" " return $field_member$.UnsafeArenaRelease(\n"
" $default_variable$, GetArenaNoVirtual());\n" " $default_variable$, GetArena());\n"
" } else {\n" " } else {\n"
" return nullptr;\n" " return nullptr;\n"
" }\n" " }\n"
@ -788,7 +776,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void $classname$::unsafe_arena_set_allocated_$name$(" "inline void $classname$::unsafe_arena_set_allocated_$name$("
"std::string* $name$) {\n" "std::string* $name$) {\n"
"$annotate_accessor$" "$annotate_accessor$"
" $DCHK$(GetArenaNoVirtual() != nullptr);\n" " $DCHK$(GetArena() != nullptr);\n"
" if (!_internal_has_$name$()) {\n" " if (!_internal_has_$name$()) {\n"
" $field_member$.UnsafeSetDefault($default_variable$);\n" " $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n" " }\n"
@ -796,7 +784,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if ($name$) {\n" " if ($name$) {\n"
" set_has_$name$();\n" " set_has_$name$();\n"
" $field_member$.UnsafeArenaSetAllocated($default_variable$, " " $field_member$.UnsafeArenaSetAllocated($default_variable$, "
"$name$, GetArenaNoVirtual());\n" "$name$, GetArena());\n"
" }\n" " }\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
"$full_name$)\n" "$full_name$)\n"
@ -906,9 +894,7 @@ void StringOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const { io::Printer* printer) const {
Formatter format(printer, variables_); Formatter format(printer, variables_);
if (SupportsArenas(descriptor_)) { if (SupportsArenas(descriptor_)) {
format( format("$field_member$.Destroy($default_variable$, GetArena());\n");
"$field_member$.Destroy($default_variable$,\n"
" GetArenaNoVirtual());\n");
} else { } else {
format("$field_member$.DestroyNoArena($default_variable$);\n"); format("$field_member$.DestroyNoArena($default_variable$);\n");
} }

@ -100,8 +100,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector --------------------------------------- // implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column, void AddError(const std::string& filename, int line, int column,
const std::string& message) { const std::string& message) {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
filename, line, column, message); message);
} }
}; };

@ -231,8 +231,9 @@ const FileDescriptor* Importer::Import(const std::string& filename) {
return pool_.FindFileByName(filename); return pool_.FindFileByName(filename);
} }
void Importer::AddUnusedImportTrackFile(const std::string& file_name) { void Importer::AddUnusedImportTrackFile(const std::string& file_name,
pool_.AddUnusedImportTrackFile(file_name); bool is_error) {
pool_.AddUnusedImportTrackFile(file_name, is_error);
} }
void Importer::ClearUnusedImportTrackFiles() { void Importer::ClearUnusedImportTrackFiles() {

@ -178,7 +178,8 @@ class PROTOBUF_EXPORT Importer {
// contents are stored. // contents are stored.
inline const DescriptorPool* pool() const { return &pool_; } inline const DescriptorPool* pool() const { return &pool_; }
void AddUnusedImportTrackFile(const std::string& file_name); void AddUnusedImportTrackFile(const std::string& file_name,
bool is_error = false);
void ClearUnusedImportTrackFiles(); void ClearUnusedImportTrackFiles();

@ -74,14 +74,14 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector --------------------------------------- // implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column, void AddError(const std::string& filename, int line, int column,
const std::string& message) { const std::string& message) {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
column, message); message);
} }
void AddWarning(const std::string& filename, int line, int column, void AddWarning(const std::string& filename, int line, int column,
const std::string& message) { const std::string& message) {
strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line,
line, column, message); column, message);
} }
}; };

@ -228,7 +228,25 @@ void EnumGenerator::Generate(io::Printer* printer) {
if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) { if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) {
printer->Print( printer->Print(
"public final com.google.protobuf.Descriptors.EnumValueDescriptor\n" "public final com.google.protobuf.Descriptors.EnumValueDescriptor\n"
" getValueDescriptor() {\n" " getValueDescriptor() {\n");
if (SupportUnknownEnumValue(descriptor_->file())) {
if (ordinal_is_index) {
printer->Print(
" if (this == UNRECOGNIZED) {\n"
" throw new java.lang.IllegalStateException(\n"
" \"Can't get the descriptor of an unrecognized enum "
"value.\");\n"
" }\n");
} else {
printer->Print(
" if (index == -1) {\n"
" throw new java.lang.IllegalStateException(\n"
" \"Can't get the descriptor of an unrecognized enum "
"value.\");\n"
" }\n");
}
}
printer->Print(
" return getDescriptor().getValues().get($index_text$);\n" " return getDescriptor().getValues().get($index_text$);\n"
"}\n" "}\n"
"public final com.google.protobuf.Descriptors.EnumDescriptor\n" "public final com.google.protobuf.Descriptors.EnumDescriptor\n"
@ -279,15 +297,22 @@ void EnumGenerator::Generate(io::Printer* printer) {
// for every enum. // for every enum.
printer->Print("values();\n"); printer->Print("values();\n");
} else { } else {
printer->Print("getStaticValuesArray();\n");
printer->Print("private static $classname$[] getStaticValuesArray() {\n",
"classname", descriptor_->name());
printer->Indent();
printer->Print( printer->Print(
"{\n" "return new $classname$[] {\n"
" "); " ",
"classname", descriptor_->name());
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
printer->Print("$name$, ", "name", descriptor_->value(i)->name()); printer->Print("$name$, ", "name", descriptor_->value(i)->name());
} }
printer->Print( printer->Print(
"\n" "\n"
"};\n"); "};\n");
printer->Outdent();
printer->Print("}");
} }
printer->Print( printer->Print(

@ -81,7 +81,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// with v2.5.0/v2.6.1, and remove the @SuppressWarnings annotations. // with v2.5.0/v2.6.1, and remove the @SuppressWarnings annotations.
(*variables)["for_number"] = "valueOf"; (*variables)["for_number"] = "valueOf";
if (SupportFieldPresence(descriptor->file())) { if (SupportFieldPresence(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit. // For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
(*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
@ -145,7 +145,7 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {} ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {}
int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const { int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const {
return SupportFieldPresence(descriptor_->file()) ? 1 : 0; return SupportFieldPresence(descriptor_) ? 1 : 0;
} }
int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const {
@ -154,7 +154,7 @@ int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const {
void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
io::Printer* printer) const { io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_, printer->Print(variables_,
"$deprecation$boolean has$capitalized_name$();\n"); "$deprecation$boolean has$capitalized_name$();\n");
@ -171,27 +171,28 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, "private int $name$_;\n"); printer->Print(variables_, "private int $name$_;\n");
PrintExtraFieldInfo(variables_, printer); PrintExtraFieldInfo(variables_, printer);
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print( printer->Print(variables_,
variables_, "@java.lang.Override $deprecation$public boolean "
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" "${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n" " return $get_has_field_bit_message$;\n"
"}\n"); "}\n");
printer->Annotate("{", "}", descriptor_); printer->Annotate("{", "}", descriptor_);
} }
if (SupportUnknownEnumValue(descriptor_->file())) { if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print( printer->Print(variables_,
variables_, "@java.lang.Override $deprecation$public int "
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" "${$get$capitalized_name$Value$}$() {\n"
" return $name$_;\n" " return $name$_;\n"
"}\n"); "}\n");
printer->Annotate("{", "}", descriptor_); printer->Annotate("{", "}", descriptor_);
} }
WriteFieldAccessorDocComment(printer, descriptor_, GETTER); WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" "@java.lang.Override $deprecation$public $type$ "
"${$get$capitalized_name$$}$() {\n"
" @SuppressWarnings(\"deprecation\")\n" " @SuppressWarnings(\"deprecation\")\n"
" $type$ result = $type$.$for_number$($name$_);\n" " $type$ result = $type$.$for_number$($name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
@ -202,22 +203,22 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
void ImmutableEnumFieldGenerator::GenerateBuilderMembers( void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const { io::Printer* printer) const {
printer->Print(variables_, "private int $name$_ = $default_number$;\n"); printer->Print(variables_, "private int $name$_ = $default_number$;\n");
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print( printer->Print(variables_,
variables_, "@java.lang.Override $deprecation$public boolean "
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" "${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_builder$;\n" " return $get_has_field_bit_builder$;\n"
"}\n"); "}\n");
printer->Annotate("{", "}", descriptor_); printer->Annotate("{", "}", descriptor_);
} }
if (SupportUnknownEnumValue(descriptor_->file())) { if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print( printer->Print(variables_,
variables_, "@java.lang.Override $deprecation$public int "
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" "${$get$capitalized_name$Value$}$() {\n"
" return $name$_;\n" " return $name$_;\n"
"}\n"); "}\n");
printer->Annotate("{", "}", descriptor_); printer->Annotate("{", "}", descriptor_);
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER, WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER,
/* builder */ true); /* builder */ true);
@ -232,6 +233,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
} }
WriteFieldAccessorDocComment(printer, descriptor_, GETTER); WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" @SuppressWarnings(\"deprecation\")\n" " @SuppressWarnings(\"deprecation\")\n"
" $type$ result = $type$.$for_number$($name$_);\n" " $type$ result = $type$.$for_number$($name$_);\n"
@ -284,7 +286,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderClearCode(
void ImmutableEnumFieldGenerator::GenerateMergingCode( void ImmutableEnumFieldGenerator::GenerateMergingCode(
io::Printer* printer) const { io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
printer->Print(variables_, printer->Print(variables_,
"if (other.has$capitalized_name$()) {\n" "if (other.has$capitalized_name$()) {\n"
" set$capitalized_name$(other.get$capitalized_name$());\n" " set$capitalized_name$(other.get$capitalized_name$());\n"
@ -302,7 +304,7 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode(
void ImmutableEnumFieldGenerator::GenerateBuildingCode( void ImmutableEnumFieldGenerator::GenerateBuildingCode(
io::Printer* printer) const { io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n"
" $set_has_field_bit_to_local$;\n" " $set_has_field_bit_to_local$;\n"
@ -386,7 +388,7 @@ ImmutableEnumOneofFieldGenerator::~ImmutableEnumOneofFieldGenerator() {}
void ImmutableEnumOneofFieldGenerator::GenerateMembers( void ImmutableEnumOneofFieldGenerator::GenerateMembers(
io::Printer* printer) const { io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer); PrintExtraFieldInfo(variables_, printer);
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print( printer->Print(
variables_, variables_,
@ -423,10 +425,11 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers(
void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
io::Printer* printer) const { io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print( printer->Print(
variables_, variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n" " return $has_oneof_case_message$;\n"
"}\n"); "}\n");
@ -436,6 +439,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print( printer->Print(
variables_, variables_,
"@java.lang.Override\n"
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" if ($has_oneof_case_message$) {\n" " if ($has_oneof_case_message$) {\n"
" return ((java.lang.Integer) $oneof_name$_).intValue();\n" " return ((java.lang.Integer) $oneof_name$_).intValue();\n"
@ -457,6 +461,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
} }
WriteFieldAccessorDocComment(printer, descriptor_, GETTER); WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n" " if ($has_oneof_case_message$) {\n"
" @SuppressWarnings(\"deprecation\")\n" " @SuppressWarnings(\"deprecation\")\n"
@ -650,6 +655,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print( printer->Print(
variables_, variables_,
"@java.lang.Override\n"
"$deprecation$public java.util.List<$type$> " "$deprecation$public java.util.List<$type$> "
"${$get$capitalized_name$List$}$() {\n" "${$get$capitalized_name$List$}$() {\n"
" return new com.google.protobuf.Internal.ListAdapter<\n" " return new com.google.protobuf.Internal.ListAdapter<\n"
@ -659,6 +665,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
printer->Print( printer->Print(
variables_, variables_,
"@java.lang.Override\n"
"$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n" " return $name$_.size();\n"
"}\n"); "}\n");
@ -666,6 +673,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
printer->Print( printer->Print(
variables_, variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_converter_.convert($name$_.get(index));\n" " return $name$_converter_.convert($name$_.get(index));\n"
"}\n"); "}\n");
@ -673,6 +681,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
if (SupportUnknownEnumValue(descriptor_->file())) { if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_, printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public java.util.List<java.lang.Integer>\n" "$deprecation$public java.util.List<java.lang.Integer>\n"
"${$get$capitalized_name$ValueList$}$() {\n" "${$get$capitalized_name$ValueList$}$() {\n"
" return $name$_;\n" " return $name$_;\n"
@ -681,6 +690,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, WriteFieldEnumValueAccessorDocComment(printer, descriptor_,
LIST_INDEXED_GETTER); LIST_INDEXED_GETTER);
printer->Print(variables_, printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public int " "$deprecation$public int "
"${$get$capitalized_name$Value$}$(int index) {\n" "${$get$capitalized_name$Value$}$(int index) {\n"
" return $name$_.get(index);\n" " return $name$_.get(index);\n"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save