Merge tag 'refs/tags/sync-piper' into sync-stage

# Conflicts:
#	java/core/src/main/java/com/google/protobuf/Utf8.java
pull/9652/head
Adam Cozzette 3 years ago
commit 2f09990544
  1. BIN
      csharp/src/Google.Protobuf.Test/testprotos.pb
  2. 2
      csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
  3. 4
      java/core/src/main/java/com/google/protobuf/AbstractMessage.java
  4. 54
      java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
  5. 3
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  6. 38
      java/core/src/main/java/com/google/protobuf/Utf8.java
  7. 12
      java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java
  8. 2
      java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java
  9. 4
      java/core/src/test/java/com/google/protobuf/MessageTest.java
  10. 3
      java/core/src/test/java/com/google/protobuf/ServiceTest.java
  11. 1
      java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java
  12. 2
      objectivec/GPBEmpty.pbobjc.h
  13. 1
      php/src/Google/Protobuf/GPBEmpty.php
  14. 5
      python/google/protobuf/descriptor.py
  15. 7
      python/google/protobuf/internal/api_implementation.py
  16. 39
      python/google/protobuf/internal/decoder.py
  17. 7
      python/google/protobuf/internal/message_test.py
  18. 10
      python/google/protobuf/internal/text_format_test.py
  19. 119
      python/google/protobuf/internal/unknown_fields_test.py
  20. 7
      python/google/protobuf/pyext/cpp_message.py
  21. 64
      python/google/protobuf/text_format.py
  22. 125
      python/google/protobuf/unknown_fields.py
  23. 7
      python/setup.py
  24. 4
      src/google/protobuf/any.h
  25. 87
      src/google/protobuf/any.pb.cc
  26. 65
      src/google/protobuf/any.pb.h
  27. 438
      src/google/protobuf/api.pb.cc
  28. 287
      src/google/protobuf/api.pb.h
  29. 1
      src/google/protobuf/arena_test_util.cc
  30. 2
      src/google/protobuf/arena_test_util.h
  31. 6
      src/google/protobuf/arena_unittest.cc
  32. 4
      src/google/protobuf/arenaz_sampler.cc
  33. 16
      src/google/protobuf/compiler/command_line_interface.cc
  34. 56
      src/google/protobuf/compiler/cpp/cpp_enum_field.cc
  35. 13
      src/google/protobuf/compiler/cpp/cpp_enum_field.h
  36. 2
      src/google/protobuf/compiler/cpp/cpp_extension.cc
  37. 19
      src/google/protobuf/compiler/cpp/cpp_field.cc
  38. 30
      src/google/protobuf/compiler/cpp/cpp_field.h
  39. 2
      src/google/protobuf/compiler/cpp/cpp_file.cc
  40. 2
      src/google/protobuf/compiler/cpp/cpp_generator.cc
  41. 54
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  42. 17
      src/google/protobuf/compiler/cpp/cpp_helpers.h
  43. 25
      src/google/protobuf/compiler/cpp/cpp_map_field.cc
  44. 5
      src/google/protobuf/compiler/cpp/cpp_map_field.h
  45. 423
      src/google/protobuf/compiler/cpp/cpp_message.cc
  46. 5
      src/google/protobuf/compiler/cpp/cpp_message.h
  47. 47
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  48. 9
      src/google/protobuf/compiler/cpp/cpp_message_field.h
  49. 1
      src/google/protobuf/compiler/cpp/cpp_options.h
  50. 40
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc
  51. 61
      src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
  52. 13
      src/google/protobuf/compiler/cpp/cpp_primitive_field.h
  53. 40
      src/google/protobuf/compiler/cpp/cpp_string_field.cc
  54. 7
      src/google/protobuf/compiler/cpp/cpp_string_field.h
  55. 18
      src/google/protobuf/compiler/cpp/cpp_unittest.inc
  56. 11
      src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
  57. 22
      src/google/protobuf/compiler/java/java_helpers.cc
  58. 25
      src/google/protobuf/compiler/java/java_plugin_unittest.cc
  59. 4
      src/google/protobuf/compiler/main.cc
  60. 59
      src/google/protobuf/compiler/parser.cc
  61. 4
      src/google/protobuf/compiler/parser.h
  62. 3
      src/google/protobuf/compiler/plugin.cc
  63. 534
      src/google/protobuf/compiler/plugin.pb.cc
  64. 494
      src/google/protobuf/compiler/plugin.pb.h
  65. 10
      src/google/protobuf/compiler/python/python_generator.cc
  66. 2
      src/google/protobuf/compiler/python/python_generator.h
  67. 2
      src/google/protobuf/compiler/python/python_helpers.cc
  68. 5
      src/google/protobuf/compiler/python/python_plugin_unittest.cc
  69. 6
      src/google/protobuf/compiler/python/python_pyi_generator.cc
  70. 2
      src/google/protobuf/compiler/python/python_pyi_generator.h
  71. 2
      src/google/protobuf/compiler/subprocess.cc
  72. 4
      src/google/protobuf/compiler/zip_writer.h
  73. 4050
      src/google/protobuf/descriptor.pb.cc
  74. 3733
      src/google/protobuf/descriptor.pb.h
  75. 62
      src/google/protobuf/duration.pb.cc
  76. 25
      src/google/protobuf/duration.pb.h
  77. 4
      src/google/protobuf/empty.pb.cc
  78. 3
      src/google/protobuf/empty.pb.h
  79. 1
      src/google/protobuf/empty.proto
  80. 56
      src/google/protobuf/extension_set.cc
  81. 3
      src/google/protobuf/extension_set_heavy.cc
  82. 60
      src/google/protobuf/extension_set_unittest.cc
  83. 45
      src/google/protobuf/field_mask.pb.cc
  84. 41
      src/google/protobuf/field_mask.pb.h
  85. 22
      src/google/protobuf/generated_message_reflection_unittest.cc
  86. 2
      src/google/protobuf/io/gzip_stream.h
  87. 21
      src/google/protobuf/io/tokenizer.cc
  88. 10
      src/google/protobuf/lite_unittest.cc
  89. 4
      src/google/protobuf/map_field_test.cc
  90. 1
      src/google/protobuf/map_lite_test_util.cc
  91. 22
      src/google/protobuf/map_test.inc
  92. 2
      src/google/protobuf/map_test_util.inc
  93. 4
      src/google/protobuf/message_lite.h
  94. 2
      src/google/protobuf/parse_context.h
  95. 11
      src/google/protobuf/port_def.inc
  96. 1
      src/google/protobuf/port_undef.inc
  97. 20
      src/google/protobuf/repeated_ptr_field.h
  98. 48
      src/google/protobuf/source_context.pb.cc
  99. 29
      src/google/protobuf/source_context.pb.h
  100. 144
      src/google/protobuf/struct.pb.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -47,8 +47,6 @@ namespace Google.Protobuf.WellKnownTypes {
/// service Foo {
/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
/// }
///
/// The JSON representation for `Empty` is empty JSON object `{}`.
/// </summary>
public sealed partial class Empty : pb::IMessage<Empty>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE

@ -94,13 +94,13 @@ public abstract class AbstractMessage
return MessageReflection.delimitWithCommas(findInitializationErrors());
}
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
// TODO(jieluo): Clear it when all subclasses have implemented this method.
@Override
public boolean hasOneof(OneofDescriptor oneof) {
throw new UnsupportedOperationException("hasOneof() is not implemented.");
}
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
// TODO(jieluo): Clear it when all subclasses have implemented this method.
@Override
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
throw new UnsupportedOperationException("getOneofFieldDescriptor() is not implemented.");

