diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index fe1bebc77b..15ee53a426 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -108,7 +108,7 @@ public abstract class AbstractMessage @Override public final String toString() { - return TextFormat.printToString(this); + return TextFormat.printer().printToString(this); } @Override @@ -468,7 +468,7 @@ public abstract class AbstractMessage @Override public String toString() { - return TextFormat.printToString(this); + return TextFormat.printer().printToString(this); } /** Construct an UninitializedMessageException reporting missing fields in the given message. */ diff --git a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 11843b6c39..f07d607212 100644 --- a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -76,6 +76,10 @@ public class ExtensionRegistryLite { // applications. Need to support this feature on smaller granularity. private static volatile boolean eagerlyParseMessageSets = false; + // short circuit the ExtensionRegistryFactory via assumevalues trickery + @SuppressWarnings("JavaOptionalSuggestions") + private static boolean doFullRuntimeInheritanceCheck = true; + // Visible for testing. static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension"; @@ -107,7 +111,9 @@ public class ExtensionRegistryLite { * available. */ public static ExtensionRegistryLite newInstance() { - return ExtensionRegistryFactory.create(); + return doFullRuntimeInheritanceCheck + ? ExtensionRegistryFactory.create() + : new ExtensionRegistryLite(); } private static volatile ExtensionRegistryLite emptyRegistry; @@ -122,7 +128,11 @@ public class ExtensionRegistryLite { synchronized (ExtensionRegistryLite.class) { result = emptyRegistry; if (result == null) { - result = emptyRegistry = ExtensionRegistryFactory.createEmpty(); + result = + emptyRegistry = + doFullRuntimeInheritanceCheck + ? ExtensionRegistryFactory.createEmpty() + : EMPTY_REGISTRY_LITE; } } } @@ -163,7 +173,7 @@ public class ExtensionRegistryLite { if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) { add((GeneratedMessageLite.GeneratedExtension) extension); } - if (ExtensionRegistryFactory.isFullRegistry(this)) { + if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) { try { this.getClass().getMethod("add", extensionClass).invoke(this, extension); } catch (Exception e) { diff --git a/java/core/src/main/java/com/google/protobuf/Message.java b/java/core/src/main/java/com/google/protobuf/Message.java index 40dcaf026e..9b3a015ba9 100644 --- a/java/core/src/main/java/com/google/protobuf/Message.java +++ b/java/core/src/main/java/com/google/protobuf/Message.java @@ -85,7 +85,7 @@ public interface Message extends MessageLite, MessageOrBuilder { /** * Converts the message to a string in protocol buffer text format. This is just a trivial wrapper - * around {@link TextFormat#printToString(MessageOrBuilder)}. + * around {@link TextFormat.Printer#printToString(MessageOrBuilder)}. */ @Override String toString(); diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index 2326a05ffb..0385b2425a 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -61,135 +61,132 @@ public final class TextFormat { * Outputs a textual representation of the Protocol Message supplied into the parameter output. * (This representation is the new version of the classic "ProtocolPrinter" output from the * original Protocol Buffer system) + * + * @deprecated Use {@code printer().print(MessageOrBuilder, Appendable)} */ + @Deprecated public static void print(final MessageOrBuilder message, final Appendable output) throws IOException { - Printer.DEFAULT.print(message, multiLineOutput(output)); + printer().print(message, output); } - /** Outputs a textual representation of {@code fields} to {@code output}. */ + /** + * Outputs a textual representation of {@code fields} to {@code output}. + * + * @deprecated Use {@code printer().print(UnknownFieldSet, Appendable)} + */ + @Deprecated public static void print(final UnknownFieldSet fields, final Appendable output) throws IOException { - Printer.DEFAULT.printUnknownFields(fields, multiLineOutput(output)); + printer().print(fields, output); } - /** Same as {@code print()}, except that non-ASCII characters are not escaped. */ + /** + * Same as {@code print()}, except that non-ASCII characters are not escaped. + * + * @deprecated Use {@code printer().escapingNonAscii(false).print(MessageOrBuilder, Appendable)} + */ + @Deprecated public static void printUnicode(final MessageOrBuilder message, final Appendable output) throws IOException { - Printer.UNICODE.print(message, multiLineOutput(output)); + printer().escapingNonAscii(false).print(message, output); } - /** Same as {@code print()}, except that non-ASCII characters are not escaped. */ + /** + * Same as {@code print()}, except that non-ASCII characters are not escaped. + * + * @deprecated Use {@code printer().escapingNonAscii(false).print(UnknownFieldSet, Appendable)} + */ + @Deprecated public static void printUnicode(final UnknownFieldSet fields, final Appendable output) throws IOException { - Printer.UNICODE.printUnknownFields(fields, multiLineOutput(output)); + printer().escapingNonAscii(false).print(fields, output); } /** * Generates a human readable form of this message, useful for debugging and other purposes, with - * no newline characters. + * no newline characters. This is just a trivial wrapper around + * {@link TextFormat.Printer#shortDebugString(MessageOrBuilder)}. */ public static String shortDebugString(final MessageOrBuilder message) { - try { - final StringBuilder text = new StringBuilder(); - Printer.DEFAULT.print(message, singleLineOutput(text)); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().shortDebugString(message); } /** * Generates a human readable form of the field, useful for debugging and other purposes, with no * newline characters. + * + * @deprecated Use {@code printer().shortDebugString(FieldDescriptor, Object)} */ + @Deprecated public static String shortDebugString(final FieldDescriptor field, final Object value) { - try { - final StringBuilder text = new StringBuilder(); - Printer.DEFAULT.printField(field, value, singleLineOutput(text)); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().shortDebugString(field, value); } /** * Generates a human readable form of the unknown fields, useful for debugging and other purposes, * with no newline characters. + * + * @deprecated Use {@code printer().shortDebugString(UnknownFieldSet)} */ + @Deprecated public static String shortDebugString(final UnknownFieldSet fields) { - try { - final StringBuilder text = new StringBuilder(); - Printer.DEFAULT.printUnknownFields(fields, singleLineOutput(text)); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().shortDebugString(fields); } - /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + /** + * Like {@code print()}, but writes directly to a {@code String} and returns it. + * + * @deprecated Use {@link MessageOrBuilder#toString()} + */ + @Deprecated public static String printToString(final MessageOrBuilder message) { - try { - final StringBuilder text = new StringBuilder(); - print(message, text); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().printToString(message); } - /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + /** + * Like {@code print()}, but writes directly to a {@code String} and returns it. + * + * @deprecated Use {@link UnknownFieldSet#toString()} + */ + @Deprecated public static String printToString(final UnknownFieldSet fields) { - try { - final StringBuilder text = new StringBuilder(); - print(fields, text); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().printToString(fields); } /** * Same as {@code printToString()}, except that non-ASCII characters in string type fields are not * escaped in backslash+octals. + * + * @deprecated Use {@code printer().escapingNonAscii(false).printToString(MessageOrBuilder)} */ + @Deprecated public static String printToUnicodeString(final MessageOrBuilder message) { - try { - final StringBuilder text = new StringBuilder(); - Printer.UNICODE.print(message, multiLineOutput(text)); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().escapingNonAscii(false).printToString(message); } /** * Same as {@code printToString()}, except that non-ASCII characters in string type fields are not * escaped in backslash+octals. + * + * @deprecated Use {@code printer().escapingNonAscii(false).printToString(UnknownFieldSet)} */ + @Deprecated public static String printToUnicodeString(final UnknownFieldSet fields) { - try { - final StringBuilder text = new StringBuilder(); - Printer.UNICODE.printUnknownFields(fields, multiLineOutput(text)); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().escapingNonAscii(false).printToString(fields); } + /** @deprecated Use {@code printer().printField(FieldDescriptor, Object, Appendable)} */ + @Deprecated public static void printField( final FieldDescriptor field, final Object value, final Appendable output) throws IOException { - Printer.DEFAULT.printField(field, value, multiLineOutput(output)); + printer().printField(field, value, output); } + /** @deprecated Use {@code printer().printFieldToString(FieldDescriptor, Object)} */ + @Deprecated public static String printFieldToString(final FieldDescriptor field, final Object value) { - try { - final StringBuilder text = new StringBuilder(); - printField(field, value, text); - return text.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return printer().printFieldToString(field, value); } /** @@ -198,29 +195,34 @@ public final class TextFormat { *

Same as {@code printFieldValue()}, except that non-ASCII characters in string type fields * are not escaped in backslash+octals. * + * @deprecated Use {@code printer().escapingNonAscii(false).printFieldValue(FieldDescriptor, + * Object, Appendable)} * @param field the descriptor of the field * @param value the value of the field * @param output the output to which to append the formatted value * @throws ClassCastException if the value is not appropriate for the given field descriptor * @throws IOException if there is an exception writing to the output */ + @Deprecated public static void printUnicodeFieldValue( final FieldDescriptor field, final Object value, final Appendable output) throws IOException { - Printer.UNICODE.printFieldValue(field, value, multiLineOutput(output)); + printer().escapingNonAscii(false).printFieldValue(field, value, output); } /** * Outputs a textual representation of the value of given field value. * + * @deprecated Use {@code printer().printFieldValue(FieldDescriptor, Object, Appendable)} * @param field the descriptor of the field * @param value the value of the field * @param output the output to which to append the formatted value * @throws ClassCastException if the value is not appropriate for the given field descriptor * @throws IOException if there is an exception writing to the output */ + @Deprecated public static void printFieldValue( final FieldDescriptor field, final Object value, final Appendable output) throws IOException { - Printer.DEFAULT.printFieldValue(field, value, multiLineOutput(output)); + printer().printFieldValue(field, value, output); } /** @@ -256,7 +258,7 @@ public final class TextFormat { generator.print("{"); generator.eol(); generator.indent(); - Printer.DEFAULT.printUnknownFields(message, generator); + Printer.printUnknownFields(message, generator); generator.outdent(); generator.print("}"); } catch (InvalidProtocolBufferException e) { @@ -267,19 +269,23 @@ public final class TextFormat { } break; case WireFormat.WIRETYPE_START_GROUP: - Printer.DEFAULT.printUnknownFields((UnknownFieldSet) value, generator); + Printer.printUnknownFields((UnknownFieldSet) value, generator); break; default: throw new IllegalArgumentException("Bad tag: " + tag); } } + /** Printer instance which escapes non-ASCII characters. */ + public static Printer printer() { + return Printer.DEFAULT; + } + /** Helper class for converting protobufs to text. */ - private static final class Printer { + public static final class Printer { + // Printer instance which escapes non-ASCII characters. - static final Printer DEFAULT = new Printer(true); - // Printer instance which emits Unicode (it still escapes newlines and quotes in strings). - static final Printer UNICODE = new Printer(false); + private static final Printer DEFAULT = new Printer(true); /** Whether to escape non ASCII characters with backslash and octal. */ private final boolean escapeNonAscii; @@ -288,12 +294,51 @@ public final class TextFormat { this.escapeNonAscii = escapeNonAscii; } + /** + * Return a new Printer instance with the specified escape mode. + * + * @param escapeNonAscii If true, the new Printer will escape non-ASCII characters (this is the + * default behavior. If false, the new Printer will print non-ASCII characters as is. In + * either case, the new Printer still escapes newlines and quotes in strings. + * @return a new Printer that clones all other configurations from the current {@link Printer}, + * with the escape mode set to the given parameter. + */ + public Printer escapingNonAscii(boolean escapeNonAscii) { + return new Printer(escapeNonAscii); + } + + /** + * Outputs a textual representation of the Protocol Message supplied into the parameter output. + * (This representation is the new version of the classic "ProtocolPrinter" output from the + * original Protocol Buffer system) + */ + public void print(final MessageOrBuilder message, final Appendable output) throws IOException { + print(message, multiLineOutput(output)); + } + + /** Outputs a textual representation of {@code fields} to {@code output}. */ + public void print(final UnknownFieldSet fields, final Appendable output) throws IOException { + printUnknownFields(fields, multiLineOutput(output)); + } + private void print(final MessageOrBuilder message, final TextGenerator generator) throws IOException { - for (Map.Entry field : message.getAllFields().entrySet()) { - printField(field.getKey(), field.getValue(), generator); + printMessage(message, generator); + } + + public String printFieldToString(final FieldDescriptor field, final Object value) { + try { + final StringBuilder text = new StringBuilder(); + printField(field, value, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); } - printUnknownFields(message.getUnknownFields(), generator); + } + + public void printField(final FieldDescriptor field, final Object value, final Appendable output) + throws IOException { + printField(field, value, multiLineOutput(output)); } private void printField( @@ -309,46 +354,19 @@ public final class TextFormat { } } - private void printSingleField( - final FieldDescriptor field, final Object value, final TextGenerator generator) + /** + * Outputs a textual representation of the value of given field value. + * + * @param field the descriptor of the field + * @param value the value of the field + * @param output the output to which to append the formatted value + * @throws ClassCastException if the value is not appropriate for the given field descriptor + * @throws IOException if there is an exception writing to the output + */ + public void printFieldValue( + final FieldDescriptor field, final Object value, final Appendable output) throws IOException { - if (field.isExtension()) { - generator.print("["); - // We special-case MessageSet elements for compatibility with proto1. - if (field.getContainingType().getOptions().getMessageSetWireFormat() - && (field.getType() == FieldDescriptor.Type.MESSAGE) - && (field.isOptional()) - // object equality - && (field.getExtensionScope() == field.getMessageType())) { - generator.print(field.getMessageType().getFullName()); - } else { - generator.print(field.getFullName()); - } - generator.print("]"); - } else { - if (field.getType() == FieldDescriptor.Type.GROUP) { - // Groups must be serialized with their original capitalization. - generator.print(field.getMessageType().getName()); - } else { - generator.print(field.getName()); - } - } - - if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - generator.print(" {"); - generator.eol(); - generator.indent(); - } else { - generator.print(": "); - } - - printFieldValue(field, value, generator); - - if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - generator.outdent(); - generator.print("}"); - } - generator.eol(); + printFieldValue(field, value, multiLineOutput(output)); } private void printFieldValue( @@ -419,7 +437,157 @@ public final class TextFormat { } } - private void printUnknownFields( + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + public String printToString(final MessageOrBuilder message) { + try { + final StringBuilder text = new StringBuilder(); + print(message, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ + public String printToString(final UnknownFieldSet fields) { + try { + final StringBuilder text = new StringBuilder(); + print(fields, text); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of this message, useful for debugging and other purposes, + * with no newline characters. + */ + public String shortDebugString(final MessageOrBuilder message) { + try { + final StringBuilder text = new StringBuilder(); + print(message, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of the field, useful for debugging and other purposes, with + * no newline characters. + */ + public String shortDebugString(final FieldDescriptor field, final Object value) { + try { + final StringBuilder text = new StringBuilder(); + printField(field, value, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + /** + * Generates a human readable form of the unknown fields, useful for debugging and other + * purposes, with no newline characters. + */ + public String shortDebugString(final UnknownFieldSet fields) { + try { + final StringBuilder text = new StringBuilder(); + printUnknownFields(fields, singleLineOutput(text)); + return text.toString(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + private static void printUnknownFieldValue( + final int tag, final Object value, final TextGenerator generator) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + generator.print(unsignedToString((Long) value)); + break; + case WireFormat.WIRETYPE_FIXED32: + generator.print(String.format((Locale) null, "0x%08x", (Integer) value)); + break; + case WireFormat.WIRETYPE_FIXED64: + generator.print(String.format((Locale) null, "0x%016x", (Long) value)); + break; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + try { + // Try to parse and print the field as an embedded message + UnknownFieldSet message = UnknownFieldSet.parseFrom((ByteString) value); + generator.print("{"); + generator.eol(); + generator.indent(); + printUnknownFields(message, generator); + generator.outdent(); + generator.print("}"); + } catch (InvalidProtocolBufferException e) { + // If not parseable as a message, print as a String + generator.print("\""); + generator.print(escapeBytes((ByteString) value)); + generator.print("\""); + } + break; + case WireFormat.WIRETYPE_START_GROUP: + printUnknownFields((UnknownFieldSet) value, generator); + break; + default: + throw new IllegalArgumentException("Bad tag: " + tag); + } + } + + private void printMessage(final MessageOrBuilder message, final TextGenerator generator) + throws IOException { + for (Map.Entry field : message.getAllFields().entrySet()) { + printField(field.getKey(), field.getValue(), generator); + } + printUnknownFields(message.getUnknownFields(), generator); + } + + private void printSingleField( + final FieldDescriptor field, final Object value, final TextGenerator generator) + throws IOException { + if (field.isExtension()) { + generator.print("["); + // We special-case MessageSet elements for compatibility with proto1. + if (field.getContainingType().getOptions().getMessageSetWireFormat() + && (field.getType() == FieldDescriptor.Type.MESSAGE) + && (field.isOptional()) + // object equality + && (field.getExtensionScope() == field.getMessageType())) { + generator.print(field.getMessageType().getFullName()); + } else { + generator.print(field.getFullName()); + } + generator.print("]"); + } else { + if (field.getType() == FieldDescriptor.Type.GROUP) { + // Groups must be serialized with their original capitalization. + generator.print(field.getMessageType().getName()); + } else { + generator.print(field.getName()); + } + } + + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + generator.print(" {"); + generator.eol(); + generator.indent(); + } else { + generator.print(": "); + } + + printFieldValue(field, value, generator); + + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + generator.outdent(); + generator.print("}"); + } + generator.eol(); + } + + private static void printUnknownFields( final UnknownFieldSet unknownFields, final TextGenerator generator) throws IOException { for (Map.Entry entry : unknownFields.asMap().entrySet()) { final int number = entry.getKey(); @@ -445,7 +613,7 @@ public final class TextFormat { } } - private void printUnknownField( + private static void printUnknownField( final int number, final int wireType, final List values, final TextGenerator generator) throws IOException { for (final Object value : values) { @@ -1994,7 +2162,7 @@ public final class TextFormat { return escapeBytes(ByteString.copyFromUtf8(input)); } - /** Escape double quotes and backslashes in a String for unicode output of a message. */ + /** Escape double quotes and backslashes in a String for emittingUnicode output of a message. */ public static String escapeDoubleQuotesAndBackslashes(final String input) { return TextFormatEscaper.escapeDoubleQuotesAndBackslashes(input); } diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index bde1303db7..ba2f9df08e 100644 --- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -140,11 +140,11 @@ public final class UnknownFieldSet implements MessageLite { /** * Converts the set to a string in protocol buffer text format. This is just a trivial wrapper - * around {@link TextFormat#printToString(UnknownFieldSet)}. + * around {@link TextFormat.Printer#printToString(UnknownFieldSet)}. */ @Override public String toString() { - return TextFormat.printToString(this); + return TextFormat.printer().printToString(this); } /** diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index 4961042f5f..bb706326c4 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -766,7 +766,7 @@ public class MapForProto2Test extends TestCase { setMapValuesUsingAccessors(builder); TestMap message = builder.build(); - String textData = TextFormat.printToString(message); + String textData = TextFormat.printer().printToString(message); builder = TestMap.newBuilder(); TextFormat.merge(textData, builder); diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index 6007d8e7de..9f1ebaed69 100644 --- a/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -857,7 +857,7 @@ public class MapTest extends TestCase { setMapValuesUsingAccessors(builder); TestMap message = builder.build(); - String textData = TextFormat.printToString(message); + String textData = TextFormat.printer().printToString(message); builder = TestMap.newBuilder(); TextFormat.merge(textData, builder); diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index f68a45e28e..4421c0cc4b 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -147,7 +147,7 @@ public class TextFormatTest extends TestCase { /** Print TestAllTypes and compare with golden file. */ public void testPrintMessage() throws Exception { - String javaText = TextFormat.printToString(TestUtil.getAllSet()); + String javaText = TextFormat.printer().printToString(TestUtil.getAllSet()); // Java likes to add a trailing ".0" to floats and doubles. C printf // (with %g format) does not. Our golden files are used for both @@ -159,7 +159,7 @@ public class TextFormatTest extends TestCase { /** Print TestAllTypes as Builder and compare with golden file. */ public void testPrintMessageBuilder() throws Exception { - String javaText = TextFormat.printToString(TestUtil.getAllSetBuilder()); + String javaText = TextFormat.printer().printToString(TestUtil.getAllSetBuilder()); // Java likes to add a trailing ".0" to floats and doubles. C printf // (with %g format) does not. Our golden files are used for both @@ -171,7 +171,7 @@ public class TextFormatTest extends TestCase { /** Print TestAllExtensions and compare with golden file. */ public void testPrintExtensions() throws Exception { - String javaText = TextFormat.printToString(TestUtil.getAllExtensionsSet()); + String javaText = TextFormat.printer().printToString(TestUtil.getAllExtensionsSet()); // Java likes to add a trailing ".0" to floats and doubles. C printf // (with %g format) does not. Our golden files are used for both @@ -237,12 +237,13 @@ public class TextFormatTest extends TestCase { + "15: 12379813812177893520\n" + "15: 0xabcd1234\n" + "15: 0xabcdef1234567890\n", - TextFormat.printToString(message)); + TextFormat.printer().printToString(message)); } public void testPrintField() throws Exception { final FieldDescriptor dataField = OneString.getDescriptor().findFieldByName("data"); - assertEquals("data: \"test data\"\n", TextFormat.printFieldToString(dataField, "test data")); + assertEquals( + "data: \"test data\"\n", TextFormat.printer().printFieldToString(dataField, "test data")); final FieldDescriptor optionalField = TestAllTypes.getDescriptor().findFieldByName("optional_nested_message"); @@ -250,7 +251,7 @@ public class TextFormatTest extends TestCase { assertEquals( "optional_nested_message {\n bb: 42\n}\n", - TextFormat.printFieldToString(optionalField, value)); + TextFormat.printer().printFieldToString(optionalField, value)); } /** @@ -885,7 +886,8 @@ public class TextFormatTest extends TestCase { private void assertPrintFieldValue(String expect, Object value, String fieldName) throws Exception { StringBuilder sb = new StringBuilder(); - TextFormat.printFieldValue(TestAllTypes.getDescriptor().findFieldByName(fieldName), value, sb); + TextFormat.printer() + .printFieldValue(TestAllTypes.getDescriptor().findFieldByName(fieldName), value, sb); assertEquals(expect, sb.toString()); } @@ -902,14 +904,17 @@ public class TextFormatTest extends TestCase { public void testShortDebugString_field() { final FieldDescriptor dataField = OneString.getDescriptor().findFieldByName("data"); - assertEquals("data: \"test data\"", TextFormat.shortDebugString(dataField, "test data")); + assertEquals( + "data: \"test data\"", + TextFormat.printer().shortDebugString(dataField, "test data")); final FieldDescriptor optionalField = TestAllTypes.getDescriptor().findFieldByName("optional_nested_message"); final Object value = NestedMessage.newBuilder().setBb(42).build(); assertEquals( - "optional_nested_message { bb: 42 }", TextFormat.shortDebugString(optionalField, value)); + "optional_nested_message { bb: 42 }", + TextFormat.printer().shortDebugString(optionalField, value)); } public void testShortDebugString_unknown() { @@ -917,7 +922,7 @@ public class TextFormatTest extends TestCase { "5: 1 5: 0x00000002 5: 0x0000000000000003 5: \"4\" 5: { 12: 6 } 5 { 10: 5 }" + " 8: 1 8: 2 8: 3 15: 12379813812177893520 15: 0xabcd1234 15:" + " 0xabcdef1234567890", - TextFormat.shortDebugString(makeUnknownFieldSet())); + TextFormat.printer().shortDebugString(makeUnknownFieldSet())); } public void testPrintToUnicodeString() throws Exception { @@ -925,23 +930,26 @@ public class TextFormatTest extends TestCase { "optional_string: \"abc\u3042efg\"\n" + "optional_bytes: \"\\343\\201\\202\"\n" + "repeated_string: \"\u3093XYZ\"\n", - TextFormat.printToUnicodeString( - TestAllTypes.newBuilder() - .setOptionalString("abc\u3042efg") - .setOptionalBytes(bytes(0xe3, 0x81, 0x82)) - .addRepeatedString("\u3093XYZ") - .build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString( + TestAllTypes.newBuilder() + .setOptionalString("abc\u3042efg") + .setOptionalBytes(bytes(0xe3, 0x81, 0x82)) + .addRepeatedString("\u3093XYZ") + .build())); // Double quotes and backslashes should be escaped assertEquals( "optional_string: \"a\\\\bc\\\"ef\\\"g\"\n", - TextFormat.printToUnicodeString( - TestAllTypes.newBuilder().setOptionalString("a\\bc\"ef\"g").build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString(TestAllTypes.newBuilder().setOptionalString("a\\bc\"ef\"g").build())); // Test escaping roundtrip TestAllTypes message = TestAllTypes.newBuilder().setOptionalString("a\\bc\\\"ef\"g").build(); TestAllTypes.Builder builder = TestAllTypes.newBuilder(); - TextFormat.merge(TextFormat.printToUnicodeString(message), builder); + TextFormat.merge(TextFormat.printer().escapingNonAscii(false).printToString(message), builder); assertEquals(message.getOptionalString(), builder.getOptionalString()); } @@ -949,48 +957,61 @@ public class TextFormatTest extends TestCase { // No newlines at start and end assertEquals( "optional_string: \"test newlines\\n\\nin\\nstring\"\n", - TextFormat.printToUnicodeString( - TestAllTypes.newBuilder().setOptionalString("test newlines\n\nin\nstring").build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString( + TestAllTypes.newBuilder() + .setOptionalString("test newlines\n\nin\nstring") + .build())); // Newlines at start and end assertEquals( "optional_string: \"\\ntest\\nnewlines\\n\\nin\\nstring\\n\"\n", - TextFormat.printToUnicodeString( - TestAllTypes.newBuilder() - .setOptionalString("\ntest\nnewlines\n\nin\nstring\n") - .build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString( + TestAllTypes.newBuilder() + .setOptionalString("\ntest\nnewlines\n\nin\nstring\n") + .build())); // Strings with 0, 1 and 2 newlines. assertEquals( "optional_string: \"\"\n", - TextFormat.printToUnicodeString(TestAllTypes.newBuilder().setOptionalString("").build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString(TestAllTypes.newBuilder().setOptionalString("").build())); assertEquals( "optional_string: \"\\n\"\n", - TextFormat.printToUnicodeString(TestAllTypes.newBuilder().setOptionalString("\n").build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString(TestAllTypes.newBuilder().setOptionalString("\n").build())); assertEquals( "optional_string: \"\\n\\n\"\n", - TextFormat.printToUnicodeString( - TestAllTypes.newBuilder().setOptionalString("\n\n").build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString(TestAllTypes.newBuilder().setOptionalString("\n\n").build())); // Test escaping roundtrip TestAllTypes message = TestAllTypes.newBuilder().setOptionalString("\ntest\nnewlines\n\nin\nstring\n").build(); TestAllTypes.Builder builder = TestAllTypes.newBuilder(); - TextFormat.merge(TextFormat.printToUnicodeString(message), builder); + TextFormat.merge(TextFormat.printer().escapingNonAscii(false).printToString(message), builder); assertEquals(message.getOptionalString(), builder.getOptionalString()); } public void testPrintToUnicodeString_unknown() { assertEquals( "1: \"\\343\\201\\202\"\n", - TextFormat.printToUnicodeString( - UnknownFieldSet.newBuilder() - .addField( - 1, - UnknownFieldSet.Field.newBuilder() - .addLengthDelimited(bytes(0xe3, 0x81, 0x82)) - .build()) - .build())); + TextFormat.printer() + .escapingNonAscii(false) + .printToString( + UnknownFieldSet.newBuilder() + .addField( + 1, + UnknownFieldSet.Field.newBuilder() + .addLengthDelimited(bytes(0xe3, 0x81, 0x82)) + .build()) + .build())); } @@ -1120,7 +1141,7 @@ public class TextFormatTest extends TestCase { TestUtil.setOneof(builder); TestOneof2 message = builder.build(); TestOneof2.Builder dest = TestOneof2.newBuilder(); - TextFormat.merge(TextFormat.printToUnicodeString(message), dest); + TextFormat.merge(TextFormat.printer().escapingNonAscii(false).printToString(message), dest); TestUtil.assertOneofSet(dest.build()); } @@ -1159,7 +1180,7 @@ public class TextFormatTest extends TestCase { .putInt32ToStringField(20, "banana") .putInt32ToStringField(30, "cherry") .build(); - String text = TextFormat.printToUnicodeString(message); + String text = TextFormat.printer().escapingNonAscii(false).printToString(message); { TestMap.Builder dest = TestMap.newBuilder(); TextFormat.merge(text, dest); diff --git a/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java b/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java index ae4e086ee1..7daef026dc 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java @@ -234,7 +234,7 @@ public class UnknownEnumValueTest extends TestCase { TestAllTypes message = builder.build(); // We can print a message with unknown enum values. - String textData = TextFormat.printToString(message); + String textData = TextFormat.printer().printToString(message); assertEquals( "optional_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_4321\n" + "repeated_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_5432\n" diff --git a/js/message.js b/js/message.js index aff8db1408..23e5af0d4b 100644 --- a/js/message.js +++ b/js/message.js @@ -958,19 +958,19 @@ jspb.Message.getMapField = function(msg, fieldNumber, noLazyCreate, // If we already have a map in the map wrappers, return that. if (fieldNumber in msg.wrappers_) { return msg.wrappers_[fieldNumber]; - } else if (noLazyCreate) { - return undefined; - } else { - // Wrap the underlying elements array with a Map. - var arr = jspb.Message.getField(msg, fieldNumber); - if (!arr) { - arr = []; - jspb.Message.setField(msg, fieldNumber, arr); + } + var arr = jspb.Message.getField(msg, fieldNumber); + // Wrap the underlying elements array with a Map. + if (!arr) { + if (noLazyCreate) { + return undefined; } - return msg.wrappers_[fieldNumber] = - new jspb.Map( - /** @type {!Array>} */ (arr), opt_valueCtor); + arr = []; + jspb.Message.setField(msg, fieldNumber, arr); } + return msg.wrappers_[fieldNumber] = + new jspb.Map( + /** @type {!Array>} */ (arr), opt_valueCtor); }; diff --git a/protobuf.pc.in b/protobuf.pc.in index 4e88b514a2..055a9d0563 100644 --- a/protobuf.pc.in +++ b/protobuf.pc.in @@ -8,5 +8,6 @@ Description: Google's Data Interchange Format Version: @VERSION@ Libs: -L${libdir} -lprotobuf @PTHREAD_LIBS@ Libs.private: @LIBS@ + Cflags: -I${includedir} @PTHREAD_CFLAGS@ Conflicts: protobuf-lite diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 9414f6f5af..ad1eb653fd 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -615,18 +615,86 @@ class SecondaryDescriptorFromDescriptorDB(DescriptorPoolTestBase, factory_test1_pb2.DESCRIPTOR.serialized_pb) self.factory_test2_fd = descriptor_pb2.FileDescriptorProto.FromString( factory_test2_pb2.DESCRIPTOR.serialized_pb) - db = descriptor_database.DescriptorDatabase() - db.Add(self.factory_test1_fd) - db.Add(self.factory_test2_fd) - db.Add(descriptor_pb2.FileDescriptorProto.FromString( + self.db = descriptor_database.DescriptorDatabase() + self.db.Add(self.factory_test1_fd) + self.db.Add(self.factory_test2_fd) + self.db.Add(descriptor_pb2.FileDescriptorProto.FromString( unittest_import_public_pb2.DESCRIPTOR.serialized_pb)) - db.Add(descriptor_pb2.FileDescriptorProto.FromString( + self.db.Add(descriptor_pb2.FileDescriptorProto.FromString( unittest_import_pb2.DESCRIPTOR.serialized_pb)) - db.Add(descriptor_pb2.FileDescriptorProto.FromString( + self.db.Add(descriptor_pb2.FileDescriptorProto.FromString( unittest_pb2.DESCRIPTOR.serialized_pb)) - db.Add(descriptor_pb2.FileDescriptorProto.FromString( + self.db.Add(descriptor_pb2.FileDescriptorProto.FromString( no_package_pb2.DESCRIPTOR.serialized_pb)) - self.pool = descriptor_pool.DescriptorPool(descriptor_db=db) + self.pool = descriptor_pool.DescriptorPool(descriptor_db=self.db) + + def testErrorCollector(self): + file_proto = descriptor_pb2.FileDescriptorProto() + file_proto.package = 'collector' + file_proto.name = 'error_file' + message_type = file_proto.message_type.add() + message_type.name = 'ErrorMessage' + field = message_type.field.add() + field.number = 1 + field.name = 'nested_message_field' + field.label = descriptor.FieldDescriptor.LABEL_OPTIONAL + field.type = descriptor.FieldDescriptor.TYPE_MESSAGE + field.type_name = 'SubMessage' + oneof = message_type.oneof_decl.add() + oneof.name = 'MyOneof' + enum_type = file_proto.enum_type.add() + enum_type.name = 'MyEnum' + enum_value = enum_type.value.add() + enum_value.name = 'MyEnumValue' + enum_value.number = 0 + self.db.Add(file_proto) + + self.assertRaisesRegexp(KeyError, 'SubMessage', + self.pool.FindMessageTypeByName, + 'collector.ErrorMessage') + self.assertRaisesRegexp(KeyError, 'SubMessage', + self.pool.FindFileByName, 'error_file') + with self.assertRaises(KeyError) as exc: + self.pool.FindFileByName('none_file') + self.assertIn(str(exc.exception), ('\'none_file\'', + '\"Couldn\'t find file none_file\"')) + + # Pure python _ConvertFileProtoToFileDescriptor() method has side effect + # that all the symbols found in the file will load into the pool even the + # file can not build. So when FindMessageTypeByName('ErrorMessage') was + # called the first time, a KeyError will be raised but call the find + # method later will return a descriptor which is not build. + # TODO(jieluo): fix pure python to revert the load if file can not be build + if api_implementation.Type() == 'cpp': + error_msg = ('Invalid proto descriptor for file "error_file":\\n ' + 'collector.ErrorMessage.nested_message_field: "SubMessage" ' + 'is not defined.\\n collector.ErrorMessage.MyOneof: Oneof ' + 'must have at least one field.\\n\'') + with self.assertRaises(KeyError) as exc: + self.pool.FindMessageTypeByName('collector.ErrorMessage') + self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for ' + 'message collector.ErrorMessage\\n' + error_msg) + + with self.assertRaises(KeyError) as exc: + self.pool.FindFieldByName('collector.ErrorMessage.nested_message_field') + self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for field' + ' collector.ErrorMessage.nested_message_field\\n' + + error_msg) + + with self.assertRaises(KeyError) as exc: + self.pool.FindEnumTypeByName('collector.MyEnum') + self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for enum' + ' collector.MyEnum\\n' + error_msg) + + with self.assertRaises(KeyError) as exc: + self.pool.FindFileContainingSymbol('collector.MyEnumValue') + self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for symbol' + ' collector.MyEnumValue\\n' + error_msg) + + with self.assertRaises(KeyError) as exc: + self.pool.FindOneofByName('collector.ErrorMessage.MyOneof') + self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for oneof' + ' collector.ErrorMessage.MyOneof\\n' + error_msg) class ProtoFile(object): diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index f4271b9dfd..939d4961e7 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -54,6 +54,7 @@ from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pool from google.protobuf import json_format +from google.protobuf.util import json_format_pb2 from google.protobuf.util import json_format_proto3_pb2 @@ -247,6 +248,22 @@ class JsonFormatTest(JsonFormatBase): } self.assertEqual(golden_dict, message_dict) + def testExtensionSerializationDictMatchesProto3SpecMore(self): + """See go/proto3-json-spec for spec. + """ + message = json_format_pb2.TestMessageWithExtension() + ext = json_format_pb2.TestExtension.ext + message.Extensions[ext].value = 'stuff' + message_dict = json_format.MessageToDict( + message + ) + expected_dict = { + '[protobuf_unittest.TestExtension.ext]': { + 'value': u'stuff', + }, + } + self.assertEqual(expected_dict, message_dict) + def testExtensionSerializationJsonMatchesProto3Spec(self): """See go/proto3-json-spec for spec. diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 80f010371a..6c3b1cb8cb 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -233,12 +233,8 @@ class _Printer(object): js[name] = [self._FieldToJsonObject(field, k) for k in value] elif field.is_extension: - f = field - if (f.containing_type.GetOptions().message_set_wire_format and - f.type == descriptor.FieldDescriptor.TYPE_MESSAGE and - f.label == descriptor.FieldDescriptor.LABEL_OPTIONAL): - f = f.message_type - name = '[%s.%s]' % (f.full_name, name) + full_qualifier = field.full_name[:-len(field.name)] + name = '[%s%s]' % (full_qualifier, name) js[name] = self._FieldToJsonObject(field, value) else: js[name] = self._FieldToJsonObject(field, value) @@ -493,10 +489,16 @@ class _Parser(object): raise ParseError('Message type {0} does not have extensions'.format( message_descriptor.full_name)) identifier = name[1:-1] # strip [] brackets - identifier = '.'.join(identifier.split('.')[:-1]) # pylint: disable=protected-access field = message.Extensions._FindExtensionByName(identifier) # pylint: enable=protected-access + if not field: + # Try looking for extension by the message type name, dropping the + # field name following the final . separator in full_name. + identifier = '.'.join(identifier.split('.')[:-1]) + # pylint: disable=protected-access + field = message.Extensions._FindExtensionByName(identifier) + # pylint: enable=protected-access if not field: if self.ignore_unknown_fields: continue diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 50b290db0a..767659204f 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -67,6 +67,38 @@ static std::unordered_map* namespace cdescriptor_pool { +// Collects errors that occur during proto file building to allow them to be +// propagated in the python exception instead of only living in ERROR logs. +class BuildFileErrorCollector : public DescriptorPool::ErrorCollector { + public: + BuildFileErrorCollector() : error_message(""), had_errors_(false) {} + + void AddError(const string& filename, const string& element_name, + const Message* descriptor, ErrorLocation location, + const string& message) override { + // Replicates the logging behavior that happens in the C++ implementation + // when an error collector is not passed in. + if (!had_errors_) { + error_message += + ("Invalid proto descriptor for file \"" + filename + "\":\n"); + had_errors_ = true; + } + // As this only happens on failure and will result in the program not + // running at all, no effort is made to optimize this string manipulation. + error_message += (" " + element_name + ": " + message + "\n"); + } + + void Clear() { + had_errors_ = false; + error_message = ""; + } + + string error_message; + + private: + bool had_errors_; +}; + // Create a Python DescriptorPool object, but does not fill the "pool" // attribute. static PyDescriptorPool* _CreateDescriptorPool() { @@ -76,6 +108,7 @@ static PyDescriptorPool* _CreateDescriptorPool() { return NULL; } + cpool->error_collector = nullptr; cpool->underlay = NULL; cpool->database = NULL; @@ -124,7 +157,8 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase( return NULL; } if (database != NULL) { - cpool->pool = new DescriptorPool(database); + cpool->error_collector = new BuildFileErrorCollector(); + cpool->pool = new DescriptorPool(database, cpool->error_collector); cpool->database = database; } else { cpool->pool = new DescriptorPool(); @@ -167,6 +201,7 @@ static void Dealloc(PyObject* pself) { delete self->descriptor_options; delete self->database; delete self->pool; + delete self->error_collector; Py_TYPE(self)->tp_free(pself); } @@ -182,6 +217,20 @@ static int GcClear(PyObject* pself) { return 0; } +PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self, + char* name, char* error_type) { + BuildFileErrorCollector* error_collector = + reinterpret_cast(self); + if (error_collector && !error_collector->error_message.empty()) { + PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s", + error_type, name, error_collector->error_message.c_str()); + error_collector->Clear(); + return NULL; + } + PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name); + return NULL; +} + static PyObject* FindMessageByName(PyObject* self, PyObject* arg) { Py_ssize_t name_size; char* name; @@ -194,8 +243,9 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) { string(name, name_size)); if (message_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name); - return NULL; + return SetErrorFromCollector( + reinterpret_cast(self)->error_collector, name, + "message"); } @@ -212,12 +262,12 @@ static PyObject* FindFileByName(PyObject* self, PyObject* arg) { return NULL; } + PyDescriptorPool* py_pool = reinterpret_cast(self); const FileDescriptor* file_descriptor = - reinterpret_cast(self)->pool->FindFileByName( - string(name, name_size)); + py_pool->pool->FindFileByName(string(name, name_size)); + if (file_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name); - return NULL; + return SetErrorFromCollector(py_pool->error_collector, name, "file"); } return PyFileDescriptor_FromDescriptor(file_descriptor); } @@ -232,9 +282,7 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) { const FieldDescriptor* field_descriptor = self->pool->FindFieldByName(string(name, name_size)); if (field_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find field %.200s", - name); - return NULL; + return SetErrorFromCollector(self->error_collector, name, "field"); } @@ -255,8 +303,8 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) { const FieldDescriptor* field_descriptor = self->pool->FindExtensionByName(string(name, name_size)); if (field_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find extension field %.200s", name); - return NULL; + return SetErrorFromCollector(self->error_collector, name, + "extension field"); } @@ -277,8 +325,7 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) { const EnumDescriptor* enum_descriptor = self->pool->FindEnumTypeByName(string(name, name_size)); if (enum_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name); - return NULL; + return SetErrorFromCollector(self->error_collector, name, "enum"); } @@ -299,8 +346,7 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) { const OneofDescriptor* oneof_descriptor = self->pool->FindOneofByName(string(name, name_size)); if (oneof_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name); - return NULL; + return SetErrorFromCollector(self->error_collector, name, "oneof"); } @@ -322,8 +368,9 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) { reinterpret_cast(self)->pool->FindServiceByName( string(name, name_size)); if (service_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find service %.200s", name); - return NULL; + return SetErrorFromCollector( + reinterpret_cast(self)->error_collector, name, + "service"); } @@ -341,8 +388,9 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) { reinterpret_cast(self)->pool->FindMethodByName( string(name, name_size)); if (method_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name); - return NULL; + return SetErrorFromCollector( + reinterpret_cast(self)->error_collector, name, + "method"); } @@ -360,8 +408,9 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) { reinterpret_cast(self)->pool->FindFileContainingSymbol( string(name, name_size)); if (file_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name); - return NULL; + return SetErrorFromCollector( + reinterpret_cast(self)->error_collector, name, + "symbol"); } @@ -384,7 +433,16 @@ static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) { reinterpret_cast(self)->pool->FindExtensionByNumber( descriptor, number); if (extension_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find extension %d", number); + BuildFileErrorCollector* error_collector = + reinterpret_cast( + reinterpret_cast(self)->error_collector); + if (error_collector && !error_collector->error_message.empty()) { + PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s", + number, error_collector->error_message.c_str()); + error_collector->Clear(); + return NULL; + } + PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number); return NULL; } @@ -511,32 +569,6 @@ static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) { } // The code below loads new Descriptors from a serialized FileDescriptorProto. - -// Collects errors that occur during proto file building to allow them to be -// propagated in the python exception instead of only living in ERROR logs. -class BuildFileErrorCollector : public DescriptorPool::ErrorCollector { - public: - BuildFileErrorCollector() : error_message(""), had_errors(false) {} - - void AddError(const string& filename, const string& element_name, - const Message* descriptor, ErrorLocation location, - const string& message) { - // Replicates the logging behavior that happens in the C++ implementation - // when an error collector is not passed in. - if (!had_errors) { - error_message += - ("Invalid proto descriptor for file \"" + filename + "\":\n"); - had_errors = true; - } - // As this only happens on failure and will result in the program not - // running at all, no effort is made to optimize this string manipulation. - error_message += (" " + element_name + ": " + message + "\n"); - } - - string error_message; - bool had_errors; -}; - static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) { PyDescriptorPool* self = reinterpret_cast(pself); char* message_type; diff --git a/python/google/protobuf/pyext/descriptor_pool.h b/python/google/protobuf/pyext/descriptor_pool.h index 541fda0380..2d456f9088 100644 --- a/python/google/protobuf/pyext/descriptor_pool.h +++ b/python/google/protobuf/pyext/descriptor_pool.h @@ -59,6 +59,10 @@ typedef struct PyDescriptorPool { // The C++ pool containing Descriptors. DescriptorPool* pool; + // The error collector to store error info. Can be NULL. This pointer is + // owned. + DescriptorPool::ErrorCollector* error_collector; + // The C++ pool acting as an underlay. Can be NULL. // This pointer is not owned and must stay alive. const DescriptorPool* underlay; diff --git a/python/setup.py b/python/setup.py index ba74443b3a..9aabbf7aaa 100755 --- a/python/setup.py +++ b/python/setup.py @@ -92,6 +92,7 @@ def GenerateUnittestProtos(): generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False) generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", False) generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False) + generate_proto("../src/google/protobuf/util/json_format.proto", False) generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False) generate_proto("google/protobuf/internal/any_test.proto", False) generate_proto("google/protobuf/internal/descriptor_pool_test1.proto", False) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 879db89725..a7d9fbe826 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -115,11 +115,6 @@ class Any::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Any::kTypeUrlFieldNumber; -const int Any::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Any::Any() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr), _any_metadata_(&type_url_, &value_) { SharedCtor(); @@ -419,10 +414,6 @@ bool Any::IsInitialized() const { return true; } -void Any::Swap(Any* other) { - if (other == this) return; - InternalSwap(other); -} void Any::InternalSwap(Any* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index d9a125d301..e3118e0848 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -126,10 +126,13 @@ class PROTOBUF_EXPORT Any : } static bool ParseAnyTypeUrl(const string& type_url, std::string* full_type_name); - void Swap(Any* other); friend void swap(Any& a, Any& b) { a.Swap(&b); } + inline void Swap(Any* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -191,9 +194,12 @@ class PROTOBUF_EXPORT Any : // accessors ------------------------------------------------------- + enum : int { + kTypeUrlFieldNumber = 1, + kValueFieldNumber = 2, + }; // string type_url = 1; void clear_type_url(); - static const int kTypeUrlFieldNumber = 1; const std::string& type_url() const; void set_type_url(const std::string& value); void set_type_url(std::string&& value); @@ -205,7 +211,6 @@ class PROTOBUF_EXPORT Any : // bytes value = 2; void clear_value(); - static const int kValueFieldNumber = 2; const std::string& value() const; void set_value(const std::string& value); void set_value(std::string&& value); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 29060c09b0..26bd56d6af 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -196,16 +196,6 @@ void Api::clear_source_context() { } source_context_ = nullptr; } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Api::kNameFieldNumber; -const int Api::kMethodsFieldNumber; -const int Api::kOptionsFieldNumber; -const int Api::kVersionFieldNumber; -const int Api::kSourceContextFieldNumber; -const int Api::kMixinsFieldNumber; -const int Api::kSyntaxFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Api::Api() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -777,10 +767,6 @@ bool Api::IsInitialized() const { return true; } -void Api::Swap(Api* other) { - if (other == this) return; - InternalSwap(other); -} void Api::InternalSwap(Api* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -811,16 +797,6 @@ class Method::_Internal { void Method::clear_options() { options_.Clear(); } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Method::kNameFieldNumber; -const int Method::kRequestTypeUrlFieldNumber; -const int Method::kRequestStreamingFieldNumber; -const int Method::kResponseTypeUrlFieldNumber; -const int Method::kResponseStreamingFieldNumber; -const int Method::kOptionsFieldNumber; -const int Method::kSyntaxFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Method::Method() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1374,10 +1350,6 @@ bool Method::IsInitialized() const { return true; } -void Method::Swap(Method* other) { - if (other == this) return; - InternalSwap(other); -} void Method::InternalSwap(Method* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1406,11 +1378,6 @@ class Mixin::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Mixin::kNameFieldNumber; -const int Mixin::kRootFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Mixin::Mixin() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1721,10 +1688,6 @@ bool Mixin::IsInitialized() const { return true; } -void Mixin::Swap(Mixin* other) { - if (other == this) return; - InternalSwap(other); -} void Mixin::InternalSwap(Mixin* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 729c3f9b0f..ae02cd461c 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -120,10 +120,13 @@ class PROTOBUF_EXPORT Api : static constexpr int kIndexInFileMessages = 0; - void Swap(Api* other); friend void swap(Api& a, Api& b) { a.Swap(&b); } + inline void Swap(Api* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -185,10 +188,18 @@ class PROTOBUF_EXPORT Api : // accessors ------------------------------------------------------- + enum : int { + kMethodsFieldNumber = 2, + kOptionsFieldNumber = 3, + kMixinsFieldNumber = 6, + kNameFieldNumber = 1, + kVersionFieldNumber = 4, + kSourceContextFieldNumber = 5, + kSyntaxFieldNumber = 7, + }; // repeated .google.protobuf.Method methods = 2; int methods_size() const; void clear_methods(); - static const int kMethodsFieldNumber = 2; PROTOBUF_NAMESPACE_ID::Method* mutable_methods(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method >* mutable_methods(); @@ -200,7 +211,6 @@ class PROTOBUF_EXPORT Api : // repeated .google.protobuf.Option options = 3; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 3; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -212,7 +222,6 @@ class PROTOBUF_EXPORT Api : // repeated .google.protobuf.Mixin mixins = 6; int mixins_size() const; void clear_mixins(); - static const int kMixinsFieldNumber = 6; PROTOBUF_NAMESPACE_ID::Mixin* mutable_mixins(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin >* mutable_mixins(); @@ -223,7 +232,6 @@ class PROTOBUF_EXPORT Api : // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -235,7 +243,6 @@ class PROTOBUF_EXPORT Api : // string version = 4; void clear_version(); - static const int kVersionFieldNumber = 4; const std::string& version() const; void set_version(const std::string& value); void set_version(std::string&& value); @@ -248,7 +255,6 @@ class PROTOBUF_EXPORT Api : // .google.protobuf.SourceContext source_context = 5; bool has_source_context() const; void clear_source_context(); - static const int kSourceContextFieldNumber = 5; const PROTOBUF_NAMESPACE_ID::SourceContext& source_context() const; PROTOBUF_NAMESPACE_ID::SourceContext* release_source_context(); PROTOBUF_NAMESPACE_ID::SourceContext* mutable_source_context(); @@ -256,7 +262,6 @@ class PROTOBUF_EXPORT Api : // .google.protobuf.Syntax syntax = 7; void clear_syntax(); - static const int kSyntaxFieldNumber = 7; PROTOBUF_NAMESPACE_ID::Syntax syntax() const; void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value); @@ -321,10 +326,13 @@ class PROTOBUF_EXPORT Method : static constexpr int kIndexInFileMessages = 1; - void Swap(Method* other); friend void swap(Method& a, Method& b) { a.Swap(&b); } + inline void Swap(Method* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -386,10 +394,18 @@ class PROTOBUF_EXPORT Method : // accessors ------------------------------------------------------- + enum : int { + kOptionsFieldNumber = 6, + kNameFieldNumber = 1, + kRequestTypeUrlFieldNumber = 2, + kResponseTypeUrlFieldNumber = 4, + kRequestStreamingFieldNumber = 3, + kResponseStreamingFieldNumber = 5, + kSyntaxFieldNumber = 7, + }; // repeated .google.protobuf.Option options = 6; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 6; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -400,7 +416,6 @@ class PROTOBUF_EXPORT Method : // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -412,7 +427,6 @@ class PROTOBUF_EXPORT Method : // string request_type_url = 2; void clear_request_type_url(); - static const int kRequestTypeUrlFieldNumber = 2; const std::string& request_type_url() const; void set_request_type_url(const std::string& value); void set_request_type_url(std::string&& value); @@ -424,7 +438,6 @@ class PROTOBUF_EXPORT Method : // string response_type_url = 4; void clear_response_type_url(); - static const int kResponseTypeUrlFieldNumber = 4; const std::string& response_type_url() const; void set_response_type_url(const std::string& value); void set_response_type_url(std::string&& value); @@ -436,19 +449,16 @@ class PROTOBUF_EXPORT Method : // bool request_streaming = 3; void clear_request_streaming(); - static const int kRequestStreamingFieldNumber = 3; bool request_streaming() const; void set_request_streaming(bool value); // bool response_streaming = 5; void clear_response_streaming(); - static const int kResponseStreamingFieldNumber = 5; bool response_streaming() const; void set_response_streaming(bool value); // .google.protobuf.Syntax syntax = 7; void clear_syntax(); - static const int kSyntaxFieldNumber = 7; PROTOBUF_NAMESPACE_ID::Syntax syntax() const; void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value); @@ -513,10 +523,13 @@ class PROTOBUF_EXPORT Mixin : static constexpr int kIndexInFileMessages = 2; - void Swap(Mixin* other); friend void swap(Mixin& a, Mixin& b) { a.Swap(&b); } + inline void Swap(Mixin* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -578,9 +591,12 @@ class PROTOBUF_EXPORT Mixin : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kRootFieldNumber = 2, + }; // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -592,7 +608,6 @@ class PROTOBUF_EXPORT Mixin : // string root = 2; void clear_root(); - static const int kRootFieldNumber = 2; const std::string& root() const; void set_root(const std::string& value); void set_root(std::string&& value); diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 52f3fb9505..dedc22122e 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -245,7 +245,7 @@ struct ArenaOptions { // well as protobuf container types like RepeatedPtrField and Map. The protocol // is internal to protobuf and is not guaranteed to be stable. Non-proto types // should not rely on this protocol. -class PROTOBUF_EXPORT Arena final { +class PROTOBUF_EXPORT alignas(8) Arena final { public: // Arena constructor taking custom options. See ArenaOptions below for // descriptions of the options available. diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 6ab5aff2f2..6ea25652d5 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -2023,6 +2023,10 @@ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) { // Error written to stdout by child process after exec() fails. ExpectErrorSubstring("no_such_file: program not found or is not executable"); + ExpectErrorSubstring( + "Please specify a program using absolute path or make sure " + "the program is available in your PATH system variable"); + // Error written by parent process when child fails. ExpectErrorSubstring( "--badplug_out: prefix-gen-badplug: Plugin failed with status code 1."); diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 4cec899b83..624bbd37a2 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -1489,9 +1489,9 @@ class ParseLoopGenerator { std::string enum_validator; if (field->type() == FieldDescriptor::TYPE_ENUM && !HasPreservingUnknownEnumSemantics(field)) { - enum_validator = StrCat( - ", ", QualifiedClassName(field->enum_type(), options_), - "_IsValid, mutable_unknown_fields(), ", field->number()); + enum_validator = + StrCat(", ", QualifiedClassName(field->enum_type(), options_), + "_IsValid, &_internal_metadata_, ", field->number()); } format_("ptr = $pi_ns$::Packed$1$Parser(mutable_$2$(), ptr, ctx$3$);\n", DeclaredTypeMethodName(field->type()), FieldName(field), diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 43dc0f57d0..3ef4665d17 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -714,6 +714,18 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) { ordered_fields.push_back(field); } + if (!ordered_fields.empty()) { + format("enum : int {\n"); + for (auto field : ordered_fields) { + Formatter::SaveState save(&format); + + std::map vars; + SetCommonFieldVariables(field, &vars, options_); + format.AddMap(vars); + format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field)); + } + format("};\n"); + } for (auto field : ordered_fields) { PrintFieldComment(format, field); @@ -735,10 +747,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) { field); } - format( - "$deprecated_attr$void ${1$clear_$name$$}$();\n" - "$deprecated_attr$static const int ${1$$2$$}$ = $number$;\n", - field, FieldConstantName(field)); + format("$deprecated_attr$void ${1$clear_$name$$}$();\n", field); // Generate type-specific accessor declarations. field_generators_.get(field).GenerateAccessorDeclarations(printer); @@ -1159,10 +1168,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { "\n", index_in_file_messages_); - if (SupportsArenas(descriptor_)) { - format("void UnsafeArenaSwap($classname$* other);\n"); - } - if (IsAnyMessage(descriptor_, options_)) { format( "// implements Any -----------------------------------------------\n" @@ -1205,10 +1210,34 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { ShouldMarkNewAsFinal(descriptor_, options_) ? "final" : ""); format( - "void Swap($classname$* other);\n" "friend void swap($classname$& a, $classname$& b) {\n" " a.Swap(&b);\n" - "}\n" + "}\n"); + + if (SupportsArenas(descriptor_)) { + format( + "inline void Swap($classname$* other) {\n" + " if (other == this) return;\n" + " if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {\n" + " InternalSwap(other);\n" + " } else {\n" + " ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);\n" + " }\n" + "}\n" + "void UnsafeArenaSwap($classname$* other) {\n" + " if (other == this) return;\n" + " $DCHK$(GetArenaNoVirtual() == other->GetArenaNoVirtual());\n" + " InternalSwap(other);\n" + "}\n"); + } else { + format( + "inline void Swap($classname$* other) {\n" + " if (other == this) return;\n" + " InternalSwap(other);\n" + "}\n"); + } + + format( "\n" "// implements Message ----------------------------------------------\n" "\n" @@ -2031,15 +2060,6 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { } } - // Generate field number constants. - format("#if !defined(_MSC_VER) || _MSC_VER >= 1900\n"); - for (auto field : FieldRange(descriptor_)) { - format("const int $classname$::$1$;\n", FieldConstantName(field)); - } - format( - "#endif // !defined(_MSC_VER) || _MSC_VER >= 1900\n" - "\n"); - GenerateStructors(printer); format("\n"); @@ -3003,40 +3023,7 @@ void MessageGenerator::GenerateOneofClear(io::Printer* printer) { void MessageGenerator::GenerateSwap(io::Printer* printer) { Formatter format(printer, variables_); - if (SupportsArenas(descriptor_)) { - // Generate the Swap member function. This is a lightweight wrapper around - // UnsafeArenaSwap() / MergeFrom() with temporaries, depending on the memory - // ownership situation: swapping across arenas or between an arena and a - // heap requires copying. - format( - "void $classname$::Swap($classname$* other) {\n" - " if (other == this) return;\n" - " if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {\n" - " InternalSwap(other);\n" - " } else {\n" - " $classname$* temp = New(GetArenaNoVirtual());\n" - " temp->MergeFrom(*other);\n" - " other->CopyFrom(*this);\n" - " InternalSwap(temp);\n" - " if (GetArenaNoVirtual() == nullptr) {\n" - " delete temp;\n" - " }\n" - " }\n" - "}\n" - "void $classname$::UnsafeArenaSwap($classname$* other) {\n" - " if (other == this) return;\n" - " $DCHK$(GetArenaNoVirtual() == other->GetArenaNoVirtual());\n" - " InternalSwap(other);\n" - "}\n"); - } else { - format( - "void $classname$::Swap($classname$* other) {\n" - " if (other == this) return;\n" - " InternalSwap(other);\n" - "}\n"); - } - // Generate the UnsafeArenaSwap member function. format("void $classname$::InternalSwap($classname$* other) {\n"); format.Indent(); format("using std::swap;\n"); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 556284f2ab..fa7e98ef5c 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -1651,7 +1651,11 @@ bool IsWellKnownTypeFile(const FileDescriptor* file) { } // anonymous namespace void Generator::GenerateHeader(const GeneratorOptions& options, + const FileDescriptor* file, io::Printer* printer) const { + if (file != nullptr) { + printer->Print("// source: $filename$\n", "filename", file->name()); + } printer->Print( "/**\n" " * @fileoverview\n" @@ -3637,7 +3641,7 @@ bool Generator::GenerateFile(const FileDescriptor* file, void Generator::GenerateFile(const GeneratorOptions& options, io::Printer* printer, const FileDescriptor* file) const { - GenerateHeader(options, printer); + GenerateHeader(options, file, printer); // Generate "require" statements. if ((options.import_style == GeneratorOptions::kImportCommonJs || @@ -3748,7 +3752,11 @@ bool Generator::GenerateAll(const std::vector& files, } } - GenerateHeader(options, &printer); + if (files.size() == 1) { + GenerateHeader(options, files[0], &printer); + } else { + GenerateHeader(options, nullptr, &printer); + } std::set provided; FindProvides(options, &printer, files, &provided); @@ -3811,7 +3819,7 @@ bool Generator::GenerateAll(const std::vector& files, output.get(), '$', options.annotate_code ? &annotation_collector : nullptr); - GenerateHeader(options, &printer); + GenerateHeader(options, file, &printer); std::set provided; for (auto one_desc : scc->descriptors) { @@ -3864,7 +3872,7 @@ bool Generator::GenerateAll(const std::vector& files, output.get(), '$', options.annotate_code ? &annotation_collector : nullptr); - GenerateHeader(options, &printer); + GenerateHeader(options, file, &printer); std::set provided; FindProvidesForEnum(options, &printer, enumdesc, &provided); @@ -3896,7 +3904,7 @@ bool Generator::GenerateAll(const std::vector& files, output.get(), '$', options.annotate_code ? &annotation_collector : nullptr); - GenerateHeader(options, &printer); + GenerateHeader(options, file, &printer); std::set provided; std::vector fields; diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h index 7895b0b063..49f19f6eb6 100644 --- a/src/google/protobuf/compiler/js/js_generator.h +++ b/src/google/protobuf/compiler/js/js_generator.h @@ -157,7 +157,7 @@ class PROTOC_EXPORT Generator : public CodeGenerator { private: void GenerateHeader(const GeneratorOptions& options, - io::Printer* printer) const; + const FileDescriptor* file, io::Printer* printer) const; // Generate goog.provides() calls. void FindProvides(const GeneratorOptions& options, io::Printer* printer, diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index e027234585..23ac4f2f38 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -225,13 +225,6 @@ class Version::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Version::kMajorFieldNumber; -const int Version::kMinorFieldNumber; -const int Version::kPatchFieldNumber; -const int Version::kSuffixFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Version::Version() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -631,10 +624,6 @@ bool Version::IsInitialized() const { return true; } -void Version::Swap(Version* other) { - if (other == this) return; - InternalSwap(other); -} void Version::InternalSwap(Version* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -676,13 +665,6 @@ CodeGeneratorRequest::_Internal::compiler_version(const CodeGeneratorRequest* ms void CodeGeneratorRequest::clear_proto_file() { proto_file_.Clear(); } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int CodeGeneratorRequest::kFileToGenerateFieldNumber; -const int CodeGeneratorRequest::kParameterFieldNumber; -const int CodeGeneratorRequest::kProtoFileFieldNumber; -const int CodeGeneratorRequest::kCompilerVersionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - CodeGeneratorRequest::CodeGeneratorRequest() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1115,10 +1097,6 @@ bool CodeGeneratorRequest::IsInitialized() const { return true; } -void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) { - if (other == this) return; - InternalSwap(other); -} void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1153,12 +1131,6 @@ class CodeGeneratorResponse_File::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int CodeGeneratorResponse_File::kNameFieldNumber; -const int CodeGeneratorResponse_File::kInsertionPointFieldNumber; -const int CodeGeneratorResponse_File::kContentFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - CodeGeneratorResponse_File::CodeGeneratorResponse_File() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1551,10 +1523,6 @@ bool CodeGeneratorResponse_File::IsInitialized() const { return true; } -void CodeGeneratorResponse_File::Swap(CodeGeneratorResponse_File* other) { - if (other == this) return; - InternalSwap(other); -} void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1584,11 +1552,6 @@ class CodeGeneratorResponse::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int CodeGeneratorResponse::kErrorFieldNumber; -const int CodeGeneratorResponse::kFileFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - CodeGeneratorResponse::CodeGeneratorResponse() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1902,10 +1865,6 @@ bool CodeGeneratorResponse::IsInitialized() const { return true; } -void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) { - if (other == this) return; - InternalSwap(other); -} void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 9226d43098..46704e5f2b 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -139,10 +139,13 @@ class PROTOC_EXPORT Version : static constexpr int kIndexInFileMessages = 0; - void Swap(Version* other); friend void swap(Version& a, Version& b) { a.Swap(&b); } + inline void Swap(Version* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -204,10 +207,15 @@ class PROTOC_EXPORT Version : // accessors ------------------------------------------------------- + enum : int { + kSuffixFieldNumber = 4, + kMajorFieldNumber = 1, + kMinorFieldNumber = 2, + kPatchFieldNumber = 3, + }; // optional string suffix = 4; bool has_suffix() const; void clear_suffix(); - static const int kSuffixFieldNumber = 4; const std::string& suffix() const; void set_suffix(const std::string& value); void set_suffix(std::string&& value); @@ -220,21 +228,18 @@ class PROTOC_EXPORT Version : // optional int32 major = 1; bool has_major() const; void clear_major(); - static const int kMajorFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 major() const; void set_major(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 minor = 2; bool has_minor() const; void clear_minor(); - static const int kMinorFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 minor() const; void set_minor(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 patch = 3; bool has_patch() const; void clear_patch(); - static const int kPatchFieldNumber = 3; ::PROTOBUF_NAMESPACE_ID::int32 patch() const; void set_patch(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -304,10 +309,13 @@ class PROTOC_EXPORT CodeGeneratorRequest : static constexpr int kIndexInFileMessages = 1; - void Swap(CodeGeneratorRequest* other); friend void swap(CodeGeneratorRequest& a, CodeGeneratorRequest& b) { a.Swap(&b); } + inline void Swap(CodeGeneratorRequest* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -369,10 +377,15 @@ class PROTOC_EXPORT CodeGeneratorRequest : // accessors ------------------------------------------------------- + enum : int { + kFileToGenerateFieldNumber = 1, + kProtoFileFieldNumber = 15, + kParameterFieldNumber = 2, + kCompilerVersionFieldNumber = 3, + }; // repeated string file_to_generate = 1; int file_to_generate_size() const; void clear_file_to_generate(); - static const int kFileToGenerateFieldNumber = 1; const std::string& file_to_generate(int index) const; std::string* mutable_file_to_generate(int index); void set_file_to_generate(int index, const std::string& value); @@ -390,7 +403,6 @@ class PROTOC_EXPORT CodeGeneratorRequest : // repeated .google.protobuf.FileDescriptorProto proto_file = 15; int proto_file_size() const; void clear_proto_file(); - static const int kProtoFileFieldNumber = 15; PROTOBUF_NAMESPACE_ID::FileDescriptorProto* mutable_proto_file(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FileDescriptorProto >* mutable_proto_file(); @@ -402,7 +414,6 @@ class PROTOC_EXPORT CodeGeneratorRequest : // optional string parameter = 2; bool has_parameter() const; void clear_parameter(); - static const int kParameterFieldNumber = 2; const std::string& parameter() const; void set_parameter(const std::string& value); void set_parameter(std::string&& value); @@ -415,7 +426,6 @@ class PROTOC_EXPORT CodeGeneratorRequest : // optional .google.protobuf.compiler.Version compiler_version = 3; bool has_compiler_version() const; void clear_compiler_version(); - static const int kCompilerVersionFieldNumber = 3; const PROTOBUF_NAMESPACE_ID::compiler::Version& compiler_version() const; PROTOBUF_NAMESPACE_ID::compiler::Version* release_compiler_version(); PROTOBUF_NAMESPACE_ID::compiler::Version* mutable_compiler_version(); @@ -487,10 +497,13 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : static constexpr int kIndexInFileMessages = 2; - void Swap(CodeGeneratorResponse_File* other); friend void swap(CodeGeneratorResponse_File& a, CodeGeneratorResponse_File& b) { a.Swap(&b); } + inline void Swap(CodeGeneratorResponse_File* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -552,10 +565,14 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kInsertionPointFieldNumber = 2, + kContentFieldNumber = 15, + }; // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -568,7 +585,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : // optional string insertion_point = 2; bool has_insertion_point() const; void clear_insertion_point(); - static const int kInsertionPointFieldNumber = 2; const std::string& insertion_point() const; void set_insertion_point(const std::string& value); void set_insertion_point(std::string&& value); @@ -581,7 +597,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File : // optional string content = 15; bool has_content() const; void clear_content(); - static const int kContentFieldNumber = 15; const std::string& content() const; void set_content(const std::string& value); void set_content(std::string&& value); @@ -656,10 +671,13 @@ class PROTOC_EXPORT CodeGeneratorResponse : static constexpr int kIndexInFileMessages = 3; - void Swap(CodeGeneratorResponse* other); friend void swap(CodeGeneratorResponse& a, CodeGeneratorResponse& b) { a.Swap(&b); } + inline void Swap(CodeGeneratorResponse* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -723,10 +741,13 @@ class PROTOC_EXPORT CodeGeneratorResponse : // accessors ------------------------------------------------------- + enum : int { + kFileFieldNumber = 15, + kErrorFieldNumber = 1, + }; // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; int file_size() const; void clear_file(); - static const int kFileFieldNumber = 15; PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File* mutable_file(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File >* mutable_file(); @@ -738,7 +759,6 @@ class PROTOC_EXPORT CodeGeneratorResponse : // optional string error = 1; bool has_error() const; void clear_error(); - static const int kErrorFieldNumber = 1; const std::string& error() const; void set_error(const std::string& value); void set_error(std::string&& value); diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index b920b2ddd4..bd6be2b09b 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -338,7 +338,10 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) { // stuff that is unsafe here. int ignored; ignored = write(STDERR_FILENO, argv[0], strlen(argv[0])); - const char* message = ": program not found or is not executable\n"; + const char* message = + ": program not found or is not executable\n" + "Please specify a program using absolute path or make sure " + "the program is available in your PATH system variable\n"; ignored = write(STDERR_FILENO, message, strlen(message)); (void)ignored; diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index be3a706219..420320d245 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1386,10 +1386,6 @@ class FileDescriptorSet::_Internal { using HasBits = decltype(std::declval()._has_bits_); }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FileDescriptorSet::kFileFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FileDescriptorSet::FileDescriptorSet() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1651,25 +1647,6 @@ bool FileDescriptorSet::IsInitialized() const { return true; } -void FileDescriptorSet::Swap(FileDescriptorSet* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FileDescriptorSet* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FileDescriptorSet::UnsafeArenaSwap(FileDescriptorSet* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1746,21 +1723,6 @@ void FileDescriptorProto::unsafe_arena_set_allocated_source_code_info( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.FileDescriptorProto.source_code_info) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FileDescriptorProto::kNameFieldNumber; -const int FileDescriptorProto::kPackageFieldNumber; -const int FileDescriptorProto::kDependencyFieldNumber; -const int FileDescriptorProto::kPublicDependencyFieldNumber; -const int FileDescriptorProto::kWeakDependencyFieldNumber; -const int FileDescriptorProto::kMessageTypeFieldNumber; -const int FileDescriptorProto::kEnumTypeFieldNumber; -const int FileDescriptorProto::kServiceFieldNumber; -const int FileDescriptorProto::kExtensionFieldNumber; -const int FileDescriptorProto::kOptionsFieldNumber; -const int FileDescriptorProto::kSourceCodeInfoFieldNumber; -const int FileDescriptorProto::kSyntaxFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FileDescriptorProto::FileDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2668,25 +2630,6 @@ bool FileDescriptorProto::IsInitialized() const { return true; } -void FileDescriptorProto::Swap(FileDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FileDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FileDescriptorProto::UnsafeArenaSwap(FileDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2751,12 +2694,6 @@ void DescriptorProto_ExtensionRange::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.DescriptorProto.ExtensionRange.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int DescriptorProto_ExtensionRange::kStartFieldNumber; -const int DescriptorProto_ExtensionRange::kEndFieldNumber; -const int DescriptorProto_ExtensionRange::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -3121,25 +3058,6 @@ bool DescriptorProto_ExtensionRange::IsInitialized() const { return true; } -void DescriptorProto_ExtensionRange::Swap(DescriptorProto_ExtensionRange* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - DescriptorProto_ExtensionRange* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void DescriptorProto_ExtensionRange::UnsafeArenaSwap(DescriptorProto_ExtensionRange* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -3169,11 +3087,6 @@ class DescriptorProto_ReservedRange::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int DescriptorProto_ReservedRange::kStartFieldNumber; -const int DescriptorProto_ReservedRange::kEndFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - DescriptorProto_ReservedRange::DescriptorProto_ReservedRange() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -3483,25 +3396,6 @@ bool DescriptorProto_ReservedRange::IsInitialized() const { return true; } -void DescriptorProto_ReservedRange::Swap(DescriptorProto_ReservedRange* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - DescriptorProto_ReservedRange* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void DescriptorProto_ReservedRange::UnsafeArenaSwap(DescriptorProto_ReservedRange* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -3550,19 +3444,6 @@ void DescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.DescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int DescriptorProto::kNameFieldNumber; -const int DescriptorProto::kFieldFieldNumber; -const int DescriptorProto::kExtensionFieldNumber; -const int DescriptorProto::kNestedTypeFieldNumber; -const int DescriptorProto::kEnumTypeFieldNumber; -const int DescriptorProto::kExtensionRangeFieldNumber; -const int DescriptorProto::kOneofDeclFieldNumber; -const int DescriptorProto::kOptionsFieldNumber; -const int DescriptorProto::kReservedRangeFieldNumber; -const int DescriptorProto::kReservedNameFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - DescriptorProto::DescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -4350,25 +4231,6 @@ bool DescriptorProto::IsInitialized() const { return true; } -void DescriptorProto::Swap(DescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - DescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void DescriptorProto::UnsafeArenaSwap(DescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void DescriptorProto::InternalSwap(DescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -4400,10 +4262,6 @@ class ExtensionRangeOptions::_Internal { using HasBits = decltype(std::declval()._has_bits_); }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int ExtensionRangeOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - ExtensionRangeOptions::ExtensionRangeOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -4694,25 +4552,6 @@ bool ExtensionRangeOptions::IsInitialized() const { return true; } -void ExtensionRangeOptions::Swap(ExtensionRangeOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - ExtensionRangeOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void ExtensionRangeOptions::UnsafeArenaSwap(ExtensionRangeOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void ExtensionRangeOptions::InternalSwap(ExtensionRangeOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -4785,19 +4624,6 @@ void FieldDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.FieldDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FieldDescriptorProto::kNameFieldNumber; -const int FieldDescriptorProto::kNumberFieldNumber; -const int FieldDescriptorProto::kLabelFieldNumber; -const int FieldDescriptorProto::kTypeFieldNumber; -const int FieldDescriptorProto::kTypeNameFieldNumber; -const int FieldDescriptorProto::kExtendeeFieldNumber; -const int FieldDescriptorProto::kDefaultValueFieldNumber; -const int FieldDescriptorProto::kOneofIndexFieldNumber; -const int FieldDescriptorProto::kJsonNameFieldNumber; -const int FieldDescriptorProto::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FieldDescriptorProto::FieldDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -5594,25 +5420,6 @@ bool FieldDescriptorProto::IsInitialized() const { return true; } -void FieldDescriptorProto::Swap(FieldDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FieldDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FieldDescriptorProto::UnsafeArenaSwap(FieldDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -5674,11 +5481,6 @@ void OneofDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.OneofDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int OneofDescriptorProto::kNameFieldNumber; -const int OneofDescriptorProto::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - OneofDescriptorProto::OneofDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -6015,25 +5817,6 @@ bool OneofDescriptorProto::IsInitialized() const { return true; } -void OneofDescriptorProto::Swap(OneofDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - OneofDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void OneofDescriptorProto::UnsafeArenaSwap(OneofDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -6063,11 +5846,6 @@ class EnumDescriptorProto_EnumReservedRange::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumDescriptorProto_EnumReservedRange::kStartFieldNumber; -const int EnumDescriptorProto_EnumReservedRange::kEndFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -6377,25 +6155,6 @@ bool EnumDescriptorProto_EnumReservedRange::IsInitialized() const { return true; } -void EnumDescriptorProto_EnumReservedRange::Swap(EnumDescriptorProto_EnumReservedRange* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumDescriptorProto_EnumReservedRange* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumDescriptorProto_EnumReservedRange::UnsafeArenaSwap(EnumDescriptorProto_EnumReservedRange* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumDescriptorProto_EnumReservedRange::InternalSwap(EnumDescriptorProto_EnumReservedRange* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -6444,14 +6203,6 @@ void EnumDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.EnumDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumDescriptorProto::kNameFieldNumber; -const int EnumDescriptorProto::kValueFieldNumber; -const int EnumDescriptorProto::kOptionsFieldNumber; -const int EnumDescriptorProto::kReservedRangeFieldNumber; -const int EnumDescriptorProto::kReservedNameFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumDescriptorProto::EnumDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -6959,25 +6710,6 @@ bool EnumDescriptorProto::IsInitialized() const { return true; } -void EnumDescriptorProto::Swap(EnumDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumDescriptorProto::UnsafeArenaSwap(EnumDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -7033,12 +6765,6 @@ void EnumValueDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.EnumValueDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumValueDescriptorProto::kNameFieldNumber; -const int EnumValueDescriptorProto::kNumberFieldNumber; -const int EnumValueDescriptorProto::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumValueDescriptorProto::EnumValueDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -7421,25 +7147,6 @@ bool EnumValueDescriptorProto::IsInitialized() const { return true; } -void EnumValueDescriptorProto::Swap(EnumValueDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumValueDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumValueDescriptorProto::UnsafeArenaSwap(EnumValueDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -7490,12 +7197,6 @@ void ServiceDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.ServiceDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int ServiceDescriptorProto::kNameFieldNumber; -const int ServiceDescriptorProto::kMethodFieldNumber; -const int ServiceDescriptorProto::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - ServiceDescriptorProto::ServiceDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -7888,25 +7589,6 @@ bool ServiceDescriptorProto::IsInitialized() const { return true; } -void ServiceDescriptorProto::Swap(ServiceDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - ServiceDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void ServiceDescriptorProto::UnsafeArenaSwap(ServiceDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -7969,15 +7651,6 @@ void MethodDescriptorProto::unsafe_arena_set_allocated_options( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.MethodDescriptorProto.options) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int MethodDescriptorProto::kNameFieldNumber; -const int MethodDescriptorProto::kInputTypeFieldNumber; -const int MethodDescriptorProto::kOutputTypeFieldNumber; -const int MethodDescriptorProto::kOptionsFieldNumber; -const int MethodDescriptorProto::kClientStreamingFieldNumber; -const int MethodDescriptorProto::kServerStreamingFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - MethodDescriptorProto::MethodDescriptorProto() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -8527,25 +8200,6 @@ bool MethodDescriptorProto::IsInitialized() const { return true; } -void MethodDescriptorProto::Swap(MethodDescriptorProto* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - MethodDescriptorProto* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void MethodDescriptorProto::UnsafeArenaSwap(MethodDescriptorProto* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -8635,30 +8289,6 @@ class FileOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FileOptions::kJavaPackageFieldNumber; -const int FileOptions::kJavaOuterClassnameFieldNumber; -const int FileOptions::kJavaMultipleFilesFieldNumber; -const int FileOptions::kJavaGenerateEqualsAndHashFieldNumber; -const int FileOptions::kJavaStringCheckUtf8FieldNumber; -const int FileOptions::kOptimizeForFieldNumber; -const int FileOptions::kGoPackageFieldNumber; -const int FileOptions::kCcGenericServicesFieldNumber; -const int FileOptions::kJavaGenericServicesFieldNumber; -const int FileOptions::kPyGenericServicesFieldNumber; -const int FileOptions::kPhpGenericServicesFieldNumber; -const int FileOptions::kDeprecatedFieldNumber; -const int FileOptions::kCcEnableArenasFieldNumber; -const int FileOptions::kObjcClassPrefixFieldNumber; -const int FileOptions::kCsharpNamespaceFieldNumber; -const int FileOptions::kSwiftPrefixFieldNumber; -const int FileOptions::kPhpClassPrefixFieldNumber; -const int FileOptions::kPhpNamespaceFieldNumber; -const int FileOptions::kPhpMetadataNamespaceFieldNumber; -const int FileOptions::kRubyPackageFieldNumber; -const int FileOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FileOptions::FileOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -10025,25 +9655,6 @@ bool FileOptions::IsInitialized() const { return true; } -void FileOptions::Swap(FileOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FileOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FileOptions::UnsafeArenaSwap(FileOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FileOptions::InternalSwap(FileOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -10108,14 +9719,6 @@ class MessageOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int MessageOptions::kMessageSetWireFormatFieldNumber; -const int MessageOptions::kNoStandardDescriptorAccessorFieldNumber; -const int MessageOptions::kDeprecatedFieldNumber; -const int MessageOptions::kMapEntryFieldNumber; -const int MessageOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - MessageOptions::MessageOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -10582,25 +10185,6 @@ bool MessageOptions::IsInitialized() const { return true; } -void MessageOptions::Swap(MessageOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - MessageOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void MessageOptions::UnsafeArenaSwap(MessageOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void MessageOptions::InternalSwap(MessageOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -10645,16 +10229,6 @@ class FieldOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FieldOptions::kCtypeFieldNumber; -const int FieldOptions::kPackedFieldNumber; -const int FieldOptions::kJstypeFieldNumber; -const int FieldOptions::kLazyFieldNumber; -const int FieldOptions::kDeprecatedFieldNumber; -const int FieldOptions::kWeakFieldNumber; -const int FieldOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FieldOptions::FieldOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -11228,25 +10802,6 @@ bool FieldOptions::IsInitialized() const { return true; } -void FieldOptions::Swap(FieldOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FieldOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FieldOptions::UnsafeArenaSwap(FieldOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FieldOptions::InternalSwap(FieldOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -11275,10 +10830,6 @@ class OneofOptions::_Internal { using HasBits = decltype(std::declval()._has_bits_); }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int OneofOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - OneofOptions::OneofOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -11569,25 +11120,6 @@ bool OneofOptions::IsInitialized() const { return true; } -void OneofOptions::Swap(OneofOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - OneofOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void OneofOptions::UnsafeArenaSwap(OneofOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void OneofOptions::InternalSwap(OneofOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -11616,12 +11148,6 @@ class EnumOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumOptions::kAllowAliasFieldNumber; -const int EnumOptions::kDeprecatedFieldNumber; -const int EnumOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumOptions::EnumOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -12010,25 +11536,6 @@ bool EnumOptions::IsInitialized() const { return true; } -void EnumOptions::Swap(EnumOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumOptions::UnsafeArenaSwap(EnumOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumOptions::InternalSwap(EnumOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -12056,11 +11563,6 @@ class EnumValueOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumValueOptions::kDeprecatedFieldNumber; -const int EnumValueOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumValueOptions::EnumValueOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -12398,25 +11900,6 @@ bool EnumValueOptions::IsInitialized() const { return true; } -void EnumValueOptions::Swap(EnumValueOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumValueOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumValueOptions::UnsafeArenaSwap(EnumValueOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumValueOptions::InternalSwap(EnumValueOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -12443,11 +11926,6 @@ class ServiceOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int ServiceOptions::kDeprecatedFieldNumber; -const int ServiceOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - ServiceOptions::ServiceOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -12785,25 +12263,6 @@ bool ServiceOptions::IsInitialized() const { return true; } -void ServiceOptions::Swap(ServiceOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - ServiceOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void ServiceOptions::UnsafeArenaSwap(ServiceOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void ServiceOptions::InternalSwap(ServiceOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -12833,12 +12292,6 @@ class MethodOptions::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int MethodOptions::kDeprecatedFieldNumber; -const int MethodOptions::kIdempotencyLevelFieldNumber; -const int MethodOptions::kUninterpretedOptionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - MethodOptions::MethodOptions() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -13243,25 +12696,6 @@ bool MethodOptions::IsInitialized() const { return true; } -void MethodOptions::Swap(MethodOptions* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - MethodOptions* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void MethodOptions::UnsafeArenaSwap(MethodOptions* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void MethodOptions::InternalSwap(MethodOptions* other) { using std::swap; _extensions_.Swap(&other->_extensions_); @@ -13292,11 +12726,6 @@ class UninterpretedOption_NamePart::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int UninterpretedOption_NamePart::kNamePartFieldNumber; -const int UninterpretedOption_NamePart::kIsExtensionFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - UninterpretedOption_NamePart::UninterpretedOption_NamePart() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -13635,25 +13064,6 @@ bool UninterpretedOption_NamePart::IsInitialized() const { return true; } -void UninterpretedOption_NamePart::Swap(UninterpretedOption_NamePart* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - UninterpretedOption_NamePart* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void UninterpretedOption_NamePart::UnsafeArenaSwap(UninterpretedOption_NamePart* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -13695,16 +13105,6 @@ class UninterpretedOption::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int UninterpretedOption::kNameFieldNumber; -const int UninterpretedOption::kIdentifierValueFieldNumber; -const int UninterpretedOption::kPositiveIntValueFieldNumber; -const int UninterpretedOption::kNegativeIntValueFieldNumber; -const int UninterpretedOption::kDoubleValueFieldNumber; -const int UninterpretedOption::kStringValueFieldNumber; -const int UninterpretedOption::kAggregateValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - UninterpretedOption::UninterpretedOption() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -14289,25 +13689,6 @@ bool UninterpretedOption::IsInitialized() const { return true; } -void UninterpretedOption::Swap(UninterpretedOption* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - UninterpretedOption* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void UninterpretedOption::UnsafeArenaSwap(UninterpretedOption* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void UninterpretedOption::InternalSwap(UninterpretedOption* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -14344,14 +13725,6 @@ class SourceCodeInfo_Location::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int SourceCodeInfo_Location::kPathFieldNumber; -const int SourceCodeInfo_Location::kSpanFieldNumber; -const int SourceCodeInfo_Location::kLeadingCommentsFieldNumber; -const int SourceCodeInfo_Location::kTrailingCommentsFieldNumber; -const int SourceCodeInfo_Location::kLeadingDetachedCommentsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - SourceCodeInfo_Location::SourceCodeInfo_Location() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -14894,25 +14267,6 @@ bool SourceCodeInfo_Location::IsInitialized() const { return true; } -void SourceCodeInfo_Location::Swap(SourceCodeInfo_Location* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - SourceCodeInfo_Location* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void SourceCodeInfo_Location::UnsafeArenaSwap(SourceCodeInfo_Location* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -14940,10 +14294,6 @@ class SourceCodeInfo::_Internal { using HasBits = decltype(std::declval()._has_bits_); }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int SourceCodeInfo::kLocationFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - SourceCodeInfo::SourceCodeInfo() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -15204,25 +14554,6 @@ bool SourceCodeInfo::IsInitialized() const { return true; } -void SourceCodeInfo::Swap(SourceCodeInfo* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - SourceCodeInfo* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void SourceCodeInfo::UnsafeArenaSwap(SourceCodeInfo* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -15253,13 +14584,6 @@ class GeneratedCodeInfo_Annotation::_Internal { } }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int GeneratedCodeInfo_Annotation::kPathFieldNumber; -const int GeneratedCodeInfo_Annotation::kSourceFileFieldNumber; -const int GeneratedCodeInfo_Annotation::kBeginFieldNumber; -const int GeneratedCodeInfo_Annotation::kEndFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -15702,25 +15026,6 @@ bool GeneratedCodeInfo_Annotation::IsInitialized() const { return true; } -void GeneratedCodeInfo_Annotation::Swap(GeneratedCodeInfo_Annotation* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - GeneratedCodeInfo_Annotation* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void GeneratedCodeInfo_Annotation::UnsafeArenaSwap(GeneratedCodeInfo_Annotation* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -15746,10 +15051,6 @@ class GeneratedCodeInfo::_Internal { using HasBits = decltype(std::declval()._has_bits_); }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int GeneratedCodeInfo::kAnnotationFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - GeneratedCodeInfo::GeneratedCodeInfo() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -16010,25 +15311,6 @@ bool GeneratedCodeInfo::IsInitialized() const { return true; } -void GeneratedCodeInfo::Swap(GeneratedCodeInfo* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - GeneratedCodeInfo* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void GeneratedCodeInfo::UnsafeArenaSwap(GeneratedCodeInfo* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 66f5c1cee4..f8a7159a4e 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -387,11 +387,22 @@ class PROTOBUF_EXPORT FileDescriptorSet : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(FileDescriptorSet* other); - void Swap(FileDescriptorSet* other); friend void swap(FileDescriptorSet& a, FileDescriptorSet& b) { a.Swap(&b); } + inline void Swap(FileDescriptorSet* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FileDescriptorSet* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -458,10 +469,12 @@ class PROTOBUF_EXPORT FileDescriptorSet : // accessors ------------------------------------------------------- + enum : int { + kFileFieldNumber = 1, + }; // repeated .google.protobuf.FileDescriptorProto file = 1; int file_size() const; void clear_file(); - static const int kFileFieldNumber = 1; PROTOBUF_NAMESPACE_ID::FileDescriptorProto* mutable_file(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FileDescriptorProto >* mutable_file(); @@ -542,11 +555,22 @@ class PROTOBUF_EXPORT FileDescriptorProto : static constexpr int kIndexInFileMessages = 1; - void UnsafeArenaSwap(FileDescriptorProto* other); - void Swap(FileDescriptorProto* other); friend void swap(FileDescriptorProto& a, FileDescriptorProto& b) { a.Swap(&b); } + inline void Swap(FileDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FileDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -613,10 +637,23 @@ class PROTOBUF_EXPORT FileDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kDependencyFieldNumber = 3, + kMessageTypeFieldNumber = 4, + kEnumTypeFieldNumber = 5, + kServiceFieldNumber = 6, + kExtensionFieldNumber = 7, + kPublicDependencyFieldNumber = 10, + kWeakDependencyFieldNumber = 11, + kNameFieldNumber = 1, + kPackageFieldNumber = 2, + kSyntaxFieldNumber = 12, + kOptionsFieldNumber = 8, + kSourceCodeInfoFieldNumber = 9, + }; // repeated string dependency = 3; int dependency_size() const; void clear_dependency(); - static const int kDependencyFieldNumber = 3; const std::string& dependency(int index) const; std::string* mutable_dependency(int index); void set_dependency(int index, const std::string& value); @@ -634,7 +671,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated .google.protobuf.DescriptorProto message_type = 4; int message_type_size() const; void clear_message_type(); - static const int kMessageTypeFieldNumber = 4; PROTOBUF_NAMESPACE_ID::DescriptorProto* mutable_message_type(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::DescriptorProto >* mutable_message_type(); @@ -646,7 +682,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; int enum_type_size() const; void clear_enum_type(); - static const int kEnumTypeFieldNumber = 5; PROTOBUF_NAMESPACE_ID::EnumDescriptorProto* mutable_enum_type(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::EnumDescriptorProto >* mutable_enum_type(); @@ -658,7 +693,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated .google.protobuf.ServiceDescriptorProto service = 6; int service_size() const; void clear_service(); - static const int kServiceFieldNumber = 6; PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto* mutable_service(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto >* mutable_service(); @@ -670,7 +704,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated .google.protobuf.FieldDescriptorProto extension = 7; int extension_size() const; void clear_extension(); - static const int kExtensionFieldNumber = 7; PROTOBUF_NAMESPACE_ID::FieldDescriptorProto* mutable_extension(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FieldDescriptorProto >* mutable_extension(); @@ -682,7 +715,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated int32 public_dependency = 10; int public_dependency_size() const; void clear_public_dependency(); - static const int kPublicDependencyFieldNumber = 10; ::PROTOBUF_NAMESPACE_ID::int32 public_dependency(int index) const; void set_public_dependency(int index, ::PROTOBUF_NAMESPACE_ID::int32 value); void add_public_dependency(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -694,7 +726,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // repeated int32 weak_dependency = 11; int weak_dependency_size() const; void clear_weak_dependency(); - static const int kWeakDependencyFieldNumber = 11; ::PROTOBUF_NAMESPACE_ID::int32 weak_dependency(int index) const; void set_weak_dependency(int index, ::PROTOBUF_NAMESPACE_ID::int32 value); void add_weak_dependency(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -706,7 +737,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -728,7 +758,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // optional string package = 2; bool has_package() const; void clear_package(); - static const int kPackageFieldNumber = 2; const std::string& package() const; void set_package(const std::string& value); void set_package(std::string&& value); @@ -750,7 +779,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // optional string syntax = 12; bool has_syntax() const; void clear_syntax(); - static const int kSyntaxFieldNumber = 12; const std::string& syntax() const; void set_syntax(const std::string& value); void set_syntax(std::string&& value); @@ -772,7 +800,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // optional .google.protobuf.FileOptions options = 8; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 8; const PROTOBUF_NAMESPACE_ID::FileOptions& options() const; PROTOBUF_NAMESPACE_ID::FileOptions* release_options(); PROTOBUF_NAMESPACE_ID::FileOptions* mutable_options(); @@ -784,7 +811,6 @@ class PROTOBUF_EXPORT FileDescriptorProto : // optional .google.protobuf.SourceCodeInfo source_code_info = 9; bool has_source_code_info() const; void clear_source_code_info(); - static const int kSourceCodeInfoFieldNumber = 9; const PROTOBUF_NAMESPACE_ID::SourceCodeInfo& source_code_info() const; PROTOBUF_NAMESPACE_ID::SourceCodeInfo* release_source_code_info(); PROTOBUF_NAMESPACE_ID::SourceCodeInfo* mutable_source_code_info(); @@ -876,11 +902,22 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : static constexpr int kIndexInFileMessages = 2; - void UnsafeArenaSwap(DescriptorProto_ExtensionRange* other); - void Swap(DescriptorProto_ExtensionRange* other); friend void swap(DescriptorProto_ExtensionRange& a, DescriptorProto_ExtensionRange& b) { a.Swap(&b); } + inline void Swap(DescriptorProto_ExtensionRange* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(DescriptorProto_ExtensionRange* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -947,10 +984,14 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : // accessors ------------------------------------------------------- + enum : int { + kOptionsFieldNumber = 3, + kStartFieldNumber = 1, + kEndFieldNumber = 2, + }; // optional .google.protobuf.ExtensionRangeOptions options = 3; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 3; const PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions& options() const; PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions* release_options(); PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions* mutable_options(); @@ -962,14 +1003,12 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange : // optional int32 start = 1; bool has_start() const; void clear_start(); - static const int kStartFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 start() const; void set_start(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 end = 2; bool has_end() const; void clear_end(); - static const int kEndFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 end() const; void set_end(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -1047,11 +1086,22 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange : static constexpr int kIndexInFileMessages = 3; - void UnsafeArenaSwap(DescriptorProto_ReservedRange* other); - void Swap(DescriptorProto_ReservedRange* other); friend void swap(DescriptorProto_ReservedRange& a, DescriptorProto_ReservedRange& b) { a.Swap(&b); } + inline void Swap(DescriptorProto_ReservedRange* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(DescriptorProto_ReservedRange* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1118,17 +1168,19 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange : // accessors ------------------------------------------------------- + enum : int { + kStartFieldNumber = 1, + kEndFieldNumber = 2, + }; // optional int32 start = 1; bool has_start() const; void clear_start(); - static const int kStartFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 start() const; void set_start(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 end = 2; bool has_end() const; void clear_end(); - static const int kEndFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 end() const; void set_end(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -1205,11 +1257,22 @@ class PROTOBUF_EXPORT DescriptorProto : static constexpr int kIndexInFileMessages = 4; - void UnsafeArenaSwap(DescriptorProto* other); - void Swap(DescriptorProto* other); friend void swap(DescriptorProto& a, DescriptorProto& b) { a.Swap(&b); } + inline void Swap(DescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(DescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1279,10 +1342,21 @@ class PROTOBUF_EXPORT DescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kFieldFieldNumber = 2, + kNestedTypeFieldNumber = 3, + kEnumTypeFieldNumber = 4, + kExtensionRangeFieldNumber = 5, + kExtensionFieldNumber = 6, + kOneofDeclFieldNumber = 8, + kReservedRangeFieldNumber = 9, + kReservedNameFieldNumber = 10, + kNameFieldNumber = 1, + kOptionsFieldNumber = 7, + }; // repeated .google.protobuf.FieldDescriptorProto field = 2; int field_size() const; void clear_field(); - static const int kFieldFieldNumber = 2; PROTOBUF_NAMESPACE_ID::FieldDescriptorProto* mutable_field(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FieldDescriptorProto >* mutable_field(); @@ -1294,7 +1368,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.DescriptorProto nested_type = 3; int nested_type_size() const; void clear_nested_type(); - static const int kNestedTypeFieldNumber = 3; PROTOBUF_NAMESPACE_ID::DescriptorProto* mutable_nested_type(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::DescriptorProto >* mutable_nested_type(); @@ -1306,7 +1379,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; int enum_type_size() const; void clear_enum_type(); - static const int kEnumTypeFieldNumber = 4; PROTOBUF_NAMESPACE_ID::EnumDescriptorProto* mutable_enum_type(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::EnumDescriptorProto >* mutable_enum_type(); @@ -1318,7 +1390,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; int extension_range_size() const; void clear_extension_range(); - static const int kExtensionRangeFieldNumber = 5; PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange* mutable_extension_range(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange >* mutable_extension_range(); @@ -1330,7 +1401,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.FieldDescriptorProto extension = 6; int extension_size() const; void clear_extension(); - static const int kExtensionFieldNumber = 6; PROTOBUF_NAMESPACE_ID::FieldDescriptorProto* mutable_extension(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FieldDescriptorProto >* mutable_extension(); @@ -1342,7 +1412,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; int oneof_decl_size() const; void clear_oneof_decl(); - static const int kOneofDeclFieldNumber = 8; PROTOBUF_NAMESPACE_ID::OneofDescriptorProto* mutable_oneof_decl(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::OneofDescriptorProto >* mutable_oneof_decl(); @@ -1354,7 +1423,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; int reserved_range_size() const; void clear_reserved_range(); - static const int kReservedRangeFieldNumber = 9; PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange* mutable_reserved_range(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange >* mutable_reserved_range(); @@ -1366,7 +1434,6 @@ class PROTOBUF_EXPORT DescriptorProto : // repeated string reserved_name = 10; int reserved_name_size() const; void clear_reserved_name(); - static const int kReservedNameFieldNumber = 10; const std::string& reserved_name(int index) const; std::string* mutable_reserved_name(int index); void set_reserved_name(int index, const std::string& value); @@ -1384,7 +1451,6 @@ class PROTOBUF_EXPORT DescriptorProto : // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -1406,7 +1472,6 @@ class PROTOBUF_EXPORT DescriptorProto : // optional .google.protobuf.MessageOptions options = 7; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 7; const PROTOBUF_NAMESPACE_ID::MessageOptions& options() const; PROTOBUF_NAMESPACE_ID::MessageOptions* release_options(); PROTOBUF_NAMESPACE_ID::MessageOptions* mutable_options(); @@ -1496,11 +1561,22 @@ class PROTOBUF_EXPORT ExtensionRangeOptions : static constexpr int kIndexInFileMessages = 5; - void UnsafeArenaSwap(ExtensionRangeOptions* other); - void Swap(ExtensionRangeOptions* other); friend void swap(ExtensionRangeOptions& a, ExtensionRangeOptions& b) { a.Swap(&b); } + inline void Swap(ExtensionRangeOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ExtensionRangeOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1567,10 +1643,12 @@ class PROTOBUF_EXPORT ExtensionRangeOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -1654,11 +1732,22 @@ class PROTOBUF_EXPORT FieldDescriptorProto : static constexpr int kIndexInFileMessages = 6; - void UnsafeArenaSwap(FieldDescriptorProto* other); - void Swap(FieldDescriptorProto* other); friend void swap(FieldDescriptorProto& a, FieldDescriptorProto& b) { a.Swap(&b); } + inline void Swap(FieldDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FieldDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1819,10 +1908,21 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kExtendeeFieldNumber = 2, + kTypeNameFieldNumber = 6, + kDefaultValueFieldNumber = 7, + kJsonNameFieldNumber = 10, + kOptionsFieldNumber = 8, + kNumberFieldNumber = 3, + kOneofIndexFieldNumber = 9, + kLabelFieldNumber = 4, + kTypeFieldNumber = 5, + }; // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -1844,7 +1944,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional string extendee = 2; bool has_extendee() const; void clear_extendee(); - static const int kExtendeeFieldNumber = 2; const std::string& extendee() const; void set_extendee(const std::string& value); void set_extendee(std::string&& value); @@ -1866,7 +1965,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional string type_name = 6; bool has_type_name() const; void clear_type_name(); - static const int kTypeNameFieldNumber = 6; const std::string& type_name() const; void set_type_name(const std::string& value); void set_type_name(std::string&& value); @@ -1888,7 +1986,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional string default_value = 7; bool has_default_value() const; void clear_default_value(); - static const int kDefaultValueFieldNumber = 7; const std::string& default_value() const; void set_default_value(const std::string& value); void set_default_value(std::string&& value); @@ -1910,7 +2007,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional string json_name = 10; bool has_json_name() const; void clear_json_name(); - static const int kJsonNameFieldNumber = 10; const std::string& json_name() const; void set_json_name(const std::string& value); void set_json_name(std::string&& value); @@ -1932,7 +2028,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional .google.protobuf.FieldOptions options = 8; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 8; const PROTOBUF_NAMESPACE_ID::FieldOptions& options() const; PROTOBUF_NAMESPACE_ID::FieldOptions* release_options(); PROTOBUF_NAMESPACE_ID::FieldOptions* mutable_options(); @@ -1944,28 +2039,24 @@ class PROTOBUF_EXPORT FieldDescriptorProto : // optional int32 number = 3; bool has_number() const; void clear_number(); - static const int kNumberFieldNumber = 3; ::PROTOBUF_NAMESPACE_ID::int32 number() const; void set_number(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 oneof_index = 9; bool has_oneof_index() const; void clear_oneof_index(); - static const int kOneofIndexFieldNumber = 9; ::PROTOBUF_NAMESPACE_ID::int32 oneof_index() const; void set_oneof_index(::PROTOBUF_NAMESPACE_ID::int32 value); // optional .google.protobuf.FieldDescriptorProto.Label label = 4; bool has_label() const; void clear_label(); - static const int kLabelFieldNumber = 4; PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label label() const; void set_label(PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value); // optional .google.protobuf.FieldDescriptorProto.Type type = 5; bool has_type() const; void clear_type(); - static const int kTypeFieldNumber = 5; PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type type() const; void set_type(PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value); @@ -2050,11 +2141,22 @@ class PROTOBUF_EXPORT OneofDescriptorProto : static constexpr int kIndexInFileMessages = 7; - void UnsafeArenaSwap(OneofDescriptorProto* other); - void Swap(OneofDescriptorProto* other); friend void swap(OneofDescriptorProto& a, OneofDescriptorProto& b) { a.Swap(&b); } + inline void Swap(OneofDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(OneofDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -2121,10 +2223,13 @@ class PROTOBUF_EXPORT OneofDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kOptionsFieldNumber = 2, + }; // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -2146,7 +2251,6 @@ class PROTOBUF_EXPORT OneofDescriptorProto : // optional .google.protobuf.OneofOptions options = 2; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 2; const PROTOBUF_NAMESPACE_ID::OneofOptions& options() const; PROTOBUF_NAMESPACE_ID::OneofOptions* release_options(); PROTOBUF_NAMESPACE_ID::OneofOptions* mutable_options(); @@ -2228,11 +2332,22 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange : static constexpr int kIndexInFileMessages = 8; - void UnsafeArenaSwap(EnumDescriptorProto_EnumReservedRange* other); - void Swap(EnumDescriptorProto_EnumReservedRange* other); friend void swap(EnumDescriptorProto_EnumReservedRange& a, EnumDescriptorProto_EnumReservedRange& b) { a.Swap(&b); } + inline void Swap(EnumDescriptorProto_EnumReservedRange* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumDescriptorProto_EnumReservedRange* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -2299,17 +2414,19 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange : // accessors ------------------------------------------------------- + enum : int { + kStartFieldNumber = 1, + kEndFieldNumber = 2, + }; // optional int32 start = 1; bool has_start() const; void clear_start(); - static const int kStartFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 start() const; void set_start(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 end = 2; bool has_end() const; void clear_end(); - static const int kEndFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 end() const; void set_end(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -2386,11 +2503,22 @@ class PROTOBUF_EXPORT EnumDescriptorProto : static constexpr int kIndexInFileMessages = 9; - void UnsafeArenaSwap(EnumDescriptorProto* other); - void Swap(EnumDescriptorProto* other); friend void swap(EnumDescriptorProto& a, EnumDescriptorProto& b) { a.Swap(&b); } + inline void Swap(EnumDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -2459,10 +2587,16 @@ class PROTOBUF_EXPORT EnumDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 2, + kReservedRangeFieldNumber = 4, + kReservedNameFieldNumber = 5, + kNameFieldNumber = 1, + kOptionsFieldNumber = 3, + }; // repeated .google.protobuf.EnumValueDescriptorProto value = 2; int value_size() const; void clear_value(); - static const int kValueFieldNumber = 2; PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto* mutable_value(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto >* mutable_value(); @@ -2474,7 +2608,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto : // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; int reserved_range_size() const; void clear_reserved_range(); - static const int kReservedRangeFieldNumber = 4; PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange* mutable_reserved_range(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange >* mutable_reserved_range(); @@ -2486,7 +2619,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto : // repeated string reserved_name = 5; int reserved_name_size() const; void clear_reserved_name(); - static const int kReservedNameFieldNumber = 5; const std::string& reserved_name(int index) const; std::string* mutable_reserved_name(int index); void set_reserved_name(int index, const std::string& value); @@ -2504,7 +2636,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto : // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -2526,7 +2657,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto : // optional .google.protobuf.EnumOptions options = 3; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 3; const PROTOBUF_NAMESPACE_ID::EnumOptions& options() const; PROTOBUF_NAMESPACE_ID::EnumOptions* release_options(); PROTOBUF_NAMESPACE_ID::EnumOptions* mutable_options(); @@ -2611,11 +2741,22 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : static constexpr int kIndexInFileMessages = 10; - void UnsafeArenaSwap(EnumValueDescriptorProto* other); - void Swap(EnumValueDescriptorProto* other); friend void swap(EnumValueDescriptorProto& a, EnumValueDescriptorProto& b) { a.Swap(&b); } + inline void Swap(EnumValueDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumValueDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -2682,10 +2823,14 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kOptionsFieldNumber = 3, + kNumberFieldNumber = 2, + }; // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -2707,7 +2852,6 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : // optional .google.protobuf.EnumValueOptions options = 3; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 3; const PROTOBUF_NAMESPACE_ID::EnumValueOptions& options() const; PROTOBUF_NAMESPACE_ID::EnumValueOptions* release_options(); PROTOBUF_NAMESPACE_ID::EnumValueOptions* mutable_options(); @@ -2719,7 +2863,6 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto : // optional int32 number = 2; bool has_number() const; void clear_number(); - static const int kNumberFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 number() const; void set_number(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -2797,11 +2940,22 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : static constexpr int kIndexInFileMessages = 11; - void UnsafeArenaSwap(ServiceDescriptorProto* other); - void Swap(ServiceDescriptorProto* other); friend void swap(ServiceDescriptorProto& a, ServiceDescriptorProto& b) { a.Swap(&b); } + inline void Swap(ServiceDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ServiceDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -2868,10 +3022,14 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kMethodFieldNumber = 2, + kNameFieldNumber = 1, + kOptionsFieldNumber = 3, + }; // repeated .google.protobuf.MethodDescriptorProto method = 2; int method_size() const; void clear_method(); - static const int kMethodFieldNumber = 2; PROTOBUF_NAMESPACE_ID::MethodDescriptorProto* mutable_method(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::MethodDescriptorProto >* mutable_method(); @@ -2883,7 +3041,6 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -2905,7 +3062,6 @@ class PROTOBUF_EXPORT ServiceDescriptorProto : // optional .google.protobuf.ServiceOptions options = 3; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 3; const PROTOBUF_NAMESPACE_ID::ServiceOptions& options() const; PROTOBUF_NAMESPACE_ID::ServiceOptions* release_options(); PROTOBUF_NAMESPACE_ID::ServiceOptions* mutable_options(); @@ -2988,11 +3144,22 @@ class PROTOBUF_EXPORT MethodDescriptorProto : static constexpr int kIndexInFileMessages = 12; - void UnsafeArenaSwap(MethodDescriptorProto* other); - void Swap(MethodDescriptorProto* other); friend void swap(MethodDescriptorProto& a, MethodDescriptorProto& b) { a.Swap(&b); } + inline void Swap(MethodDescriptorProto* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(MethodDescriptorProto* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -3059,10 +3226,17 @@ class PROTOBUF_EXPORT MethodDescriptorProto : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kInputTypeFieldNumber = 2, + kOutputTypeFieldNumber = 3, + kOptionsFieldNumber = 4, + kClientStreamingFieldNumber = 5, + kServerStreamingFieldNumber = 6, + }; // optional string name = 1; bool has_name() const; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -3084,7 +3258,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto : // optional string input_type = 2; bool has_input_type() const; void clear_input_type(); - static const int kInputTypeFieldNumber = 2; const std::string& input_type() const; void set_input_type(const std::string& value); void set_input_type(std::string&& value); @@ -3106,7 +3279,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto : // optional string output_type = 3; bool has_output_type() const; void clear_output_type(); - static const int kOutputTypeFieldNumber = 3; const std::string& output_type() const; void set_output_type(const std::string& value); void set_output_type(std::string&& value); @@ -3128,7 +3300,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto : // optional .google.protobuf.MethodOptions options = 4; bool has_options() const; void clear_options(); - static const int kOptionsFieldNumber = 4; const PROTOBUF_NAMESPACE_ID::MethodOptions& options() const; PROTOBUF_NAMESPACE_ID::MethodOptions* release_options(); PROTOBUF_NAMESPACE_ID::MethodOptions* mutable_options(); @@ -3140,14 +3311,12 @@ class PROTOBUF_EXPORT MethodDescriptorProto : // optional bool client_streaming = 5 [default = false]; bool has_client_streaming() const; void clear_client_streaming(); - static const int kClientStreamingFieldNumber = 5; bool client_streaming() const; void set_client_streaming(bool value); // optional bool server_streaming = 6 [default = false]; bool has_server_streaming() const; void clear_server_streaming(); - static const int kServerStreamingFieldNumber = 6; bool server_streaming() const; void set_server_streaming(bool value); @@ -3228,11 +3397,22 @@ class PROTOBUF_EXPORT FileOptions : static constexpr int kIndexInFileMessages = 13; - void UnsafeArenaSwap(FileOptions* other); - void Swap(FileOptions* other); friend void swap(FileOptions& a, FileOptions& b) { a.Swap(&b); } + inline void Swap(FileOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FileOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -3331,10 +3511,32 @@ class PROTOBUF_EXPORT FileOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kJavaPackageFieldNumber = 1, + kJavaOuterClassnameFieldNumber = 8, + kGoPackageFieldNumber = 11, + kObjcClassPrefixFieldNumber = 36, + kCsharpNamespaceFieldNumber = 37, + kSwiftPrefixFieldNumber = 39, + kPhpClassPrefixFieldNumber = 40, + kPhpNamespaceFieldNumber = 41, + kPhpMetadataNamespaceFieldNumber = 44, + kRubyPackageFieldNumber = 45, + kJavaMultipleFilesFieldNumber = 10, + kJavaGenerateEqualsAndHashFieldNumber = 20, + kJavaStringCheckUtf8FieldNumber = 27, + kCcGenericServicesFieldNumber = 16, + kJavaGenericServicesFieldNumber = 17, + kPyGenericServicesFieldNumber = 18, + kPhpGenericServicesFieldNumber = 42, + kDeprecatedFieldNumber = 23, + kCcEnableArenasFieldNumber = 31, + kOptimizeForFieldNumber = 9, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -3346,7 +3548,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string java_package = 1; bool has_java_package() const; void clear_java_package(); - static const int kJavaPackageFieldNumber = 1; const std::string& java_package() const; void set_java_package(const std::string& value); void set_java_package(std::string&& value); @@ -3368,7 +3569,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string java_outer_classname = 8; bool has_java_outer_classname() const; void clear_java_outer_classname(); - static const int kJavaOuterClassnameFieldNumber = 8; const std::string& java_outer_classname() const; void set_java_outer_classname(const std::string& value); void set_java_outer_classname(std::string&& value); @@ -3390,7 +3590,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string go_package = 11; bool has_go_package() const; void clear_go_package(); - static const int kGoPackageFieldNumber = 11; const std::string& go_package() const; void set_go_package(const std::string& value); void set_go_package(std::string&& value); @@ -3412,7 +3611,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string objc_class_prefix = 36; bool has_objc_class_prefix() const; void clear_objc_class_prefix(); - static const int kObjcClassPrefixFieldNumber = 36; const std::string& objc_class_prefix() const; void set_objc_class_prefix(const std::string& value); void set_objc_class_prefix(std::string&& value); @@ -3434,7 +3632,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string csharp_namespace = 37; bool has_csharp_namespace() const; void clear_csharp_namespace(); - static const int kCsharpNamespaceFieldNumber = 37; const std::string& csharp_namespace() const; void set_csharp_namespace(const std::string& value); void set_csharp_namespace(std::string&& value); @@ -3456,7 +3653,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string swift_prefix = 39; bool has_swift_prefix() const; void clear_swift_prefix(); - static const int kSwiftPrefixFieldNumber = 39; const std::string& swift_prefix() const; void set_swift_prefix(const std::string& value); void set_swift_prefix(std::string&& value); @@ -3478,7 +3674,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string php_class_prefix = 40; bool has_php_class_prefix() const; void clear_php_class_prefix(); - static const int kPhpClassPrefixFieldNumber = 40; const std::string& php_class_prefix() const; void set_php_class_prefix(const std::string& value); void set_php_class_prefix(std::string&& value); @@ -3500,7 +3695,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string php_namespace = 41; bool has_php_namespace() const; void clear_php_namespace(); - static const int kPhpNamespaceFieldNumber = 41; const std::string& php_namespace() const; void set_php_namespace(const std::string& value); void set_php_namespace(std::string&& value); @@ -3522,7 +3716,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string php_metadata_namespace = 44; bool has_php_metadata_namespace() const; void clear_php_metadata_namespace(); - static const int kPhpMetadataNamespaceFieldNumber = 44; const std::string& php_metadata_namespace() const; void set_php_metadata_namespace(const std::string& value); void set_php_metadata_namespace(std::string&& value); @@ -3544,7 +3737,6 @@ class PROTOBUF_EXPORT FileOptions : // optional string ruby_package = 45; bool has_ruby_package() const; void clear_ruby_package(); - static const int kRubyPackageFieldNumber = 45; const std::string& ruby_package() const; void set_ruby_package(const std::string& value); void set_ruby_package(std::string&& value); @@ -3566,70 +3758,60 @@ class PROTOBUF_EXPORT FileOptions : // optional bool java_multiple_files = 10 [default = false]; bool has_java_multiple_files() const; void clear_java_multiple_files(); - static const int kJavaMultipleFilesFieldNumber = 10; bool java_multiple_files() const; void set_java_multiple_files(bool value); // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; PROTOBUF_DEPRECATED bool has_java_generate_equals_and_hash() const; PROTOBUF_DEPRECATED void clear_java_generate_equals_and_hash(); - PROTOBUF_DEPRECATED static const int kJavaGenerateEqualsAndHashFieldNumber = 20; PROTOBUF_DEPRECATED bool java_generate_equals_and_hash() const; PROTOBUF_DEPRECATED void set_java_generate_equals_and_hash(bool value); // optional bool java_string_check_utf8 = 27 [default = false]; bool has_java_string_check_utf8() const; void clear_java_string_check_utf8(); - static const int kJavaStringCheckUtf8FieldNumber = 27; bool java_string_check_utf8() const; void set_java_string_check_utf8(bool value); // optional bool cc_generic_services = 16 [default = false]; bool has_cc_generic_services() const; void clear_cc_generic_services(); - static const int kCcGenericServicesFieldNumber = 16; bool cc_generic_services() const; void set_cc_generic_services(bool value); // optional bool java_generic_services = 17 [default = false]; bool has_java_generic_services() const; void clear_java_generic_services(); - static const int kJavaGenericServicesFieldNumber = 17; bool java_generic_services() const; void set_java_generic_services(bool value); // optional bool py_generic_services = 18 [default = false]; bool has_py_generic_services() const; void clear_py_generic_services(); - static const int kPyGenericServicesFieldNumber = 18; bool py_generic_services() const; void set_py_generic_services(bool value); // optional bool php_generic_services = 42 [default = false]; bool has_php_generic_services() const; void clear_php_generic_services(); - static const int kPhpGenericServicesFieldNumber = 42; bool php_generic_services() const; void set_php_generic_services(bool value); // optional bool deprecated = 23 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 23; bool deprecated() const; void set_deprecated(bool value); // optional bool cc_enable_arenas = 31 [default = false]; bool has_cc_enable_arenas() const; void clear_cc_enable_arenas(); - static const int kCcEnableArenasFieldNumber = 31; bool cc_enable_arenas() const; void set_cc_enable_arenas(bool value); // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; bool has_optimize_for() const; void clear_optimize_for(); - static const int kOptimizeForFieldNumber = 9; PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode optimize_for() const; void set_optimize_for(PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value); @@ -3728,11 +3910,22 @@ class PROTOBUF_EXPORT MessageOptions : static constexpr int kIndexInFileMessages = 14; - void UnsafeArenaSwap(MessageOptions* other); - void Swap(MessageOptions* other); friend void swap(MessageOptions& a, MessageOptions& b) { a.Swap(&b); } + inline void Swap(MessageOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(MessageOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -3799,10 +3992,16 @@ class PROTOBUF_EXPORT MessageOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kMessageSetWireFormatFieldNumber = 1, + kNoStandardDescriptorAccessorFieldNumber = 2, + kDeprecatedFieldNumber = 3, + kMapEntryFieldNumber = 7, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -3814,28 +4013,24 @@ class PROTOBUF_EXPORT MessageOptions : // optional bool message_set_wire_format = 1 [default = false]; bool has_message_set_wire_format() const; void clear_message_set_wire_format(); - static const int kMessageSetWireFormatFieldNumber = 1; bool message_set_wire_format() const; void set_message_set_wire_format(bool value); // optional bool no_standard_descriptor_accessor = 2 [default = false]; bool has_no_standard_descriptor_accessor() const; void clear_no_standard_descriptor_accessor(); - static const int kNoStandardDescriptorAccessorFieldNumber = 2; bool no_standard_descriptor_accessor() const; void set_no_standard_descriptor_accessor(bool value); // optional bool deprecated = 3 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; bool deprecated() const; void set_deprecated(bool value); // optional bool map_entry = 7; bool has_map_entry() const; void clear_map_entry(); - static const int kMapEntryFieldNumber = 7; bool map_entry() const; void set_map_entry(bool value); @@ -3918,11 +4113,22 @@ class PROTOBUF_EXPORT FieldOptions : static constexpr int kIndexInFileMessages = 15; - void UnsafeArenaSwap(FieldOptions* other); - void Swap(FieldOptions* other); friend void swap(FieldOptions& a, FieldOptions& b) { a.Swap(&b); } + inline void Swap(FieldOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FieldOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4053,10 +4259,18 @@ class PROTOBUF_EXPORT FieldOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kCtypeFieldNumber = 1, + kPackedFieldNumber = 2, + kLazyFieldNumber = 5, + kDeprecatedFieldNumber = 3, + kWeakFieldNumber = 10, + kJstypeFieldNumber = 6, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4068,42 +4282,36 @@ class PROTOBUF_EXPORT FieldOptions : // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; bool has_ctype() const; void clear_ctype(); - static const int kCtypeFieldNumber = 1; PROTOBUF_NAMESPACE_ID::FieldOptions_CType ctype() const; void set_ctype(PROTOBUF_NAMESPACE_ID::FieldOptions_CType value); // optional bool packed = 2; bool has_packed() const; void clear_packed(); - static const int kPackedFieldNumber = 2; bool packed() const; void set_packed(bool value); // optional bool lazy = 5 [default = false]; bool has_lazy() const; void clear_lazy(); - static const int kLazyFieldNumber = 5; bool lazy() const; void set_lazy(bool value); // optional bool deprecated = 3 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; bool deprecated() const; void set_deprecated(bool value); // optional bool weak = 10 [default = false]; bool has_weak() const; void clear_weak(); - static const int kWeakFieldNumber = 10; bool weak() const; void set_weak(bool value); // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; bool has_jstype() const; void clear_jstype(); - static const int kJstypeFieldNumber = 6; PROTOBUF_NAMESPACE_ID::FieldOptions_JSType jstype() const; void set_jstype(PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value); @@ -4188,11 +4396,22 @@ class PROTOBUF_EXPORT OneofOptions : static constexpr int kIndexInFileMessages = 16; - void UnsafeArenaSwap(OneofOptions* other); - void Swap(OneofOptions* other); friend void swap(OneofOptions& a, OneofOptions& b) { a.Swap(&b); } + inline void Swap(OneofOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(OneofOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4259,10 +4478,12 @@ class PROTOBUF_EXPORT OneofOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4346,11 +4567,22 @@ class PROTOBUF_EXPORT EnumOptions : static constexpr int kIndexInFileMessages = 17; - void UnsafeArenaSwap(EnumOptions* other); - void Swap(EnumOptions* other); friend void swap(EnumOptions& a, EnumOptions& b) { a.Swap(&b); } + inline void Swap(EnumOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4417,10 +4649,14 @@ class PROTOBUF_EXPORT EnumOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kAllowAliasFieldNumber = 2, + kDeprecatedFieldNumber = 3, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4432,14 +4668,12 @@ class PROTOBUF_EXPORT EnumOptions : // optional bool allow_alias = 2; bool has_allow_alias() const; void clear_allow_alias(); - static const int kAllowAliasFieldNumber = 2; bool allow_alias() const; void set_allow_alias(bool value); // optional bool deprecated = 3 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; bool deprecated() const; void set_deprecated(bool value); @@ -4520,11 +4754,22 @@ class PROTOBUF_EXPORT EnumValueOptions : static constexpr int kIndexInFileMessages = 18; - void UnsafeArenaSwap(EnumValueOptions* other); - void Swap(EnumValueOptions* other); friend void swap(EnumValueOptions& a, EnumValueOptions& b) { a.Swap(&b); } + inline void Swap(EnumValueOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumValueOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4591,10 +4836,13 @@ class PROTOBUF_EXPORT EnumValueOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kDeprecatedFieldNumber = 1, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4606,7 +4854,6 @@ class PROTOBUF_EXPORT EnumValueOptions : // optional bool deprecated = 1 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 1; bool deprecated() const; void set_deprecated(bool value); @@ -4686,11 +4933,22 @@ class PROTOBUF_EXPORT ServiceOptions : static constexpr int kIndexInFileMessages = 19; - void UnsafeArenaSwap(ServiceOptions* other); - void Swap(ServiceOptions* other); friend void swap(ServiceOptions& a, ServiceOptions& b) { a.Swap(&b); } + inline void Swap(ServiceOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ServiceOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4757,10 +5015,13 @@ class PROTOBUF_EXPORT ServiceOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kDeprecatedFieldNumber = 33, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4772,7 +5033,6 @@ class PROTOBUF_EXPORT ServiceOptions : // optional bool deprecated = 33 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 33; bool deprecated() const; void set_deprecated(bool value); @@ -4852,11 +5112,22 @@ class PROTOBUF_EXPORT MethodOptions : static constexpr int kIndexInFileMessages = 20; - void UnsafeArenaSwap(MethodOptions* other); - void Swap(MethodOptions* other); friend void swap(MethodOptions& a, MethodOptions& b) { a.Swap(&b); } + inline void Swap(MethodOptions* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(MethodOptions* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -4955,10 +5226,14 @@ class PROTOBUF_EXPORT MethodOptions : // accessors ------------------------------------------------------- + enum : int { + kUninterpretedOptionFieldNumber = 999, + kDeprecatedFieldNumber = 33, + kIdempotencyLevelFieldNumber = 34, + }; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; int uninterpreted_option_size() const; void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; PROTOBUF_NAMESPACE_ID::UninterpretedOption* mutable_uninterpreted_option(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption >* mutable_uninterpreted_option(); @@ -4970,14 +5245,12 @@ class PROTOBUF_EXPORT MethodOptions : // optional bool deprecated = 33 [default = false]; bool has_deprecated() const; void clear_deprecated(); - static const int kDeprecatedFieldNumber = 33; bool deprecated() const; void set_deprecated(bool value); // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; bool has_idempotency_level() const; void clear_idempotency_level(); - static const int kIdempotencyLevelFieldNumber = 34; PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel idempotency_level() const; void set_idempotency_level(PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value); @@ -5058,11 +5331,22 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart : static constexpr int kIndexInFileMessages = 21; - void UnsafeArenaSwap(UninterpretedOption_NamePart* other); - void Swap(UninterpretedOption_NamePart* other); friend void swap(UninterpretedOption_NamePart& a, UninterpretedOption_NamePart& b) { a.Swap(&b); } + inline void Swap(UninterpretedOption_NamePart* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(UninterpretedOption_NamePart* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -5129,10 +5413,13 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart : // accessors ------------------------------------------------------- + enum : int { + kNamePartFieldNumber = 1, + kIsExtensionFieldNumber = 2, + }; // required string name_part = 1; bool has_name_part() const; void clear_name_part(); - static const int kNamePartFieldNumber = 1; const std::string& name_part() const; void set_name_part(const std::string& value); void set_name_part(std::string&& value); @@ -5154,7 +5441,6 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart : // required bool is_extension = 2; bool has_is_extension() const; void clear_is_extension(); - static const int kIsExtensionFieldNumber = 2; bool is_extension() const; void set_is_extension(bool value); @@ -5234,11 +5520,22 @@ class PROTOBUF_EXPORT UninterpretedOption : static constexpr int kIndexInFileMessages = 22; - void UnsafeArenaSwap(UninterpretedOption* other); - void Swap(UninterpretedOption* other); friend void swap(UninterpretedOption& a, UninterpretedOption& b) { a.Swap(&b); } + inline void Swap(UninterpretedOption* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(UninterpretedOption* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -5307,10 +5604,18 @@ class PROTOBUF_EXPORT UninterpretedOption : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 2, + kIdentifierValueFieldNumber = 3, + kStringValueFieldNumber = 7, + kAggregateValueFieldNumber = 8, + kPositiveIntValueFieldNumber = 4, + kNegativeIntValueFieldNumber = 5, + kDoubleValueFieldNumber = 6, + }; // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; int name_size() const; void clear_name(); - static const int kNameFieldNumber = 2; PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart* mutable_name(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart >* mutable_name(); @@ -5322,7 +5627,6 @@ class PROTOBUF_EXPORT UninterpretedOption : // optional string identifier_value = 3; bool has_identifier_value() const; void clear_identifier_value(); - static const int kIdentifierValueFieldNumber = 3; const std::string& identifier_value() const; void set_identifier_value(const std::string& value); void set_identifier_value(std::string&& value); @@ -5344,7 +5648,6 @@ class PROTOBUF_EXPORT UninterpretedOption : // optional bytes string_value = 7; bool has_string_value() const; void clear_string_value(); - static const int kStringValueFieldNumber = 7; const std::string& string_value() const; void set_string_value(const std::string& value); void set_string_value(std::string&& value); @@ -5366,7 +5669,6 @@ class PROTOBUF_EXPORT UninterpretedOption : // optional string aggregate_value = 8; bool has_aggregate_value() const; void clear_aggregate_value(); - static const int kAggregateValueFieldNumber = 8; const std::string& aggregate_value() const; void set_aggregate_value(const std::string& value); void set_aggregate_value(std::string&& value); @@ -5388,21 +5690,18 @@ class PROTOBUF_EXPORT UninterpretedOption : // optional uint64 positive_int_value = 4; bool has_positive_int_value() const; void clear_positive_int_value(); - static const int kPositiveIntValueFieldNumber = 4; ::PROTOBUF_NAMESPACE_ID::uint64 positive_int_value() const; void set_positive_int_value(::PROTOBUF_NAMESPACE_ID::uint64 value); // optional int64 negative_int_value = 5; bool has_negative_int_value() const; void clear_negative_int_value(); - static const int kNegativeIntValueFieldNumber = 5; ::PROTOBUF_NAMESPACE_ID::int64 negative_int_value() const; void set_negative_int_value(::PROTOBUF_NAMESPACE_ID::int64 value); // optional double double_value = 6; bool has_double_value() const; void clear_double_value(); - static const int kDoubleValueFieldNumber = 6; double double_value() const; void set_double_value(double value); @@ -5484,11 +5783,22 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : static constexpr int kIndexInFileMessages = 23; - void UnsafeArenaSwap(SourceCodeInfo_Location* other); - void Swap(SourceCodeInfo_Location* other); friend void swap(SourceCodeInfo_Location& a, SourceCodeInfo_Location& b) { a.Swap(&b); } + inline void Swap(SourceCodeInfo_Location* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(SourceCodeInfo_Location* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -5555,10 +5865,16 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : // accessors ------------------------------------------------------- + enum : int { + kPathFieldNumber = 1, + kSpanFieldNumber = 2, + kLeadingDetachedCommentsFieldNumber = 6, + kLeadingCommentsFieldNumber = 3, + kTrailingCommentsFieldNumber = 4, + }; // repeated int32 path = 1 [packed = true]; int path_size() const; void clear_path(); - static const int kPathFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 path(int index) const; void set_path(int index, ::PROTOBUF_NAMESPACE_ID::int32 value); void add_path(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -5570,7 +5886,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : // repeated int32 span = 2 [packed = true]; int span_size() const; void clear_span(); - static const int kSpanFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 span(int index) const; void set_span(int index, ::PROTOBUF_NAMESPACE_ID::int32 value); void add_span(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -5582,7 +5897,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : // repeated string leading_detached_comments = 6; int leading_detached_comments_size() const; void clear_leading_detached_comments(); - static const int kLeadingDetachedCommentsFieldNumber = 6; const std::string& leading_detached_comments(int index) const; std::string* mutable_leading_detached_comments(int index); void set_leading_detached_comments(int index, const std::string& value); @@ -5600,7 +5914,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : // optional string leading_comments = 3; bool has_leading_comments() const; void clear_leading_comments(); - static const int kLeadingCommentsFieldNumber = 3; const std::string& leading_comments() const; void set_leading_comments(const std::string& value); void set_leading_comments(std::string&& value); @@ -5622,7 +5935,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location : // optional string trailing_comments = 4; bool has_trailing_comments() const; void clear_trailing_comments(); - static const int kTrailingCommentsFieldNumber = 4; const std::string& trailing_comments() const; void set_trailing_comments(const std::string& value); void set_trailing_comments(std::string&& value); @@ -5719,11 +6031,22 @@ class PROTOBUF_EXPORT SourceCodeInfo : static constexpr int kIndexInFileMessages = 24; - void UnsafeArenaSwap(SourceCodeInfo* other); - void Swap(SourceCodeInfo* other); friend void swap(SourceCodeInfo& a, SourceCodeInfo& b) { a.Swap(&b); } + inline void Swap(SourceCodeInfo* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(SourceCodeInfo* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -5792,10 +6115,12 @@ class PROTOBUF_EXPORT SourceCodeInfo : // accessors ------------------------------------------------------- + enum : int { + kLocationFieldNumber = 1, + }; // repeated .google.protobuf.SourceCodeInfo.Location location = 1; int location_size() const; void clear_location(); - static const int kLocationFieldNumber = 1; PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location* mutable_location(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location >* mutable_location(); @@ -5876,11 +6201,22 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : static constexpr int kIndexInFileMessages = 25; - void UnsafeArenaSwap(GeneratedCodeInfo_Annotation* other); - void Swap(GeneratedCodeInfo_Annotation* other); friend void swap(GeneratedCodeInfo_Annotation& a, GeneratedCodeInfo_Annotation& b) { a.Swap(&b); } + inline void Swap(GeneratedCodeInfo_Annotation* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(GeneratedCodeInfo_Annotation* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -5947,10 +6283,15 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : // accessors ------------------------------------------------------- + enum : int { + kPathFieldNumber = 1, + kSourceFileFieldNumber = 2, + kBeginFieldNumber = 3, + kEndFieldNumber = 4, + }; // repeated int32 path = 1 [packed = true]; int path_size() const; void clear_path(); - static const int kPathFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 path(int index) const; void set_path(int index, ::PROTOBUF_NAMESPACE_ID::int32 value); void add_path(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -5962,7 +6303,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : // optional string source_file = 2; bool has_source_file() const; void clear_source_file(); - static const int kSourceFileFieldNumber = 2; const std::string& source_file() const; void set_source_file(const std::string& value); void set_source_file(std::string&& value); @@ -5984,14 +6324,12 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation : // optional int32 begin = 3; bool has_begin() const; void clear_begin(); - static const int kBeginFieldNumber = 3; ::PROTOBUF_NAMESPACE_ID::int32 begin() const; void set_begin(::PROTOBUF_NAMESPACE_ID::int32 value); // optional int32 end = 4; bool has_end() const; void clear_end(); - static const int kEndFieldNumber = 4; ::PROTOBUF_NAMESPACE_ID::int32 end() const; void set_end(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -6071,11 +6409,22 @@ class PROTOBUF_EXPORT GeneratedCodeInfo : static constexpr int kIndexInFileMessages = 26; - void UnsafeArenaSwap(GeneratedCodeInfo* other); - void Swap(GeneratedCodeInfo* other); friend void swap(GeneratedCodeInfo& a, GeneratedCodeInfo& b) { a.Swap(&b); } + inline void Swap(GeneratedCodeInfo* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(GeneratedCodeInfo* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -6144,10 +6493,12 @@ class PROTOBUF_EXPORT GeneratedCodeInfo : // accessors ------------------------------------------------------- + enum : int { + kAnnotationFieldNumber = 1, + }; // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; int annotation_size() const; void clear_annotation(); - static const int kAnnotationFieldNumber = 1; PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation* mutable_annotation(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation >* mutable_annotation(); diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 864a4407e8..6aea3636cc 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -90,11 +90,6 @@ class Duration::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Duration::kSecondsFieldNumber; -const int Duration::kNanosFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Duration::Duration() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -386,25 +381,6 @@ bool Duration::IsInitialized() const { return true; } -void Duration::Swap(Duration* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Duration* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Duration::UnsafeArenaSwap(Duration* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Duration::InternalSwap(Duration* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index beed27900a..0a43178af4 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -116,11 +116,22 @@ class PROTOBUF_EXPORT Duration : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(Duration* other); - void Swap(Duration* other); friend void swap(Duration& a, Duration& b) { a.Swap(&b); } + inline void Swap(Duration* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Duration* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -187,15 +198,17 @@ class PROTOBUF_EXPORT Duration : // accessors ------------------------------------------------------- + enum : int { + kSecondsFieldNumber = 1, + kNanosFieldNumber = 2, + }; // int64 seconds = 1; void clear_seconds(); - static const int kSecondsFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int64 seconds() const; void set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value); // int32 nanos = 2; void clear_nanos(); - static const int kNanosFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 nanos() const; void set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value); diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 835fd5fc12..412d6f792f 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -87,9 +87,6 @@ class Empty::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Empty::Empty() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -286,25 +283,6 @@ bool Empty::IsInitialized() const { return true; } -void Empty::Swap(Empty* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Empty* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Empty::UnsafeArenaSwap(Empty* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Empty::InternalSwap(Empty* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 3556bd9cc3..0f4b9f8278 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -116,11 +116,22 @@ class PROTOBUF_EXPORT Empty : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(Empty* other); - void Swap(Empty* other); friend void swap(Empty& a, Empty& b) { a.Swap(&b); } + inline void Swap(Empty* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Empty* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h index 4e6995ef1e..9e15a17c4a 100644 --- a/src/google/protobuf/extension_set_inl.h +++ b/src/google/protobuf/extension_set_inl.h @@ -71,8 +71,7 @@ const char* ExtensionSet::ParseFieldWithExtensionInfo( MutableRawRepeatedField(number, extension.type, extension.is_packed, extension.descriptor), ptr, ctx, extension.enum_validity_check.func, - extension.enum_validity_check.arg, - metadata->mutable_unknown_fields(), number); + extension.enum_validity_check.arg, metadata, number); case WireFormatLite::TYPE_STRING: case WireFormatLite::TYPE_BYTES: case WireFormatLite::TYPE_GROUP: diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 4f75e4a6a7..ca88d38ef7 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -89,10 +89,6 @@ class FieldMask::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FieldMask::kPathsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FieldMask::FieldMask() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -356,25 +352,6 @@ bool FieldMask::IsInitialized() const { return true; } -void FieldMask::Swap(FieldMask* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FieldMask* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FieldMask::UnsafeArenaSwap(FieldMask* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FieldMask::InternalSwap(FieldMask* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 22a23db1e9..ab7152959a 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -116,11 +116,22 @@ class PROTOBUF_EXPORT FieldMask : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(FieldMask* other); - void Swap(FieldMask* other); friend void swap(FieldMask& a, FieldMask& b) { a.Swap(&b); } + inline void Swap(FieldMask* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FieldMask* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -187,10 +198,12 @@ class PROTOBUF_EXPORT FieldMask : // accessors ------------------------------------------------------- + enum : int { + kPathsFieldNumber = 1, + }; // repeated string paths = 1; int paths_size() const; void clear_paths(); - static const int kPathsFieldNumber = 1; const std::string& paths(int index) const; std::string* mutable_paths(int index); void set_paths(int index, const std::string& value); diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 363eca42bc..36d7307a50 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -747,6 +747,15 @@ MessageLite* DuplicateIfNonNullInternal(MessageLite* message) { } } +void GenericSwap(MessageLite* m1, MessageLite* m2) { + std::unique_ptr tmp(m1->New()); + tmp->CheckTypeAndMergeFrom(*m1); + m1->Clear(); + m1->CheckTypeAndMergeFrom(*m2); + m2->Clear(); + m2->CheckTypeAndMergeFrom(*tmp); +} + // Returns a message owned by this Arena. This may require Own()ing or // duplicating the message. MessageLite* GetOwnedMessageInternal(Arena* message_arena, diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index bf0e5b9b0f..4e8ad9142f 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -145,6 +145,7 @@ PROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message); PROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena, MessageLite* submessage, Arena* submessage_arena); +PROTOBUF_EXPORT void GenericSwap(MessageLite* m1, MessageLite* m2); template T* DuplicateIfNonNull(T* message) { diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 56259bb5cf..804c2ce018 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -158,6 +158,11 @@ class ReflectionAccessor { return reflection->MutableRawRepeatedField( msg, field, FieldDescriptor::CPPTYPE_ENUM, 0, nullptr); } + + static InternalMetadataWithArena* MutableInternalMetadataWithArena( + const Reflection* reflection, Message* msg) { + return reflection->MutableInternalMetadataWithArena(msg); + } }; } // namespace internal @@ -263,7 +268,9 @@ const char* ParsePackedField(const FieldDescriptor* field, Message* msg, } else { return internal::PackedEnumParserArg( object, ptr, ctx, ReflectiveValidator, field->enum_type(), - reflection->MutableUnknownFields(msg), field->number()); + internal::ReflectionAccessor::MutableInternalMetadataWithArena( + reflection, msg), + field->number()); } } HANDLE_PACKED_TYPE(FIXED32, uint32, Fixed32); diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index b6e966d341..da44a363a5 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -982,7 +982,7 @@ class PROTOBUF_EXPORT Reflection final { inline const internal::InternalMetadataWithArena& GetInternalMetadataWithArena(const Message& message) const; - inline internal::InternalMetadataWithArena* MutableInternalMetadataWithArena( + internal::InternalMetadataWithArena* MutableInternalMetadataWithArena( Message* message) const; inline bool IsInlined(const FieldDescriptor* field) const; diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 9efa521e19..d514079e9f 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -421,14 +421,15 @@ const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx) { } const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx, - bool (*is_valid)(int), std::string* unknown, + bool (*is_valid)(int), + InternalMetadataWithArenaLite* metadata, int field_num) { return ctx->ReadPackedVarint( - ptr, [object, is_valid, unknown, field_num](uint64 val) { + ptr, [object, is_valid, metadata, field_num](uint64 val) { if (is_valid(val)) { static_cast*>(object)->Add(val); } else { - WriteVarint(field_num, val, unknown); + WriteVarint(field_num, val, metadata->mutable_unknown_fields()); } }); } @@ -436,14 +437,15 @@ const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx, const char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(const void*, int), - const void* data, std::string* unknown, + const void* data, + InternalMetadataWithArenaLite* metadata, int field_num) { return ctx->ReadPackedVarint( - ptr, [object, is_valid, data, unknown, field_num](uint64 val) { + ptr, [object, is_valid, data, metadata, field_num](uint64 val) { if (is_valid(data, val)) { static_cast*>(object)->Add(val); } else { - WriteVarint(field_num, val, unknown); + WriteVarint(field_num, val, metadata->mutable_unknown_fields()); } }); } diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 04db357227..72355f81cf 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -718,11 +718,11 @@ PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser( void* object, const char* ptr, ParseContext* ctx); PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser( void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(int), - std::string* unknown, int field_num); + InternalMetadataWithArenaLite* metadata, int field_num); PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParserArg( void* object, const char* ptr, ParseContext* ctx, - bool (*is_valid)(const void*, int), const void* data, std::string* unknown, - int field_num); + bool (*is_valid)(const void*, int), const void* data, + InternalMetadataWithArenaLite* metadata, int field_num); PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedBoolParser( void* object, const char* ptr, ParseContext* ctx); diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index e4a7b62a4c..47c9987041 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -118,6 +118,10 @@ inline int CalculateReserve(Iter begin, Iter end) { // set-by-index, and add accessors that are generated for all repeated fields. template class RepeatedField final { + static_assert( + alignof(Arena) >= alignof(Element), + "We only support types that have an alignment smaller than Arena"); + public: RepeatedField(); explicit RepeatedField(Arena* arena); @@ -289,23 +293,30 @@ class RepeatedField final { // Element is double and pointer is 32bit). static const size_t kRepHeaderSize; - // We reuse the Rep* for an Arena* when total_size == 0, to avoid having to do - // an allocation in the constructor when we have an Arena. - union Pointer { - Pointer(Arena* a) : arena(a) {} - Arena* arena; // When total_size_ == 0. - Element* elements; // When total_size_ != 0, this is Rep->elements of Rep. - } ptr_; + // If total_size_ == 0 this points to an Arena otherwise it points to the + // elements member of a Rep struct. Using this invariant allows the storage of + // the arena pointer without an extra allocation in the constructor. + void* arena_or_elements_; + // Return pointer to elements array. + // pre-condition: the array must have been allocated. Element* elements() const { GOOGLE_DCHECK_GT(total_size_, 0); - return ptr_.elements; + // Because of above pre-condition this cast is safe. + return unsafe_elements(); + } + + // Return pointer to elements array if it exists otherwise either null or + // a invalid pointer is returned. This only happens for empty repeated fields, + // where you can't dereference this pointer anyway (it's empty). + Element* unsafe_elements() const { + return static_cast(arena_or_elements_); } + // Return pointer to the Rep struct. + // pre-condition: the Rep must have been allocated, ie elements() is safe. Rep* rep() const { - GOOGLE_DCHECK_GT(total_size_, 0); - char* addr = - reinterpret_cast(ptr_.elements) - offsetof(Rep, elements); + char* addr = reinterpret_cast(elements()) - offsetof(Rep, elements); return reinterpret_cast(addr); } @@ -323,7 +334,8 @@ class RepeatedField final { // Internal helper expected by Arena methods. inline Arena* GetArenaNoVirtual() const { - return (total_size_ == 0) ? ptr_.arena : rep()->arena; + return (total_size_ == 0) ? static_cast(arena_or_elements_) + : rep()->arena; } // Internal helper to delete all elements and deallocate the storage. @@ -346,9 +358,6 @@ class RepeatedField final { } } } - - friend class internal::WireFormatLite; - const Element* unsafe_data() const; }; template @@ -1057,15 +1066,15 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { template inline RepeatedField::RepeatedField() - : current_size_(0), total_size_(0), ptr_(NULL) {} + : current_size_(0), total_size_(0), arena_or_elements_(nullptr) {} template inline RepeatedField::RepeatedField(Arena* arena) - : current_size_(0), total_size_(0), ptr_(arena) {} + : current_size_(0), total_size_(0), arena_or_elements_(arena) {} template inline RepeatedField::RepeatedField(const RepeatedField& other) - : current_size_(0), total_size_(0), ptr_(NULL) { + : current_size_(0), total_size_(0), arena_or_elements_(nullptr) { if (other.current_size_ != 0) { Reserve(other.size()); AddNAlreadyReserved(other.size()); @@ -1076,7 +1085,7 @@ inline RepeatedField::RepeatedField(const RepeatedField& other) template template RepeatedField::RepeatedField(Iter begin, const Iter& end) - : current_size_(0), total_size_(0), ptr_(NULL) { + : current_size_(0), total_size_(0), arena_or_elements_(nullptr) { Add(begin, end); } @@ -1153,13 +1162,11 @@ template inline Element* RepeatedField::AddNAlreadyReserved(int n) { GOOGLE_DCHECK_GE(total_size_ - current_size_, n) << total_size_ << ", " << current_size_; - // Warning: sometimes people call this when n==0 and total_size_==0. This - // forces us to add this branch, to avoid reading the non-active union member - // (which is UB). Luckily the compiler is smart enough to optimize the branch - // away. - Element* ret = - total_size_ == 0 ? reinterpret_cast(ptr_.arena) : ptr_.elements; - ret += current_size_; + // Warning: sometimes people call this when n == 0 and total_size_ == 0. In + // this case the return pointer points to a zero size array (n == 0). Hence + // we can just use unsafe_elements(), because the user cannot dereference the + // pointer anyway. + Element* ret = unsafe_elements() + current_size_; current_size_ += n; return ret; } @@ -1313,17 +1320,12 @@ inline typename RepeatedField::iterator RepeatedField::erase( template inline Element* RepeatedField::mutable_data() { - return total_size_ > 0 ? elements() : NULL; + return unsafe_elements(); } template inline const Element* RepeatedField::data() const { - return total_size_ > 0 ? elements() : NULL; -} - -template -inline const Element* RepeatedField::unsafe_data() const { - return elements(); + return unsafe_elements(); } template @@ -1331,7 +1333,7 @@ inline void RepeatedField::InternalSwap(RepeatedField* other) { GOOGLE_DCHECK(this != other); GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - std::swap(ptr_, other->ptr_); + std::swap(arena_or_elements_, other->arena_or_elements_); std::swap(current_size_, other->current_size_); std::swap(total_size_, other->total_size_); } @@ -1364,31 +1366,31 @@ void RepeatedField::SwapElements(int index1, int index2) { template inline typename RepeatedField::iterator RepeatedField::begin() { - return total_size_ > 0 ? elements() : NULL; + return unsafe_elements(); } template inline typename RepeatedField::const_iterator RepeatedField::begin() const { - return total_size_ > 0 ? elements() : NULL; + return unsafe_elements(); } template inline typename RepeatedField::const_iterator RepeatedField::cbegin() const { - return total_size_ > 0 ? elements() : NULL; + return unsafe_elements(); } template inline typename RepeatedField::iterator RepeatedField::end() { - return total_size_ > 0 ? elements() + current_size_ : NULL; + return unsafe_elements() + current_size_; } template inline typename RepeatedField::const_iterator RepeatedField::end() const { - return total_size_ > 0 ? elements() + current_size_ : NULL; + return unsafe_elements() + current_size_; } template inline typename RepeatedField::const_iterator RepeatedField::cend() const { - return total_size_ > 0 ? elements() + current_size_ : NULL; + return unsafe_elements() + current_size_; } template @@ -1420,7 +1422,7 @@ void RepeatedField::Reserve(int new_size) { new_rep->arena = arena; int old_total_size = total_size_; total_size_ = new_size; - ptr_.elements = new_rep->elements; + arena_or_elements_ = new_rep->elements; // Invoke placement-new on newly allocated elements. We shouldn't have to do // this, since Element is supposed to be POD, but a previous version of this // code allocated storage with "new Element[size]" and some code uses diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index e7e66aa1e7..5263fc6152 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -90,10 +90,6 @@ class SourceContext::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int SourceContext::kFileNameFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - SourceContext::SourceContext() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -343,10 +339,6 @@ bool SourceContext::IsInitialized() const { return true; } -void SourceContext::Swap(SourceContext* other) { - if (other == this) return; - InternalSwap(other); -} void SourceContext::InternalSwap(SourceContext* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index d46bbc5fd8..0383fb52e4 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -110,10 +110,13 @@ class PROTOBUF_EXPORT SourceContext : static constexpr int kIndexInFileMessages = 0; - void Swap(SourceContext* other); friend void swap(SourceContext& a, SourceContext& b) { a.Swap(&b); } + inline void Swap(SourceContext* other) { + if (other == this) return; + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -175,9 +178,11 @@ class PROTOBUF_EXPORT SourceContext : // accessors ------------------------------------------------------- + enum : int { + kFileNameFieldNumber = 1, + }; // string file_name = 1; void clear_file_name(); - static const int kFileNameFieldNumber = 1; const std::string& file_name() const; void set_file_name(const std::string& value); void set_file_name(std::string&& value); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index a3de868d53..124fdfa018 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -199,10 +199,6 @@ class Struct::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Struct::kFieldsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Struct::Struct() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -535,25 +531,6 @@ bool Struct::IsInitialized() const { return true; } -void Struct::Swap(Struct* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Struct* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Struct::UnsafeArenaSwap(Struct* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Struct::InternalSwap(Struct* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -622,15 +599,6 @@ void Value::set_allocated_list_value(PROTOBUF_NAMESPACE_ID::ListValue* list_valu } // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Value::kNullValueFieldNumber; -const int Value::kNumberValueFieldNumber; -const int Value::kStringValueFieldNumber; -const int Value::kBoolValueFieldNumber; -const int Value::kStructValueFieldNumber; -const int Value::kListValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Value::Value() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1181,25 +1149,6 @@ bool Value::IsInitialized() const { return true; } -void Value::Swap(Value* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Value* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Value::UnsafeArenaSwap(Value* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Value::InternalSwap(Value* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1220,10 +1169,6 @@ class ListValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int ListValue::kValuesFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - ListValue::ListValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1482,25 +1427,6 @@ bool ListValue::IsInitialized() const { return true; } -void ListValue::Swap(ListValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - ListValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void ListValue::UnsafeArenaSwap(ListValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void ListValue::InternalSwap(ListValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 2a639f675a..63df3c976e 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -188,11 +188,22 @@ class PROTOBUF_EXPORT Struct : static constexpr int kIndexInFileMessages = 1; - void UnsafeArenaSwap(Struct* other); - void Swap(Struct* other); friend void swap(Struct& a, Struct& b) { a.Swap(&b); } + inline void Swap(Struct* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Struct* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -260,10 +271,12 @@ class PROTOBUF_EXPORT Struct : // accessors ------------------------------------------------------- + enum : int { + kFieldsFieldNumber = 1, + }; // map fields = 1; int fields_size() const; void clear_fields(); - static const int kFieldsFieldNumber = 1; const ::PROTOBUF_NAMESPACE_ID::Map< std::string, PROTOBUF_NAMESPACE_ID::Value >& fields() const; ::PROTOBUF_NAMESPACE_ID::Map< std::string, PROTOBUF_NAMESPACE_ID::Value >* @@ -348,11 +361,22 @@ class PROTOBUF_EXPORT Value : static constexpr int kIndexInFileMessages = 2; - void UnsafeArenaSwap(Value* other); - void Swap(Value* other); friend void swap(Value& a, Value& b) { a.Swap(&b); } + inline void Swap(Value* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -419,12 +443,19 @@ class PROTOBUF_EXPORT Value : // accessors ------------------------------------------------------- + enum : int { + kNullValueFieldNumber = 1, + kNumberValueFieldNumber = 2, + kStringValueFieldNumber = 3, + kBoolValueFieldNumber = 4, + kStructValueFieldNumber = 5, + kListValueFieldNumber = 6, + }; // .google.protobuf.NullValue null_value = 1; private: bool has_null_value() const; public: void clear_null_value(); - static const int kNullValueFieldNumber = 1; PROTOBUF_NAMESPACE_ID::NullValue null_value() const; void set_null_value(PROTOBUF_NAMESPACE_ID::NullValue value); @@ -433,7 +464,6 @@ class PROTOBUF_EXPORT Value : bool has_number_value() const; public: void clear_number_value(); - static const int kNumberValueFieldNumber = 2; double number_value() const; void set_number_value(double value); @@ -442,7 +472,6 @@ class PROTOBUF_EXPORT Value : bool has_string_value() const; public: void clear_string_value(); - static const int kStringValueFieldNumber = 3; const std::string& string_value() const; void set_string_value(const std::string& value); void set_string_value(std::string&& value); @@ -466,14 +495,12 @@ class PROTOBUF_EXPORT Value : bool has_bool_value() const; public: void clear_bool_value(); - static const int kBoolValueFieldNumber = 4; bool bool_value() const; void set_bool_value(bool value); // .google.protobuf.Struct struct_value = 5; bool has_struct_value() const; void clear_struct_value(); - static const int kStructValueFieldNumber = 5; const PROTOBUF_NAMESPACE_ID::Struct& struct_value() const; PROTOBUF_NAMESPACE_ID::Struct* release_struct_value(); PROTOBUF_NAMESPACE_ID::Struct* mutable_struct_value(); @@ -485,7 +512,6 @@ class PROTOBUF_EXPORT Value : // .google.protobuf.ListValue list_value = 6; bool has_list_value() const; void clear_list_value(); - static const int kListValueFieldNumber = 6; const PROTOBUF_NAMESPACE_ID::ListValue& list_value() const; PROTOBUF_NAMESPACE_ID::ListValue* release_list_value(); PROTOBUF_NAMESPACE_ID::ListValue* mutable_list_value(); @@ -579,11 +605,22 @@ class PROTOBUF_EXPORT ListValue : static constexpr int kIndexInFileMessages = 3; - void UnsafeArenaSwap(ListValue* other); - void Swap(ListValue* other); friend void swap(ListValue& a, ListValue& b) { a.Swap(&b); } + inline void Swap(ListValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ListValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -650,10 +687,12 @@ class PROTOBUF_EXPORT ListValue : // accessors ------------------------------------------------------- + enum : int { + kValuesFieldNumber = 1, + }; // repeated .google.protobuf.Value values = 1; int values_size() const; void clear_values(); - static const int kValuesFieldNumber = 1; PROTOBUF_NAMESPACE_ID::Value* mutable_values(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Value >* mutable_values(); diff --git a/src/google/protobuf/stubs/mathutil.h b/src/google/protobuf/stubs/mathutil.h index b87b286980..479032d064 100644 --- a/src/google/protobuf/stubs/mathutil.h +++ b/src/google/protobuf/stubs/mathutil.h @@ -126,8 +126,7 @@ bool MathUtil::WithinFractionOrMargin(const T x, const T y, if (MathLimits::kIsInteger) { return x == y; } else { - // IsFinite checks are to make kPosInf and kNegInf not within fraction - if (!MathLimits::IsFinite(x) && !MathLimits::IsFinite(y)) { + if (!MathLimits::IsFinite(x) || !MathLimits::IsFinite(y)) { return false; } T relative_margin = static_cast(fraction * Max(Abs(x), Abs(y))); diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 4c26287297..c05fb1269b 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -90,11 +90,6 @@ class Timestamp::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Timestamp::kSecondsFieldNumber; -const int Timestamp::kNanosFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Timestamp::Timestamp() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -386,25 +381,6 @@ bool Timestamp::IsInitialized() const { return true; } -void Timestamp::Swap(Timestamp* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Timestamp* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Timestamp::UnsafeArenaSwap(Timestamp* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Timestamp::InternalSwap(Timestamp* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 76d33296ec..3cd5fdf57d 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -116,11 +116,22 @@ class PROTOBUF_EXPORT Timestamp : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(Timestamp* other); - void Swap(Timestamp* other); friend void swap(Timestamp& a, Timestamp& b) { a.Swap(&b); } + inline void Swap(Timestamp* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Timestamp* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -187,15 +198,17 @@ class PROTOBUF_EXPORT Timestamp : // accessors ------------------------------------------------------- + enum : int { + kSecondsFieldNumber = 1, + kNanosFieldNumber = 2, + }; // int64 seconds = 1; void clear_seconds(); - static const int kSecondsFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int64 seconds() const; void set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value); // int32 nanos = 2; void clear_nanos(); - static const int kNanosFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 nanos() const; void set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value); diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 28f42d9183..e6c061f2fa 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -388,15 +388,6 @@ void Type::clear_source_context() { } source_context_ = nullptr; } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Type::kNameFieldNumber; -const int Type::kFieldsFieldNumber; -const int Type::kOneofsFieldNumber; -const int Type::kOptionsFieldNumber; -const int Type::kSourceContextFieldNumber; -const int Type::kSyntaxFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Type::Type() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -930,25 +921,6 @@ bool Type::IsInitialized() const { return true; } -void Type::Swap(Type* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Type* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Type::UnsafeArenaSwap(Type* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Type::InternalSwap(Type* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -974,19 +946,6 @@ class Field::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Field::kKindFieldNumber; -const int Field::kCardinalityFieldNumber; -const int Field::kNumberFieldNumber; -const int Field::kNameFieldNumber; -const int Field::kTypeUrlFieldNumber; -const int Field::kOneofIndexFieldNumber; -const int Field::kPackedFieldNumber; -const int Field::kOptionsFieldNumber; -const int Field::kJsonNameFieldNumber; -const int Field::kDefaultValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Field::Field() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1702,25 +1661,6 @@ bool Field::IsInitialized() const { return true; } -void Field::Swap(Field* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Field* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Field::UnsafeArenaSwap(Field* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Field::InternalSwap(Field* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1779,14 +1719,6 @@ void Enum::clear_source_context() { } source_context_ = nullptr; } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Enum::kNameFieldNumber; -const int Enum::kEnumvalueFieldNumber; -const int Enum::kOptionsFieldNumber; -const int Enum::kSourceContextFieldNumber; -const int Enum::kSyntaxFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Enum::Enum() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2260,25 +2192,6 @@ bool Enum::IsInitialized() const { return true; } -void Enum::Swap(Enum* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Enum* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Enum::UnsafeArenaSwap(Enum* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Enum::InternalSwap(Enum* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2303,12 +2216,6 @@ class EnumValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int EnumValue::kNameFieldNumber; -const int EnumValue::kNumberFieldNumber; -const int EnumValue::kOptionsFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - EnumValue::EnumValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2671,25 +2578,6 @@ bool EnumValue::IsInitialized() const { return true; } -void EnumValue::Swap(EnumValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - EnumValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void EnumValue::UnsafeArenaSwap(EnumValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void EnumValue::InternalSwap(EnumValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2738,11 +2626,6 @@ void Option::clear_value() { } value_ = nullptr; } -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Option::kNameFieldNumber; -const int Option::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Option::Option() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -3059,25 +2942,6 @@ bool Option::IsInitialized() const { return true; } -void Option::Swap(Option* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Option* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Option::UnsafeArenaSwap(Option* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Option::InternalSwap(Option* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 3aad0fa8af..0dd0a2ae1f 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -229,11 +229,22 @@ class PROTOBUF_EXPORT Type : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(Type* other); - void Swap(Type* other); friend void swap(Type& a, Type& b) { a.Swap(&b); } + inline void Swap(Type* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Type* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -300,10 +311,17 @@ class PROTOBUF_EXPORT Type : // accessors ------------------------------------------------------- + enum : int { + kFieldsFieldNumber = 2, + kOneofsFieldNumber = 3, + kOptionsFieldNumber = 4, + kNameFieldNumber = 1, + kSourceContextFieldNumber = 5, + kSyntaxFieldNumber = 6, + }; // repeated .google.protobuf.Field fields = 2; int fields_size() const; void clear_fields(); - static const int kFieldsFieldNumber = 2; PROTOBUF_NAMESPACE_ID::Field* mutable_fields(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Field >* mutable_fields(); @@ -315,7 +333,6 @@ class PROTOBUF_EXPORT Type : // repeated string oneofs = 3; int oneofs_size() const; void clear_oneofs(); - static const int kOneofsFieldNumber = 3; const std::string& oneofs(int index) const; std::string* mutable_oneofs(int index); void set_oneofs(int index, const std::string& value); @@ -333,7 +350,6 @@ class PROTOBUF_EXPORT Type : // repeated .google.protobuf.Option options = 4; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 4; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -344,7 +360,6 @@ class PROTOBUF_EXPORT Type : // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -366,7 +381,6 @@ class PROTOBUF_EXPORT Type : // .google.protobuf.SourceContext source_context = 5; bool has_source_context() const; void clear_source_context(); - static const int kSourceContextFieldNumber = 5; const PROTOBUF_NAMESPACE_ID::SourceContext& source_context() const; PROTOBUF_NAMESPACE_ID::SourceContext* release_source_context(); PROTOBUF_NAMESPACE_ID::SourceContext* mutable_source_context(); @@ -377,7 +391,6 @@ class PROTOBUF_EXPORT Type : // .google.protobuf.Syntax syntax = 6; void clear_syntax(); - static const int kSyntaxFieldNumber = 6; PROTOBUF_NAMESPACE_ID::Syntax syntax() const; void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value); @@ -450,11 +463,22 @@ class PROTOBUF_EXPORT Field : static constexpr int kIndexInFileMessages = 1; - void UnsafeArenaSwap(Field* other); - void Swap(Field* other); friend void swap(Field& a, Field& b) { a.Swap(&b); } + inline void Swap(Field* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Field* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -619,10 +643,21 @@ class PROTOBUF_EXPORT Field : // accessors ------------------------------------------------------- + enum : int { + kOptionsFieldNumber = 9, + kNameFieldNumber = 4, + kTypeUrlFieldNumber = 6, + kJsonNameFieldNumber = 10, + kDefaultValueFieldNumber = 11, + kKindFieldNumber = 1, + kCardinalityFieldNumber = 2, + kNumberFieldNumber = 3, + kOneofIndexFieldNumber = 7, + kPackedFieldNumber = 8, + }; // repeated .google.protobuf.Option options = 9; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 9; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -633,7 +668,6 @@ class PROTOBUF_EXPORT Field : // string name = 4; void clear_name(); - static const int kNameFieldNumber = 4; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -654,7 +688,6 @@ class PROTOBUF_EXPORT Field : // string type_url = 6; void clear_type_url(); - static const int kTypeUrlFieldNumber = 6; const std::string& type_url() const; void set_type_url(const std::string& value); void set_type_url(std::string&& value); @@ -675,7 +708,6 @@ class PROTOBUF_EXPORT Field : // string json_name = 10; void clear_json_name(); - static const int kJsonNameFieldNumber = 10; const std::string& json_name() const; void set_json_name(const std::string& value); void set_json_name(std::string&& value); @@ -696,7 +728,6 @@ class PROTOBUF_EXPORT Field : // string default_value = 11; void clear_default_value(); - static const int kDefaultValueFieldNumber = 11; const std::string& default_value() const; void set_default_value(const std::string& value); void set_default_value(std::string&& value); @@ -717,31 +748,26 @@ class PROTOBUF_EXPORT Field : // .google.protobuf.Field.Kind kind = 1; void clear_kind(); - static const int kKindFieldNumber = 1; PROTOBUF_NAMESPACE_ID::Field_Kind kind() const; void set_kind(PROTOBUF_NAMESPACE_ID::Field_Kind value); // .google.protobuf.Field.Cardinality cardinality = 2; void clear_cardinality(); - static const int kCardinalityFieldNumber = 2; PROTOBUF_NAMESPACE_ID::Field_Cardinality cardinality() const; void set_cardinality(PROTOBUF_NAMESPACE_ID::Field_Cardinality value); // int32 number = 3; void clear_number(); - static const int kNumberFieldNumber = 3; ::PROTOBUF_NAMESPACE_ID::int32 number() const; void set_number(::PROTOBUF_NAMESPACE_ID::int32 value); // int32 oneof_index = 7; void clear_oneof_index(); - static const int kOneofIndexFieldNumber = 7; ::PROTOBUF_NAMESPACE_ID::int32 oneof_index() const; void set_oneof_index(::PROTOBUF_NAMESPACE_ID::int32 value); // bool packed = 8; void clear_packed(); - static const int kPackedFieldNumber = 8; bool packed() const; void set_packed(bool value); @@ -818,11 +844,22 @@ class PROTOBUF_EXPORT Enum : static constexpr int kIndexInFileMessages = 2; - void UnsafeArenaSwap(Enum* other); - void Swap(Enum* other); friend void swap(Enum& a, Enum& b) { a.Swap(&b); } + inline void Swap(Enum* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Enum* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -889,10 +926,16 @@ class PROTOBUF_EXPORT Enum : // accessors ------------------------------------------------------- + enum : int { + kEnumvalueFieldNumber = 2, + kOptionsFieldNumber = 3, + kNameFieldNumber = 1, + kSourceContextFieldNumber = 4, + kSyntaxFieldNumber = 5, + }; // repeated .google.protobuf.EnumValue enumvalue = 2; int enumvalue_size() const; void clear_enumvalue(); - static const int kEnumvalueFieldNumber = 2; PROTOBUF_NAMESPACE_ID::EnumValue* mutable_enumvalue(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::EnumValue >* mutable_enumvalue(); @@ -904,7 +947,6 @@ class PROTOBUF_EXPORT Enum : // repeated .google.protobuf.Option options = 3; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 3; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -915,7 +957,6 @@ class PROTOBUF_EXPORT Enum : // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -937,7 +978,6 @@ class PROTOBUF_EXPORT Enum : // .google.protobuf.SourceContext source_context = 4; bool has_source_context() const; void clear_source_context(); - static const int kSourceContextFieldNumber = 4; const PROTOBUF_NAMESPACE_ID::SourceContext& source_context() const; PROTOBUF_NAMESPACE_ID::SourceContext* release_source_context(); PROTOBUF_NAMESPACE_ID::SourceContext* mutable_source_context(); @@ -948,7 +988,6 @@ class PROTOBUF_EXPORT Enum : // .google.protobuf.Syntax syntax = 5; void clear_syntax(); - static const int kSyntaxFieldNumber = 5; PROTOBUF_NAMESPACE_ID::Syntax syntax() const; void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value); @@ -1020,11 +1059,22 @@ class PROTOBUF_EXPORT EnumValue : static constexpr int kIndexInFileMessages = 3; - void UnsafeArenaSwap(EnumValue* other); - void Swap(EnumValue* other); friend void swap(EnumValue& a, EnumValue& b) { a.Swap(&b); } + inline void Swap(EnumValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(EnumValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1091,10 +1141,14 @@ class PROTOBUF_EXPORT EnumValue : // accessors ------------------------------------------------------- + enum : int { + kOptionsFieldNumber = 3, + kNameFieldNumber = 1, + kNumberFieldNumber = 2, + }; // repeated .google.protobuf.Option options = 3; int options_size() const; void clear_options(); - static const int kOptionsFieldNumber = 3; PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >* mutable_options(); @@ -1105,7 +1159,6 @@ class PROTOBUF_EXPORT EnumValue : // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -1126,7 +1179,6 @@ class PROTOBUF_EXPORT EnumValue : // int32 number = 2; void clear_number(); - static const int kNumberFieldNumber = 2; ::PROTOBUF_NAMESPACE_ID::int32 number() const; void set_number(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -1196,11 +1248,22 @@ class PROTOBUF_EXPORT Option : static constexpr int kIndexInFileMessages = 4; - void UnsafeArenaSwap(Option* other); - void Swap(Option* other); friend void swap(Option& a, Option& b) { a.Swap(&b); } + inline void Swap(Option* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Option* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1267,9 +1330,12 @@ class PROTOBUF_EXPORT Option : // accessors ------------------------------------------------------- + enum : int { + kNameFieldNumber = 1, + kValueFieldNumber = 2, + }; // string name = 1; void clear_name(); - static const int kNameFieldNumber = 1; const std::string& name() const; void set_name(const std::string& value); void set_name(std::string&& value); @@ -1291,7 +1357,6 @@ class PROTOBUF_EXPORT Option : // .google.protobuf.Any value = 2; bool has_value() const; void clear_value(); - static const int kValueFieldNumber = 2; const PROTOBUF_NAMESPACE_ID::Any& value() const; PROTOBUF_NAMESPACE_ID::Any* release_value(); PROTOBUF_NAMESPACE_ID::Any* mutable_value(); diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index 2f8b763681..92e1cfea49 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -287,28 +287,30 @@ uint8* UnknownField::SerializeLengthDelimitedNoTagToArray(uint8* target) const { #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER namespace internal { const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx, - bool (*is_valid)(int), UnknownFieldSet* unknown, + bool (*is_valid)(int), + InternalMetadataWithArena* metadata, int field_num) { return ctx->ReadPackedVarint( - ptr, [object, is_valid, unknown, field_num](uint64 val) { + ptr, [object, is_valid, metadata, field_num](uint64 val) { if (is_valid(val)) { static_cast*>(object)->Add(val); } else { - WriteVarint(field_num, val, unknown); + WriteVarint(field_num, val, metadata->mutable_unknown_fields()); } }); } const char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(const void*, int), - const void* data, UnknownFieldSet* unknown, + const void* data, + InternalMetadataWithArena* metadata, int field_num) { return ctx->ReadPackedVarint( - ptr, [object, is_valid, data, unknown, field_num](uint64 val) { + ptr, [object, is_valid, data, metadata, field_num](uint64 val) { if (is_valid(data, val)) { static_cast*>(object)->Add(val); } else { - WriteVarint(field_num, val, unknown); + WriteVarint(field_num, val, metadata->mutable_unknown_fields()); } }); } diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index 4d5cc060e5..9f4a4741b4 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -196,13 +196,14 @@ inline void WriteLengthDelimited(uint32 num, StringPiece val, PROTOBUF_EXPORT const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx, - bool (*is_valid)(int), UnknownFieldSet* unknown, - int field_num); + bool (*is_valid)(int), + InternalMetadataWithArena* unknown, int field_num); PROTOBUF_EXPORT const char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(const void*, int), - const void* data, UnknownFieldSet* unknown, + const void* data, + InternalMetadataWithArena* unknown, int field_num); PROTOBUF_EXPORT diff --git a/src/google/protobuf/util/field_comparator_test.cc b/src/google/protobuf/util/field_comparator_test.cc index 6b7ee49a19..7e538f8951 100644 --- a/src/google/protobuf/util/field_comparator_test.cc +++ b/src/google/protobuf/util/field_comparator_test.cc @@ -388,6 +388,20 @@ TEST_F(DefaultFieldComparatorTest, EXPECT_EQ( FieldComparator::SAME, comparator_.Compare(message_1_, message_2_, field_double, -1, -1, NULL)); + + // Finite values and inf should not be equal, even for a positive fraction. + message_1_.set_optional_float(std::numeric_limits::infinity()); + message_2_.set_optional_float(0.0f); + message_1_.set_optional_double(std::numeric_limits::infinity()); + message_2_.set_optional_double(0.0); + comparator_.SetFractionAndMargin(field_float, 0.1, 0.0); + comparator_.SetFractionAndMargin(field_double, 0.1, 0.0); + EXPECT_EQ(FieldComparator::DIFFERENT, + comparator_.Compare(message_1_, message_2_, field_float, -1, -1, + nullptr)); + EXPECT_EQ(FieldComparator::DIFFERENT, + comparator_.Compare(message_1_, message_2_, field_double, -1, -1, + nullptr)); } TEST_F(DefaultFieldComparatorTest, diff --git a/src/google/protobuf/util/json_format.proto b/src/google/protobuf/util/json_format.proto index d773267216..7434fc3e81 100644 --- a/src/google/protobuf/util/json_format.proto +++ b/src/google/protobuf/util/json_format.proto @@ -117,3 +117,14 @@ message TestStringSerializer { repeated string repeated_string = 2; map string_map = 3; } + +message TestMessageWithExtension { + extensions 100 to max; +} + +message TestExtension { + extend TestMessageWithExtension { + optional TestExtension ext = 100; + } + optional string value = 1; +} diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 3e2b346932..421db45fbf 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -1640,7 +1640,8 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( for (int j = start_offset; j < count2; j++) { if (match_list2->at(j) != -1) { - if (!is_treated_as_smart_set || num_diffs_list1[i] == 0) { + if (!is_treated_as_smart_set || num_diffs_list1[i] == 0 || + num_diffs_list1[match_list2->at(j)] == 0) { continue; } } @@ -1662,8 +1663,13 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( // Replace with the one with fewer diffs. const int32 num_diffs = num_diffs_reporter.GetNumDiffs(); if (num_diffs < num_diffs_list1[i]) { - num_diffs_list1[i] = num_diffs; - match = true; + // If j has been already matched to some element, ensure the + // current num_diffs is smaller. + if (match_list2->at(j) == -1 || + num_diffs < num_diffs_list1[match_list2->at(j)]) { + num_diffs_list1[i] = num_diffs; + match = true; + } } } } diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 702f99fbd6..afb99fa1bf 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -1158,6 +1158,65 @@ TEST(MessageDifferencerTest, RepeatedFieldSmartSetTest) { diff_report); } +TEST(MessageDifferencerTest, RepeatedFieldSmartSetTest_IdenticalElements) { + // Create the testing protos + protobuf_unittest::TestDiffMessage msg1; + protobuf_unittest::TestDiffMessage msg2; + protobuf_unittest::TestField elem; + + elem.set_a(1); + elem.set_b(1); + elem.set_c(1); + + *msg1.add_rm() = elem; + *msg1.add_rm() = elem; + *msg2.add_rm() = elem; + *msg2.add_rm() = elem; + + util::MessageDifferencer differencer; + differencer.set_repeated_field_comparison( + util::MessageDifferencer::AS_SMART_SET); + EXPECT_TRUE(differencer.Compare(msg1, msg2)); +} + +TEST(MessageDifferencerTest, RepeatedFieldSmartSetTest_PreviouslyMatch) { + // Create the testing protos + protobuf_unittest::TestDiffMessage msg1; + protobuf_unittest::TestDiffMessage msg2; + protobuf_unittest::TestField elem1_1, elem1_2; + protobuf_unittest::TestField elem2_1, elem2_2; + + elem1_1.set_a(1); + elem1_1.set_b(1); + elem1_1.set_c(1); + elem1_2.set_a(1); + elem1_2.set_b(1); + elem1_2.set_c(0); + + elem2_1.set_a(1); + elem2_1.set_b(1); + elem2_1.set_c(1); + elem2_2.set_a(1); + elem2_2.set_b(0); + elem2_2.set_c(1); + + *msg1.add_rm() = elem1_1; + *msg1.add_rm() = elem2_1; + *msg2.add_rm() = elem1_2; + *msg2.add_rm() = elem2_2; + + string diff_report; + util::MessageDifferencer differencer; + differencer.ReportDifferencesToString(&diff_report); + differencer.set_repeated_field_comparison( + util::MessageDifferencer::AS_SMART_SET); + EXPECT_FALSE(differencer.Compare(msg1, msg2)); + EXPECT_EQ( + "modified: rm[0].c: 1 -> 0\n" + "modified: rm[1].b: 1 -> 0\n", + diff_report); +} + TEST(MessageDifferencerTest, RepeatedFieldSmartSet_MultipleMatches) { // Create the testing protos protobuf_unittest::TestDiffMessage msg1; diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index c25b59a198..244edf1357 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -1427,7 +1427,7 @@ inline uint8* WireFormatLite::WritePrimitiveNoTagToArray( const int n = value.size(); GOOGLE_DCHECK_GT(n, 0); - const T* ii = value.unsafe_data(); + const T* ii = value.data(); int i = 0; do { target = Writer(ii[i], target); @@ -1445,7 +1445,7 @@ inline uint8* WireFormatLite::WriteFixedNoTagToArray( const int n = value.size(); GOOGLE_DCHECK_GT(n, 0); - const T* ii = value.unsafe_data(); + const T* ii = value.data(); const int bytes = n * static_cast(sizeof(ii[0])); memcpy(target, ii, static_cast(bytes)); return target + bytes; @@ -1591,7 +1591,7 @@ inline uint8* WireFormatLite::WritePrimitiveToArray( return target; } - const T* ii = value.unsafe_data(); + const T* ii = value.data(); int i = 0; do { target = Writer(field_number, ii[i], target); diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index a4846613e7..73d8c4227d 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -311,10 +311,6 @@ class DoubleValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int DoubleValue::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - DoubleValue::DoubleValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -558,25 +554,6 @@ bool DoubleValue::IsInitialized() const { return true; } -void DoubleValue::Swap(DoubleValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - DoubleValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void DoubleValue::UnsafeArenaSwap(DoubleValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void DoubleValue::InternalSwap(DoubleValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -596,10 +573,6 @@ class FloatValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int FloatValue::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - FloatValue::FloatValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -843,25 +816,6 @@ bool FloatValue::IsInitialized() const { return true; } -void FloatValue::Swap(FloatValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - FloatValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void FloatValue::UnsafeArenaSwap(FloatValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void FloatValue::InternalSwap(FloatValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -881,10 +835,6 @@ class Int64Value::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Int64Value::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Int64Value::Int64Value() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1130,25 +1080,6 @@ bool Int64Value::IsInitialized() const { return true; } -void Int64Value::Swap(Int64Value* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Int64Value* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Int64Value::UnsafeArenaSwap(Int64Value* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Int64Value::InternalSwap(Int64Value* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1168,10 +1099,6 @@ class UInt64Value::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int UInt64Value::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - UInt64Value::UInt64Value() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1417,25 +1344,6 @@ bool UInt64Value::IsInitialized() const { return true; } -void UInt64Value::Swap(UInt64Value* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - UInt64Value* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void UInt64Value::UnsafeArenaSwap(UInt64Value* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void UInt64Value::InternalSwap(UInt64Value* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1455,10 +1363,6 @@ class Int32Value::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int Int32Value::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - Int32Value::Int32Value() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1704,25 +1608,6 @@ bool Int32Value::IsInitialized() const { return true; } -void Int32Value::Swap(Int32Value* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - Int32Value* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void Int32Value::UnsafeArenaSwap(Int32Value* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void Int32Value::InternalSwap(Int32Value* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -1742,10 +1627,6 @@ class UInt32Value::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int UInt32Value::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - UInt32Value::UInt32Value() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -1991,25 +1872,6 @@ bool UInt32Value::IsInitialized() const { return true; } -void UInt32Value::Swap(UInt32Value* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - UInt32Value* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void UInt32Value::UnsafeArenaSwap(UInt32Value* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void UInt32Value::InternalSwap(UInt32Value* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2029,10 +1891,6 @@ class BoolValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int BoolValue::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - BoolValue::BoolValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2276,25 +2134,6 @@ bool BoolValue::IsInitialized() const { return true; } -void BoolValue::Swap(BoolValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - BoolValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void BoolValue::UnsafeArenaSwap(BoolValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void BoolValue::InternalSwap(BoolValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2314,10 +2153,6 @@ class StringValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int StringValue::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - StringValue::StringValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2582,25 +2417,6 @@ bool StringValue::IsInitialized() const { return true; } -void StringValue::Swap(StringValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - StringValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void StringValue::UnsafeArenaSwap(StringValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void StringValue::InternalSwap(StringValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2621,10 +2437,6 @@ class BytesValue::_Internal { public: }; -#if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int BytesValue::kValueFieldNumber; -#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 - BytesValue::BytesValue() : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { SharedCtor(); @@ -2877,25 +2689,6 @@ bool BytesValue::IsInitialized() const { return true; } -void BytesValue::Swap(BytesValue* other) { - if (other == this) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - BytesValue* temp = New(GetArenaNoVirtual()); - temp->MergeFrom(*other); - other->CopyFrom(*this); - InternalSwap(temp); - if (GetArenaNoVirtual() == nullptr) { - delete temp; - } - } -} -void BytesValue::UnsafeArenaSwap(BytesValue* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} void BytesValue::InternalSwap(BytesValue* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index c8f09f2bcb..8038d988d1 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -148,11 +148,22 @@ class PROTOBUF_EXPORT DoubleValue : static constexpr int kIndexInFileMessages = 0; - void UnsafeArenaSwap(DoubleValue* other); - void Swap(DoubleValue* other); friend void swap(DoubleValue& a, DoubleValue& b) { a.Swap(&b); } + inline void Swap(DoubleValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(DoubleValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -219,9 +230,11 @@ class PROTOBUF_EXPORT DoubleValue : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // double value = 1; void clear_value(); - static const int kValueFieldNumber = 1; double value() const; void set_value(double value); @@ -289,11 +302,22 @@ class PROTOBUF_EXPORT FloatValue : static constexpr int kIndexInFileMessages = 1; - void UnsafeArenaSwap(FloatValue* other); - void Swap(FloatValue* other); friend void swap(FloatValue& a, FloatValue& b) { a.Swap(&b); } + inline void Swap(FloatValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FloatValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -360,9 +384,11 @@ class PROTOBUF_EXPORT FloatValue : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // float value = 1; void clear_value(); - static const int kValueFieldNumber = 1; float value() const; void set_value(float value); @@ -430,11 +456,22 @@ class PROTOBUF_EXPORT Int64Value : static constexpr int kIndexInFileMessages = 2; - void UnsafeArenaSwap(Int64Value* other); - void Swap(Int64Value* other); friend void swap(Int64Value& a, Int64Value& b) { a.Swap(&b); } + inline void Swap(Int64Value* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Int64Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -501,9 +538,11 @@ class PROTOBUF_EXPORT Int64Value : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // int64 value = 1; void clear_value(); - static const int kValueFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int64 value() const; void set_value(::PROTOBUF_NAMESPACE_ID::int64 value); @@ -571,11 +610,22 @@ class PROTOBUF_EXPORT UInt64Value : static constexpr int kIndexInFileMessages = 3; - void UnsafeArenaSwap(UInt64Value* other); - void Swap(UInt64Value* other); friend void swap(UInt64Value& a, UInt64Value& b) { a.Swap(&b); } + inline void Swap(UInt64Value* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(UInt64Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -642,9 +692,11 @@ class PROTOBUF_EXPORT UInt64Value : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // uint64 value = 1; void clear_value(); - static const int kValueFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::uint64 value() const; void set_value(::PROTOBUF_NAMESPACE_ID::uint64 value); @@ -712,11 +764,22 @@ class PROTOBUF_EXPORT Int32Value : static constexpr int kIndexInFileMessages = 4; - void UnsafeArenaSwap(Int32Value* other); - void Swap(Int32Value* other); friend void swap(Int32Value& a, Int32Value& b) { a.Swap(&b); } + inline void Swap(Int32Value* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Int32Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -783,9 +846,11 @@ class PROTOBUF_EXPORT Int32Value : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // int32 value = 1; void clear_value(); - static const int kValueFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::int32 value() const; void set_value(::PROTOBUF_NAMESPACE_ID::int32 value); @@ -853,11 +918,22 @@ class PROTOBUF_EXPORT UInt32Value : static constexpr int kIndexInFileMessages = 5; - void UnsafeArenaSwap(UInt32Value* other); - void Swap(UInt32Value* other); friend void swap(UInt32Value& a, UInt32Value& b) { a.Swap(&b); } + inline void Swap(UInt32Value* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(UInt32Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -924,9 +1000,11 @@ class PROTOBUF_EXPORT UInt32Value : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // uint32 value = 1; void clear_value(); - static const int kValueFieldNumber = 1; ::PROTOBUF_NAMESPACE_ID::uint32 value() const; void set_value(::PROTOBUF_NAMESPACE_ID::uint32 value); @@ -994,11 +1072,22 @@ class PROTOBUF_EXPORT BoolValue : static constexpr int kIndexInFileMessages = 6; - void UnsafeArenaSwap(BoolValue* other); - void Swap(BoolValue* other); friend void swap(BoolValue& a, BoolValue& b) { a.Swap(&b); } + inline void Swap(BoolValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(BoolValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1065,9 +1154,11 @@ class PROTOBUF_EXPORT BoolValue : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // bool value = 1; void clear_value(); - static const int kValueFieldNumber = 1; bool value() const; void set_value(bool value); @@ -1135,11 +1226,22 @@ class PROTOBUF_EXPORT StringValue : static constexpr int kIndexInFileMessages = 7; - void UnsafeArenaSwap(StringValue* other); - void Swap(StringValue* other); friend void swap(StringValue& a, StringValue& b) { a.Swap(&b); } + inline void Swap(StringValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(StringValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1206,9 +1308,11 @@ class PROTOBUF_EXPORT StringValue : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // string value = 1; void clear_value(); - static const int kValueFieldNumber = 1; const std::string& value() const; void set_value(const std::string& value); void set_value(std::string&& value); @@ -1291,11 +1395,22 @@ class PROTOBUF_EXPORT BytesValue : static constexpr int kIndexInFileMessages = 8; - void UnsafeArenaSwap(BytesValue* other); - void Swap(BytesValue* other); friend void swap(BytesValue& a, BytesValue& b) { a.Swap(&b); } + inline void Swap(BytesValue* other) { + if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(BytesValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + InternalSwap(other); + } // implements Message ---------------------------------------------- @@ -1362,9 +1477,11 @@ class PROTOBUF_EXPORT BytesValue : // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; // bytes value = 1; void clear_value(); - static const int kValueFieldNumber = 1; const std::string& value() const; void set_value(const std::string& value); void set_value(std::string&& value);