@ -996,8 +996,6 @@ public abstract class CodedOutputStream extends ByteOutput {
writeLazy(bytes, 0, bytes.length);
} catch (IndexOutOfBoundsException e) {
throw new OutOfSpaceException(e);
} catch (OutOfSpaceException e) {
throw e;
}
}
@ -1345,49 +1343,19 @@ public abstract class CodedOutputStream extends ByteOutput {
@Override
public final void writeUInt32NoTag(int value) throws IOException {
if (HAS_UNSAFE_ARRAY_OPERATIONS
&& !Android.isOnAndroidDevice()
&& spaceLeft() >= MAX_VARINT32_SIZE) {
if ((value & ~0x7F) == 0) {
UnsafeUtil.putByte(buffer, position++, (byte) value);
return;
}
UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
value >>>= 7;
if ((value & ~0x7F) == 0) {
UnsafeUtil.putByte(buffer, position++, (byte) value);
return;
}
UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
value >>>= 7;
if ((value & ~0x7F) == 0) {
UnsafeUtil.putByte(buffer, position++, (byte) value);
return;
}
UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
value >>>= 7;
if ((value & ~0x7F) == 0) {
UnsafeUtil.putByte(buffer, position++, (byte) value);
return;
}
UnsafeUtil.putByte(buffer, position++, (byte) (value | 0x80));
value >>>= 7;
UnsafeUtil.putByte(buffer, position++, (byte) value);
} else {
try {
while (true) {
if ((value & ~0x7F) == 0) {
buffer[position++] = (byte) value;
return;
} else {
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
value >>>= 7;
}
try {
while (true) {
if ((value & ~0x7F) == 0) {
buffer[position++] = (byte) value;
return;
} else {
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
value >>>= 7;
}
} catch (IndexOutOfBoundsException e) {
throw new OutOfSpaceException(
String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
}
} catch (IndexOutOfBoundsException e) {
throw new OutOfSpaceException(
String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
}
}

@ -43,6 +43,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -1552,7 +1553,6 @@ public final class TextFormat {
* control the parser behavior.
*/
public static class Parser {
private int debugStringSilentMarker;
/**
* A valid silent marker appears between a field name and its value. If there is a ":" in
@ -1803,7 +1803,6 @@ public final class TextFormat {
while (!tokenizer.atEnd()) {
mergeField(tokenizer, extensionRegistry, target, unknownFields);
}
checkUnknownFields(unknownFields);
}

@ -1366,30 +1366,26 @@ final class Utf8 {
}
@Override
String decodeUtf8(byte[] bytes, int index, int size)
throws InvalidProtocolBufferException {
try {
String s = new String(bytes, index, size, Internal.UTF_8);
// "\uFFFD" is UTF-8 default replacement string, which illegal byte sequences get replaced with.
if (!s.contains("\uFFFD")) {
return s;
}
String decodeUtf8(byte[] bytes, int index, int size) throws InvalidProtocolBufferException {
String s = new String(bytes, index, size, Internal.UTF_8);
// Since s contains "\uFFFD" there are 2 options:
// 1) The byte array slice is invalid UTF-8.
// 2) The byte array slice is valid UTF-8 and contains encodings for "\uFFFD".
// To rule out (1), we encode s and compare it to the byte array slice.
// If the byte array slice was invalid UTF-8, then we would get a different sequence of bytes.
if (Arrays.equals(s.getBytes(Internal.UTF_8), Arrays.copyOfRange(bytes, index, index + size))) {
return s;
}
// "\uFFFD" is UTF-8 default replacement string, which illegal byte sequences get replaced
// with.
if (!s.contains("\uFFFD")) {
return s;
}
throw InvalidProtocolBufferException.invalidUtf8();
} catch (IndexOutOfBoundsException e) {
throw new ArrayIndexOutOfBoundsException(
String.format("buffer length=%d, index=%d, size=%d", bytes.length, index, size));
// Since s contains "\uFFFD" there are 2 options:
// 1) The byte array slice is invalid UTF-8.
// 2) The byte array slice is valid UTF-8 and contains encodings for "\uFFFD".
// To rule out (1), we encode s and compare it to the byte array slice.
// If the byte array slice was invalid UTF-8, then we would get a different sequence of bytes.
if (Arrays.equals(
s.getBytes(Internal.UTF_8), Arrays.copyOfRange(bytes, index, index + size))) {
return s;
}
throw InvalidProtocolBufferException.invalidUtf8();
}
@Override

@ -253,13 +253,13 @@ public class DecodeUtf8Test extends TestCase {
try {
UNSAFE_PROCESSOR.decodeUtf8(bytes, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
SAFE_PROCESSOR.decodeUtf8(bytes, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
@ -269,13 +269,13 @@ public class DecodeUtf8Test extends TestCase {
try {
UNSAFE_PROCESSOR.decodeUtf8(direct, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
SAFE_PROCESSOR.decodeUtf8(direct, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
@ -285,13 +285,13 @@ public class DecodeUtf8Test extends TestCase {
try {
UNSAFE_PROCESSOR.decodeUtf8(heap, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
SAFE_PROCESSOR.decodeUtf8(heap, index, size);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// Expected.
}
}

@ -76,7 +76,7 @@ public class LazyStringEndToEndTest {
ByteString bytes = tV2.toByteString();
assertThat(bytes).isEqualTo(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
tV2.getOptionalString();
String unused = tV2.getOptionalString();
bytes = tV2.toByteString();
assertThat(bytes).isEqualTo(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
}

@ -337,7 +337,7 @@ public class MessageTest {
/** Test reading unset repeated message from DynamicMessage. */
@Test
public void testDynamicRepeatedMessageNull() throws Exception {
TestRequired.getDescriptor();
Descriptors.Descriptor unused = TestRequired.getDescriptor();
DynamicMessage result =
DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
.mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
@ -365,7 +365,7 @@ public class MessageTest {
.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
.build();
TestRequired.getDescriptor();
Descriptors.Descriptor unused = TestRequired.getDescriptor();
DynamicMessage result =
DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
.mergeFrom(DynamicMessage.newBuilder(repeatedNested).build())

@ -251,7 +251,4 @@ public class ServiceTest {
assertThat(file.getServices().get(0).getMethods()).hasSize(1);
assertThat(file.getServices().get(0).getMethods().get(0).getName()).isEqualTo("Foo");
}
// =================================================================
}

@ -49,6 +49,7 @@ public class TestBadIdentifiers extends TestCase {
TestBadIdentifiersProto.Override.getDefaultInstance();
}
@SuppressWarnings("IgnoredPureGetter") // TODO(b/221602772): Fix this
public void testGetDescriptor() {
TestBadIdentifiersProto.getDescriptor();
TestBadIdentifiersProto.Descriptor.getDefaultInstance().getDescriptor();

@ -46,8 +46,6 @@ GPB_FINAL @interface GPBEmptyRoot : GPBRootObject
* service Foo {
* rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
* }
*
* The JSON representation for `Empty` is empty JSON object `{}`.
**/
GPB_FINAL @interface GPBEmpty : GPBMessage

@ -15,7 +15,6 @@ use Google\Protobuf\Internal\GPBUtil;
* service Foo {
* rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
* }
* The JSON representation for `Empty` is empty JSON object `{}`.
*
* Generated from protobuf message <code>google.protobuf.Empty</code>
*/

@ -44,7 +44,10 @@ if api_implementation.Type() == 'cpp':
# Used by MakeDescriptor in cpp mode
import binascii
import os
from google.protobuf.pyext import _message
if api_implementation._Version() == 3:
from google3.third_party.upb.python import _message
else:
from google.protobuf.pyext import _message
_USE_C_DESCRIPTORS = True

@ -31,6 +31,7 @@
"""Determine which implementation of the protobuf API is used in this process.
"""
import importlib
import os
import sys
import warnings
@ -48,6 +49,7 @@ if _api_version == 1:
raise ValueError('api_version=1 is no longer supported.')
_default_implementation_type = ('cpp' if _api_version > 0 else 'python')
@ -102,6 +104,11 @@ def _SetType(implementation_type):
_implementation_type = implementation_type
def _Version():
"""Never use! For protobuf internal use only."""
return _api_version
# See comment on 'Type' above.
def Version():
return 2

@ -831,6 +831,45 @@ def MessageSetItemDecoder(descriptor):
return DecodeItem
def UnknownMessageSetItemDecoder():
"""Returns a decoder for a Unknown MessageSet item."""
type_id_tag_bytes = encoder.TagBytes(2, wire_format.WIRETYPE_VARINT)
message_tag_bytes = encoder.TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)
item_end_tag_bytes = encoder.TagBytes(1, wire_format.WIRETYPE_END_GROUP)
def DecodeUnknownItem(buffer):
pos = 0
end = len(buffer)
message_start = -1
message_end = -1
while 1:
(tag_bytes, pos) = ReadTag(buffer, pos)
if tag_bytes == type_id_tag_bytes:
(type_id, pos) = _DecodeVarint(buffer, pos)
elif tag_bytes == message_tag_bytes:
(size, message_start) = _DecodeVarint(buffer, pos)
pos = message_end = message_start + size
elif tag_bytes == item_end_tag_bytes:
break
else:
pos = SkipField(buffer, pos, end, tag_bytes)
if pos == -1:
raise _DecodeError('Missing group end tag.')
if pos > end:
raise _DecodeError('Truncated message.')
if type_id == -1:
raise _DecodeError('MessageSet item missing type_id.')
if message_start == -1:
raise _DecodeError('MessageSet item missing message.')
return (type_id, buffer[message_start:message_end].tobytes())
return DecodeUnknownItem
# --------------------------------------------------------------------
def MapDecoder(field_descriptor, new_default, is_message_map):

@ -129,10 +129,13 @@ class MessageTest(unittest.TestCase):
# TODO(jieluo): Fix cpp extension to raise error instead of warning.
# b/27494216
end_tag = encoder.TagBytes(1, 4)
if api_implementation.Type() == 'python':
if (api_implementation.Type() == 'python' or
api_implementation._Version() == 3):
with self.assertRaises(message.DecodeError) as context:
msg.FromString(end_tag)
self.assertEqual('Unexpected end-group tag.', str(context.exception))
if api_implementation.Type() == 'python':
# Only pure-Python has an error message this specific.
self.assertEqual('Unexpected end-group tag.', str(context.exception))
# Field number 0 is illegal.
self.assertRaises(message.DecodeError, msg.FromString, b'\3\4')

@ -48,6 +48,7 @@ from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import any_test_pb2 as test_extend_any
from google.protobuf.internal import api_implementation
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import test_proto3_optional_pb2
from google.protobuf.internal import test_util
@ -582,6 +583,10 @@ class TextFormatMessageToStringTests(TextFormatBase):
text_format.Parse(expected_text, parsed_proto)
self.assertEqual(message_proto, parsed_proto)
@unittest.skipIf(
api_implementation._Version() == 3,
"upb API doesn't support old UnknownField API. The TextFormat library "
"needs to convert to the new API.")
def testPrintUnknownFieldsEmbeddedMessageInBytes(self, message_module):
inner_msg = message_module.TestAllTypes()
inner_msg.optional_int32 = 101
@ -1470,9 +1475,11 @@ class Proto2Tests(TextFormatBase):
text = ('message_set {\n'
' [unknown_extension] {\n'
' i: 23\n'
' bin: "\xe0"'
' repeated_i: []\n'
' bin: "\xe0"\n'
' [nested_unknown_ext]: {\n'
' i: 23\n'
' repeated_i: [1, 2]\n'
' x: x\n'
' test: "test_string"\n'
' floaty_float: -0.315\n'
@ -1485,6 +1492,7 @@ class Proto2Tests(TextFormatBase):
' i: 24\n'
' pointfloat: .3\n'
' test: "test_string"\n'
' repeated_test: ["test_string1", "test_string2"]\n'
' floaty_float: -0.315\n'
' num: -inf\n'
' long_string: "test" "test2" \n'

@ -49,7 +49,7 @@ from google.protobuf.internal import testing_refleaks
from google.protobuf.internal import type_checkers
from google.protobuf.internal import wire_format
from google.protobuf import descriptor
from google.protobuf import unknown_fields
try:
import tracemalloc # pylint: disable=g-import-not-at-top
except ImportError:
@ -106,14 +106,14 @@ class UnknownFieldsTest(unittest.TestCase):
proto = message_set_extensions_pb2.TestMessageSet()
proto.MergeFromString(serialized)
unknown_fields = proto.UnknownFields()
self.assertEqual(len(unknown_fields), 1)
unknown_field_set = unknown_fields.UnknownFieldSet(proto)
self.assertEqual(len(unknown_field_set), 1)
# Unknown field should have wire format data which can be parsed back to
# original message.
self.assertEqual(unknown_fields[0].field_number, item.type_id)
self.assertEqual(unknown_fields[0].wire_type,
self.assertEqual(unknown_field_set[0].field_number, item.type_id)
self.assertEqual(unknown_field_set[0].wire_type,
wire_format.WIRETYPE_LENGTH_DELIMITED)
d = unknown_fields[0].data
d = unknown_field_set[0].data
message_new = message_set_extensions_pb2.TestMessageSetExtension1()
message_new.ParseFromString(d)
self.assertEqual(message1, message_new)
@ -196,11 +196,11 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
decoder(memoryview(value), 0, len(value), self.all_fields, result_dict)
self.assertEqual(expected_value, result_dict[field_descriptor])
def CheckUnknownField(self, name, unknown_fields, expected_value):
def CheckUnknownField(self, name, unknown_field_set, expected_value):
field_descriptor = self.descriptor.fields_by_name[name]
expected_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[
field_descriptor.type]
for unknown_field in unknown_fields:
for unknown_field in unknown_field_set:
if unknown_field.field_number == field_descriptor.number:
self.assertEqual(expected_type, unknown_field.wire_type)
if expected_type == 3:
@ -218,57 +218,57 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
self.assertEqual(expected_value, unknown_field.data)
def testCheckUnknownFieldValue(self):
unknown_fields = self.empty_message.UnknownFields()
unknown_field_set = unknown_fields.UnknownFieldSet(self.empty_message)
# Test enum.
self.CheckUnknownField('optional_nested_enum',
unknown_fields,
unknown_field_set,
self.all_fields.optional_nested_enum)
self.InternalCheckUnknownField('optional_nested_enum',
self.all_fields.optional_nested_enum)
# Test repeated enum.
self.CheckUnknownField('repeated_nested_enum',
unknown_fields,
unknown_field_set,
self.all_fields.repeated_nested_enum)
self.InternalCheckUnknownField('repeated_nested_enum',
self.all_fields.repeated_nested_enum)
# Test varint.
self.CheckUnknownField('optional_int32',
unknown_fields,
unknown_field_set,
self.all_fields.optional_int32)
self.InternalCheckUnknownField('optional_int32',
self.all_fields.optional_int32)
# Test fixed32.
self.CheckUnknownField('optional_fixed32',
unknown_fields,
unknown_field_set,
self.all_fields.optional_fixed32)
self.InternalCheckUnknownField('optional_fixed32',
self.all_fields.optional_fixed32)
# Test fixed64.
self.CheckUnknownField('optional_fixed64',
unknown_fields,
unknown_field_set,
self.all_fields.optional_fixed64)
self.InternalCheckUnknownField('optional_fixed64',
self.all_fields.optional_fixed64)
# Test length delimited.
self.CheckUnknownField('optional_string',
unknown_fields,
unknown_field_set,
self.all_fields.optional_string.encode('utf-8'))
self.InternalCheckUnknownField('optional_string',
self.all_fields.optional_string)
# Test group.
self.CheckUnknownField('optionalgroup',
unknown_fields,
unknown_field_set,
(17, 0, 117))
self.InternalCheckUnknownField('optionalgroup',
self.all_fields.optionalgroup)
self.assertEqual(97, len(unknown_fields))
self.assertEqual(97, len(unknown_field_set))
def testCopyFrom(self):
message = unittest_pb2.TestEmptyMessage()
@ -286,18 +286,18 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
message.optional_int64 = 3
message.optional_uint32 = 4
destination = unittest_pb2.TestEmptyMessage()
unknown_fields = destination.UnknownFields()
self.assertEqual(0, len(unknown_fields))
unknown_field_set = unknown_fields.UnknownFieldSet(destination)
self.assertEqual(0, len(unknown_field_set))
destination.ParseFromString(message.SerializeToString())
# ParseFromString clears the message thus unknown fields is invalid.
with self.assertRaises(ValueError) as context:
len(unknown_fields)
self.assertIn('UnknownFields does not exist.',
str(context.exception))
unknown_fields = destination.UnknownFields()
self.assertEqual(2, len(unknown_fields))
# TODO(jieluo): add this back after implement new cpp unknown fields
# b/217277954
if api_implementation.Type() == 'cpp':
return
self.assertEqual(0, len(unknown_field_set))
unknown_field_set = unknown_fields.UnknownFieldSet(destination)
self.assertEqual(2, len(unknown_field_set))
destination.MergeFrom(source)
self.assertEqual(4, len(unknown_fields))
self.assertEqual(2, len(unknown_field_set))
# Check that the fields where correctly merged, even stored in the unknown
# fields set.
message.ParseFromString(destination.SerializeToString())
@ -306,14 +306,15 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
self.assertEqual(message.optional_int64, 3)
def testClear(self):
unknown_fields = self.empty_message.UnknownFields()
unknown_field_set = unknown_fields.UnknownFieldSet(self.empty_message)
self.empty_message.Clear()
# All cleared, even unknown fields.
self.assertEqual(self.empty_message.SerializeToString(), b'')
with self.assertRaises(ValueError) as context:
len(unknown_fields)
self.assertIn('UnknownFields does not exist.',
str(context.exception))
# TODO(jieluo): add this back after implement new cpp unknown fields
# b/217277954
if api_implementation.Type() == 'cpp':
return
self.assertEqual(len(unknown_field_set), 97)
@unittest.skipIf((sys.version_info.major, sys.version_info.minor) < (3, 4),
'tracemalloc requires python 3.4+')
@ -323,7 +324,7 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
def leaking_function():
for _ in range(nb_leaks):
self.empty_message.UnknownFields()
unknown_fields.UnknownFieldSet(self.empty_message)
tracemalloc.start()
snapshot1 = tracemalloc.take_snapshot()
@ -340,49 +341,47 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
message.optionalgroup.a = 123
destination = unittest_pb2.TestEmptyMessage()
destination.ParseFromString(message.SerializeToString())
sub_unknown_fields = destination.UnknownFields()[0].data
sub_unknown_fields = unknown_fields.UnknownFieldSet(destination)[0].data
self.assertEqual(1, len(sub_unknown_fields))
self.assertEqual(sub_unknown_fields[0].data, 123)
destination.Clear()
with self.assertRaises(ValueError) as context:
len(sub_unknown_fields)
self.assertIn('UnknownFields does not exist.',
str(context.exception))
with self.assertRaises(ValueError) as context:
# pylint: disable=pointless-statement
sub_unknown_fields[0]
self.assertIn('UnknownFields does not exist.',
str(context.exception))
# TODO(jieluo): add this back after implement new cpp unknown fields
# b/217277954
if api_implementation.Type() == 'cpp':
return
self.assertEqual(1, len(sub_unknown_fields))
self.assertEqual(sub_unknown_fields[0].data, 123)
message.Clear()
message.optional_uint32 = 456
nested_message = unittest_pb2.NestedTestAllTypes()
nested_message.payload.optional_nested_message.ParseFromString(
message.SerializeToString())
unknown_fields = (
nested_message.payload.optional_nested_message.UnknownFields())
self.assertEqual(unknown_fields[0].data, 456)
unknown_field_set = unknown_fields.UnknownFieldSet(
nested_message.payload.optional_nested_message)
self.assertEqual(unknown_field_set[0].data, 456)
nested_message.ClearField('payload')
self.assertEqual(unknown_fields[0].data, 456)
unknown_fields = (
nested_message.payload.optional_nested_message.UnknownFields())
self.assertEqual(0, len(unknown_fields))
self.assertEqual(unknown_field_set[0].data, 456)
unknown_field_set = unknown_fields.UnknownFieldSet(
nested_message.payload.optional_nested_message)
self.assertEqual(0, len(unknown_field_set))
def testUnknownField(self):
message = unittest_pb2.TestAllTypes()
message.optional_int32 = 123
destination = unittest_pb2.TestEmptyMessage()
destination.ParseFromString(message.SerializeToString())
unknown_field = destination.UnknownFields()[0]
unknown_field = unknown_fields.UnknownFieldSet(destination)[0]
destination.Clear()
with self.assertRaises(ValueError) as context:
unknown_field.data # pylint: disable=pointless-statement
self.assertIn('The parent message might be cleared.',
str(context.exception))
# TODO(jieluo): add this back after implement new cpp unknown fields
# b/217277954
if api_implementation.Type() == 'cpp':
return
self.assertEqual(unknown_field.data, 123)
def testUnknownExtensions(self):
message = unittest_pb2.TestEmptyMessageWithExtensions()
message.ParseFromString(self.all_fields_data)
self.assertEqual(len(message.UnknownFields()), 97)
self.assertEqual(len(unknown_fields.UnknownFieldSet(message)), 97)
self.assertEqual(message.SerializeToString(), self.all_fields_data)
@ -416,9 +415,9 @@ class UnknownEnumValuesTest(unittest.TestCase):
def CheckUnknownField(self, name, expected_value):
field_descriptor = self.descriptor.fields_by_name[name]
unknown_fields = self.missing_message.UnknownFields()
unknown_field_set = unknown_fields.UnknownFieldSet(self.missing_message)
count = 0
for field in unknown_fields:
for field in unknown_field_set:
if field.field_number == field_descriptor.number:
count += 1
if field_descriptor.label == descriptor.FieldDescriptor.LABEL_REPEATED:
@ -458,8 +457,8 @@ class UnknownEnumValuesTest(unittest.TestCase):
self.assertEqual([], self.missing_message.packed_nested_enum)
def testCheckUnknownFieldValueForEnum(self):
unknown_fields = self.missing_message.UnknownFields()
self.assertEqual(len(unknown_fields), 5)
unknown_field_set = unknown_fields.UnknownFieldSet(self.missing_message)
self.assertEqual(len(unknown_field_set), 5)
self.CheckUnknownField('optional_nested_enum',
self.message.optional_nested_enum)
self.CheckUnknownField('repeated_nested_enum',

@ -36,7 +36,12 @@ Descriptor objects at runtime backed by the protocol buffer C++ API.
__author__ = 'tibell@google.com (Johan Tibell)'
from google.protobuf.pyext import _message
from google.protobuf.internal import api_implementation
if api_implementation._Version() == 3:
from google3.third_party.upb.python import _message
else:
from google.protobuf.pyext import _message
class GeneratedProtocolMessageType(_message.MessageMeta):

@ -53,6 +53,7 @@ from google.protobuf.internal import decoder
from google.protobuf.internal import type_checkers
from google.protobuf import descriptor
from google.protobuf import text_encoding
from google.protobuf import unknown_fields
# pylint: disable=g-import-not-at-top
__all__ = ['MessageToString', 'Parse', 'PrintMessage', 'PrintField',
@ -136,8 +137,6 @@ def MessageToString(
Args:
message: The protocol buffers message.
as_utf8: Return unescaped Unicode for non-ASCII characters.
In Python 3 actual Unicode characters may appear as is in strings.
In Python 2 the return value will be valid UTF-8 rather than only ASCII.
as_one_line: Don't introduce newlines between fields.
use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
@ -223,6 +222,36 @@ def PrintMessage(message,
message_formatter=None,
print_unknown_fields=False,
force_colon=False):
"""Convert the message to text format and write it to the out stream.
Args:
message: The Message object to convert to text format.
out: A file handle to write the message to.
indent: The initial indent level for pretty print.
as_utf8: Return unescaped Unicode for non-ASCII characters.
as_one_line: Don't introduce newlines between fields.
use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
nesting.
use_index_order: If True, print fields of a proto message using the order
defined in source code instead of the field number. By default, use the
field number order.
float_format: If set, use this to specify float field formatting
(per the "Format Specification Mini-Language"); otherwise, shortest
float that has same value in wire will be printed. Also affect double
field if double_format is not set but float_format is set.
double_format: If set, use this to specify double field formatting
(per the "Format Specification Mini-Language"); if it is not set but
float_format is set, use float_format. Otherwise, str() is used.
use_field_number: If True, print field numbers instead of names.
descriptor_pool: A DescriptorPool used to resolve Any types.
message_formatter: A function(message, indent, as_one_line): unicode|None
to custom format selected sub-messages (usually based on message type).
Use to pretty print parts of the protobuf for easier diffing.
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.
"""
printer = _Printer(
out=out, indent=indent, as_utf8=as_utf8,
as_one_line=as_one_line,
@ -347,8 +376,6 @@ class _Printer(object):
out: To record the text format result.
indent: The initial indent level for pretty print.
as_utf8: Return unescaped Unicode for non-ASCII characters.
In Python 3 actual Unicode characters may appear as is in strings.
In Python 2 the return value will be valid UTF-8 rather than ASCII.
as_one_line: Don't introduce newlines between fields.
use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
@ -454,12 +481,12 @@ class _Printer(object):
self.PrintField(field, value)
if self.print_unknown_fields:
self._PrintUnknownFields(message.UnknownFields())
self._PrintUnknownFields(unknown_fields.UnknownFieldSet(message))
def _PrintUnknownFields(self, unknown_fields):
def _PrintUnknownFields(self, unknown_field_set):
"""Print unknown fields."""
out = self.out
for field in unknown_fields:
for field in unknown_field_set:
out.write(' ' * self.indent)
out.write(str(field.field_number))
if field.wire_type == WIRETYPE_START_GROUP:
@ -1143,9 +1170,12 @@ def _SkipFieldContents(tokenizer):
# start with "{" or "<" which indicates the beginning of a message body.
# If there is no ":" or there is a "{" or "<" after ":", this field has
# to be a message or the input is ill-formed.
if tokenizer.TryConsume(':') and not tokenizer.LookingAt(
'{') and not tokenizer.LookingAt('<'):
_SkipFieldValue(tokenizer)
if tokenizer.TryConsume(
':') and not tokenizer.LookingAt('{') and not tokenizer.LookingAt('<'):
if tokenizer.LookingAt('['):
_SkipRepeatedFieldValue(tokenizer)
else:
_SkipFieldValue(tokenizer)
else:
_SkipFieldMessage(tokenizer)
@ -1214,6 +1244,20 @@ def _SkipFieldValue(tokenizer):
raise ParseError('Invalid field value: ' + tokenizer.token)
def _SkipRepeatedFieldValue(tokenizer):
"""Skips over a repeated field value.
Args:
tokenizer: A tokenizer to parse the field value.
"""
tokenizer.Consume('[')
if not tokenizer.LookingAt(']'):
_SkipFieldValue(tokenizer)
while tokenizer.TryConsume(','):
_SkipFieldValue(tokenizer)
tokenizer.Consume(']')
class Tokenizer(object):
"""Protocol buffer text representation tokenizer.

@ -0,0 +1,125 @@
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# https://developers.google.com/protocol-buffers/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Contains Unknown Fields APIs.
Simple usage example:
unknown_field_set = UnknownFieldSet(message)
for unknown_field in unknown_field_set:
wire_type = unknown_field.wire_type
field_number = unknown_field.field_number
data = unknown_field.data
"""
from google.protobuf.internal import api_implementation
from google.protobuf.internal import decoder
from google.protobuf.internal import wire_format
if api_implementation.Type() == 'cpp':
def UnknownFieldSet(msg):
# New UnknownFieldSet in cpp extension has not implemented yet. Fall
# back to old API
# TODO(jieluo): Add UnknownFieldSet for cpp extension.
return msg.UnknownFields()
else:
class UnknownField:
"""A parsed unknown field."""
# Disallows assignment to other attributes.
__slots__ = ['_field_number', '_wire_type', '_data']
def __init__(self, field_number, wire_type, data):
self._field_number = field_number
self._wire_type = wire_type
self._data = data
return
@property
def field_number(self):
return self._field_number
@property
def wire_type(self):
return self._wire_type
@property
def data(self):
return self._data
class UnknownFieldSet:
"""UnknownField container."""
# Disallows assignment to other attributes.
__slots__ = ['_values']
def __init__(self, msg):
def InternalAdd(field_number, wire_type, data):
unknown_field = UnknownField(field_number, wire_type, data)
self._values.append(unknown_field)
self._values = []
msg_des = msg.DESCRIPTOR
# pylint: disable=protected-access
unknown_fields = msg._unknown_fields
if (msg_des.has_options and
msg_des.GetOptions().message_set_wire_format):
local_decoder = decoder.UnknownMessageSetItemDecoder()
for _, buffer in unknown_fields:
(field_number, data) = local_decoder(memoryview(buffer))
InternalAdd(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED, data)
else:
for tag_bytes, buffer in unknown_fields:
# pylint: disable=protected-access
(tag, _) = decoder._DecodeVarint(tag_bytes, 0)
field_number, wire_type = wire_format.UnpackTag(tag)
if field_number == 0:
raise RuntimeError('Field number 0 is illegal.')
(data, _) = decoder._DecodeUnknownField(
memoryview(buffer), 0, wire_type)
InternalAdd(field_number, wire_type, data)
def __getitem__(self, index):
size = len(self._values)
if index < 0:
index += size
if index < 0 or index >= size:
raise IndexError('index %d out of range'.index)
return self._values[index]
def __len__(self):
return len(self._values)
def __iter__(self):
return iter(self._values)

@ -115,8 +115,11 @@ def GenerateUnittestProtos():
GenProto('google/protobuf/internal/factory_test1.proto', False)
GenProto('google/protobuf/internal/factory_test2.proto', False)
GenProto('google/protobuf/internal/file_options_test.proto', False)
GenProto('google/protobuf/internal/import_test_package/import_public.proto', False)
GenProto('google/protobuf/internal/import_test_package/import_public_nested.proto', False)
GenProto('google/protobuf/internal/import_test_package/import_public.proto',
False)
GenProto(
'google/protobuf/internal/import_test_package/import_public_nested.proto',
False)
GenProto('google/protobuf/internal/import_test_package/inner.proto', False)
GenProto('google/protobuf/internal/import_test_package/outer.proto', False)
GenProto('google/protobuf/internal/missing_enum_values.proto', False)

@ -130,8 +130,8 @@ class PROTOBUF_EXPORT AnyMetadata {
// *full_type_name. Returns false if the type_url does not have a "/"
// in the type url separating the full type name.
//
// NOTE: this function is available publicly as:
// google::protobuf::Any() // static method on the generated message type.
// NOTE: this function is available publicly as a static method on the
// generated message type: google::protobuf::Any::ParseAnyTypeUrl()
bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name);
// Get the proto type name and prefix from Any::type_url value. For example,

@ -26,10 +26,11 @@ namespace _pbi = _pb::internal;
#endif // __llvm__
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Any::Any(
::_pbi::ConstantInitialized)
: type_url_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, value_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, _any_metadata_(&type_url_, &value_){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.type_url_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.value_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._any_metadata_)*/{&_impl_.type_url_, &_impl_.value_}} {}
struct AnyDefaultTypeInternal {
PROTOBUF_CONSTEXPR AnyDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -51,8 +52,8 @@ const uint32_t TableStruct_google_2fprotobuf_2fany_2eproto::offsets[] PROTOBUF_S
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, value_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.value_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Any)},
@ -108,43 +109,56 @@ class Any::_Internal {
Any::Any(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
_any_metadata_(&type_url_, &value_) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Any)
}
Any::Any(const Any& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_any_metadata_(&type_url_, &value_) {
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.type_url_){}
, decltype(_impl_.value_){}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._any_metadata_)*/{&_impl_.type_url_, &_impl_.value_}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
type_url_.InitDefault();
_impl_.type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set("", GetArenaForAllocation());
_impl_.type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_type_url().empty()) {
type_url_.Set(from._internal_type_url(),
_impl_.type_url_.Set(from._internal_type_url(),
GetArenaForAllocation());
}
value_.InitDefault();
_impl_.value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set("", GetArenaForAllocation());
_impl_.value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_value().empty()) {
value_.Set(from._internal_value(),
_impl_.value_.Set(from._internal_value(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
}
inline void Any::SharedCtor() {
type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
inline void Any::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.type_url_){}
, decltype(_impl_.value_){}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._any_metadata_)*/{&_impl_.type_url_, &_impl_.value_}
};
_impl_.type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
Any::~Any() {
@ -158,12 +172,13 @@ Any::~Any() {
inline void Any::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
type_url_.Destroy();
value_.Destroy();
_impl_.type_url_.Destroy();
_impl_.value_.Destroy();
_impl_._any_metadata_.~AnyMetadata();
}
void Any::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Any::Clear() {
@ -172,8 +187,8 @@ void Any::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
type_url_.ClearToEmpty();
value_.ClearToEmpty();
_impl_.type_url_.ClearToEmpty();
_impl_.value_.ClearToEmpty();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -277,7 +292,7 @@ size_t Any::ByteSizeLong() const {
this->_internal_value());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Any::_class_data_ = {
@ -325,12 +340,12 @@ void Any::InternalSwap(Any* other) {
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&type_url_, lhs_arena,
&other->type_url_, rhs_arena
&_impl_.type_url_, lhs_arena,
&other->_impl_.type_url_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&value_, lhs_arena,
&other->value_, rhs_arena
&_impl_.value_, lhs_arena,
&other->_impl_.value_, rhs_arena
);
}

@ -109,14 +109,14 @@ class PROTOBUF_EXPORT Any final :
// implements Any -----------------------------------------------
bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message) {
return _any_metadata_.PackFrom(GetArena(), message);
return _impl_._any_metadata_.PackFrom(GetArena(), message);
}
bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message,
::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) {
return _any_metadata_.PackFrom(GetArena(), message, type_url_prefix);
return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix);
}
bool UnpackTo(::PROTOBUF_NAMESPACE_ID::Message* message) const {
return _any_metadata_.UnpackTo(message);
return _impl_._any_metadata_.UnpackTo(message);
}
static bool GetAnyFieldDescriptors(
const ::PROTOBUF_NAMESPACE_ID::Message& message,
@ -124,18 +124,18 @@ class PROTOBUF_EXPORT Any final :
const ::PROTOBUF_NAMESPACE_ID::FieldDescriptor** value_field);
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
bool PackFrom(const T& message) {
return _any_metadata_.PackFrom<T>(GetArena(), message);
return _impl_._any_metadata_.PackFrom<T>(GetArena(), message);
}
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
bool PackFrom(const T& message,
::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) {
return _any_metadata_.PackFrom<T>(GetArena(), message, type_url_prefix);}
return _impl_._any_metadata_.PackFrom<T>(GetArena(), message, type_url_prefix);}
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
bool UnpackTo(T* message) const {
return _any_metadata_.UnpackTo<T>(message);
return _impl_._any_metadata_.UnpackTo<T>(message);
}
template<typename T> bool Is() const {
return _any_metadata_.Is<T>();
return _impl_._any_metadata_.Is<T>();
}
static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url,
std::string* full_type_name);
@ -180,10 +180,10 @@ class PROTOBUF_EXPORT Any final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(Any* other);
@ -246,10 +246,13 @@ class PROTOBUF_EXPORT Any final :
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 value_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata _any_metadata_;
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata _any_metadata_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fany_2eproto;
};
// ===================================================================
@ -265,7 +268,7 @@ class PROTOBUF_EXPORT Any final :
// string type_url = 1;
inline void Any::clear_type_url() {
type_url_.ClearToEmpty();
_impl_.type_url_.ClearToEmpty();
}
inline const std::string& Any::type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
@ -275,7 +278,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Any::set_type_url(ArgT0&& arg0, ArgT... args) {
type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
}
inline std::string* Any::mutable_type_url() {
@ -284,19 +287,19 @@ inline std::string* Any::mutable_type_url() {
return _s;
}
inline const std::string& Any::_internal_type_url() const {
return type_url_.Get();
return _impl_.type_url_.Get();
}
inline void Any::_internal_set_type_url(const std::string& value) {
type_url_.Set(value, GetArenaForAllocation());
_impl_.type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_type_url() {
return type_url_.Mutable(GetArenaForAllocation());
return _impl_.type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
return type_url_.Release();
return _impl_.type_url_.Release();
}
inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) {
@ -304,10 +307,10 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
} else {
}
type_url_.SetAllocated(type_url, GetArenaForAllocation());
_impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (type_url_.IsDefault()) {
type_url_.Set("", GetArenaForAllocation());
if (_impl_.type_url_.IsDefault()) {
_impl_.type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
@ -315,7 +318,7 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
// bytes value = 2;
inline void Any::clear_value() {
value_.ClearToEmpty();
_impl_.value_.ClearToEmpty();
}
inline const std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
@ -325,7 +328,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Any::set_value(ArgT0&& arg0, ArgT... args) {
value_.SetBytes(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.value_.SetBytes(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
inline std::string* Any::mutable_value() {
@ -334,19 +337,19 @@ inline std::string* Any::mutable_value() {
return _s;
}
inline const std::string& Any::_internal_value() const {
return value_.Get();
return _impl_.value_.Get();
}
inline void Any::_internal_set_value(const std::string& value) {
value_.Set(value, GetArenaForAllocation());
_impl_.value_.Set(value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_value() {
return value_.Mutable(GetArenaForAllocation());
return _impl_.value_.Mutable(GetArenaForAllocation());
}
inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.Release();
return _impl_.value_.Release();
}
inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) {
@ -354,10 +357,10 @@ inline void Any::set_allocated_value(std::string* value) {
} else {
}
value_.SetAllocated(value, GetArenaForAllocation());
_impl_.value_.SetAllocated(value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (value_.IsDefault()) {
value_.Set("", GetArenaForAllocation());
if (_impl_.value_.IsDefault()) {
_impl_.value_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)

@ -22,15 +22,15 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Api::Api(
::_pbi::ConstantInitialized)
: methods_()
, options_()
, mixins_()
, name_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, version_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, source_context_(nullptr)
, syntax_(0)
{}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.methods_)*/{}
, /*decltype(_impl_.options_)*/{}
, /*decltype(_impl_.mixins_)*/{}
, /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.version_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.source_context_)*/nullptr
, /*decltype(_impl_.syntax_)*/0
, /*decltype(_impl_._cached_size_)*/{}} {}
struct ApiDefaultTypeInternal {
PROTOBUF_CONSTEXPR ApiDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -41,15 +41,15 @@ struct ApiDefaultTypeInternal {
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ApiDefaultTypeInternal _Api_default_instance_;
PROTOBUF_CONSTEXPR Method::Method(
::_pbi::ConstantInitialized)
: options_()
, name_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, request_type_url_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, response_type_url_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, request_streaming_(false)
, response_streaming_(false)
, syntax_(0)
{}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.options_)*/{}
, /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.request_type_url_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.response_type_url_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.request_streaming_)*/false
, /*decltype(_impl_.response_streaming_)*/false
, /*decltype(_impl_.syntax_)*/0
, /*decltype(_impl_._cached_size_)*/{}} {}
struct MethodDefaultTypeInternal {
PROTOBUF_CONSTEXPR MethodDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -60,9 +60,10 @@ struct MethodDefaultTypeInternal {
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodDefaultTypeInternal _Method_default_instance_;
PROTOBUF_CONSTEXPR Mixin::Mixin(
::_pbi::ConstantInitialized)
: name_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{})
, root_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_.root_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_._cached_size_)*/{}} {}
struct MixinDefaultTypeInternal {
PROTOBUF_CONSTEXPR MixinDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -84,34 +85,34 @@ const uint32_t TableStruct_google_2fprotobuf_2fapi_2eproto::offsets[] PROTOBUF_S
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, methods_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, options_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, version_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, source_context_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, mixins_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, syntax_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.methods_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.options_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.version_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.source_context_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.mixins_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.syntax_),
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, request_type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, request_streaming_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, response_type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, response_streaming_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, options_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, syntax_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_streaming_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_type_url_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_streaming_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.options_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.syntax_),
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, root_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.root_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Api)},
@ -176,70 +177,81 @@ class Api::_Internal {
const ::PROTOBUF_NAMESPACE_ID::SourceContext&
Api::_Internal::source_context(const Api* msg) {
return *msg->source_context_;
return *msg->_impl_.source_context_;
}
void Api::clear_options() {
options_.Clear();
_impl_.options_.Clear();
}
void Api::clear_source_context() {
if (GetArenaForAllocation() == nullptr && source_context_ != nullptr) {
delete source_context_;
if (GetArenaForAllocation() == nullptr && _impl_.source_context_ != nullptr) {
delete _impl_.source_context_;
}
source_context_ = nullptr;
_impl_.source_context_ = nullptr;
}
Api::Api(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
methods_(arena),
options_(arena),
mixins_(arena) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Api)
}
Api::Api(const Api& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
methods_(from.methods_),
options_(from.options_),
mixins_(from.mixins_) {
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.methods_){from._impl_.methods_}
, decltype(_impl_.options_){from._impl_.options_}
, decltype(_impl_.mixins_){from._impl_.mixins_}
, decltype(_impl_.name_){}
, decltype(_impl_.version_){}
, decltype(_impl_.source_context_){nullptr}
, decltype(_impl_.syntax_){}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(from._internal_name(),
_impl_.name_.Set(from._internal_name(),
GetArenaForAllocation());
}
version_.InitDefault();
_impl_.version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set("", GetArenaForAllocation());
_impl_.version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_version().empty()) {
version_.Set(from._internal_version(),
_impl_.version_.Set(from._internal_version(),
GetArenaForAllocation());
}
if (from._internal_has_source_context()) {
source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_);
} else {
source_context_ = nullptr;
_impl_.source_context_ = new ::PROTOBUF_NAMESPACE_ID::SourceContext(*from._impl_.source_context_);
}
syntax_ = from.syntax_;
_impl_.syntax_ = from._impl_.syntax_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.Api)
}
inline void Api::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
reinterpret_cast<char*>(&source_context_)) + sizeof(syntax_));
inline void Api::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.methods_){arena}
, decltype(_impl_.options_){arena}
, decltype(_impl_.mixins_){arena}
, decltype(_impl_.name_){}
, decltype(_impl_.version_){}
, decltype(_impl_.source_context_){nullptr}
, decltype(_impl_.syntax_){0}
, /*decltype(_impl_._cached_size_)*/{}
};
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
Api::~Api() {
@ -253,13 +265,16 @@ Api::~Api() {
inline void Api::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.Destroy();
version_.Destroy();
if (this != internal_default_instance()) delete source_context_;
_impl_.methods_.~RepeatedPtrField();
_impl_.options_.~RepeatedPtrField();
_impl_.mixins_.~RepeatedPtrField();
_impl_.name_.Destroy();
_impl_.version_.Destroy();
if (this != internal_default_instance()) delete _impl_.source_context_;
}
void Api::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Api::Clear() {
@ -268,16 +283,16 @@ void Api::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
methods_.Clear();
options_.Clear();
mixins_.Clear();
name_.ClearToEmpty();
version_.ClearToEmpty();
if (GetArenaForAllocation() == nullptr && source_context_ != nullptr) {
delete source_context_;
_impl_.methods_.Clear();
_impl_.options_.Clear();
_impl_.mixins_.Clear();
_impl_.name_.ClearToEmpty();
_impl_.version_.ClearToEmpty();
if (GetArenaForAllocation() == nullptr && _impl_.source_context_ != nullptr) {
delete _impl_.source_context_;
}
source_context_ = nullptr;
syntax_ = 0;
_impl_.source_context_ = nullptr;
_impl_.syntax_ = 0;
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -468,21 +483,21 @@ size_t Api::ByteSizeLong() const {
// repeated .google.protobuf.Method methods = 2;
total_size += 1UL * this->_internal_methods_size();
for (const auto& msg : this->methods_) {
for (const auto& msg : this->_impl_.methods_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
// repeated .google.protobuf.Option options = 3;
total_size += 1UL * this->_internal_options_size();
for (const auto& msg : this->options_) {
for (const auto& msg : this->_impl_.options_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
// repeated .google.protobuf.Mixin mixins = 6;
total_size += 1UL * this->_internal_mixins_size();
for (const auto& msg : this->mixins_) {
for (const auto& msg : this->_impl_.mixins_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
@ -505,7 +520,7 @@ size_t Api::ByteSizeLong() const {
if (this->_internal_has_source_context()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(
*source_context_);
*_impl_.source_context_);
}
// .google.protobuf.Syntax syntax = 7;
@ -514,7 +529,7 @@ size_t Api::ByteSizeLong() const {
::_pbi::WireFormatLite::EnumSize(this->_internal_syntax());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Api::_class_data_ = {
@ -536,9 +551,9 @@ void Api::MergeFrom(const Api& from) {
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
methods_.MergeFrom(from.methods_);
options_.MergeFrom(from.options_);
mixins_.MergeFrom(from.mixins_);
_impl_.methods_.MergeFrom(from._impl_.methods_);
_impl_.options_.MergeFrom(from._impl_.options_);
_impl_.mixins_.MergeFrom(from._impl_.mixins_);
if (!from._internal_name().empty()) {
_internal_set_name(from._internal_name());
}
@ -570,23 +585,23 @@ void Api::InternalSwap(Api* other) {
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
methods_.InternalSwap(&other->methods_);
options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_);
_impl_.methods_.InternalSwap(&other->_impl_.methods_);
_impl_.options_.InternalSwap(&other->_impl_.options_);
_impl_.mixins_.InternalSwap(&other->_impl_.mixins_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&name_, lhs_arena,
&other->name_, rhs_arena
&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&version_, lhs_arena,
&other->version_, rhs_arena
&_impl_.version_, lhs_arena,
&other->_impl_.version_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Api, syntax_)
+ sizeof(Api::syntax_)
- PROTOBUF_FIELD_OFFSET(Api, source_context_)>(
reinterpret_cast<char*>(&source_context_),
reinterpret_cast<char*>(&other->source_context_));
PROTOBUF_FIELD_OFFSET(Api, _impl_.syntax_)
+ sizeof(Api::_impl_.syntax_)
- PROTOBUF_FIELD_OFFSET(Api, _impl_.source_context_)>(
reinterpret_cast<char*>(&_impl_.source_context_),
reinterpret_cast<char*>(&other->_impl_.source_context_));
}
::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const {
@ -602,66 +617,83 @@ class Method::_Internal {
};
void Method::clear_options() {
options_.Clear();
_impl_.options_.Clear();
}
Method::Method(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
options_(arena) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Method)
}
Method::Method(const Method& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
options_(from.options_) {
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.options_){from._impl_.options_}
, decltype(_impl_.name_){}
, decltype(_impl_.request_type_url_){}
, decltype(_impl_.response_type_url_){}
, decltype(_impl_.request_streaming_){}
, decltype(_impl_.response_streaming_){}
, decltype(_impl_.syntax_){}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(from._internal_name(),
_impl_.name_.Set(from._internal_name(),
GetArenaForAllocation());
}
request_type_url_.InitDefault();
_impl_.request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set("", GetArenaForAllocation());
_impl_.request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_request_type_url().empty()) {
request_type_url_.Set(from._internal_request_type_url(),
_impl_.request_type_url_.Set(from._internal_request_type_url(),
GetArenaForAllocation());
}
response_type_url_.InitDefault();
_impl_.response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set("", GetArenaForAllocation());
_impl_.response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_response_type_url().empty()) {
response_type_url_.Set(from._internal_response_type_url(),
_impl_.response_type_url_.Set(from._internal_response_type_url(),
GetArenaForAllocation());
}
::memcpy(&request_streaming_, &from.request_streaming_,
static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_));
::memcpy(&_impl_.request_streaming_, &from._impl_.request_streaming_,
static_cast<size_t>(reinterpret_cast<char*>(&_impl_.syntax_) -
reinterpret_cast<char*>(&_impl_.request_streaming_)) + sizeof(_impl_.syntax_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.Method)
}
inline void Method::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&request_streaming_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_));
inline void Method::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.options_){arena}
, decltype(_impl_.name_){}
, decltype(_impl_.request_type_url_){}
, decltype(_impl_.response_type_url_){}
, decltype(_impl_.request_streaming_){false}
, decltype(_impl_.response_streaming_){false}
, decltype(_impl_.syntax_){0}
, /*decltype(_impl_._cached_size_)*/{}
};
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
Method::~Method() {
@ -675,13 +707,14 @@ Method::~Method() {
inline void Method::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.Destroy();
request_type_url_.Destroy();
response_type_url_.Destroy();
_impl_.options_.~RepeatedPtrField();
_impl_.name_.Destroy();
_impl_.request_type_url_.Destroy();
_impl_.response_type_url_.Destroy();
}
void Method::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Method::Clear() {
@ -690,13 +723,13 @@ void Method::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
options_.Clear();
name_.ClearToEmpty();
request_type_url_.ClearToEmpty();
response_type_url_.ClearToEmpty();
::memset(&request_streaming_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&syntax_) -
reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_));
_impl_.options_.Clear();
_impl_.name_.ClearToEmpty();
_impl_.request_type_url_.ClearToEmpty();
_impl_.response_type_url_.ClearToEmpty();
::memset(&_impl_.request_streaming_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&_impl_.syntax_) -
reinterpret_cast<char*>(&_impl_.request_streaming_)) + sizeof(_impl_.syntax_));
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -729,7 +762,7 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
// bool request_streaming = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 24)) {
request_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
_impl_.request_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else
goto handle_unusual;
@ -747,7 +780,7 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
// bool response_streaming = 5;
case 5:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 40)) {
response_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
_impl_.response_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else
goto handle_unusual;
@ -878,7 +911,7 @@ size_t Method::ByteSizeLong() const {
// repeated .google.protobuf.Option options = 6;
total_size += 1UL * this->_internal_options_size();
for (const auto& msg : this->options_) {
for (const auto& msg : this->_impl_.options_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
@ -920,7 +953,7 @@ size_t Method::ByteSizeLong() const {
::_pbi::WireFormatLite::EnumSize(this->_internal_syntax());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Method::_class_data_ = {
@ -942,7 +975,7 @@ void Method::MergeFrom(const Method& from) {
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
options_.MergeFrom(from.options_);
_impl_.options_.MergeFrom(from._impl_.options_);
if (!from._internal_name().empty()) {
_internal_set_name(from._internal_name());
}
@ -980,25 +1013,25 @@ void Method::InternalSwap(Method* other) {
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
options_.InternalSwap(&other->options_);
_impl_.options_.InternalSwap(&other->_impl_.options_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&name_, lhs_arena,
&other->name_, rhs_arena
&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&request_type_url_, lhs_arena,
&other->request_type_url_, rhs_arena
&_impl_.request_type_url_, lhs_arena,
&other->_impl_.request_type_url_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&response_type_url_, lhs_arena,
&other->response_type_url_, rhs_arena
&_impl_.response_type_url_, lhs_arena,
&other->_impl_.response_type_url_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Method, syntax_)
+ sizeof(Method::syntax_)
- PROTOBUF_FIELD_OFFSET(Method, request_streaming_)>(
reinterpret_cast<char*>(&request_streaming_),
reinterpret_cast<char*>(&other->request_streaming_));
PROTOBUF_FIELD_OFFSET(Method, _impl_.syntax_)
+ sizeof(Method::_impl_.syntax_)
- PROTOBUF_FIELD_OFFSET(Method, _impl_.request_streaming_)>(
reinterpret_cast<char*>(&_impl_.request_streaming_),
reinterpret_cast<char*>(&other->_impl_.request_streaming_));
}
::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const {
@ -1016,40 +1049,53 @@ class Mixin::_Internal {
Mixin::Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Mixin)
}
Mixin::Mixin(const Mixin& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.name_){}
, decltype(_impl_.root_){}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(from._internal_name(),
_impl_.name_.Set(from._internal_name(),
GetArenaForAllocation());
}
root_.InitDefault();
_impl_.root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set("", GetArenaForAllocation());
_impl_.root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_root().empty()) {
root_.Set(from._internal_root(),
_impl_.root_.Set(from._internal_root(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
}
inline void Mixin::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
inline void Mixin::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.name_){}
, decltype(_impl_.root_){}
, /*decltype(_impl_._cached_size_)*/{}
};
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
Mixin::~Mixin() {
@ -1063,12 +1109,12 @@ Mixin::~Mixin() {
inline void Mixin::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.Destroy();
root_.Destroy();
_impl_.name_.Destroy();
_impl_.root_.Destroy();
}
void Mixin::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Mixin::Clear() {
@ -1077,8 +1123,8 @@ void Mixin::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
name_.ClearToEmpty();
root_.ClearToEmpty();
_impl_.name_.ClearToEmpty();
_impl_.root_.ClearToEmpty();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -1187,7 +1233,7 @@ size_t Mixin::ByteSizeLong() const {
this->_internal_root());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Mixin::_class_data_ = {
@ -1235,12 +1281,12 @@ void Mixin::InternalSwap(Mixin* other) {
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&name_, lhs_arena,
&other->name_, rhs_arena
&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&root_, lhs_arena,
&other->root_, rhs_arena
&_impl_.root_, lhs_arena,
&other->_impl_.root_, rhs_arena
);
}

@ -157,10 +157,10 @@ class PROTOBUF_EXPORT Api final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(Api* other);
@ -309,14 +309,17 @@ class PROTOBUF_EXPORT Api final :
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::Option > options_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin > mixins_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_;
::PROTOBUF_NAMESPACE_ID::SourceContext* source_context_;
int syntax_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
::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::Mixin > mixins_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_;
::PROTOBUF_NAMESPACE_ID::SourceContext* source_context_;
int syntax_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto;
};
// -------------------------------------------------------------------
@ -412,10 +415,10 @@ class PROTOBUF_EXPORT Method final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(Method* other);
@ -542,14 +545,17 @@ class PROTOBUF_EXPORT Method final :
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::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr response_type_url_;
bool request_streaming_;
bool response_streaming_;
int syntax_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option > options_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr response_type_url_;
bool request_streaming_;
bool response_streaming_;
int syntax_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto;
};
// -------------------------------------------------------------------
@ -645,10 +651,10 @@ class PROTOBUF_EXPORT Mixin final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(Mixin* other);
@ -711,9 +717,12 @@ class PROTOBUF_EXPORT Mixin final :
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 root_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto;
};
// ===================================================================
@ -729,7 +738,7 @@ class PROTOBUF_EXPORT Mixin final :
// string name = 1;
inline void Api::clear_name() {
name_.ClearToEmpty();
_impl_.name_.ClearToEmpty();
}
inline const std::string& Api::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.name)
@ -739,7 +748,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Api::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.name)
}
inline std::string* Api::mutable_name() {
@ -748,19 +757,19 @@ inline std::string* Api::mutable_name() {
return _s;
}
inline const std::string& Api::_internal_name() const {
return name_.Get();
return _impl_.name_.Get();
}
inline void Api::_internal_set_name(const std::string& value) {
name_.Set(value, GetArenaForAllocation());
_impl_.name_.Set(value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_name() {
return name_.Mutable(GetArenaForAllocation());
return _impl_.name_.Mutable(GetArenaForAllocation());
}
inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name)
return name_.Release();
return _impl_.name_.Release();
}
inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -768,10 +777,10 @@ inline void Api::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(name, GetArenaForAllocation());
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set("", GetArenaForAllocation());
if (_impl_.name_.IsDefault()) {
_impl_.name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
@ -779,32 +788,32 @@ inline void Api::set_allocated_name(std::string* name) {
// repeated .google.protobuf.Method methods = 2;
inline int Api::_internal_methods_size() const {
return methods_.size();
return _impl_.methods_.size();
}
inline int Api::methods_size() const {
return _internal_methods_size();
}
inline void Api::clear_methods() {
methods_.Clear();
_impl_.methods_.Clear();
}
inline ::PROTOBUF_NAMESPACE_ID::Method* Api::mutable_methods(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.Api.methods)
return methods_.Mutable(index);
return _impl_.methods_.Mutable(index);
}
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >*
Api::mutable_methods() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.methods)
return &methods_;
return &_impl_.methods_;
}
inline const ::PROTOBUF_NAMESPACE_ID::Method& Api::_internal_methods(int index) const {
return methods_.Get(index);
return _impl_.methods_.Get(index);
}
inline const ::PROTOBUF_NAMESPACE_ID::Method& Api::methods(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.methods)
return _internal_methods(index);
}
inline ::PROTOBUF_NAMESPACE_ID::Method* Api::_internal_add_methods() {
return methods_.Add();
return _impl_.methods_.Add();
}
inline ::PROTOBUF_NAMESPACE_ID::Method* Api::add_methods() {
::PROTOBUF_NAMESPACE_ID::Method* _add = _internal_add_methods();
@ -814,34 +823,34 @@ inline ::PROTOBUF_NAMESPACE_ID::Method* Api::add_methods() {
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >&
Api::methods() const {
// @@protoc_insertion_point(field_list:google.protobuf.Api.methods)
return methods_;
return _impl_.methods_;
}
// repeated .google.protobuf.Option options = 3;
inline int Api::_internal_options_size() const {
return options_.size();
return _impl_.options_.size();
}
inline int Api::options_size() const {
return _internal_options_size();
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Api::mutable_options(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.Api.options)
return options_.Mutable(index);
return _impl_.options_.Mutable(index);
}
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >*
Api::mutable_options() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.options)
return &options_;
return &_impl_.options_;
}
inline const ::PROTOBUF_NAMESPACE_ID::Option& Api::_internal_options(int index) const {
return options_.Get(index);
return _impl_.options_.Get(index);
}
inline const ::PROTOBUF_NAMESPACE_ID::Option& Api::options(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.options)
return _internal_options(index);
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Api::_internal_add_options() {
return options_.Add();
return _impl_.options_.Add();
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Api::add_options() {
::PROTOBUF_NAMESPACE_ID::Option* _add = _internal_add_options();
@ -851,12 +860,12 @@ inline ::PROTOBUF_NAMESPACE_ID::Option* Api::add_options() {
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >&
Api::options() const {
// @@protoc_insertion_point(field_list:google.protobuf.Api.options)
return options_;
return _impl_.options_;
}
// string version = 4;
inline void Api::clear_version() {
version_.ClearToEmpty();
_impl_.version_.ClearToEmpty();
}
inline const std::string& Api::version() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.version)
@ -866,7 +875,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Api::set_version(ArgT0&& arg0, ArgT... args) {
version_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.version_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.version)
}
inline std::string* Api::mutable_version() {
@ -875,19 +884,19 @@ inline std::string* Api::mutable_version() {
return _s;
}
inline const std::string& Api::_internal_version() const {
return version_.Get();
return _impl_.version_.Get();
}
inline void Api::_internal_set_version(const std::string& value) {
version_.Set(value, GetArenaForAllocation());
_impl_.version_.Set(value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_version() {
return version_.Mutable(GetArenaForAllocation());
return _impl_.version_.Mutable(GetArenaForAllocation());
}
inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version)
return version_.Release();
return _impl_.version_.Release();
}
inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) {
@ -895,10 +904,10 @@ inline void Api::set_allocated_version(std::string* version) {
} else {
}
version_.SetAllocated(version, GetArenaForAllocation());
_impl_.version_.SetAllocated(version, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (version_.IsDefault()) {
version_.Set("", GetArenaForAllocation());
if (_impl_.version_.IsDefault()) {
_impl_.version_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
@ -906,13 +915,13 @@ inline void Api::set_allocated_version(std::string* version) {
// .google.protobuf.SourceContext source_context = 5;
inline bool Api::_internal_has_source_context() const {
return this != internal_default_instance() && source_context_ != nullptr;
return this != internal_default_instance() && _impl_.source_context_ != nullptr;
}
inline bool Api::has_source_context() const {
return _internal_has_source_context();
}
inline const ::PROTOBUF_NAMESPACE_ID::SourceContext& Api::_internal_source_context() const {
const ::PROTOBUF_NAMESPACE_ID::SourceContext* p = source_context_;
const ::PROTOBUF_NAMESPACE_ID::SourceContext* p = _impl_.source_context_;
return p != nullptr ? *p : reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::SourceContext&>(
::PROTOBUF_NAMESPACE_ID::_SourceContext_default_instance_);
}
@ -923,9 +932,9 @@ inline const ::PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const
inline void Api::unsafe_arena_set_allocated_source_context(
::PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
if (GetArenaForAllocation() == nullptr) {
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_);
}
source_context_ = source_context;
_impl_.source_context_ = source_context;
if (source_context) {
} else {
@ -935,8 +944,8 @@ inline void Api::unsafe_arena_set_allocated_source_context(
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
::PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
source_context_ = nullptr;
::PROTOBUF_NAMESPACE_ID::SourceContext* temp = _impl_.source_context_;
_impl_.source_context_ = nullptr;
#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
auto* old = reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(temp);
temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp);
@ -951,17 +960,17 @@ inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_context() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
::PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
source_context_ = nullptr;
::PROTOBUF_NAMESPACE_ID::SourceContext* temp = _impl_.source_context_;
_impl_.source_context_ = nullptr;
return temp;
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() {
if (source_context_ == nullptr) {
if (_impl_.source_context_ == nullptr) {
auto* p = CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceContext>(GetArenaForAllocation());
source_context_ = p;
_impl_.source_context_ = p;
}
return source_context_;
return _impl_.source_context_;
}
inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
::PROTOBUF_NAMESPACE_ID::SourceContext* _msg = _internal_mutable_source_context();
@ -971,7 +980,7 @@ inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation();
if (message_arena == nullptr) {
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_);
}
if (source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
@ -985,38 +994,38 @@ inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCon
} else {
}
source_context_ = source_context;
_impl_.source_context_ = source_context;
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context)
}
// repeated .google.protobuf.Mixin mixins = 6;
inline int Api::_internal_mixins_size() const {
return mixins_.size();
return _impl_.mixins_.size();
}
inline int Api::mixins_size() const {
return _internal_mixins_size();
}
inline void Api::clear_mixins() {
mixins_.Clear();
_impl_.mixins_.Clear();
}
inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::mutable_mixins(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.Api.mixins)
return mixins_.Mutable(index);
return _impl_.mixins_.Mutable(index);
}
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >*
Api::mutable_mixins() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.mixins)
return &mixins_;
return &_impl_.mixins_;
}
inline const ::PROTOBUF_NAMESPACE_ID::Mixin& Api::_internal_mixins(int index) const {
return mixins_.Get(index);
return _impl_.mixins_.Get(index);
}
inline const ::PROTOBUF_NAMESPACE_ID::Mixin& Api::mixins(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.mixins)
return _internal_mixins(index);
}
inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::_internal_add_mixins() {
return mixins_.Add();
return _impl_.mixins_.Add();
}
inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::add_mixins() {
::PROTOBUF_NAMESPACE_ID::Mixin* _add = _internal_add_mixins();
@ -1026,15 +1035,15 @@ inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::add_mixins() {
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >&
Api::mixins() const {
// @@protoc_insertion_point(field_list:google.protobuf.Api.mixins)
return mixins_;
return _impl_.mixins_;
}
// .google.protobuf.Syntax syntax = 7;
inline void Api::clear_syntax() {
syntax_ = 0;
_impl_.syntax_ = 0;
}
inline ::PROTOBUF_NAMESPACE_ID::Syntax Api::_internal_syntax() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(syntax_);
return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(_impl_.syntax_);
}
inline ::PROTOBUF_NAMESPACE_ID::Syntax Api::syntax() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.syntax)
@ -1042,7 +1051,7 @@ inline ::PROTOBUF_NAMESPACE_ID::Syntax Api::syntax() const {
}
inline void Api::_internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
syntax_ = value;
_impl_.syntax_ = value;
}
inline void Api::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
_internal_set_syntax(value);
@ -1055,7 +1064,7 @@ inline void Api::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1;
inline void Method::clear_name() {
name_.ClearToEmpty();
_impl_.name_.ClearToEmpty();
}
inline const std::string& Method::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.name)
@ -1065,7 +1074,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.name)
}
inline std::string* Method::mutable_name() {
@ -1074,19 +1083,19 @@ inline std::string* Method::mutable_name() {
return _s;
}
inline const std::string& Method::_internal_name() const {
return name_.Get();
return _impl_.name_.Get();
}
inline void Method::_internal_set_name(const std::string& value) {
name_.Set(value, GetArenaForAllocation());
_impl_.name_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_name() {
return name_.Mutable(GetArenaForAllocation());
return _impl_.name_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name)
return name_.Release();
return _impl_.name_.Release();
}
inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1094,10 +1103,10 @@ inline void Method::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(name, GetArenaForAllocation());
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set("", GetArenaForAllocation());
if (_impl_.name_.IsDefault()) {
_impl_.name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
@ -1105,7 +1114,7 @@ inline void Method::set_allocated_name(std::string* name) {
// string request_type_url = 2;
inline void Method::clear_request_type_url() {
request_type_url_.ClearToEmpty();
_impl_.request_type_url_.ClearToEmpty();
}
inline const std::string& Method::request_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url)
@ -1115,7 +1124,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) {
request_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.request_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url)
}
inline std::string* Method::mutable_request_type_url() {
@ -1124,19 +1133,19 @@ inline std::string* Method::mutable_request_type_url() {
return _s;
}
inline const std::string& Method::_internal_request_type_url() const {
return request_type_url_.Get();
return _impl_.request_type_url_.Get();
}
inline void Method::_internal_set_request_type_url(const std::string& value) {
request_type_url_.Set(value, GetArenaForAllocation());
_impl_.request_type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_request_type_url() {
return request_type_url_.Mutable(GetArenaForAllocation());
return _impl_.request_type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_request_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
return request_type_url_.Release();
return _impl_.request_type_url_.Release();
}
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) {
@ -1144,10 +1153,10 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
} else {
}
request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation());
_impl_.request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (request_type_url_.IsDefault()) {
request_type_url_.Set("", GetArenaForAllocation());
if (_impl_.request_type_url_.IsDefault()) {
_impl_.request_type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
@ -1155,10 +1164,10 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
// bool request_streaming = 3;
inline void Method::clear_request_streaming() {
request_streaming_ = false;
_impl_.request_streaming_ = false;
}
inline bool Method::_internal_request_streaming() const {
return request_streaming_;
return _impl_.request_streaming_;
}
inline bool Method::request_streaming() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_streaming)
@ -1166,7 +1175,7 @@ inline bool Method::request_streaming() const {
}
inline void Method::_internal_set_request_streaming(bool value) {
request_streaming_ = value;
_impl_.request_streaming_ = value;
}
inline void Method::set_request_streaming(bool value) {
_internal_set_request_streaming(value);
@ -1175,7 +1184,7 @@ inline void Method::set_request_streaming(bool value) {
// string response_type_url = 4;
inline void Method::clear_response_type_url() {
response_type_url_.ClearToEmpty();
_impl_.response_type_url_.ClearToEmpty();
}
inline const std::string& Method::response_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url)
@ -1185,7 +1194,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) {
response_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.response_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url)
}
inline std::string* Method::mutable_response_type_url() {
@ -1194,19 +1203,19 @@ inline std::string* Method::mutable_response_type_url() {
return _s;
}
inline const std::string& Method::_internal_response_type_url() const {
return response_type_url_.Get();
return _impl_.response_type_url_.Get();
}
inline void Method::_internal_set_response_type_url(const std::string& value) {
response_type_url_.Set(value, GetArenaForAllocation());
_impl_.response_type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_response_type_url() {
return response_type_url_.Mutable(GetArenaForAllocation());
return _impl_.response_type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_response_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
return response_type_url_.Release();
return _impl_.response_type_url_.Release();
}
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) {
@ -1214,10 +1223,10 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
} else {
}
response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation());
_impl_.response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (response_type_url_.IsDefault()) {
response_type_url_.Set("", GetArenaForAllocation());
if (_impl_.response_type_url_.IsDefault()) {
_impl_.response_type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
@ -1225,10 +1234,10 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
// bool response_streaming = 5;
inline void Method::clear_response_streaming() {
response_streaming_ = false;
_impl_.response_streaming_ = false;
}
inline bool Method::_internal_response_streaming() const {
return response_streaming_;
return _impl_.response_streaming_;
}
inline bool Method::response_streaming() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_streaming)
@ -1236,7 +1245,7 @@ inline bool Method::response_streaming() const {
}
inline void Method::_internal_set_response_streaming(bool value) {
response_streaming_ = value;
_impl_.response_streaming_ = value;
}
inline void Method::set_response_streaming(bool value) {
_internal_set_response_streaming(value);
@ -1245,29 +1254,29 @@ inline void Method::set_response_streaming(bool value) {
// repeated .google.protobuf.Option options = 6;
inline int Method::_internal_options_size() const {
return options_.size();
return _impl_.options_.size();
}
inline int Method::options_size() const {
return _internal_options_size();
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Method::mutable_options(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.Method.options)
return options_.Mutable(index);
return _impl_.options_.Mutable(index);
}
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >*
Method::mutable_options() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.Method.options)
return &options_;
return &_impl_.options_;
}
inline const ::PROTOBUF_NAMESPACE_ID::Option& Method::_internal_options(int index) const {
return options_.Get(index);
return _impl_.options_.Get(index);
}
inline const ::PROTOBUF_NAMESPACE_ID::Option& Method::options(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.options)
return _internal_options(index);
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Method::_internal_add_options() {
return options_.Add();
return _impl_.options_.Add();
}
inline ::PROTOBUF_NAMESPACE_ID::Option* Method::add_options() {
::PROTOBUF_NAMESPACE_ID::Option* _add = _internal_add_options();
@ -1277,15 +1286,15 @@ inline ::PROTOBUF_NAMESPACE_ID::Option* Method::add_options() {
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >&
Method::options() const {
// @@protoc_insertion_point(field_list:google.protobuf.Method.options)
return options_;
return _impl_.options_;
}
// .google.protobuf.Syntax syntax = 7;
inline void Method::clear_syntax() {
syntax_ = 0;
_impl_.syntax_ = 0;
}
inline ::PROTOBUF_NAMESPACE_ID::Syntax Method::_internal_syntax() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(syntax_);
return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(_impl_.syntax_);
}
inline ::PROTOBUF_NAMESPACE_ID::Syntax Method::syntax() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.syntax)
@ -1293,7 +1302,7 @@ inline ::PROTOBUF_NAMESPACE_ID::Syntax Method::syntax() const {
}
inline void Method::_internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
syntax_ = value;
_impl_.syntax_ = value;
}
inline void Method::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
_internal_set_syntax(value);
@ -1306,7 +1315,7 @@ inline void Method::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1;
inline void Mixin::clear_name() {
name_.ClearToEmpty();
_impl_.name_.ClearToEmpty();
}
inline const std::string& Mixin::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
@ -1316,7 +1325,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
}
inline std::string* Mixin::mutable_name() {
@ -1325,19 +1334,19 @@ inline std::string* Mixin::mutable_name() {
return _s;
}
inline const std::string& Mixin::_internal_name() const {
return name_.Get();
return _impl_.name_.Get();
}
inline void Mixin::_internal_set_name(const std::string& value) {
name_.Set(value, GetArenaForAllocation());
_impl_.name_.Set(value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_name() {
return name_.Mutable(GetArenaForAllocation());
return _impl_.name_.Mutable(GetArenaForAllocation());
}
inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
return name_.Release();
return _impl_.name_.Release();
}
inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1345,10 +1354,10 @@ inline void Mixin::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(name, GetArenaForAllocation());
_impl_.name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set("", GetArenaForAllocation());
if (_impl_.name_.IsDefault()) {
_impl_.name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
@ -1356,7 +1365,7 @@ inline void Mixin::set_allocated_name(std::string* name) {
// string root = 2;
inline void Mixin::clear_root() {
root_.ClearToEmpty();
_impl_.root_.ClearToEmpty();
}
inline const std::string& Mixin::root() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
@ -1366,7 +1375,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_root(ArgT0&& arg0, ArgT... args) {
root_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.root_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
}
inline std::string* Mixin::mutable_root() {
@ -1375,19 +1384,19 @@ inline std::string* Mixin::mutable_root() {
return _s;
}
inline const std::string& Mixin::_internal_root() const {
return root_.Get();
return _impl_.root_.Get();
}
inline void Mixin::_internal_set_root(const std::string& value) {
root_.Set(value, GetArenaForAllocation());
_impl_.root_.Set(value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_root() {
return root_.Mutable(GetArenaForAllocation());
return _impl_.root_.Mutable(GetArenaForAllocation());
}
inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
return root_.Release();
return _impl_.root_.Release();
}
inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) {
@ -1395,10 +1404,10 @@ inline void Mixin::set_allocated_root(std::string* root) {
} else {
}
root_.SetAllocated(root, GetArenaForAllocation());
_impl_.root_.SetAllocated(root, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (root_.IsDefault()) {
root_.Set("", GetArenaForAllocation());
if (_impl_.root_.IsDefault()) {
_impl_.root_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)

@ -29,6 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>

@ -33,9 +33,9 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/arena.h>
namespace google {
namespace protobuf {

@ -41,17 +41,17 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_arena.pb.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/repeated_field.h>

@ -55,13 +55,13 @@ void UnsampleSlow(ThreadSafeArenaStats* info) {
namespace {
PROTOBUF_CONSTINIT std::atomic<bool> g_arenaz_enabled{true};
PROTOBUF_CONSTINIT std::atomic<int32_t> g_arenaz_sample_parameter{1 << 20};
PROTOBUF_CONSTINIT std::atomic<int32_t> g_arenaz_sample_parameter{1 << 15};
PROTOBUF_THREAD_LOCAL absl::profiling_internal::ExponentialBiased
g_exponential_biased_generator;
} // namespace
PROTOBUF_THREAD_LOCAL int64_t global_next_sample = 1LL << 20;
PROTOBUF_THREAD_LOCAL int64_t global_next_sample = 1LL << 15;
ThreadSafeArenaStats::ThreadSafeArenaStats() { PrepareForSampling(); }
ThreadSafeArenaStats::~ThreadSafeArenaStats() = default;

@ -34,8 +34,6 @@
#include <google/protobuf/compiler/command_line_interface.h>
#include <cstdint>
#include <google/protobuf/stubs/platform_macros.h>
#include <stdio.h>
@ -70,20 +68,20 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/compiler/subprocess.h>
#include <google/protobuf/compiler/zip_writer.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/zip_writer.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/stl_util.h>

@ -131,11 +131,6 @@ void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
format("swap($field$, other->$field$);\n");
}
void EnumFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$ = $default$;\n");
}
void EnumFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
@ -158,10 +153,22 @@ void EnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
" ::_pbi::WireFormatLite::EnumSize(this->_internal_$name$());\n");
}
void EnumFieldGenerator::GenerateConstinitInitializer(
void EnumFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/$default$");
}
void EnumFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_($default$)\n");
format("decltype($field$){$default$}");
}
void EnumFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){}");
}
// ===================================================================
@ -336,6 +343,12 @@ void RepeatedEnumFieldGenerator::GenerateConstructorCode(
// Not needed for repeated fields.
}
void RepeatedEnumFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.~RepeatedField();\n");
}
void RepeatedEnumFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
@ -392,13 +405,36 @@ void RepeatedEnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
format("}\n");
}
void RepeatedEnumFieldGenerator::GenerateConstinitInitializer(
void RepeatedEnumFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/{}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}
void RepeatedEnumFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){arena}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
// std::atomic has no copy constructor, which prevents explicit aggregate
// initialization pre-C++17.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}
void RepeatedEnumFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_()");
format("decltype($field$){from.$field$}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format("\n, $cached_byte_size_name$(0)");
// std::atomic has no copy constructor.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}

@ -57,12 +57,15 @@ class EnumFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
@ -99,10 +102,14 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator);

@ -78,7 +78,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
break;
}
SetCommonVars(options, &variables_);
SetCommonMessageDataVariables(&variables_);
SetCommonMessageDataVariables(descriptor_->containing_type(), &variables_);
variables_["extendee"] =
QualifiedClassName(descriptor_->containing_type(), options_);
variables_["type_traits"] = type_traits_;

@ -236,7 +236,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
std::map<std::string, std::string>* variables,
const Options& options) {
SetCommonVars(options, variables);
SetCommonMessageDataVariables(variables);
SetCommonMessageDataVariables(descriptor->containing_type(), variables);
(*variables)["ns"] = Namespace(descriptor, options);
(*variables)["name"] = FieldName(descriptor);
@ -304,6 +304,23 @@ void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) {
"u");
}
void FieldGenerator::GenerateAggregateInitializer(io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){arena}");
}
void FieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/{}");
}
void FieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){from.$field$}");
}
void SetCommonOneofFieldVariables(
const FieldDescriptor* descriptor,
std::map<std::string, std::string>* variables) {

@ -165,10 +165,32 @@ class FieldGenerator {
}
// Generate initialization code for private members declared by
// GeneratePrivateMembers(), specifically for the constexpr constructor.
// These go into the constructor's initializer list and must follow that
// syntax (eg `field_(args)`). Does not include `:` or `,` separators.
virtual void GenerateConstinitInitializer(io::Printer* printer) const {}
// GeneratePrivateMembers(). These go into the SharedCtor's
// aggregate initialization of the _impl_ struct and must follow the syntax
// (e.g. `decltype($field$){$default$}`). Does not include `:` or `,`
// separators. Default values should be specified here when possible.
//
// Note: We use `decltype($field$)` for both explicit construction and the
// fact that it's self-documenting. Pre-C++17, copy elision isn't guaranteed
// in aggregate initialization so a valid copy/move constructor must exist
// (even though it's not used). Because of this, we need to comment out the
// decltype and fallback to implicit construction.
virtual void GenerateAggregateInitializer(io::Printer* printer) const;
// Generate constinit initialization code for private members declared by
// GeneratePrivateMembers(). These go into the constexpr constructor's
// aggregate initialization of the _impl_ struct and must follow the syntax
// (e.g. `/*decltype($field$)*/{}`, see above). Does not
// include `:` or `,` separators.
virtual void GenerateConstexprAggregateInitializer(
io::Printer* printer) const;
// Generate copy initialization code for private members declared by
// GeneratePrivateMembers(). These go into the copy constructor's
// aggregate initialization of the _impl_ struct and must follow the syntax
// (e.g. `decltype($field$){from.$field$}`, see above). Does not
// include `:` or `,` separators.
virtual void GenerateCopyAggregateInitializer(io::Printer* printer) const;
// Generate lines to serialize this field directly to the array "target",
// which are placed within the message's SerializeWithCachedSizesToArray()

@ -510,7 +510,7 @@ void FileGenerator::GenerateSourceDefaultInstance(int idx,
// Force the initialization of the inlined string in the default instance.
format(
"PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 std::true_type "
"$1$::_init_inline_$2$_ = "
"$1$::Impl_::_init_inline_$2$_ = "
"($3$._instance.$4$.Init(), std::true_type{});\n",
ClassName(generator->descriptor_), FieldName(field),
DefaultInstanceName(generator->descriptor_, options_),

@ -141,6 +141,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.unverified_lazy_message_sets = true;
} else if (options[i].first == "eagerly_verified_lazy") {
file_options.eagerly_verified_lazy = true;
} else if (options[i].first == "message_owned_arena_trial") {
file_options.message_owned_arena_trial = true;
} else if (options[i].first == "force_eagerly_verified_lazy") {
file_options.force_eagerly_verified_lazy = true;
} else if (options[i].first == "experimental_tail_call_table_mode") {

@ -184,6 +184,12 @@ bool IsEagerlyVerifiedLazyImpl(const FieldDescriptor* field,
return false;
}
// Returns true if the message can potentially allocate memory for its field.
// This is used to determine if message-owned arena will be useful.
bool AllocExpected(const Descriptor* descriptor) {
return false;
}
} // namespace
bool IsLazy(const FieldDescriptor* field, const Options& options,
@ -230,15 +236,18 @@ void SetCommonVars(const Options& options,
}
void SetCommonMessageDataVariables(
const Descriptor* descriptor,
std::map<std::string, std::string>* variables) {
(*variables)["any_metadata"] = "_any_metadata_";
(*variables)["cached_size"] = "_cached_size_";
(*variables)["extensions"] = "_extensions_";
(*variables)["has_bits"] = "_has_bits_";
(*variables)["inlined_string_donated_array"] = "_inlined_string_donated_";
(*variables)["oneof_case"] = "_oneof_case_";
(*variables)["tracker"] = "_tracker_";
(*variables)["weak_field_map"] = "_weak_field_map_";
std::string prefix = IsMapEntryMessage(descriptor) ? "" : "_impl_.";
(*variables)["any_metadata"] = prefix + "_any_metadata_";
(*variables)["cached_size"] = prefix + "_cached_size_";
(*variables)["extensions"] = prefix + "_extensions_";
(*variables)["has_bits"] = prefix + "_has_bits_";
(*variables)["inlined_string_donated_array"] =
prefix + "_inlined_string_donated_";
(*variables)["oneof_case"] = prefix + "_oneof_case_";
(*variables)["tracker"] = "Impl_::_tracker_";
(*variables)["weak_field_map"] = prefix + "_weak_field_map_";
}
void SetUnknownFieldsVariable(const Descriptor* descriptor,
@ -466,11 +475,13 @@ std::string FieldName(const FieldDescriptor* field) {
}
std::string FieldMemberName(const FieldDescriptor* field) {
StringPiece prefix =
IsMapEntryMessage(field->containing_type()) ? "" : "_impl_.";
if (field->real_containing_oneof() == nullptr) {
return StrCat(FieldName(field), "_");
return StrCat(prefix, FieldName(field), "_");
}
return StrCat(field->containing_oneof()->name(), "_.", FieldName(field),
"_");
return StrCat(prefix, field->containing_oneof()->name(), "_.",
FieldName(field), "_");
}
std::string OneofCaseConstantName(const FieldDescriptor* field) {
@ -987,6 +998,16 @@ bool ShouldVerify(const FileDescriptor* file, const Options& options,
return false;
}
bool IsUtf8String(const FieldDescriptor* field) {
return IsProto3(field->file()) &&
field->type() == FieldDescriptor::TYPE_STRING;
}
bool ShouldVerifySimple(const Descriptor* descriptor) {
(void)descriptor;
return false;
}
bool IsStringOrMessage(const FieldDescriptor* field) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
@ -1505,12 +1526,23 @@ FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
return FileOptions::SPEED;
}
inline bool IsMessageOwnedArenaEligible(const Descriptor* desc,
const Options& options) {
return GetOptimizeFor(desc->file(), options) != FileOptions::LITE_RUNTIME &&
AllocExpected(desc) && !options.bootstrap;
}
bool EnableMessageOwnedArena(const Descriptor* desc, const Options& options) {
(void)desc;
(void)options;
return false;
}
bool EnableMessageOwnedArenaTrial(const Descriptor* desc,
const Options& options) {
return false;
}
} // namespace cpp
} // namespace compiler
} // namespace protobuf

@ -89,6 +89,7 @@ void SetCommonVars(const Options& options,
// Variables to access message data from the message scope.
void SetCommonMessageDataVariables(
const Descriptor* descriptor,
std::map<std::string, std::string>* variables);
void SetUnknownFieldsVariable(const Descriptor* descriptor,
@ -485,8 +486,8 @@ inline bool IsCrossFileMessage(const FieldDescriptor* field) {
}
inline std::string MakeDefaultName(const FieldDescriptor* field) {
return "_i_give_permission_to_break_this_code_default_" + FieldName(field) +
"_";
return StrCat("_i_give_permission_to_break_this_code_default_",
FieldName(field), "_");
}
// Semantically distinct from MakeDefaultName in that it gives the C++ code
@ -500,7 +501,7 @@ inline std::string MakeDefaultName(const FieldDescriptor* field) {
// exists at some nested level like:
// internal_container_._i_give_permission_to_break_this_code_default_field_;
inline std::string MakeDefaultFieldName(const FieldDescriptor* field) {
return MakeDefaultName(field);
return StrCat("Impl_::", MakeDefaultName(field));
}
inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) {
@ -519,7 +520,7 @@ inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) {
// like:
// internal_container_._field_cached_byte_size_;
inline std::string MakeVarintCachedSizeFieldName(const FieldDescriptor* field) {
return StrCat("_", FieldName(field), "_cached_byte_size_");
return StrCat("_impl_._", FieldName(field), "_cached_byte_size_");
}
// Note: A lot of libraries detect Any protos based on Descriptor::full_name()
@ -1011,10 +1012,18 @@ PROTOC_EXPORT std::string StripProto(const std::string& filename);
bool EnableMessageOwnedArena(const Descriptor* desc, const Options& options);
bool EnableMessageOwnedArenaTrial(const Descriptor* desc,
const Options& options);
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
bool ShouldVerifySimple(const Descriptor* descriptor);
bool IsUtf8String(const FieldDescriptor* field);
} // namespace cpp
} // namespace compiler
} // namespace protobuf

@ -226,8 +226,7 @@ void MapFieldGenerator::GenerateSerializeWithCachedSizesToArray(
format);
}
}
format(
"};\n");
format("};\n");
}
format(
@ -271,21 +270,37 @@ void MapFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
"false;\n");
}
void MapFieldGenerator::GenerateConstinitInitializer(
void MapFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (HasDescriptorMethods(descriptor_->file(), options_)) {
format("$name$_(::$proto_ns$::internal::ConstantInitialized{})");
format("/*decltype($field$)*/{::_pbi::ConstantInitialized()}");
} else {
format("$name$_()");
format("/*decltype($field$)*/{}");
}
}
void MapFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
// MapField has no move constructor, which prevents explicit aggregate
// initialization pre-C++17.
format("/*decltype($field$)*/{}");
}
void MapFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
// MapField has no move constructor.
format("/*decltype($field$)*/{::_pbi::ArenaInitialized(), arena}");
}
void MapFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("$field$.Destruct();\n");
format("$field$.~MapField$lite$();\n");
}
void MapFieldGenerator::GenerateArenaDestructorCode(

@ -61,7 +61,10 @@ class MapFieldGenerator : public FieldGenerator {
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateIsInitialized(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateArenaDestructorCode(io::Printer* printer) const override;
ArenaDtorNeeds NeedsArenaDestructor() const override;

@ -83,7 +83,7 @@ static constexpr int kNoHasbit = -1;
// masks must be non-zero.
std::string ConditionalToCheckBitmasks(
const std::vector<uint32_t>& masks, bool return_success = true,
StringPiece has_bits_var = "_has_bits_") {
StringPiece has_bits_var = "_impl_._has_bits_") {
std::vector<std::string> parts;
for (int i = 0; i < masks.size(); i++) {
if (masks[i] == 0) continue;
@ -403,7 +403,7 @@ static int popcnt(uint32_t n) {
class ColdChunkSkipper {
public:
ColdChunkSkipper(
const Options& options,
const Descriptor* descriptor, const Options& options,
const std::vector<std::vector<const FieldDescriptor*>>& chunks,
const std::vector<int>& has_bit_indices, const double cold_threshold)
: chunks_(chunks),
@ -411,7 +411,7 @@ class ColdChunkSkipper {
access_info_map_(options.access_info_map),
cold_threshold_(cold_threshold) {
SetCommonVars(options, &variables_);
SetCommonMessageDataVariables(&variables_);
SetCommonMessageDataVariables(descriptor, &variables_);
}
// May open an external if check for a batch of cold fields. "from" is the
@ -495,7 +495,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index,
if (this_word == cached_has_word_index) {
format("(cached_has_bits & 0x$mask$u) != 0");
} else {
format("($1$_has_bits_[$2$] & 0x$mask$u) != 0", from, this_word);
format("($1$_impl_._has_bits_[$2$] & 0x$mask$u) != 0", from, this_word);
}
}
format(")) {\n");
@ -617,7 +617,7 @@ MessageGenerator::MessageGenerator(
if (!message_layout_helper_) {
message_layout_helper_.reset(new PaddingOptimizer());
}
SetCommonMessageDataVariables(&variables_);
SetCommonMessageDataVariables(descriptor, &variables_);
// Variables that apply to this class
variables_["classname"] = classname_;
@ -1398,6 +1398,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format(
"inline $classname$() : $classname$("
"::$proto_ns$::Arena::InternalCreateMessageOwnedArena(), true) {}\n");
} else if (EnableMessageOwnedArenaTrial(descriptor_, options_)) {
format(
"inline $classname$() : $classname$(InMoaTrial() ? "
"::$proto_ns$::Arena::InternalCreateMessageOwnedArena() : nullptr, "
"InMoaTrial()) {}\n");
} else {
format("inline $classname$() : $classname$(nullptr) {}\n");
}
@ -1676,7 +1681,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"int GetCachedSize() const final { return "
"$cached_size$.Get(); }"
"\n\nprivate:\n"
"void SharedCtor();\n"
"void SharedCtor(::$proto_ns$::Arena* arena, bool is_message_owned);\n"
"void SharedDtor();\n"
"void SetCachedSize(int size) const$ full_final$;\n"
"void InternalSwap($classname$* other);\n");
@ -1837,12 +1842,21 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
: StrCat("::$proto_ns$::internal::HasBits<",
sizeof_has_bits, "> _has_bits_;\n");
format(
"template <typename T> friend class "
"::$proto_ns$::Arena::InternalHelper;\n"
"typedef void InternalArenaConstructable_;\n"
"typedef void DestructorSkippable_;\n");
// To minimize padding, data members are divided into three sections:
// (1) members assumed to align to 8 bytes
// (2) members corresponding to message fields, re-ordered to optimize
// alignment.
// (3) members assumed to align to 4 bytes.
format("struct Impl_ {\n");
format.Indent();
// Members assumed to align to 8 bytes:
if (descriptor_->extension_range_count() > 0) {
@ -1866,12 +1880,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
InlinedStringDonatedSize());
}
format(
"template <typename T> friend class "
"::$proto_ns$::Arena::InternalHelper;\n"
"typedef void InternalArenaConstructable_;\n"
"typedef void DestructorSkippable_;\n");
if (!has_bit_indices_.empty()) {
// _has_bits_ is frequently accessed, so to reduce code size and improve
// speed, it should be close to the start of the object. Placing
@ -1941,6 +1949,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format("::$proto_ns$::internal::AnyMetadata _any_metadata_;\n");
}
format.Outdent();
format(
"};\n"
"union { Impl_ _impl_; };\n");
// The TableStruct struct needs access to the private parts, in order to
// construct the offsets of all members.
format("friend struct ::$tablename$;\n");
@ -2250,7 +2263,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
int count = 0;
for (auto oneof : OneOfRange(descriptor_)) {
format("PROTOBUF_FIELD_OFFSET($classtype$, $1$_),\n", oneof->name());
format("PROTOBUF_FIELD_OFFSET($classtype$, _impl_.$1$_),\n", oneof->name());
count++;
}
GOOGLE_CHECK_EQ(count, descriptor_->real_oneof_decl_count());
@ -2286,15 +2299,110 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* printer) {
if (HasSimpleBaseClass(descriptor_, options_)) return;
Formatter format(printer, variables_);
format("inline void $classname$::SharedCtor() {\n");
format(
"inline void $classname$::SharedCtor(\n"
" ::_pb::Arena* arena, bool is_message_owned) {\n"
" (void)arena;\n"
" (void)is_message_owned;\n");
format.Indent();
// Impl_ _impl_.
format("new (&_impl_) Impl_{");
format.Indent();
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
// Note: any fields without move/copy constructors can't be explicitly
// aggregate initialized pre-C++17.
if (descriptor_->extension_range_count() > 0) {
put_sep();
format("/*decltype($extensions$)*/{::_pbi::ArenaInitialized(), arena}");
}
if (!inlined_string_indices_.empty()) {
put_sep();
format("decltype($inlined_string_donated_array$){}");
}
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_);
if (!has_bit_indices_.empty()) {
put_sep();
format("decltype($has_bits$){}");
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
need_to_emit_cached_size = false;
}
}
// Initialize member variables with arena constructor.
for (auto field : optimized_order_) {
GOOGLE_DCHECK(!IsFieldStripped(field, options_));
put_sep();
field_generators_.get(field).GenerateAggregateInitializer(printer);
}
for (auto oneof : OneOfRange(descriptor_)) {
put_sep();
format("decltype(_impl_.$1$_){}", oneof->name());
}
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
}
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("/*decltype($oneof_case$)*/{}");
}
if (num_weak_fields_ > 0) {
put_sep();
format("decltype($weak_field_map$){arena}");
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
// AnyMetadata has no move constructor.
format("/*decltype($any_metadata$)*/{&_impl_.type_url_, &_impl_.value_}");
}
format.Outdent();
format("\n};\n");
std::vector<bool> processed(optimized_order_.size(), false);
GenerateConstructorBody(printer, processed, false);
if (!inlined_string_indices_.empty()) {
// Donate inline string fields.
format.Indent();
// The last bit is the tracking bit for registering ArenaDtor. The bit is 1
// means ArenaDtor is not registered on construction, and on demand register
// is needed.
format("if (arena != nullptr) {\n");
if (NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand) {
format(
" if (!is_message_owned) {\n"
" $inlined_string_donated_array$[0] = ~0u;\n"
" } else {\n"
// We should not register ArenaDtor for MOA.
" $inlined_string_donated_array$[0] = 0xFFFFFFFEu;\n"
" }\n");
} else {
format(" $inlined_string_donated_array$[0] = 0xFFFFFFFEu;\n");
}
for (size_t i = 1; i < InlinedStringDonatedSize(); ++i) {
format(" $inlined_string_donated_array$[$1$] = ~0u;\n", i);
}
format("}\n");
format.Outdent();
}
for (const FieldDescriptor* field : optimized_order_) {
field_generators_.get(field).GenerateConstructorCode(printer);
}
for (auto oneof : OneOfRange(descriptor_)) {
format("clear_has_$1$();\n", oneof->name());
}
format.Outdent();
format("}\n\n");
}
@ -2305,6 +2413,11 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* printer) {
format("inline void $classname$::SharedDtor() {\n");
format.Indent();
format("$DCHK$(GetArenaForAllocation() == nullptr);\n");
if (descriptor_->extension_range_count() > 0) {
format("$extensions$.~ExtensionSet();\n");
}
// Write the destructors for each field except oneof members.
// optimized_order_ does not contain oneof fields.
for (auto field : optimized_order_) {
@ -2323,6 +2436,11 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* printer) {
if (num_weak_fields_) {
format("$weak_field_map$.ClearAll();\n");
}
if (IsAnyMessage(descriptor_, options_)) {
format("$any_metadata$.~AnyMetadata();\n");
}
format.Outdent();
format(
"}\n"
@ -2378,71 +2496,90 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* printer) {
void MessageGenerator::GenerateConstexprConstructor(io::Printer* printer) {
Formatter format(printer, variables_);
if (IsMapEntryMessage(descriptor_)) {
format(
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized) {}\n");
return;
}
format(
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized)");
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_);
format(": _impl_{");
format.Indent();
const char* field_sep = ":";
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
if (!IsMapEntryMessage(descriptor_)) {
// Process non-oneof fields first.
for (auto field : optimized_order_) {
auto& gen = field_generators_.get(field);
if (descriptor_->extension_range_count() > 0) {
put_sep();
format("/*decltype($extensions$)*/{}");
}
if (!inlined_string_indices_.empty()) {
put_sep();
format("/*decltype($inlined_string_donated_array$)*/{}");
}
if (!has_bit_indices_.empty()) {
put_sep();
format("/*decltype($has_bits$)*/{}");
if (need_to_emit_cached_size) {
put_sep();
gen.GenerateConstinitInitializer(printer);
format("/*decltype($cached_size$)*/{}");
need_to_emit_cached_size = false;
}
}
for (auto field : optimized_order_) {
put_sep();
field_generators_.get(field).GenerateConstexprAggregateInitializer(printer);
}
for (auto oneof : OneOfRange(descriptor_)) {
put_sep();
format("/*decltype(_impl_.$1$_)*/{}", oneof->name());
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
format("_any_metadata_(&type_url_, &value_)");
}
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
}
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("_oneof_case_{}");
}
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("/*decltype($oneof_case$)*/{}");
}
if (num_weak_fields_) {
put_sep();
format("/*decltype($weak_field_map$)*/{}");
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
format(
"/*decltype($any_metadata$)*/{&_impl_.type_url_, "
"&_impl_.value_}");
}
format.Outdent();
format("{}\n");
format("} {}\n");
}
void MessageGenerator::GenerateConstructorBody(io::Printer* printer,
std::vector<bool> processed,
bool copy_constructor) const {
void MessageGenerator::GenerateCopyConstructorBody(io::Printer* printer) const {
Formatter format(printer, variables_);
const RunMap runs = FindRuns(
optimized_order_, [copy_constructor, this](const FieldDescriptor* field) {
return (copy_constructor && IsPOD(field)) ||
(!copy_constructor &&
CanBeManipulatedAsRawBytes(field, options_, scc_analyzer_));
});
std::string pod_template;
if (copy_constructor) {
pod_template =
"::memcpy(&$first$, &from.$first$,\n"
" static_cast<size_t>(reinterpret_cast<char*>(&$last$) -\n"
" reinterpret_cast<char*>(&$first$)) + sizeof($last$));\n";
} else {
pod_template =
"::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(\n"
" reinterpret_cast<char*>(&$first$) - "
"reinterpret_cast<char*>(this)),\n"
" 0, static_cast<size_t>(reinterpret_cast<char*>(&$last$) -\n"
" reinterpret_cast<char*>(&$first$)) + sizeof($last$));\n";
}
const RunMap runs =
FindRuns(optimized_order_,
[](const FieldDescriptor* field) { return IsPOD(field); });
for (int i = 0; i < optimized_order_.size(); ++i) {
if (processed[i]) {
continue;
}
std::string pod_template =
"::memcpy(&$first$, &from.$first$,\n"
" static_cast<size_t>(reinterpret_cast<char*>(&$last$) -\n"
" reinterpret_cast<char*>(&$first$)) + sizeof($last$));\n";
for (size_t i = 0; i < optimized_order_.size(); ++i) {
const FieldDescriptor* field = optimized_order_[i];
const auto it = runs.find(field);
@ -2463,11 +2600,7 @@ void MessageGenerator::GenerateConstructorBody(io::Printer* printer,
i += run_length - 1;
// ++i at the top of the loop.
} else {
if (copy_constructor) {
field_generators_.get(field).GenerateCopyConstructorCode(printer);
} else {
field_generators_.get(field).GenerateConstructorCode(printer);
}
field_generators_.get(field).GenerateCopyConstructorCode(printer);
}
}
}
@ -2475,78 +2608,14 @@ void MessageGenerator::GenerateConstructorBody(io::Printer* printer,
void MessageGenerator::GenerateStructors(io::Printer* printer) {
Formatter format(printer, variables_);
std::string superclass;
superclass = SuperClassName(descriptor_, options_);
std::string initializer_with_arena = superclass + "(arena, is_message_owned)";
if (descriptor_->extension_range_count() > 0) {
initializer_with_arena += ",\n _extensions_(arena)";
}
// Initialize member variables with arena constructor.
for (auto field : optimized_order_) {
GOOGLE_DCHECK(!IsFieldStripped(field, options_));
bool has_arena_constructor = field->is_repeated();
if (!field->real_containing_oneof() &&
(IsLazy(field, options_, scc_analyzer_) ||
IsStringPiece(field, options_) ||
(IsString(field, options_) && IsStringInlined(field, options_)))) {
has_arena_constructor = true;
}
if (has_arena_constructor) {
initializer_with_arena +=
std::string(",\n ") + FieldName(field) + std::string("_(arena)");
}
}
if (IsAnyMessage(descriptor_, options_)) {
initializer_with_arena += ",\n _any_metadata_(&type_url_, &value_)";
}
if (num_weak_fields_ > 0) {
initializer_with_arena += ", _weak_field_map_(arena)";
}
std::string initializer_null = superclass + "()";
if (IsAnyMessage(descriptor_, options_)) {
initializer_null += ", _any_metadata_(&type_url_, &value_)";
}
if (num_weak_fields_ > 0) {
initializer_null += ", _weak_field_map_(nullptr)";
}
format(
"$classname$::$classname$(::$proto_ns$::Arena* arena,\n"
" bool is_message_owned)\n"
" : $1$ {\n",
initializer_with_arena);
if (!inlined_string_indices_.empty()) {
// Donate inline string fields.
format.Indent();
// The last bit is the tracking bit for registering ArenaDtor. The bit is 1
// means ArenaDtor is not registered on construction, and on demand register
// is needed.
format("if (arena != nullptr) {\n");
if (NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand) {
format(
" if (!is_message_owned) {\n"
" $inlined_string_donated_array$[0] = ~0u;\n"
" } else {\n"
// We should not register ArenaDtor for MOA.
" $inlined_string_donated_array$[0] = 0xFFFFFFFEu;\n"
" }\n");
} else {
format(" $inlined_string_donated_array$[0] = 0xFFFFFFFEu;\n");
}
for (size_t i = 1; i < InlinedStringDonatedSize(); ++i) {
format(" $inlined_string_donated_array$[$1$] = ~0u;\n", i);
}
format("}\n");
format.Outdent();
}
" : $1$(arena, is_message_owned) {\n",
SuperClassName(descriptor_, options_));
if (!HasSimpleBaseClass(descriptor_, options_)) {
format(" SharedCtor();\n");
format(" SharedCtor(arena, is_message_owned);\n");
if (NeedsArenaDestructor() == ArenaDtorNeeds::kRequired) {
format(
" if (arena != nullptr && !is_message_owned) {\n"
@ -2576,40 +2645,68 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) {
} else {
format(
"$classname$::$classname$(const $classname$& from)\n"
" : $superclass$()");
format.Indent();
format.Indent();
" : $superclass$() {\n");
format.Indent();
// Do not copy inlined_string_donated_, because this is not an arena
// constructor.
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
format("new (&_impl_) Impl_{");
format.Indent();
if (descriptor_->extension_range_count() > 0) {
put_sep();
format("/*decltype($extensions$)*/{}");
}
if (!inlined_string_indices_.empty()) {
// Do not copy inlined_string_donated_, because this is not an arena
// constructor.
put_sep();
format("decltype($inlined_string_donated_array$){}");
}
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_);
if (!has_bit_indices_.empty()) {
format(",\n_has_bits_(from._has_bits_)");
put_sep();
format("decltype($has_bits$){from.$has_bits$}");
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
need_to_emit_cached_size = false;
}
}
std::vector<bool> processed(optimized_order_.size(), false);
for (int i = 0; i < optimized_order_.size(); i++) {
auto field = optimized_order_[i];
if (!(field->is_repeated() && !(field->is_map())) &&
!IsCord(field, options_)) {
continue;
}
// Initialize member variables with arena constructor.
for (auto field : optimized_order_) {
put_sep();
field_generators_.get(field).GenerateCopyAggregateInitializer(printer);
}
for (auto oneof : OneOfRange(descriptor_)) {
put_sep();
format("decltype(_impl_.$1$_){}", oneof->name());
}
processed[i] = true;
format(",\n$1$_(from.$1$_)", FieldName(field));
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
}
if (IsAnyMessage(descriptor_, options_)) {
format(",\n_any_metadata_(&type_url_, &value_)");
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("/*decltype($oneof_case$)*/{}");
}
if (num_weak_fields_ > 0) {
format(",\n_weak_field_map_(from._weak_field_map_)");
put_sep();
format("decltype($weak_field_map$){from.$weak_field_map$}");
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
format("/*decltype($any_metadata$)*/{&_impl_.type_url_, &_impl_.value_}");
}
format.Outdent();
format.Outdent();
format(" {\n");
format("};\n\n");
format(
"_internal_metadata_.MergeFrom<$unknown_fields_type$>(from._internal_"
@ -2621,7 +2718,7 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) {
"from.$extensions$);\n");
}
GenerateConstructorBody(printer, processed, true);
GenerateCopyConstructorBody(printer);
// Copy oneof fields. Oneof field requires oneof case check.
for (auto oneof : OneOfRange(descriptor_)) {
@ -2763,7 +2860,8 @@ void MessageGenerator::GenerateClear(io::Printer* printer) {
return same;
});
ColdChunkSkipper cold_skipper(options_, chunks, has_bit_indices_, kColdRatio);
ColdChunkSkipper cold_skipper(descriptor_, options_, chunks, has_bit_indices_,
kColdRatio);
int cached_has_word_index = -1;
for (int chunk_index = 0; chunk_index < chunks.size(); chunk_index++) {
@ -3002,14 +3100,11 @@ void MessageGenerator::GenerateSwap(io::Printer* printer) {
}
for (auto oneof : OneOfRange(descriptor_)) {
format("swap($1$_, other->$1$_);\n", oneof->name());
format("swap(_impl_.$1$_, other->_impl_.$1$_);\n", oneof->name());
}
for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
format(
"swap($oneof_case$[$1$], "
"other->$oneof_case$[$1$]);\n",
i);
format("swap($oneof_case$[$1$], other->$oneof_case$[$1$]);\n", i);
}
if (num_weak_fields_) {
@ -3109,7 +3204,8 @@ void MessageGenerator::GenerateClassSpecificMergeFrom(io::Printer* printer) {
return HasByteIndex(a) == HasByteIndex(b);
});
ColdChunkSkipper cold_skipper(options_, chunks, has_bit_indices_, kColdRatio);
ColdChunkSkipper cold_skipper(descriptor_, options_, chunks, has_bit_indices_,
kColdRatio);
// cached_has_word_index maintains that:
// cached_has_bits = from._has_bits_[cached_has_word_index]
@ -3485,7 +3581,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(
// Reload.
int new_index = has_bit_index / 32;
format_("cached_has_bits = _has_bits_[$1$];\n", new_index);
format_("cached_has_bits = _impl_._has_bits_[$1$];\n", new_index);
cached_has_bit_index_ = new_index;
}
@ -3885,7 +3981,8 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) {
chunks.erase(std::remove_if(chunks.begin(), chunks.end(), IsRequired),
chunks.end());
ColdChunkSkipper cold_skipper(options_, chunks, has_bit_indices_, kColdRatio);
ColdChunkSkipper cold_skipper(descriptor_, options_, chunks, has_bit_indices_,
kColdRatio);
int cached_has_word_index = -1;
format(

@ -161,9 +161,8 @@ class MessageGenerator {
void GenerateFieldClear(const FieldDescriptor* field, bool is_inline,
Formatter format);
void GenerateConstructorBody(io::Printer* printer,
std::vector<bool> already_processed,
bool copy_constructor) const;
// Generates the body of the message's copy constructor.
void GenerateCopyConstructorBody(io::Printer* printer) const;
// Returns the level that this message needs ArenaDtor. If the message has
// a field that is not arena-exclusive, it needs an ArenaDtor

@ -157,8 +157,7 @@ void MessageFieldGenerator::GenerateAccessorDeclarations(
}
void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions(
io::Printer* printer) const {
}
io::Printer* printer) const {}
void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
io::Printer* printer) const {
@ -438,14 +437,6 @@ void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
format("delete $field$;\n");
}
void MessageFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("$field$ = nullptr;\n");
}
void MessageFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
@ -454,8 +445,6 @@ void MessageFieldGenerator::GenerateCopyConstructorCode(
format(
"if (from._internal_has_$name$()) {\n"
" $field$ = new $type$(*from.$field$);\n"
"} else {\n"
" $field$ = nullptr;\n"
"}\n");
}
@ -500,10 +489,22 @@ void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
"}\n");
}
void MessageFieldGenerator::GenerateConstinitInitializer(
void MessageFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/nullptr");
}
void MessageFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){nullptr}");
}
void MessageFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_(nullptr)");
format("decltype($field$){nullptr}");
}
// ===================================================================
@ -846,6 +847,18 @@ void RepeatedMessageFieldGenerator::GenerateConstructorCode(
// Not needed for repeated fields.
}
void RepeatedMessageFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
if (implicit_weak_field_) {
format("$field$.~WeakRepeatedPtrField();\n");
} else {
format("$field$.~RepeatedPtrField();\n");
}
}
void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
@ -922,12 +935,6 @@ void RepeatedMessageFieldGenerator::GenerateIsInitialized(
}
}
void RepeatedMessageFieldGenerator::GenerateConstinitInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_()");
}
} // namespace cpp
} // namespace compiler
} // namespace protobuf

@ -67,13 +67,16 @@ class MessageFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateIsInitialized(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
protected:
const bool implicit_weak_field_;
@ -124,11 +127,11 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateIsInitialized(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
private:
const bool implicit_weak_field_;

@ -82,6 +82,7 @@ struct Options {
bool unverified_lazy_message_sets = true;
bool eagerly_verified_lazy = true;
bool profile_driven_inline_string = true;
bool message_owned_arena_trial = false;
bool force_split = false;
#ifdef PROTOBUF_STABLE_EXPERIMENTS
bool force_eagerly_verified_lazy = true;

@ -231,8 +231,7 @@ std::vector<const FieldDescriptor*> FilterMiniParsedFields(
break;
case FieldDescriptor::TYPE_ENUM:
if (field->is_repeated() &&
!HasPreservingUnknownEnumSemantics(field)) {
if (field->is_repeated() && !HasPreservingUnknownEnumSemantics(field)) {
// TODO(b/206890171): handle packed repeated closed enums
// Non-packed repeated can be handled using tables, but we still
// need to generate fallback code for all repeated enums in order to
@ -244,15 +243,15 @@ std::vector<const FieldDescriptor*> FilterMiniParsedFields(
}
break;
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING:
if (IsStringInlined(field, options)) {
// TODO(b/198211897): support InilnedStringField.
handled = false;
} else {
handled = true;
}
break;
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING:
if (IsStringInlined(field, options)) {
// TODO(b/198211897): support InilnedStringField.
handled = false;
} else {
handled = true;
}
break;
case FieldDescriptor::TYPE_MESSAGE:
case FieldDescriptor::TYPE_GROUP:
@ -291,8 +290,9 @@ TailCallTableInfo::TailCallTableInfo(
GOOGLE_LOG_IF(DFATAL, ordered_fields.empty())
<< "Invalid message: " << descriptor->full_name() << " has "
<< oneof_count << " oneof declarations, but no fields";
aux_entries.push_back(StrCat(
"_fl::Offset{offsetof(", ClassName(descriptor), ", _oneof_case_)}"));
aux_entries.push_back(StrCat("_fl::Offset{offsetof(",
ClassName(descriptor),
", _impl_._oneof_case_)}"));
}
// If this message has any inlined string fields, store the donation state
@ -301,7 +301,7 @@ TailCallTableInfo::TailCallTableInfo(
aux_entries.resize(2); // pad if necessary
aux_entries[1] =
StrCat("_fl::Offset{offsetof(", ClassName(descriptor),
", _inlined_string_donated_)}");
", _impl_._inlined_string_donated_)}");
}
// Fill in mini table entries.
@ -444,7 +444,7 @@ ParseFunctionGenerator::ParseFunctionGenerator(
inlined_string_indices, scc_analyzer));
}
SetCommonVars(options_, &variables_);
SetCommonMessageDataVariables(&variables_);
SetCommonMessageDataVariables(descriptor_, &variables_);
SetUnknownFieldsVariable(descriptor_, options_, &variables_);
variables_["classname"] = ClassName(descriptor, false);
}
@ -547,13 +547,13 @@ void ParseFunctionGenerator::GenerateTailcallFallbackFunction(
if (num_hasbits_ > 0) {
// Sync hasbits
format("typed_msg->_has_bits_[0] = hasbits;\n");
format("typed_msg->_impl_._has_bits_[0] = hasbits;\n");
}
format("uint32_t tag = data.tag();\n");
format.Set("msg", "typed_msg->");
format.Set("this", "typed_msg");
format.Set("has_bits", "typed_msg->_has_bits_");
format.Set("has_bits", "typed_msg->_impl_._has_bits_");
format.Set("next_tag", "goto next_tag");
GenerateParseIterationBody(format, descriptor_,
tc_table_info_->fallback_fields);
@ -649,7 +649,7 @@ void ParseFunctionGenerator::GenerateLoopingParseFunction(Formatter& format) {
format("_Internal::HasBits has_bits{};\n");
format.Set("has_bits", "has_bits");
} else {
format.Set("has_bits", "_has_bits_");
format.Set("has_bits", "_impl_._has_bits_");
}
format.Set("next_tag", "continue");
format("while (!ctx->Done(&ptr)) {\n");
@ -665,7 +665,7 @@ void ParseFunctionGenerator::GenerateLoopingParseFunction(Formatter& format) {
format.Outdent();
format("message_done:\n");
if (hasbits_size) format(" _has_bits_.Or(has_bits);\n");
if (hasbits_size) format(" _impl_._has_bits_.Or(has_bits);\n");
format(
" return ptr;\n"
@ -774,7 +774,7 @@ void ParseFunctionGenerator::GenerateTailCallTable(Formatter& format) {
{
auto header_scope = format.ScopedIndent();
if (num_hasbits_ > 0 || IsMapEntryMessage(descriptor_)) {
format("PROTOBUF_FIELD_OFFSET($classname$, _has_bits_),\n");
format("PROTOBUF_FIELD_OFFSET($classname$, _impl_._has_bits_),\n");
} else {
format("0, // no _has_bits_\n");
}

@ -186,12 +186,6 @@ void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
format("swap($field$, other->$field$);\n");
}
void PrimitiveFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$ = $default$;\n");
}
void PrimitiveFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
@ -230,10 +224,22 @@ void PrimitiveFieldGenerator::GenerateByteSize(io::Printer* printer) const {
}
}
void PrimitiveFieldGenerator::GenerateConstinitInitializer(
void PrimitiveFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/$default$");
}
void PrimitiveFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){$default$}");
}
void PrimitiveFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_($default$)");
format("decltype($field$){}");
}
// ===================================================================
@ -407,6 +413,12 @@ void RepeatedPrimitiveFieldGenerator::GenerateSwappingCode(
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.~RepeatedField();\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
@ -460,7 +472,8 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize(
format(
"if (data_size > 0) {\n"
" total_size += $tag_size$ +\n"
" ::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
" "
"::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
"}\n");
if (FixedSize(descriptor_->type()) == -1) {
format(
@ -480,13 +493,37 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize(
format("}\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateConstinitInitializer(
void RepeatedPrimitiveFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/{}");
if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}
void RepeatedPrimitiveFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_()");
format("decltype($field$){arena}");
if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 &&
HasGeneratedMethods(descriptor_->file(), options_)) {
// std::atomic has no move constructor, which prevents explicit aggregate
// initialization pre-C++17.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}
void RepeatedPrimitiveFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){from.$field$}");
if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format("\n, $cached_byte_size_name$(0)");
// std::atomic has no move constructor.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
}
}

@ -58,12 +58,15 @@ class PrimitiveFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
@ -100,10 +103,14 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator);

@ -118,7 +118,7 @@ void StringFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
//
// `_init_inline_xxx` is used for initializing default instances.
format(
"union { ::$proto_ns$::internal::InlinedStringField $name$_; };\n"
"::$proto_ns$::internal::InlinedStringField $name$_;\n"
"static std::true_type _init_inline_$name$_;\n");
}
}
@ -522,22 +522,38 @@ void StringFieldGenerator::GenerateByteSize(io::Printer* printer) const {
" this->_internal_$name$());\n");
}
void StringFieldGenerator::GenerateConstinitInitializer(
void StringFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (inlined_) {
format("$name$_(nullptr, false)");
format("/*decltype($field$)*/{nullptr, false}");
return;
}
if (descriptor_->default_value_string().empty()) {
format(
"$name$_(&::_pbi::fixed_address_empty_string, "
"::_pbi::ConstantInitialized{})");
"/*decltype($field$)*/{&::_pbi::fixed_address_empty_string, "
"::_pbi::ConstantInitialized{}}");
} else {
format("$name$_(nullptr, ::_pbi::ConstantInitialized{})");
format("/*decltype($field$)*/{nullptr, ::_pbi::ConstantInitialized{}}");
}
}
void StringFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (!inlined_) {
format("decltype($field$){}");
} else {
format("decltype($field$)(arena)");
}
}
void StringFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){}");
}
// ===================================================================
StringOneofFieldGenerator::StringOneofFieldGenerator(
@ -867,6 +883,12 @@ void RepeatedStringFieldGenerator::GenerateSwappingCode(
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedStringFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.~RepeatedPtrField();\n");
}
void RepeatedStringFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
@ -899,12 +921,6 @@ void RepeatedStringFieldGenerator::GenerateByteSize(
"}\n");
}
void RepeatedStringFieldGenerator::GenerateConstinitInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_()");
}
} // namespace cpp
} // namespace compiler
} // namespace protobuf

@ -69,7 +69,10 @@ class StringFieldGenerator : public FieldGenerator {
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
bool IsInlined() const override { return inlined_; }
ArenaDtorNeeds NeedsArenaDestructor() const override;
@ -113,10 +116,10 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator);

@ -339,19 +339,6 @@ TEST(GENERATED_MESSAGE_TEST_NAME, Clear) {
TestUtil::SetAllFields(&message);
message.Clear();
TestUtil::ExpectClear(message);
// Unlike with the defaults test, we do NOT expect that requesting embedded
// messages will return a pointer to the default instance. Instead, they
// should return the objects that were created when mutable_blah() was
// called.
EXPECT_NE(&UNITTEST::TestAllTypes::OptionalGroup::default_instance(),
&message.optionalgroup());
EXPECT_NE(&UNITTEST::TestAllTypes::NestedMessage::default_instance(),
&message.optional_nested_message());
EXPECT_NE(&UNITTEST::ForeignMessage::default_instance(),
&message.optional_foreign_message());
EXPECT_NE(&UNITTEST_IMPORT::ImportMessage::default_instance(),
&message.optional_import_message());
}
TEST(GENERATED_MESSAGE_TEST_NAME, EmbeddedNullsInBytesCharStar) {
@ -503,6 +490,9 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ADLSwap) {
// Note the address of one of the repeated fields, to verify it was swapped
// rather than copied.
const int32_t* addr = &message1.repeated_int32().Get(0);
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
const int32_t value = *addr;
#endif
using std::swap;
swap(message1, message2);
@ -512,7 +502,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ADLSwap) {
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
EXPECT_NE(addr, &message2.repeated_int32().Get(0));
EXPECT_EQ(*addr, message2.repeated_int32().Get(0));
EXPECT_EQ(value, message2.repeated_int32().Get(0));
#else
EXPECT_EQ(addr, &message2.repeated_int32().Get(0));
#endif

@ -49,17 +49,6 @@ TEST(JavaDocCommentTest, Escaping) {
EXPECT_EQ("&#64;deprecated", EscapeJavadoc("@deprecated"));
}
// TODO(kenton): It's hard to write a robust test of the doc comments -- we
// can only really compare the output against a golden value, which is a
// fairly tedious and fragile testing strategy. If we want to go that route,
// it probably makes sense to bite the bullet and write a test that compares
// the whole generated output for unittest.proto against a golden value, with
// a very simple script that can be run to regenerate it with the latest code.
// This would mean that updates to the golden file would have to be included
// in any change to the code generator, which would actually be fairly useful
// as it allows the reviewer to see clearly how the generated code is
// changing.
} // namespace
} // namespace java
} // namespace compiler

@ -261,18 +261,18 @@ std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) {
return name;
}
// Names that should be avoided as field names in Kotlin.
// All Kotlin hard keywords are in this list.
const std::unordered_set<std::string>* kKotlinForbiddenNames =
new std::unordered_set<std::string>({
"as", "as?", "break", "class", "continue", "do", "else",
"false", "for", "fun", "if", "in", "!in", "interface",
"is", "!is", "null", "object", "package", "return", "super",
"this", "throw", "true", "try", "typealias", "typeof", "val",
"var", "when", "while",
});
bool IsForbiddenKotlin(const std::string& field_name) {
// Names that should be avoided as field names in Kotlin.
// All Kotlin hard keywords are in this list.
const std::unordered_set<std::string>* kKotlinForbiddenNames =
new std::unordered_set<std::string>({
"as", "as?", "break", "class", "continue", "do",
"else", "false", "for", "fun", "if", "in",
"!in", "interface", "is", "!is", "null", "object",
"package", "return", "super", "this", "throw", "true",
"try", "typealias", "typeof", "val", "var", "when",
"while",
});
return kKotlinForbiddenNames->find(field_name) !=
kKotlinForbiddenNames->end();
}

@ -29,12 +29,9 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
//
// TODO(kenton): Share code with the versions of this test in other languages?
// It seemed like parameterizing it would add more complexity than it is
// worth.
#include <memory>
#include <string>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
@ -42,6 +39,7 @@
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@ -109,6 +107,25 @@ TEST(JavaPluginTest, PluginTest) {
test_out.c_str(), "test.proto"};
EXPECT_EQ(0, cli.Run(5, argv));
// Loop over the lines of the generated code and verify that we find what we
// expect
std::string output;
GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/Test.java", &output,
true));
std::vector<std::string> lines = Split(output, "\n");
bool found_generated_annotation = false;
bool found_do_not_edit = false;
for (const auto& line : lines) {
if (line.find(" DO NOT EDIT!") != std::string::npos) {
found_do_not_edit = true;
}
if (line.find("@com.google.protobuf.Generated") != std::string::npos) {
found_generated_annotation = true;
}
}
EXPECT_TRUE(found_do_not_edit);
}
} // namespace

@ -33,11 +33,11 @@
#include <google/protobuf/compiler/java/java_kotlin_generator.h>
#include <google/protobuf/compiler/js/js_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/python/python_generator.h>
#include <google/protobuf/compiler/python/python_pyi_generator.h>
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include <google/protobuf/compiler/objectivec/objectivec_generator.h>
#include <google/protobuf/compiler/php/php_generator.h>
#include <google/protobuf/compiler/python/python_generator.h>
#include <google/protobuf/compiler/python/python_pyi_generator.h>
#include <google/protobuf/compiler/ruby/ruby_generator.h>
// Must be included last.

@ -976,37 +976,14 @@ bool Parser::ParseMessageFieldNoLabel(
if (TryConsume("map")) {
if (LookingAt("<")) {
map_field.is_map_field = true;
DO(ParseMapType(&map_field, field, location));
} else {
// False positive
type_parsed = true;
type_name = "map";
}
}
if (map_field.is_map_field) {
if (field->has_oneof_index()) {
AddError("Map fields are not allowed in oneofs.");
return false;
}
if (field->has_label()) {
AddError(
"Field labels (required/optional/repeated) are not allowed on "
"map fields.");
return false;
}
if (field->has_extendee()) {
AddError("Map fields are not allowed to be extensions.");
return false;
}
field->set_label(FieldDescriptorProto::LABEL_REPEATED);
DO(Consume("<"));
DO(ParseType(&map_field.key_type, &map_field.key_type_name));
DO(Consume(","));
DO(ParseType(&map_field.value_type, &map_field.value_type_name));
DO(Consume(">"));
// Defer setting of the type name of the map field until the
// field name is parsed. Add the source location though.
location.AddPath(FieldDescriptorProto::kTypeNameFieldNumber);
} else {
if (!map_field.is_map_field) {
// Handle the case where no explicit label is given for a non-map field.
if (!field->has_label() && DefaultToOptionalFields()) {
field->set_label(FieldDescriptorProto::LABEL_OPTIONAL);
@ -1018,8 +995,8 @@ bool Parser::ParseMessageFieldNoLabel(
field->set_label(FieldDescriptorProto::LABEL_OPTIONAL);
}
// Handle the case where the actual type is a message or enum named "map",
// which we already consumed in the code above.
// Handle the case where the actual type is a message or enum named
// "map", which we already consumed in the code above.
if (!type_parsed) {
DO(ParseType(&type, &type_name));
}
@ -1127,6 +1104,34 @@ bool Parser::ParseMessageFieldNoLabel(
return true;
}
bool Parser::ParseMapType(MapField* map_field, FieldDescriptorProto* field,
LocationRecorder& type_name_location) {
if (field->has_oneof_index()) {
AddError("Map fields are not allowed in oneofs.");
return false;
}
if (field->has_label()) {
AddError(
"Field labels (required/optional/repeated) are not allowed on "
"map fields.");
return false;
}
if (field->has_extendee()) {
AddError("Map fields are not allowed to be extensions.");
return false;
}
field->set_label(FieldDescriptorProto::LABEL_REPEATED);
DO(Consume("<"));
DO(ParseType(&map_field->key_type, &map_field->key_type_name));
DO(Consume(","));
DO(ParseType(&map_field->value_type, &map_field->value_type_name));
DO(Consume(">"));
// Defer setting of the type name of the map field until the
// field name is parsed. Add the source location though.
type_name_location.AddPath(FieldDescriptorProto::kTypeNameFieldNumber);
return true;
}
void Parser::GenerateMapEntry(const MapField& map_field,
FieldDescriptorProto* field,
RepeatedPtrField<DescriptorProto>* messages) {

@ -122,6 +122,7 @@ class PROTOBUF_EXPORT Parser {
private:
class LocationRecorder;
struct MapField;
// =================================================================
// Error recovery helpers
@ -378,6 +379,9 @@ class PROTOBUF_EXPORT Parser {
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file);
bool ParseMapType(MapField* map_field, FieldDescriptorProto* field,
LocationRecorder& type_name_location);
// Parse an "extensions" declaration.
bool ParseExtensions(DescriptorProto* message,
const LocationRecorder& extensions_location,

@ -45,9 +45,10 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
namespace google {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -54,15 +54,15 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/compiler/python/python_helpers.h>
#include <google/protobuf/compiler/python/python_pyi_generator.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/python/python_helpers.h>
#include <google/protobuf/compiler/python/python_pyi_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
namespace google {
namespace protobuf {

@ -37,8 +37,8 @@
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/compiler/code_generator.h>
// Must be included last.
#include <google/protobuf/port_def.inc>

@ -32,9 +32,9 @@
#include <algorithm>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/descriptor.pb.h>
namespace google {

@ -29,12 +29,9 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
//
// TODO(kenton): Share code with the versions of this test in other languages?
// It seemed like parameterizing it would add more complexity than it is
// worth.
#include <memory>
#include <string>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>

@ -32,12 +32,12 @@
#include <string>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/compiler/python/python_helpers.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
namespace google {
namespace protobuf {

@ -38,8 +38,8 @@
#include <map>
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/compiler/code_generator.h>
// Must be included last.
#include <google/protobuf/port_def.inc>

@ -45,8 +45,8 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/message.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/message.h>
namespace google {
namespace protobuf {

@ -29,6 +29,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
#ifndef GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__
#define GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__
#include <cstdint>
#include <vector>
@ -63,3 +65,5 @@ class ZipWriter {
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_ZIP_WRITER_H__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -22,9 +22,10 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Duration::Duration(
::_pbi::ConstantInitialized)
: seconds_(int64_t{0})
, nanos_(0){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.seconds_)*/int64_t{0}
, /*decltype(_impl_.nanos_)*/0
, /*decltype(_impl_._cached_size_)*/{}} {}
struct DurationDefaultTypeInternal {
PROTOBUF_CONSTEXPR DurationDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -46,8 +47,8 @@ const uint32_t TableStruct_google_2fprotobuf_2fduration_2eproto::offsets[] PROTO
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, seconds_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, nanos_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.seconds_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.nanos_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Duration)},
@ -91,23 +92,32 @@ class Duration::_Internal {
Duration::Duration(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Duration)
}
Duration::Duration(const Duration& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.seconds_){}
, decltype(_impl_.nanos_){}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::memcpy(&seconds_, &from.seconds_,
static_cast<size_t>(reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
::memcpy(&_impl_.seconds_, &from._impl_.seconds_,
static_cast<size_t>(reinterpret_cast<char*>(&_impl_.nanos_) -
reinterpret_cast<char*>(&_impl_.seconds_)) + sizeof(_impl_.nanos_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.Duration)
}
inline void Duration::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&seconds_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
inline void Duration::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.seconds_){int64_t{0}}
, decltype(_impl_.nanos_){0}
, /*decltype(_impl_._cached_size_)*/{}
};
}
Duration::~Duration() {
@ -124,7 +134,7 @@ inline void Duration::SharedDtor() {
}
void Duration::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Duration::Clear() {
@ -133,9 +143,9 @@ void Duration::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
::memset(&seconds_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
::memset(&_impl_.seconds_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&_impl_.nanos_) -
reinterpret_cast<char*>(&_impl_.seconds_)) + sizeof(_impl_.nanos_));
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -148,7 +158,7 @@ const char* Duration::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx)
// int64 seconds = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 8)) {
seconds_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
_impl_.seconds_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else
goto handle_unusual;
@ -156,7 +166,7 @@ const char* Duration::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx)
// int32 nanos = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 16)) {
nanos_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
_impl_.nanos_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
CHK_(ptr);
} else
goto handle_unusual;
@ -228,7 +238,7 @@ size_t Duration::ByteSizeLong() const {
total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(this->_internal_nanos());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Duration::_class_data_ = {
@ -274,11 +284,11 @@ void Duration::InternalSwap(Duration* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Duration, nanos_)
+ sizeof(Duration::nanos_)
- PROTOBUF_FIELD_OFFSET(Duration, seconds_)>(
reinterpret_cast<char*>(&seconds_),
reinterpret_cast<char*>(&other->seconds_));
PROTOBUF_FIELD_OFFSET(Duration, _impl_.nanos_)
+ sizeof(Duration::_impl_.nanos_)
- PROTOBUF_FIELD_OFFSET(Duration, _impl_.seconds_)>(
reinterpret_cast<char*>(&_impl_.seconds_),
reinterpret_cast<char*>(&other->_impl_.seconds_));
}
::PROTOBUF_NAMESPACE_ID::Metadata Duration::GetMetadata() const {

@ -147,10 +147,10 @@ class PROTOBUF_EXPORT Duration final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(Duration* other);
@ -203,9 +203,12 @@ class PROTOBUF_EXPORT Duration final :
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
int64_t seconds_;
int32_t nanos_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
int64_t seconds_;
int32_t nanos_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fduration_2eproto;
};
// ===================================================================
@ -221,10 +224,10 @@ class PROTOBUF_EXPORT Duration final :
// int64 seconds = 1;
inline void Duration::clear_seconds() {
seconds_ = int64_t{0};
_impl_.seconds_ = int64_t{0};
}
inline int64_t Duration::_internal_seconds() const {
return seconds_;
return _impl_.seconds_;
}
inline int64_t Duration::seconds() const {
// @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds)
@ -232,7 +235,7 @@ inline int64_t Duration::seconds() const {
}
inline void Duration::_internal_set_seconds(int64_t value) {
seconds_ = value;
_impl_.seconds_ = value;
}
inline void Duration::set_seconds(int64_t value) {
_internal_set_seconds(value);
@ -241,10 +244,10 @@ inline void Duration::set_seconds(int64_t value) {
// int32 nanos = 2;
inline void Duration::clear_nanos() {
nanos_ = 0;
_impl_.nanos_ = 0;
}
inline int32_t Duration::_internal_nanos() const {
return nanos_;
return _impl_.nanos_;
}
inline int32_t Duration::nanos() const {
// @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos)
@ -252,7 +255,7 @@ inline int32_t Duration::nanos() const {
}
inline void Duration::_internal_set_nanos(int32_t value) {
nanos_ = value;
_impl_.nanos_ = value;
}
inline void Duration::set_nanos(int32_t value) {
_internal_set_nanos(value);

@ -22,7 +22,7 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Empty::Empty(
::_pbi::ConstantInitialized){}
::_pbi::ConstantInitialized): _impl_{} {}
struct EmptyDefaultTypeInternal {
PROTOBUF_CONSTEXPR EmptyDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -90,6 +90,8 @@ Empty::Empty(::PROTOBUF_NAMESPACE_ID::Arena* arena,
}
Empty::Empty(const Empty& from)
: ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase() {
new (&_impl_) Impl_{};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Empty)
}

@ -169,6 +169,9 @@ class PROTOBUF_EXPORT Empty final :
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
struct Impl_ {
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fempty_2eproto;
};
// ===================================================================

@ -48,5 +48,4 @@ option cc_enable_arenas = true;
// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
// }
//
// The JSON representation for `Empty` is empty JSON object `{}`.
message Empty {}

@ -949,49 +949,41 @@ void ExtensionSet::Clear() {
}
namespace {
// Computes the size of a std::set_union without constructing the union.
// Computes the size of an ExtensionSet union without actually constructing the
// union. Note that we do not count cleared extensions from the source to be
// part of the total, because there is no need to allocate space for those. We
// do include cleared extensions in the destination, though, because those are
// already allocated and will not be going away.
template <typename ItX, typename ItY>
size_t SizeOfUnion(ItX it_xs, ItX end_xs, ItY it_ys, ItY end_ys) {
size_t SizeOfUnion(ItX it_dest, ItX end_dest, ItY it_source, ItY end_source) {
size_t result = 0;
while (it_xs != end_xs && it_ys != end_ys) {
++result;
if (it_xs->first < it_ys->first) {
++it_xs;
} else if (it_xs->first == it_ys->first) {
++it_xs;
++it_ys;
while (it_dest != end_dest && it_source != end_source) {
if (it_dest->first < it_source->first) {
++result;
++it_dest;
} else if (it_dest->first == it_source->first) {
++result;
++it_dest;
++it_source;
} else {
++it_ys;
if (!it_source->second.is_cleared) {
++result;
}
++it_source;
}
}
result += std::distance(it_dest, end_dest);
for (; it_source != end_source; ++it_source) {
if (!it_source->second.is_cleared) {
++result;
}
}
result += std::distance(it_xs, end_xs);
result += std::distance(it_ys, end_ys);
return result;
}
} // namespace
void ExtensionSet::MergeFrom(const MessageLite* extendee,
const ExtensionSet& other) {
// check if the other is cleared
bool is_other_all_cleared = true;
if (PROTOBUF_PREDICT_TRUE(!other.is_large())){
for (const KeyValue* it = other.flat_begin(); it != other.flat_end(); it++){
is_other_all_cleared = is_other_all_cleared && it->second.is_cleared;
if (!is_other_all_cleared){
break;
}
}
} else {
for (LargeMap::iterator it = other.map_.large->begin(); it != other.map_.large->end(); it++){
is_other_all_cleared = is_other_all_cleared && it->second.is_cleared;
if (!is_other_all_cleared){
break;
}
}
}
if (is_other_all_cleared){
return;
}
if (PROTOBUF_PREDICT_TRUE(!is_large())) {
if (PROTOBUF_PREDICT_TRUE(!other.is_large())) {
GrowCapacity(SizeOfUnion(flat_begin(), flat_end(), other.flat_begin(),

@ -359,7 +359,8 @@ int ExtensionSet::SpaceUsedExcludingSelf() const {
}
size_t ExtensionSet::SpaceUsedExcludingSelfLong() const {
size_t total_size = (is_large() ? map_.large->size() : flat_capacity_) * sizeof(KeyValue);
size_t total_size =
(is_large() ? map_.large->size() : flat_capacity_) * sizeof(KeyValue);
ForEach([&total_size](int /* number */, const Extension& ext) {
total_size += ext.SpaceUsedExcludingSelfLong();
});

@ -107,20 +107,6 @@ TEST(ExtensionSetTest, Clear) {
message.Clear();
TestUtil::ExpectExtensionsClear(message);
// Unlike with the defaults test, we do NOT expect that requesting embedded
// messages will return a pointer to the default instance. Instead, they
// should return the objects that were created when mutable_blah() was
// called.
EXPECT_NE(&unittest::OptionalGroup_extension::default_instance(),
&message.GetExtension(unittest::optionalgroup_extension));
EXPECT_NE(&unittest::TestAllTypes::NestedMessage::default_instance(),
&message.GetExtension(unittest::optional_nested_message_extension));
EXPECT_NE(
&unittest::ForeignMessage::default_instance(),
&message.GetExtension(unittest::optional_foreign_message_extension));
EXPECT_NE(&unittest_import::ImportMessage::default_instance(),
&message.GetExtension(unittest::optional_import_message_extension));
// Make sure setting stuff again after clearing works. (This takes slightly
// different code paths since the objects are reused.)
TestUtil::SetAllExtensions(&message);
@ -414,6 +400,46 @@ TEST(ExtensionSetTest, ArenaMergeFrom) {
TestUtil::ExpectAllExtensionsSet(message2);
}
TEST(ExtensionSetTest, ArenaMergeFromWithClearedExtensions) {
Arena arena;
{
auto* message1 = Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
auto* message2 = Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
// Set an extension and then clear it
message1->SetExtension(unittest::optional_int32_extension, 1);
message1->ClearExtension(unittest::optional_int32_extension);
// Since all extensions in message1 have been cleared, we should be able to
// merge it into message2 without allocating any additional memory.
uint64_t space_used_before_merge = arena.SpaceUsed();
message2->MergeFrom(*message1);
EXPECT_EQ(space_used_before_merge, arena.SpaceUsed());
}
{
// As more complicated case, let's have message1 and message2 share some
// uncleared extensions in common.
auto* message1 = Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
auto* message2 = Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
// Set int32 and uint32 on both messages.
message1->SetExtension(unittest::optional_int32_extension, 1);
message2->SetExtension(unittest::optional_int32_extension, 2);
message1->SetExtension(unittest::optional_uint32_extension, 1);
message2->SetExtension(unittest::optional_uint32_extension, 2);
// Set and clear int64 and uint64 on message1.
message1->SetExtension(unittest::optional_int64_extension, 0);
message1->ClearExtension(unittest::optional_int64_extension);
message1->SetExtension(unittest::optional_uint64_extension, 0);
message1->ClearExtension(unittest::optional_uint64_extension);
uint64_t space_used_before_merge = arena.SpaceUsed();
message2->MergeFrom(*message1);
EXPECT_EQ(space_used_before_merge, arena.SpaceUsed());
}
}
TEST(ExtensionSetTest, ArenaSetAllocatedMessageAndRelease) {
Arena arena;
unittest::TestAllExtensions* message =
@ -1340,13 +1366,13 @@ TEST(ExtensionSetTest, ConstInit) {
TEST(ExtensionSetTest, ExtensionSetSpaceUsed) {
unittest::TestAllExtensions msg;
long l = msg.SpaceUsedLong();
size_t l = msg.SpaceUsedLong();
msg.SetExtension(unittest::optional_int32_extension, 100);
unittest::TestAllExtensions msg2(msg);
long l2 = msg2.SpaceUsedLong();
size_t l2 = msg2.SpaceUsedLong();
msg.ClearExtension(unittest::optional_int32_extension);
unittest::TestAllExtensions msg3(msg);
long l3 = msg3.SpaceUsedLong();
size_t l3 = msg3.SpaceUsedLong();
EXPECT_TRUE((l2 - l) > (l3 - l));
}

@ -22,8 +22,9 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR FieldMask::FieldMask(
::_pbi::ConstantInitialized)
: paths_(){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.paths_)*/{}
, /*decltype(_impl_._cached_size_)*/{}} {}
struct FieldMaskDefaultTypeInternal {
PROTOBUF_CONSTEXPR FieldMaskDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -45,7 +46,7 @@ const uint32_t TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets[] P
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, paths_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _impl_.paths_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldMask)},
@ -88,19 +89,28 @@ class FieldMask::_Internal {
FieldMask::FieldMask(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
paths_(arena) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.FieldMask)
}
FieldMask::FieldMask(const FieldMask& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
paths_(from.paths_) {
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.paths_){from._impl_.paths_}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldMask)
}
inline void FieldMask::SharedCtor() {
inline void FieldMask::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.paths_){arena}
, /*decltype(_impl_._cached_size_)*/{}
};
}
FieldMask::~FieldMask() {
@ -114,10 +124,11 @@ FieldMask::~FieldMask() {
inline void FieldMask::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
_impl_.paths_.~RepeatedPtrField();
}
void FieldMask::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void FieldMask::Clear() {
@ -126,7 +137,7 @@ void FieldMask::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
paths_.Clear();
_impl_.paths_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -208,13 +219,13 @@ size_t FieldMask::ByteSizeLong() const {
// repeated string paths = 1;
total_size += 1 *
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(paths_.size());
for (int i = 0, n = paths_.size(); i < n; i++) {
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_impl_.paths_.size());
for (int i = 0, n = _impl_.paths_.size(); i < n; i++) {
total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
paths_.Get(i));
_impl_.paths_.Get(i));
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldMask::_class_data_ = {
@ -236,7 +247,7 @@ void FieldMask::MergeFrom(const FieldMask& from) {
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
paths_.MergeFrom(from.paths_);
_impl_.paths_.MergeFrom(from._impl_.paths_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
@ -254,7 +265,7 @@ bool FieldMask::IsInitialized() const {
void FieldMask::InternalSwap(FieldMask* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
paths_.InternalSwap(&other->paths_);
_impl_.paths_.InternalSwap(&other->_impl_.paths_);
}
::PROTOBUF_NAMESPACE_ID::Metadata FieldMask::GetMetadata() const {

@ -147,10 +147,10 @@ class PROTOBUF_EXPORT FieldMask final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(FieldMask* other);
@ -208,8 +208,11 @@ class PROTOBUF_EXPORT FieldMask final :
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string> paths_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string> paths_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto;
};
// ===================================================================
@ -225,13 +228,13 @@ class PROTOBUF_EXPORT FieldMask final :
// repeated string paths = 1;
inline int FieldMask::_internal_paths_size() const {
return paths_.size();
return _impl_.paths_.size();
}
inline int FieldMask::paths_size() const {
return _internal_paths_size();
}
inline void FieldMask::clear_paths() {
paths_.Clear();
_impl_.paths_.Clear();
}
inline std::string* FieldMask::add_paths() {
std::string* _s = _internal_add_paths();
@ -239,7 +242,7 @@ inline std::string* FieldMask::add_paths() {
return _s;
}
inline const std::string& FieldMask::_internal_paths(int index) const {
return paths_.Get(index);
return _impl_.paths_.Get(index);
}
inline const std::string& FieldMask::paths(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldMask.paths)
@ -247,55 +250,55 @@ inline const std::string& FieldMask::paths(int index) const {
}
inline std::string* FieldMask::mutable_paths(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.FieldMask.paths)
return paths_.Mutable(index);
return _impl_.paths_.Mutable(index);
}
inline void FieldMask::set_paths(int index, const std::string& value) {
paths_.Mutable(index)->assign(value);
_impl_.paths_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
}
inline void FieldMask::set_paths(int index, std::string&& value) {
paths_.Mutable(index)->assign(std::move(value));
_impl_.paths_.Mutable(index)->assign(std::move(value));
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
}
inline void FieldMask::set_paths(int index, const char* value) {
GOOGLE_DCHECK(value != nullptr);
paths_.Mutable(index)->assign(value);
_impl_.paths_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths)
}
inline void FieldMask::set_paths(int index, const char* value, size_t size) {
paths_.Mutable(index)->assign(
_impl_.paths_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths)
}
inline std::string* FieldMask::_internal_add_paths() {
return paths_.Add();
return _impl_.paths_.Add();
}
inline void FieldMask::add_paths(const std::string& value) {
paths_.Add()->assign(value);
_impl_.paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
inline void FieldMask::add_paths(std::string&& value) {
paths_.Add(std::move(value));
_impl_.paths_.Add(std::move(value));
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
inline void FieldMask::add_paths(const char* value) {
GOOGLE_DCHECK(value != nullptr);
paths_.Add()->assign(value);
_impl_.paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths)
}
inline void FieldMask::add_paths(const char* value, size_t size) {
paths_.Add()->assign(reinterpret_cast<const char*>(value), size);
_impl_.paths_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.FieldMask.paths)
}
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>&
FieldMask::paths() const {
// @@protoc_insertion_point(field_list:google.protobuf.FieldMask.paths)
return paths_;
return _impl_.paths_;
}
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>*
FieldMask::mutable_paths() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldMask.paths)
return &paths_;
return &_impl_.paths_;
}
#ifdef __GNUC__

@ -152,28 +152,6 @@ TEST(GeneratedMessageReflectionTest, GetStringReference) {
}
TEST(GeneratedMessageReflectionTest, DefaultsAfterClear) {
// Check that after setting all fields and then clearing, getting an
// embedded message does NOT return the default instance.
unittest::TestAllTypes message;
TestUtil::ReflectionTester reflection_tester(
unittest::TestAllTypes::descriptor());
TestUtil::SetAllFields(&message);
message.Clear();
const Reflection* reflection = message.GetReflection();
EXPECT_NE(&unittest::TestAllTypes::OptionalGroup::default_instance(),
&reflection->GetMessage(message, F("optionalgroup")));
EXPECT_NE(&unittest::TestAllTypes::NestedMessage::default_instance(),
&reflection->GetMessage(message, F("optional_nested_message")));
EXPECT_NE(&unittest::ForeignMessage::default_instance(),
&reflection->GetMessage(message, F("optional_foreign_message")));
EXPECT_NE(&unittest_import::ImportMessage::default_instance(),
&reflection->GetMessage(message, F("optional_import_message")));
}
class GeneratedMessageReflectionSwapTest : public testing::TestWithParam<bool> {
protected:
void Swap(const Reflection* reflection, Message* lhs, Message* rhs) {

@ -47,7 +47,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/port.h>
#include <zlib.h>
#include "zlib.h"
// Must be included last.
#include <google/protobuf/port_def.inc>

@ -98,6 +98,9 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/stl_util.h>
// Must be included last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace io {
@ -937,12 +940,23 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value,
// token, but Tokenizer still think it's integer.
return false;
}
if (static_cast<uint64_t>(digit) > max_value ||
result > (max_value - digit) / base) {
if (static_cast<uint64_t>(digit) > max_value) return false;
#if PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW
// If there is a uint64_t overflow, there is a result * base logical
// overflow. This is done to avoid division.
if (__builtin_mul_overflow(result, base, &result) ||
result > (max_value - digit)) {
// Overflow.
return false;
}
result += digit;
#else
if (result > (max_value - digit) / base) {
// Overflow.
return false;
}
result = result * base + digit;
#endif // PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW
}
*output = result;
@ -1183,3 +1197,6 @@ bool Tokenizer::IsIdentifier(const std::string& text) {
} // namespace io
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>

@ -35,18 +35,18 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/map_lite_test_util.h>
#include <google/protobuf/map_lite_unittest.pb.h>
#include <google/protobuf/test_util_lite.h>
#include <google/protobuf/unittest_lite.pb.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/map_lite_test_util.h>
#include <google/protobuf/test_util_lite.h>
#include <google/protobuf/wire_format_lite.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
namespace google {
namespace protobuf {

@ -34,8 +34,6 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/map_test_util.h>
#include <google/protobuf/map_unittest.pb.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/arena.h>
@ -44,6 +42,8 @@
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <gtest/gtest.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/map_test_util.h>
// Must be included last.
#include <google/protobuf/port_def.inc>

@ -29,6 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/map_lite_test_util.h>
#include <google/protobuf/map_lite_unittest.pb.h>
#include <google/protobuf/map_test_util_impl.h>

@ -49,12 +49,17 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/descriptor.pb.h>
#include <gmock/gmock.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h>
@ -67,11 +72,6 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/util/message_differencer.h>
#include <google/protobuf/util/time_util.h>
#include <gmock/gmock.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/substitute.h>
// Must be included last.
@ -3625,13 +3625,17 @@ TEST(TextFormatMapTest, Sorted) {
&expected_text, true));
CleanStringLineEndings(&expected_text, false);
EXPECT_EQ(message.DebugString(), expected_text);
TextFormat::Printer printer;
std::string actual_text;
printer.PrintToString(message, &actual_text);
EXPECT_EQ(actual_text, expected_text);
// Test again on the reverse order.
UNITTEST::TestMap message2;
tester.SetMapFieldsViaReflection(&message2);
tester.SwapMapsViaReflection(&message2);
EXPECT_EQ(message2.DebugString(), expected_text);
printer.PrintToString(message2, &actual_text);
EXPECT_EQ(actual_text, expected_text);
}
TEST(TextFormatMapTest, ParseCorruptedString) {

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/map_test_util_impl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/map_test_util_impl.h>
#include <google/protobuf/message.h>
namespace google {

@ -440,6 +440,10 @@ class PROTOBUF_EXPORT MessageLite {
// messages, etc), or owning incoming objects (e.g., set allocated).
Arena* GetArenaForAllocation() const { return _internal_metadata_.arena(); }
// Returns true if this message is enabled for message-owned arena (MOA)
// trials. No lite messages are eligible for MOA.
static bool InMoaTrial() { return false; }
internal::InternalMetadata _internal_metadata_;
public:

@ -34,6 +34,7 @@
#include <cstdint>
#include <cstring>
#include <string>
#include <type_traits>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
@ -374,6 +375,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream {
using LazyEagerVerifyFnType = const char* (*)(const char* ptr,
ParseContext* ctx);
using LazyEagerVerifyFnRef = std::remove_pointer<LazyEagerVerifyFnType>::type&;
// ParseContext holds all data that is global to the entire parse. Most
// importantly it contains the input stream, but also recursion depth and also

@ -535,6 +535,17 @@
#define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred)
#endif
// PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW tells the compiler if it has
// __builtin_mul_overflow intrinsic to check for multiplication overflow.
#ifdef PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW
#error PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW was previously defined
#endif
#if __has_builtin(__builtin_mul_overflow)
#define PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW 1
#else
#define PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW 0
#endif
// Specify memory alignment for structs, classes, etc.
// Use like:
// class PROTOBUF_ALIGNAS(16) MyClass { ... }

@ -72,6 +72,7 @@
#undef PROTOBUF_NAMESPACE_CLOSE
#undef PROTOBUF_UNUSED
#undef PROTOBUF_ASSUME
#undef PROTOBUF_HAS_BUILTIN_MUL_OVERFLOW
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
#undef PROTOBUF_ALIGNAS

@ -872,8 +872,28 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase {
const Element& Get(int index) const;
Element* Mutable(int index);
// Unlike std::vector, adding an element to a RepeatedPtrField doesn't always
// make a new element; it might re-use an element left over from when the
// field was Clear()'d or reize()'d smaller. For this reason, Add() is the
// fastest API for adding a new element.
Element* Add();
// `Add(std::move(value));` is equivalent to `*Add() = std::move(value);`
// It will either move-construct to the end of this field, or swap value
// with the new-or-recycled element at the end of this field. Note that
// this operation is very slow if this RepeatedPtrField is not on the
// same Arena, if any, as `value`.
void Add(Element&& value);
// Copying to the end of this RepeatedPtrField is slowest of all; it can't
// reliably copy-construct to the last element of this RepeatedPtrField, for
// example (unlike std::vector).
// We currently block this API. The right way to add to the end is to call
// Add() and modify the element it points to.
// If you must add an existing value, call `*Add() = value;`
void Add(const Element& value) = delete;
// Append elements in the range [begin, end) after reserving
// the appropriate number of elements.
template <typename Iter>

@ -22,8 +22,9 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR SourceContext::SourceContext(
::_pbi::ConstantInitialized)
: file_name_(&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.file_name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}
, /*decltype(_impl_._cached_size_)*/{}} {}
struct SourceContextDefaultTypeInternal {
PROTOBUF_CONSTEXPR SourceContextDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -45,7 +46,7 @@ const uint32_t TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, file_name_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _impl_.file_name_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceContext)},
@ -89,28 +90,39 @@ class SourceContext::_Internal {
SourceContext::SourceContext(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.SourceContext)
}
SourceContext::SourceContext(const SourceContext& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.file_name_){}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
file_name_.InitDefault();
_impl_.file_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
file_name_.Set("", GetArenaForAllocation());
_impl_.file_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_file_name().empty()) {
file_name_.Set(from._internal_file_name(),
_impl_.file_name_.Set(from._internal_file_name(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext)
}
inline void SourceContext::SharedCtor() {
file_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
file_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
inline void SourceContext::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.file_name_){}
, /*decltype(_impl_._cached_size_)*/{}
};
_impl_.file_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.file_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
SourceContext::~SourceContext() {
@ -124,11 +136,11 @@ SourceContext::~SourceContext() {
inline void SourceContext::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
file_name_.Destroy();
_impl_.file_name_.Destroy();
}
void SourceContext::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void SourceContext::Clear() {
@ -137,7 +149,7 @@ void SourceContext::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
file_name_.ClearToEmpty();
_impl_.file_name_.ClearToEmpty();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -219,7 +231,7 @@ size_t SourceContext::ByteSizeLong() const {
this->_internal_file_name());
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceContext::_class_data_ = {
@ -264,8 +276,8 @@ void SourceContext::InternalSwap(SourceContext* other) {
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&file_name_, lhs_arena,
&other->file_name_, rhs_arena
&_impl_.file_name_, lhs_arena,
&other->_impl_.file_name_, rhs_arena
);
}

@ -147,10 +147,10 @@ class PROTOBUF_EXPORT SourceContext final :
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
uint8_t* _InternalSerialize(
uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
int GetCachedSize() const final { return _cached_size_.Get(); }
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
private:
void SharedCtor();
void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned);
void SharedDtor();
void SetCachedSize(int size) const final;
void InternalSwap(SourceContext* other);
@ -198,8 +198,11 @@ class PROTOBUF_EXPORT SourceContext final :
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr file_name_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr file_name_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto;
};
// ===================================================================
@ -215,7 +218,7 @@ class PROTOBUF_EXPORT SourceContext final :
// string file_name = 1;
inline void SourceContext::clear_file_name() {
file_name_.ClearToEmpty();
_impl_.file_name_.ClearToEmpty();
}
inline const std::string& SourceContext::file_name() const {
// @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name)
@ -225,7 +228,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void SourceContext::set_file_name(ArgT0&& arg0, ArgT... args) {
file_name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
_impl_.file_name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name)
}
inline std::string* SourceContext::mutable_file_name() {
@ -234,19 +237,19 @@ inline std::string* SourceContext::mutable_file_name() {
return _s;
}
inline const std::string& SourceContext::_internal_file_name() const {
return file_name_.Get();
return _impl_.file_name_.Get();
}
inline void SourceContext::_internal_set_file_name(const std::string& value) {
file_name_.Set(value, GetArenaForAllocation());
_impl_.file_name_.Set(value, GetArenaForAllocation());
}
inline std::string* SourceContext::_internal_mutable_file_name() {
return file_name_.Mutable(GetArenaForAllocation());
return _impl_.file_name_.Mutable(GetArenaForAllocation());
}
inline std::string* SourceContext::release_file_name() {
// @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name)
return file_name_.Release();
return _impl_.file_name_.Release();
}
inline void SourceContext::set_allocated_file_name(std::string* file_name) {
if (file_name != nullptr) {
@ -254,10 +257,10 @@ inline void SourceContext::set_allocated_file_name(std::string* file_name) {
} else {
}
file_name_.SetAllocated(file_name, GetArenaForAllocation());
_impl_.file_name_.SetAllocated(file_name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (file_name_.IsDefault()) {
file_name_.Set("", GetArenaForAllocation());
if (_impl_.file_name_.IsDefault()) {
_impl_.file_name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)

@ -22,7 +22,7 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Struct_FieldsEntry_DoNotUse::Struct_FieldsEntry_DoNotUse(
::_pbi::ConstantInitialized){}
::_pbi::ConstantInitialized) {}
struct Struct_FieldsEntry_DoNotUseDefaultTypeInternal {
PROTOBUF_CONSTEXPR Struct_FieldsEntry_DoNotUseDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -33,8 +33,9 @@ struct Struct_FieldsEntry_DoNotUseDefaultTypeInternal {
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_;
PROTOBUF_CONSTEXPR Struct::Struct(
::_pbi::ConstantInitialized)
: fields_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.fields_)*/{::_pbi::ConstantInitialized()}
, /*decltype(_impl_._cached_size_)*/{}} {}
struct StructDefaultTypeInternal {
PROTOBUF_CONSTEXPR StructDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -45,8 +46,10 @@ struct StructDefaultTypeInternal {
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StructDefaultTypeInternal _Struct_default_instance_;
PROTOBUF_CONSTEXPR Value::Value(
::_pbi::ConstantInitialized)
: _oneof_case_{}{}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.kind_)*/{}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._oneof_case_)*/{}} {}
struct ValueDefaultTypeInternal {
PROTOBUF_CONSTEXPR ValueDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -57,8 +60,9 @@ struct ValueDefaultTypeInternal {
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ValueDefaultTypeInternal _Value_default_instance_;
PROTOBUF_CONSTEXPR ListValue::ListValue(
::_pbi::ConstantInitialized)
: values_(){}
::_pbi::ConstantInitialized): _impl_{
/*decltype(_impl_.values_)*/{}
, /*decltype(_impl_._cached_size_)*/{}} {}
struct ListValueDefaultTypeInternal {
PROTOBUF_CONSTEXPR ListValueDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -90,11 +94,11 @@ const uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBU
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, fields_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, _impl_.fields_),
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _internal_metadata_),
~0u, // no _extensions_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _oneof_case_[0]),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_._oneof_case_[0]),
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
::_pbi::kInvalidFieldOffsetTag,
@ -103,14 +107,14 @@ const uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBU
::_pbi::kInvalidFieldOffsetTag,
::_pbi::kInvalidFieldOffsetTag,
::_pbi::kInvalidFieldOffsetTag,
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, kind_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_.kind_),
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, values_),
PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _impl_.values_),
};
static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, 8, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse)},
@ -196,9 +200,8 @@ class Struct::_Internal {
Struct::Struct(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
fields_(arena) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
if (arena != nullptr && !is_message_owned) {
arena->OwnCustomDestructor(this, &Struct::ArenaDtor);
}
@ -206,12 +209,23 @@ Struct::Struct(::PROTOBUF_NAMESPACE_ID::Arena* arena,
}
Struct::Struct(const Struct& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
/*decltype(_impl_.fields_)*/{}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
fields_.MergeFrom(from.fields_);
_impl_.fields_.MergeFrom(from._impl_.fields_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Struct)
}
inline void Struct::SharedCtor() {
inline void Struct::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
/*decltype(_impl_.fields_)*/{::_pbi::ArenaInitialized(), arena}
, /*decltype(_impl_._cached_size_)*/{}
};
}
Struct::~Struct() {
@ -226,15 +240,16 @@ Struct::~Struct() {
inline void Struct::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
fields_.Destruct();
_impl_.fields_.Destruct();
_impl_.fields_.~MapField();
}
void Struct::ArenaDtor(void* object) {
Struct* _this = reinterpret_cast< Struct* >(object);
_this->fields_.Destruct();
_this->_impl_.fields_.Destruct();
}
void Struct::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Struct::Clear() {
@ -243,7 +258,7 @@ void Struct::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
fields_.Clear();
_impl_.fields_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -259,7 +274,7 @@ const char* Struct::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseMessage(&fields_, ptr);
ptr = ctx->ParseMessage(&_impl_.fields_, ptr);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr));
@ -346,7 +361,7 @@ size_t Struct::ByteSizeLong() const {
total_size += Struct_FieldsEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second);
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Struct::_class_data_ = {
@ -368,7 +383,7 @@ void Struct::MergeFrom(const Struct& from) {
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
fields_.MergeFrom(from.fields_);
_impl_.fields_.MergeFrom(from._impl_.fields_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
@ -386,7 +401,7 @@ bool Struct::IsInitialized() const {
void Struct::InternalSwap(Struct* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
fields_.InternalSwap(&other->fields_);
_impl_.fields_.InternalSwap(&other->_impl_.fields_);
}
::PROTOBUF_NAMESPACE_ID::Metadata Struct::GetMetadata() const {
@ -405,11 +420,11 @@ class Value::_Internal {
const ::PROTOBUF_NAMESPACE_ID::Struct&
Value::_Internal::struct_value(const Value* msg) {
return *msg->kind_.struct_value_;
return *msg->_impl_.kind_.struct_value_;
}
const ::PROTOBUF_NAMESPACE_ID::ListValue&
Value::_Internal::list_value(const Value* msg) {
return *msg->kind_.list_value_;
return *msg->_impl_.kind_.list_value_;
}
void Value::set_allocated_struct_value(::PROTOBUF_NAMESPACE_ID::Struct* struct_value) {
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation();
@ -422,7 +437,7 @@ void Value::set_allocated_struct_value(::PROTOBUF_NAMESPACE_ID::Struct* struct_v
message_arena, struct_value, submessage_arena);
}
set_has_struct_value();
kind_.struct_value_ = struct_value;
_impl_.kind_.struct_value_ = struct_value;
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value)
}
@ -437,18 +452,23 @@ void Value::set_allocated_list_value(::PROTOBUF_NAMESPACE_ID::ListValue* list_va
message_arena, list_value, submessage_arena);
}
set_has_list_value();
kind_.list_value_ = list_value;
_impl_.kind_.list_value_ = list_value;
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value)
}
Value::Value(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Value)
}
Value::Value(const Value& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.kind_){}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._oneof_case_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
clear_has_kind();
switch (from.kind_case()) {
@ -483,8 +503,16 @@ Value::Value(const Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Value)
}
inline void Value::SharedCtor() {
clear_has_kind();
inline void Value::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.kind_){}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_._oneof_case_)*/{}
};
clear_has_kind();
}
Value::~Value() {
@ -504,7 +532,7 @@ inline void Value::SharedDtor() {
}
void Value::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void Value::clear_kind() {
@ -519,7 +547,7 @@ void Value::clear_kind() {
break;
}
case kStringValue: {
kind_.string_value_.Destroy();
_impl_.kind_.string_value_.Destroy();
break;
}
case kBoolValue: {
@ -528,13 +556,13 @@ void Value::clear_kind() {
}
case kStructValue: {
if (GetArenaForAllocation() == nullptr) {
delete kind_.struct_value_;
delete _impl_.kind_.struct_value_;
}
break;
}
case kListValue: {
if (GetArenaForAllocation() == nullptr) {
delete kind_.list_value_;
delete _impl_.kind_.list_value_;
}
break;
}
@ -542,7 +570,7 @@ void Value::clear_kind() {
break;
}
}
_oneof_case_[0] = KIND_NOT_SET;
_impl_._oneof_case_[0] = KIND_NOT_SET;
}
@ -729,21 +757,21 @@ size_t Value::ByteSizeLong() const {
case kStructValue: {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(
*kind_.struct_value_);
*_impl_.kind_.struct_value_);
break;
}
// .google.protobuf.ListValue list_value = 6;
case kListValue: {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(
*kind_.list_value_);
*_impl_.kind_.list_value_);
break;
}
case KIND_NOT_SET: {
break;
}
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Value::_class_data_ = {
@ -811,8 +839,8 @@ bool Value::IsInitialized() const {
void Value::InternalSwap(Value* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(kind_, other->kind_);
swap(_oneof_case_[0], other->_oneof_case_[0]);
swap(_impl_.kind_, other->_impl_.kind_);
swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]);
}
::PROTOBUF_NAMESPACE_ID::Metadata Value::GetMetadata() const {
@ -829,19 +857,28 @@ class ListValue::_Internal {
ListValue::ListValue(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
values_(arena) {
SharedCtor();
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor(arena, is_message_owned);
// @@protoc_insertion_point(arena_constructor:google.protobuf.ListValue)
}
ListValue::ListValue(const ListValue& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
values_(from.values_) {
: ::PROTOBUF_NAMESPACE_ID::Message() {
new (&_impl_) Impl_{
decltype(_impl_.values_){from._impl_.values_}
, /*decltype(_impl_._cached_size_)*/{}};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.ListValue)
}
inline void ListValue::SharedCtor() {
inline void ListValue::SharedCtor(
::_pb::Arena* arena, bool is_message_owned) {
(void)arena;
(void)is_message_owned;
new (&_impl_) Impl_{
decltype(_impl_.values_){arena}
, /*decltype(_impl_._cached_size_)*/{}
};
}
ListValue::~ListValue() {
@ -855,10 +892,11 @@ ListValue::~ListValue() {
inline void ListValue::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
_impl_.values_.~RepeatedPtrField();
}
void ListValue::SetCachedSize(int size) const {
_cached_size_.Set(size);
_impl_._cached_size_.Set(size);
}
void ListValue::Clear() {
@ -867,7 +905,7 @@ void ListValue::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
values_.Clear();
_impl_.values_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -945,12 +983,12 @@ size_t ListValue::ByteSizeLong() const {
// repeated .google.protobuf.Value values = 1;
total_size += 1UL * this->_internal_values_size();
for (const auto& msg : this->values_) {
for (const auto& msg : this->_impl_.values_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListValue::_class_data_ = {
@ -972,7 +1010,7 @@ void ListValue::MergeFrom(const ListValue& from) {
uint32_t cached_has_bits = 0;
(void) cached_has_bits;
values_.MergeFrom(from.values_);
_impl_.values_.MergeFrom(from._impl_.values_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
@ -990,7 +1028,7 @@ bool ListValue::IsInitialized() const {
void ListValue::InternalSwap(ListValue* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
values_.InternalSwap(&other->values_);
_impl_.values_.InternalSwap(&other->_impl_.values_);
}
::PROTOBUF_NAMESPACE_ID::Metadata ListValue::GetMetadata() const {

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

Loading…
Cancel
Save