return array[index];
}
+ @Override
+ public int indexOf(Object element) {
+ if (!(element instanceof Boolean)) {
+ return -1;
+ }
+ boolean unboxedElement = (Boolean) element;
+ int numElems = size();
+ for (int i = 0; i < numElems; i++) {
+ if (array[i] == unboxedElement) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(Object element) {
+ return indexOf(element) != -1;
+ }
+
@Override
public int size() {
return size;
diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
index f2c7cc4723..e20a8858c2 100644
--- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
+++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
@@ -484,7 +484,7 @@ public abstract class CodedInputStream {
* Returns true if the stream has reached the end of the input. This is the case if either the end
* of the underlying input source has been reached or if the stream has reached a limit created
* using {@link #pushLimit(int)}. This function may get blocked when using StreamDecoder as it
- * invokes {@link #StreamDecoder.tryRefillBuffer(int)} in this function which will try to read
+ * invokes {@link StreamDecoder#tryRefillBuffer(int)} in this function which will try to read
* bytes from input.
*/
public abstract boolean isAtEnd() throws IOException;
diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java
index a20829e56d..960ff5da8f 100644
--- a/java/core/src/main/java/com/google/protobuf/Descriptors.java
+++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java
@@ -1125,6 +1125,34 @@ public final class Descriptors {
return containingOneof;
}
+ /**
+ * Returns true if this field was syntactically written with "optional" in the .proto file.
+ * Excludes singular proto3 fields that do not have a label.
+ */
+ public boolean hasOptionalKeyword() {
+ return isProto3Optional
+ || (file.getSyntax() == Syntax.PROTO2 && isOptional() && getContainingOneof() == null);
+ }
+
+ /**
+ * Returns true if this is a non-oneof field that tracks presence.
+ *
+ * This includes all "required" and "optional" fields in the .proto file, but excludes oneof
+ * fields and singular proto3 fields without "optional".
+ *
+ *
In implementations that use hasbits, this method will probably indicate whether this field
+ * uses a hasbit.
+ */
+ boolean isSingularWithPresence() {
+ if (isRepeated()) {
+ return false;
+ }
+ if (getContainingOneof() != null && !getContainingOneof().isSynthetic()) {
+ return false;
+ }
+ return getType() == Type.MESSAGE || isProto3Optional || file.getSyntax() == Syntax.PROTO2;
+ }
+
/**
* For extensions defined nested within message types, gets the outer type. Not valid for
* non-extension fields. For example, consider this {@code .proto} file:
@@ -1203,6 +1231,7 @@ public final class Descriptors {
private final String jsonName;
private final FileDescriptor file;
private final Descriptor extensionScope;
+ private final boolean isProto3Optional;
// Possibly initialized during cross-linking.
private Type type;
@@ -1327,6 +1356,8 @@ public final class Descriptors {
type = Type.valueOf(proto.getType());
}
+ isProto3Optional = proto.getProto3Optional();
+
if (getNumber() <= 0) {
throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
}
@@ -2627,6 +2658,10 @@ public final class Descriptors {
return proto.getOptions();
}
+ public boolean isSynthetic() {
+ return fields.length == 1 && fields[0].isProto3Optional;
+ }
+
/** Get a list of this message type's fields. */
public List getFields() {
return Collections.unmodifiableList(Arrays.asList(fields));
diff --git a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
index ac14949e6f..12824abe66 100644
--- a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
@@ -140,6 +140,26 @@ final class DoubleArrayList extends AbstractProtobufList
return array[index];
}
+ @Override
+ public int indexOf(Object element) {
+ if (!(element instanceof Double)) {
+ return -1;
+ }
+ double unboxedElement = (Double) element;
+ int numElems = size();
+ for (int i = 0; i < numElems; i++) {
+ if (array[i] == unboxedElement) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(Object element) {
+ return indexOf(element) != -1;
+ }
+
@Override
public int size() {
return size;
diff --git a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
index 9d2ab71d7c..9589816f8e 100644
--- a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
@@ -139,6 +139,26 @@ final class FloatArrayList extends AbstractProtobufList
return array[index];
}
+ @Override
+ public int indexOf(Object element) {
+ if (!(element instanceof Float)) {
+ return -1;
+ }
+ float unboxedElement = (Float) element;
+ int numElems = size();
+ for (int i = 0; i < numElems; i++) {
+ if (array[i] == unboxedElement) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(Object element) {
+ return indexOf(element) != -1;
+ }
+
@Override
public int size() {
return size;
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
index 1ee785de8e..8456713fa0 100644
--- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
+++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
@@ -121,7 +121,11 @@ public abstract class GeneratedMessageLite<
return true;
}
- if (!getDefaultInstanceForType().getClass().isInstance(other)) {
+ if (other == null) {
+ return false;
+ }
+
+ if (this.getClass() != other.getClass()) {
return false;
}
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
index 4a0e28e127..86f88a0228 100644
--- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
+++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
@@ -1987,9 +1987,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
int oneofsSize = oneofs.length;
for (int i = 0; i < oneofsSize; i++) {
- oneofs[i] = new OneofAccessor(
- descriptor, camelCaseNames[i + fieldsSize],
- messageClass, builderClass);
+ oneofs[i] =
+ new OneofAccessor(
+ descriptor, i, camelCaseNames[i + fieldsSize], messageClass, builderClass);
}
initialized = true;
camelCaseNames = null;
@@ -2057,14 +2057,22 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
/** OneofAccessor provides access to a single oneof. */
private static class OneofAccessor {
OneofAccessor(
- final Descriptor descriptor, final String camelCaseName,
+ final Descriptor descriptor,
+ final int oneofIndex,
+ final String camelCaseName,
final Class extends GeneratedMessageV3> messageClass,
final Class extends Builder> builderClass) {
this.descriptor = descriptor;
- caseMethod =
- getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
- caseMethodBuilder =
- getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
+ OneofDescriptor oneofDescriptor = descriptor.getOneofs().get(oneofIndex);
+ if (oneofDescriptor.isSynthetic()) {
+ caseMethod = null;
+ caseMethodBuilder = null;
+ fieldDescriptor = oneofDescriptor.getFields().get(0);
+ } else {
+ caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
+ caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
+ fieldDescriptor = null;
+ }
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
}
@@ -2072,33 +2080,51 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
private final Method caseMethod;
private final Method caseMethodBuilder;
private final Method clearMethod;
+ private final FieldDescriptor fieldDescriptor;
public boolean has(final GeneratedMessageV3 message) {
- if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
- return false;
+ if (fieldDescriptor != null) {
+ return message.hasField(fieldDescriptor);
+ } else {
+ if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
+ return false;
+ }
}
return true;
}
public boolean has(GeneratedMessageV3.Builder builder) {
- if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
- return false;
+ if (fieldDescriptor != null) {
+ return builder.hasField(fieldDescriptor);
+ } else {
+ if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
+ return false;
+ }
}
return true;
}
public FieldDescriptor get(final GeneratedMessageV3 message) {
- int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
- if (fieldNumber > 0) {
- return descriptor.findFieldByNumber(fieldNumber);
+ if (fieldDescriptor != null) {
+ return message.hasField(fieldDescriptor) ? fieldDescriptor : null;
+ } else {
+ int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
}
return null;
}
public FieldDescriptor get(GeneratedMessageV3.Builder builder) {
- int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
- if (fieldNumber > 0) {
- return descriptor.findFieldByNumber(fieldNumber);
+ if (fieldDescriptor != null) {
+ return builder.hasField(fieldDescriptor) ? fieldDescriptor : null;
+ } else {
+ int fieldNumber =
+ ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
}
return null;
}
@@ -2108,10 +2134,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
}
}
- private static boolean supportFieldPresence(FileDescriptor file) {
- return file.getSyntax() == FileDescriptor.Syntax.PROTO2;
- }
-
// ---------------------------------------------------------------
private static class SingularFieldAccessor implements FieldAccessor {
@@ -2216,9 +2238,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
final Class extends GeneratedMessageV3> messageClass,
final Class extends Builder> builderClass,
final String containingOneofCamelCaseName) {
- isOneofField = descriptor.getContainingOneof() != null;
- hasHasMethod = supportFieldPresence(descriptor.getFile())
- || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
+ isOneofField =
+ descriptor.getContainingOneof() != null
+ && !descriptor.getContainingOneof().isSynthetic();
+ hasHasMethod =
+ descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2
+ || descriptor.hasOptionalKeyword()
+ || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
ReflectionInvoker reflectionInvoker =
new ReflectionInvoker(
descriptor,
diff --git a/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/java/core/src/main/java/com/google/protobuf/IntArrayList.java
index 98f1f81331..e9c3b1aee0 100644
--- a/java/core/src/main/java/com/google/protobuf/IntArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/IntArrayList.java
@@ -139,6 +139,26 @@ final class IntArrayList extends AbstractProtobufList
return array[index];
}
+ @Override
+ public int indexOf(Object element) {
+ if (!(element instanceof Integer)) {
+ return -1;
+ }
+ int unboxedElement = (Integer) element;
+ int numElems = size();
+ for (int i = 0; i < numElems; i++) {
+ if (array[i] == unboxedElement) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(Object element) {
+ return indexOf(element) != -1;
+ }
+
@Override
public int size() {
return size;
diff --git a/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java
index 2dd15b4deb..04f44756c4 100644
--- a/java/core/src/main/java/com/google/protobuf/LongArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java
@@ -139,6 +139,26 @@ final class LongArrayList extends AbstractProtobufList
return array[index];
}
+ @Override
+ public int indexOf(Object element) {
+ if (!(element instanceof Long)) {
+ return -1;
+ }
+ long unboxedElement = (Long) element;
+ int numElems = size();
+ for (int i = 0; i < numElems; i++) {
+ if (array[i] == unboxedElement) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(Object element) {
+ return indexOf(element) != -1;
+ }
+
@Override
public int size() {
return size;
diff --git a/java/core/src/main/java/com/google/protobuf/MessageSchema.java b/java/core/src/main/java/com/google/protobuf/MessageSchema.java
index 8f9ce7328e..139e55a971 100755
--- a/java/core/src/main/java/com/google/protobuf/MessageSchema.java
+++ b/java/core/src/main/java/com/google/protobuf/MessageSchema.java
@@ -89,6 +89,7 @@ final class MessageSchema implements Schema {
private static final int FIELD_TYPE_MASK = 0x0FF00000;
private static final int REQUIRED_MASK = 0x10000000;
private static final int ENFORCE_UTF8_MASK = 0x20000000;
+ private static final int NO_PRESENCE_SENTINEL = -1 & OFFSET_MASK;
private static final int[] EMPTY_INT_ARRAY = new int[0];
/** An offset applied to the field type ID for scalar fields that are a member of a oneof. */
@@ -118,6 +119,11 @@ final class MessageSchema implements Schema {
* [70 - 75] field presence mask shift (unused for oneof/repeated fields)
* [76 - 95] presence field offset / oneof case field offset / cached size field offset
*
+ *
+ * Note that presence field offset can only use 20 bits - 1. All bits set to 1 is the sentinel
+ * value for non-presence. This is not validated at runtime, we simply assume message layouts
+ * will not exceed 1MB (assuming ~10 bytes per field, that implies 100k fields which should hit
+ * other javac limits first).
*/
private final int[] buffer;
@@ -260,7 +266,7 @@ final class MessageSchema implements Schema {
}
next = result | (next << shift);
}
- final int flags = next;
+ final int unusedFlags = next;
next = info.charAt(i++);
if (next >= 0xD800) {
@@ -464,8 +470,7 @@ final class MessageSchema implements Schema {
|| oneofFieldType == 17 /* FieldType.GROUP */) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
} else if (oneofFieldType == 12 /* FieldType.ENUM */) {
- // proto2
- if ((flags & 0x1) == 0x1) {
+ if (!isProto3) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
}
}
@@ -508,7 +513,7 @@ final class MessageSchema implements Schema {
} else if (fieldType == 12 /* FieldType.ENUM */
|| fieldType == 30 /* FieldType.ENUM_LIST */
|| fieldType == 44 /* FieldType.ENUM_LIST_PACKED */) {
- if ((flags & 0x1) == 0x1) {
+ if (!isProto3) {
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
}
} else if (fieldType == 50 /* FieldType.MAP */) {
@@ -520,7 +525,8 @@ final class MessageSchema implements Schema {
}
fieldOffset = (int) unsafe.objectFieldOffset(field);
- if ((flags & 0x1) == 0x1 && fieldType <= 17 /* FieldType.GROUP */) {
+ boolean hasHasBit = (fieldTypeWithExtraBits & 0x1000) == 0x1000;
+ if (hasHasBit && fieldType <= 17 /* FieldType.GROUP */) {
next = info.charAt(i++);
if (next >= 0xD800) {
int result = next & 0x1FFF;
@@ -546,7 +552,7 @@ final class MessageSchema implements Schema {
presenceFieldOffset = (int) unsafe.objectFieldOffset(hasBitsField);
presenceMaskShift = hasBitsIndex % 32;
} else {
- presenceFieldOffset = 0;
+ presenceFieldOffset = NO_PRESENCE_SENTINEL;
presenceMaskShift = 0;
}
@@ -662,7 +668,7 @@ final class MessageSchema implements Schema {
// We found the entry for the next field. Store the entry in the manifest for
// this field and increment the field index.
- storeFieldData(fi, buffer, bufferIndex, isProto3, objects);
+ storeFieldData(fi, buffer, bufferIndex, objects);
// Convert field number to index
if (checkInitializedIndex < checkInitialized.length
@@ -719,7 +725,7 @@ final class MessageSchema implements Schema {
}
private static void storeFieldData(
- FieldInfo fi, int[] buffer, int bufferIndex, boolean proto3, Object[] objects) {
+ FieldInfo fi, int[] buffer, int bufferIndex, Object[] objects) {
final int fieldOffset;
final int typeId;
final int presenceMaskShift;
@@ -735,8 +741,13 @@ final class MessageSchema implements Schema {
FieldType type = fi.getType();
fieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getField());
typeId = type.id();
- if (!proto3 && !type.isList() && !type.isMap()) {
- presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getPresenceField());
+ if (!type.isList() && !type.isMap()) {
+ Field presenceField = fi.getPresenceField();
+ if (presenceField == null) {
+ presenceFieldOffset = NO_PRESENCE_SENTINEL;
+ } else {
+ presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(presenceField);
+ }
presenceMaskShift = Integer.numberOfTrailingZeros(fi.getPresenceMask());
} else {
if (fi.getCachedSizeField() == null) {
@@ -1408,13 +1419,13 @@ final class MessageSchema implements Schema {
public int getSerializedSize(T message) {
return proto3 ? getSerializedSizeProto3(message) : getSerializedSizeProto2(message);
}
-
+
@SuppressWarnings("unchecked")
private int getSerializedSizeProto2(T message) {
int size = 0;
final sun.misc.Unsafe unsafe = UNSAFE;
- int currentPresenceFieldOffset = -1;
+ int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0;
for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) {
final int typeAndOffset = typeAndOffsetAt(i);
@@ -2548,7 +2559,7 @@ final class MessageSchema implements Schema {
nextExtension = extensionIterator.next();
}
}
- int currentPresenceFieldOffset = -1;
+ int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0;
final int bufferLength = buffer.length;
final sun.misc.Unsafe unsafe = UNSAFE;
@@ -2924,7 +2935,6 @@ final class MessageSchema implements Schema {
nextExtension = extensionIterator.next();
}
}
-
final int bufferLength = buffer.length;
for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) {
final int typeAndOffset = typeAndOffsetAt(pos);
@@ -4867,7 +4877,7 @@ final class MessageSchema implements Schema {
T message, byte[] data, int position, int limit, int endGroup, Registers registers)
throws IOException {
final sun.misc.Unsafe unsafe = UNSAFE;
- int currentPresenceFieldOffset = -1;
+ int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0;
int tag = 0;
int oldNumber = -1;
@@ -4901,7 +4911,7 @@ final class MessageSchema implements Schema {
// We cache the 32-bit has-bits integer value and only write it back when parsing a field
// using a different has-bits integer.
if (presenceFieldOffset != currentPresenceFieldOffset) {
- if (currentPresenceFieldOffset != -1) {
+ if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
}
currentPresenceFieldOffset = presenceFieldOffset;
@@ -5143,7 +5153,7 @@ final class MessageSchema implements Schema {
tag, data, position, limit, getMutableUnknownFields(message), registers);
}
}
- if (currentPresenceFieldOffset != -1) {
+ if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
}
UnknownFieldSetLite unknownFields = null;
@@ -5175,6 +5185,8 @@ final class MessageSchema implements Schema {
private int parseProto3Message(
T message, byte[] data, int position, int limit, Registers registers) throws IOException {
final sun.misc.Unsafe unsafe = UNSAFE;
+ int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
+ int currentPresenceField = 0;
int tag = 0;
int oldNumber = -1;
int pos = 0;
@@ -5200,11 +5212,30 @@ final class MessageSchema implements Schema {
final int fieldType = type(typeAndOffset);
final long fieldOffset = offset(typeAndOffset);
if (fieldType <= 17) {
+ // Proto3 optional fields have has-bits.
+ final int presenceMaskAndOffset = buffer[pos + 2];
+ final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
+ final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
+ // We cache the 32-bit has-bits integer value and only write it back when parsing a field
+ // using a different has-bits integer.
+ //
+ // Note that for fields that do not have hasbits, we unconditionally write and discard
+ // the data.
+ if (presenceFieldOffset != currentPresenceFieldOffset) {
+ if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
+ unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
+ }
+ if (presenceFieldOffset != NO_PRESENCE_SENTINEL) {
+ currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset);
+ }
+ currentPresenceFieldOffset = presenceFieldOffset;
+ }
switch (fieldType) {
case 0: // DOUBLE:
if (wireType == WireFormat.WIRETYPE_FIXED64) {
UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position));
position += 8;
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5212,6 +5243,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_FIXED32) {
UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position));
position += 4;
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5220,6 +5252,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint64(data, position, registers);
unsafe.putLong(message, fieldOffset, registers.long1);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5228,6 +5261,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint32(data, position, registers);
unsafe.putInt(message, fieldOffset, registers.int1);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5236,6 +5270,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_FIXED64) {
unsafe.putLong(message, fieldOffset, decodeFixed64(data, position));
position += 8;
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5244,6 +5279,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_FIXED32) {
unsafe.putInt(message, fieldOffset, decodeFixed32(data, position));
position += 4;
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5251,6 +5287,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint64(data, position, registers);
UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5262,6 +5299,7 @@ final class MessageSchema implements Schema {
position = decodeStringRequireUtf8(data, position, registers);
}
unsafe.putObject(message, fieldOffset, registers.object1);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5277,6 +5315,7 @@ final class MessageSchema implements Schema {
unsafe.putObject(
message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1));
}
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5284,6 +5323,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) {
position = decodeBytes(data, position, registers);
unsafe.putObject(message, fieldOffset, registers.object1);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5291,6 +5331,7 @@ final class MessageSchema implements Schema {
if (wireType == WireFormat.WIRETYPE_VARINT) {
position = decodeVarint32(data, position, registers);
unsafe.putInt(message, fieldOffset, registers.int1);
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5299,6 +5340,7 @@ final class MessageSchema implements Schema {
position = decodeVarint32(data, position, registers);
unsafe.putInt(
message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1));
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5307,6 +5349,7 @@ final class MessageSchema implements Schema {
position = decodeVarint64(data, position, registers);
unsafe.putLong(
message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1));
+ currentPresenceField |= presenceMask;
continue;
}
break;
@@ -5381,6 +5424,9 @@ final class MessageSchema implements Schema {
position = decodeUnknownField(
tag, data, position, limit, getMutableUnknownFields(message), registers);
}
+ if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
+ unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
+ }
if (position != limit) {
throw InvalidProtocolBufferException.parseFailure();
}
@@ -5502,28 +5548,26 @@ final class MessageSchema implements Schema {
@Override
public final boolean isInitialized(T message) {
- int currentPresenceFieldOffset = -1;
+ int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
int currentPresenceField = 0;
for (int i = 0; i < checkInitializedCount; i++) {
final int pos = intArray[i];
final int number = numberAt(pos);
-
final int typeAndOffset = typeAndOffsetAt(pos);
- int presenceMaskAndOffset = 0;
- int presenceMask = 0;
- if (!proto3) {
- presenceMaskAndOffset = buffer[pos + 2];
- final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
- presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
- if (presenceFieldOffset != currentPresenceFieldOffset) {
- currentPresenceFieldOffset = presenceFieldOffset;
+ int presenceMaskAndOffset = buffer[pos + 2];
+ final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
+ int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
+ if (presenceFieldOffset != currentPresenceFieldOffset) {
+ currentPresenceFieldOffset = presenceFieldOffset;
+ if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
currentPresenceField = UNSAFE.getInt(message, (long) presenceFieldOffset);
}
}
if (isRequired(typeAndOffset)) {
- if (!isFieldPresent(message, pos, currentPresenceField, presenceMask)) {
+ if (!isFieldPresent(
+ message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)) {
return false;
}
// If a required message field is set but has no required fields of it's own, we still
@@ -5534,7 +5578,8 @@ final class MessageSchema implements Schema {
switch (type(typeAndOffset)) {
case 9: // MESSAGE
case 17: // GROUP
- if (isFieldPresent(message, pos, currentPresenceField, presenceMask)
+ if (isFieldPresent(
+ message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)
&& !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) {
return false;
}
@@ -5744,8 +5789,9 @@ final class MessageSchema implements Schema {
return isFieldPresent(message, pos) == isFieldPresent(other, pos);
}
- private boolean isFieldPresent(T message, int pos, int presenceField, int presenceMask) {
- if (proto3) {
+ private boolean isFieldPresent(
+ T message, int pos, int presenceFieldOffset, int presenceField, int presenceMask) {
+ if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
return isFieldPresent(message, pos);
} else {
return (presenceField & presenceMask) != 0;
@@ -5753,7 +5799,9 @@ final class MessageSchema implements Schema {
}
private boolean isFieldPresent(T message, int pos) {
- if (proto3) {
+ final int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
+ final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
+ if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
final int typeAndOffset = typeAndOffsetAt(pos);
final long offset = offset(typeAndOffset);
switch (type(typeAndOffset)) {
@@ -5804,20 +5852,18 @@ final class MessageSchema implements Schema {
throw new IllegalArgumentException();
}
} else {
- int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
return (UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) & presenceMask) != 0;
}
}
private void setFieldPresent(T message, int pos) {
- if (proto3) {
- // Proto3 doesn't have presence fields
+ int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
+ final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
+ if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
return;
}
- int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
- final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
UnsafeUtil.putInt(
message,
presenceFieldOffset,
diff --git a/java/core/src/main/java/com/google/protobuf/RawMessageInfo.java b/java/core/src/main/java/com/google/protobuf/RawMessageInfo.java
index b9a3d2bb55..72f56ed88e 100755
--- a/java/core/src/main/java/com/google/protobuf/RawMessageInfo.java
+++ b/java/core/src/main/java/com/google/protobuf/RawMessageInfo.java
@@ -96,7 +96,7 @@ final class RawMessageInfo implements MessageInfo {
* If the field is in an oneof:
*
*
- * - [2]: oenof index
+ *
- [2]: oneof index
*
*
* For other types, the field entry only has field number and field type.
diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
index f3b09fbacc..f51436c83d 100644
--- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
+++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
@@ -346,9 +346,8 @@ public class RepeatedFieldBuilder<
// If we can inspect the size, we can more efficiently add messages.
int size = -1;
if (values instanceof Collection) {
- @SuppressWarnings("unchecked")
- final Collection collection = (Collection) values;
- if (collection.size() == 0) {
+ final Collection> collection = (Collection>) values;
+ if (collection.isEmpty()) {
return this;
}
size = collection.size();
@@ -408,8 +407,7 @@ public class RepeatedFieldBuilder<
/**
* Removes the element at the specified position in this list. Shifts any subsequent elements to
- * the left (subtracts one from their indices). Returns the element that was removed from the
- * list.
+ * the left (subtracts one from their indices).
*
* @param index the index at which to remove the message
*/
diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
index fb1667c4c6..91bc3e286d 100644
--- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
+++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
@@ -346,9 +346,8 @@ public class RepeatedFieldBuilderV3<
// If we can inspect the size, we can more efficiently add messages.
int size = -1;
if (values instanceof Collection) {
- @SuppressWarnings("unchecked")
- final Collection collection = (Collection) values;
- if (collection.size() == 0) {
+ final Collection> collection = (Collection>) values;
+ if (collection.isEmpty()) {
return this;
}
size = collection.size();
@@ -408,8 +407,7 @@ public class RepeatedFieldBuilderV3<
/**
* Removes the element at the specified position in this list. Shifts any subsequent elements to
- * the left (subtracts one from their indices). Returns the element that was removed from the
- * list.
+ * the left (subtracts one from their indices).
*
* @param index the index at which to remove the message
*/
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 f3f1011a58..673343d4ea 100644
--- a/java/core/src/main/java/com/google/protobuf/TextFormat.java
+++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java
@@ -34,10 +34,12 @@ import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.MessageReflection.MergeTarget;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.CharBuffer;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -137,7 +139,7 @@ public final class TextFormat {
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*
- * @deprecated Use {@link MessageOrBuilder#toString()}
+ * @deprecated Use {@code message.toString()}
*/
@Deprecated
public static String printToString(final MessageOrBuilder message) {
@@ -419,7 +421,17 @@ public final class TextFormat {
private void printField(
final FieldDescriptor field, final Object value, final TextGenerator generator)
throws IOException {
- if (field.isRepeated()) {
+ // Sort map field entries by key
+ if (field.isMapField()) {
+ List adapters = new ArrayList<>();
+ for (Object entry : (List>) value) {
+ adapters.add(new MapEntryAdapter(entry, field));
+ }
+ Collections.sort(adapters);
+ for (MapEntryAdapter adapter : adapters) {
+ printSingleField(field, adapter.getEntry(), generator);
+ }
+ } else if (field.isRepeated()) {
// Repeated field. Print each element.
for (Object element : (List>) value) {
printSingleField(field, element, generator);
@@ -429,6 +441,94 @@ public final class TextFormat {
}
}
+ /**
+ * An adapter class that can take a MapEntry or a MutableMapEntry and returns its key and entry.
+ * This class is created solely for the purpose of sorting map entries by its key and prevent
+ * duplicated logic by having a separate comparator for MapEntry and MutableMapEntry.
+ */
+ private static class MapEntryAdapter implements Comparable {
+ private Object entry;
+
+ @SuppressWarnings({"rawtypes"})
+ private MapEntry mapEntry;
+
+
+ private final FieldDescriptor.JavaType fieldType;
+
+ public MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
+ if (entry instanceof MapEntry) {
+ this.mapEntry = (MapEntry) entry;
+ } else {
+ this.entry = entry;
+ }
+ this.fieldType = extractFieldType(fieldDescriptor);
+ }
+
+ private static FieldDescriptor.JavaType extractFieldType(FieldDescriptor fieldDescriptor) {
+ return fieldDescriptor.getMessageType().getFields().get(0).getJavaType();
+ }
+
+ public Object getKey() {
+ if (mapEntry != null) {
+ return mapEntry.getKey();
+ }
+ return null;
+ }
+
+ public Object getEntry() {
+ if (mapEntry != null) {
+ return mapEntry;
+ }
+ return entry;
+ }
+
+ @Override
+ public int compareTo(MapEntryAdapter b) {
+ if (getKey() == null || b.getKey() == null) {
+ logger.info("Invalid key for map field.");
+ return -1;
+ }
+ switch (fieldType) {
+ case BOOLEAN:
+ boolean aBoolean = (boolean) getKey();
+ boolean bBoolean = (boolean) b.getKey();
+ if (aBoolean == bBoolean) {
+ return 0;
+ } else if (aBoolean) {
+ return 1;
+ } else {
+ return -1;
+ }
+ case LONG:
+ long aLong = (long) getKey();
+ long bLong = (long) b.getKey();
+ if (aLong < bLong) {
+ return -1;
+ } else if (aLong > bLong) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT:
+ return (int) getKey() - (int) b.getKey();
+ case STRING:
+ String aString = (String) getKey();
+ String bString = (String) b.getKey();
+ if (aString == null && bString == null) {
+ return 0;
+ } else if (aString == null && bString != null) {
+ return -1;
+ } else if (aString != null && bString == null) {
+ return 1;
+ } else {
+ return aString.compareTo(bString);
+ }
+ default:
+ return 0;
+ }
+ }
+ }
+
/**
* Outputs a textual representation of the value of given field value.
*
@@ -1708,6 +1808,12 @@ public final class TextFormat {
final Descriptor type = target.getDescriptorForType();
ExtensionRegistry.ExtensionInfo extension = null;
+ if ("google.protobuf.Any".equals(type.getFullName()) && tokenizer.tryConsume("[")) {
+ mergeAnyFieldValue(tokenizer, extensionRegistry, target, parseTreeBuilder, unknownFields,
+ type);
+ return;
+ }
+
if (tokenizer.tryConsume("[")) {
// An extension.
final StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier());
@@ -1928,9 +2034,13 @@ public final class TextFormat {
// Try to parse human readable format of Any in the form: [type_url]: { ... }
if (field.getMessageType().getFullName().equals("google.protobuf.Any")
&& tokenizer.tryConsume("[")) {
- value =
- consumeAnyFieldValue(
- tokenizer, extensionRegistry, field, parseTreeBuilder, unknownFields);
+ // Use Proto reflection here since depending on Any would intoduce a cyclic dependency
+ // (java_proto_library for any_java_proto depends on the protobuf_impl).
+ Message anyBuilder = DynamicMessage.getDefaultInstance(field.getMessageType());
+ MessageReflection.MergeTarget anyField = target.newMergeTargetForField(field, anyBuilder);
+ mergeAnyFieldValue(tokenizer, extensionRegistry, anyField, parseTreeBuilder,
+ unknownFields, field.getMessageType());
+ value = anyField.finish();
tokenizer.consume(endToken);
} else {
Message defaultInstance = (extension == null) ? null : extension.defaultInstance;
@@ -2052,12 +2162,13 @@ public final class TextFormat {
}
}
- private Object consumeAnyFieldValue(
+ private void mergeAnyFieldValue(
final Tokenizer tokenizer,
final ExtensionRegistry extensionRegistry,
- final FieldDescriptor field,
+ MergeTarget target,
final TextFormatParseInfoTree.Builder parseTreeBuilder,
- List unknownFields)
+ List unknownFields,
+ Descriptor anyDescriptor)
throws ParseException {
// Try to parse human readable format of Any in the form: [type_url]: { ... }
StringBuilder typeUrlBuilder = new StringBuilder();
@@ -2105,21 +2216,13 @@ public final class TextFormat {
mergeField(tokenizer, extensionRegistry, contentTarget, parseTreeBuilder, unknownFields);
}
- // Serialize the content and put it back into an Any. Note that we can't depend on Any here
- // because of a cyclic dependency (java_proto_library for any_java_proto depends on the
- // protobuf_impl), so we need to construct the Any using proto reflection.
- Descriptor anyDescriptor = field.getMessageType();
- Message.Builder anyBuilder =
- DynamicMessage.getDefaultInstance(anyDescriptor).newBuilderForType();
- anyBuilder.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
- anyBuilder.setField(
+ target.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
+ target.setField(
anyDescriptor.findFieldByName("value"), contentBuilder.build().toByteString());
-
- return anyBuilder.build();
}
/** Skips the next field including the field's name and value. */
- private void skipField(Tokenizer tokenizer) throws ParseException {
+ private static void skipField(Tokenizer tokenizer) throws ParseException {
if (tokenizer.tryConsume("[")) {
// Extension name.
do {
@@ -2151,7 +2254,7 @@ public final class TextFormat {
/**
* Skips the whole body of a message including the beginning delimiter and the ending delimiter.
*/
- private void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
+ private static void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
final String delimiter;
if (tokenizer.tryConsume("<")) {
delimiter = ">";
@@ -2166,7 +2269,7 @@ public final class TextFormat {
}
/** Skips a field value. */
- private void skipFieldValue(Tokenizer tokenizer) throws ParseException {
+ private static void skipFieldValue(Tokenizer tokenizer) throws ParseException {
if (tokenizer.tryConsumeString()) {
while (tokenizer.tryConsumeString()) {}
return;
diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
index 2f6315c80d..b2cb7be4ba 100644
--- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
+++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
@@ -301,7 +301,7 @@ public final class UnknownFieldSetLite {
return size;
}
- private static boolean equals(int[] tags1, int[] tags2, int count) {
+ private static boolean tagsEquals(int[] tags1, int[] tags2, int count) {
for (int i = 0; i < count; ++i) {
if (tags1[i] != tags2[i]) {
return false;
@@ -310,7 +310,7 @@ public final class UnknownFieldSetLite {
return true;
}
- private static boolean equals(Object[] objects1, Object[] objects2, int count) {
+ private static boolean objectsEquals(Object[] objects1, Object[] objects2, int count) {
for (int i = 0; i < count; ++i) {
if (!objects1[i].equals(objects2[i])) {
return false;
@@ -335,8 +335,8 @@ public final class UnknownFieldSetLite {
UnknownFieldSetLite other = (UnknownFieldSetLite) obj;
if (count != other.count
- || !equals(tags, other.tags, count)
- || !equals(objects, other.objects, count)) {
+ || !tagsEquals(tags, other.tags, count)
+ || !objectsEquals(objects, other.objects, count)) {
return false;
}
diff --git a/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
index ae50071398..805b7b042f 100644
--- a/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
+++ b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
@@ -140,6 +140,68 @@ public class BooleanArrayListTest extends TestCase {
}
}
+ public void testIndexOf_nullElement() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(null));
+ }
+
+ public void testIndexOf_incompatibleElementType() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
+ }
+
+ public void testIndexOf_notInList() {
+ assertEquals(-1, UNARY_LIST.indexOf(false));
+ }
+
+ public void testIndexOf_notInListWithDuplicates() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
+ assertEquals(-1, listWithDupes.indexOf(false));
+ }
+
+ public void testIndexOf_inList() {
+ assertEquals(1, TERTIARY_LIST.indexOf(false));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchAtHead() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
+ assertEquals(0, listWithDupes.indexOf(true));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchMidList() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
+ assertEquals(1, listWithDupes.indexOf(true));
+ }
+
+ public void testContains_nullElement() {
+ assertEquals(false, TERTIARY_LIST.contains(null));
+ }
+
+ public void testContains_incompatibleElementType() {
+ assertEquals(false, TERTIARY_LIST.contains(new Object()));
+ }
+
+ public void testContains_notInList() {
+ assertEquals(false, UNARY_LIST.contains(false));
+ }
+
+ public void testContains_notInListWithDuplicates() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
+ assertEquals(false, listWithDupes.contains(false));
+ }
+
+ public void testContains_inList() {
+ assertEquals(true, TERTIARY_LIST.contains(false));
+ }
+
+ public void testContains_inListWithDuplicates_matchAtHead() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
+ assertEquals(true, listWithDupes.contains(true));
+ }
+
+ public void testContains_inListWithDuplicates_matchMidList() {
+ BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
+ assertEquals(true, listWithDupes.contains(true));
+ }
+
public void testSize() {
assertEquals(0, BooleanArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size());
diff --git a/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
index 3a8254aa69..019b5a1444 100644
--- a/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
+++ b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
@@ -139,6 +139,68 @@ public class DoubleArrayListTest extends TestCase {
}
}
+ public void testIndexOf_nullElement() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(null));
+ }
+
+ public void testIndexOf_incompatibleElementType() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
+ }
+
+ public void testIndexOf_notInList() {
+ assertEquals(-1, UNARY_LIST.indexOf(2D));
+ }
+
+ public void testIndexOf_notInListWithDuplicates() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
+ assertEquals(-1, listWithDupes.indexOf(2D));
+ }
+
+ public void testIndexOf_inList() {
+ assertEquals(1, TERTIARY_LIST.indexOf(2D));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchAtHead() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
+ assertEquals(0, listWithDupes.indexOf(1D));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchMidList() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
+ assertEquals(1, listWithDupes.indexOf(1D));
+ }
+
+ public void testContains_nullElement() {
+ assertEquals(false, TERTIARY_LIST.contains(null));
+ }
+
+ public void testContains_incompatibleElementType() {
+ assertEquals(false, TERTIARY_LIST.contains(new Object()));
+ }
+
+ public void testContains_notInList() {
+ assertEquals(false, UNARY_LIST.contains(2D));
+ }
+
+ public void testContains_notInListWithDuplicates() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
+ assertEquals(false, listWithDupes.contains(2D));
+ }
+
+ public void testContains_inList() {
+ assertEquals(true, TERTIARY_LIST.contains(2D));
+ }
+
+ public void testContains_inListWithDuplicates_matchAtHead() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
+ assertEquals(true, listWithDupes.contains(1D));
+ }
+
+ public void testContains_inListWithDuplicates_matchMidList() {
+ DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
+ assertEquals(true, listWithDupes.contains(1D));
+ }
+
public void testSize() {
assertEquals(0, DoubleArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size());
diff --git a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
index db4ecfedaa..53ec6fe68c 100644
--- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
+++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
@@ -34,6 +34,7 @@ import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.OneofDescriptor;
import com.google.protobuf.FieldPresenceTestProto.TestAllTypes;
import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly;
import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly;
@@ -100,6 +101,7 @@ public class FieldPresenceTest extends TestCase {
UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OneofBytes");
}
+
public void testOneofEquals() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
TestAllTypes message1 = builder.build();
diff --git a/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
index 77a2839b90..091ac5bb78 100644
--- a/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
+++ b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
@@ -139,6 +139,68 @@ public class FloatArrayListTest extends TestCase {
}
}
+ public void testIndexOf_nullElement() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(null));
+ }
+
+ public void testIndexOf_incompatibleElementType() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
+ }
+
+ public void testIndexOf_notInList() {
+ assertEquals(-1, UNARY_LIST.indexOf(2F));
+ }
+
+ public void testIndexOf_notInListWithDuplicates() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
+ assertEquals(-1, listWithDupes.indexOf(2F));
+ }
+
+ public void testIndexOf_inList() {
+ assertEquals(1, TERTIARY_LIST.indexOf(2F));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchAtHead() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
+ assertEquals(0, listWithDupes.indexOf(1F));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchMidList() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
+ assertEquals(1, listWithDupes.indexOf(1F));
+ }
+
+ public void testContains_nullElement() {
+ assertEquals(false, TERTIARY_LIST.contains(null));
+ }
+
+ public void testContains_incompatibleElementType() {
+ assertEquals(false, TERTIARY_LIST.contains(new Object()));
+ }
+
+ public void testContains_notInList() {
+ assertEquals(false, UNARY_LIST.contains(2F));
+ }
+
+ public void testContains_notInListWithDuplicates() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
+ assertEquals(false, listWithDupes.contains(2F));
+ }
+
+ public void testContains_inList() {
+ assertEquals(true, TERTIARY_LIST.contains(2F));
+ }
+
+ public void testContains_inListWithDuplicates_matchAtHead() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
+ assertEquals(true, listWithDupes.contains(1F));
+ }
+
+ public void testContains_inListWithDuplicates_matchMidList() {
+ FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
+ assertEquals(true, listWithDupes.contains(1F));
+ }
+
public void testSize() {
assertEquals(0, FloatArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size());
diff --git a/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
index 51ebc987d0..2ad94f83de 100644
--- a/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
+++ b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
@@ -139,6 +139,68 @@ public class IntArrayListTest extends TestCase {
}
}
+ public void testIndexOf_nullElement() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(null));
+ }
+
+ public void testIndexOf_incompatibleElementType() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
+ }
+
+ public void testIndexOf_notInList() {
+ assertEquals(-1, UNARY_LIST.indexOf(2));
+ }
+
+ public void testIndexOf_notInListWithDuplicates() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
+ assertEquals(-1, listWithDupes.indexOf(2));
+ }
+
+ public void testIndexOf_inList() {
+ assertEquals(1, TERTIARY_LIST.indexOf(2));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchAtHead() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
+ assertEquals(0, listWithDupes.indexOf(1));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchMidList() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
+ assertEquals(1, listWithDupes.indexOf(1));
+ }
+
+ public void testContains_nullElement() {
+ assertEquals(false, TERTIARY_LIST.contains(null));
+ }
+
+ public void testContains_incompatibleElementType() {
+ assertEquals(false, TERTIARY_LIST.contains(new Object()));
+ }
+
+ public void testContains_notInList() {
+ assertEquals(false, UNARY_LIST.contains(2));
+ }
+
+ public void testContains_notInListWithDuplicates() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
+ assertEquals(false, listWithDupes.contains(2));
+ }
+
+ public void testContains_inList() {
+ assertEquals(true, TERTIARY_LIST.contains(2));
+ }
+
+ public void testContains_inListWithDuplicates_matchAtHead() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
+ assertEquals(true, listWithDupes.contains(1));
+ }
+
+ public void testContains_inListWithDuplicates_matchMidList() {
+ IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
+ assertEquals(true, listWithDupes.contains(1));
+ }
+
public void testSize() {
assertEquals(0, IntArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size());
diff --git a/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
index 1935100503..d6fbaf9d95 100644
--- a/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
+++ b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
@@ -139,6 +139,68 @@ public class LongArrayListTest extends TestCase {
}
}
+ public void testIndexOf_nullElement() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(null));
+ }
+
+ public void testIndexOf_incompatibleElementType() {
+ assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
+ }
+
+ public void testIndexOf_notInList() {
+ assertEquals(-1, UNARY_LIST.indexOf(2L));
+ }
+
+ public void testIndexOf_notInListWithDuplicates() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
+ assertEquals(-1, listWithDupes.indexOf(2L));
+ }
+
+ public void testIndexOf_inList() {
+ assertEquals(1, TERTIARY_LIST.indexOf(2L));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchAtHead() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
+ assertEquals(0, listWithDupes.indexOf(1L));
+ }
+
+ public void testIndexOf_inListWithDuplicates_matchMidList() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
+ assertEquals(1, listWithDupes.indexOf(1L));
+ }
+
+ public void testContains_nullElement() {
+ assertEquals(false, TERTIARY_LIST.contains(null));
+ }
+
+ public void testContains_incompatibleElementType() {
+ assertEquals(false, TERTIARY_LIST.contains(new Object()));
+ }
+
+ public void testContains_notInList() {
+ assertEquals(false, UNARY_LIST.contains(2L));
+ }
+
+ public void testContains_notInListWithDuplicates() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
+ assertEquals(false, listWithDupes.contains(2L));
+ }
+
+ public void testContains_inList() {
+ assertEquals(true, TERTIARY_LIST.contains(2L));
+ }
+
+ public void testContains_inListWithDuplicates_matchAtHead() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
+ assertEquals(true, listWithDupes.contains(1L));
+ }
+
+ public void testContains_inListWithDuplicates_matchMidList() {
+ LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
+ assertEquals(true, listWithDupes.contains(1L));
+ }
+
public void testSize() {
assertEquals(0, LongArrayList.emptyList().size());
assertEquals(1, UNARY_LIST.size());
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 dd0e8c847c..50ba0168da 100644
--- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java
+++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java
@@ -1536,4 +1536,42 @@ public class TextFormatTest extends TestCase {
index, line, column));
}
}
+
+ public void testSortMapFields() throws Exception {
+ TestMap message =
+ TestMap.newBuilder()
+ .putStringToInt32Field("cherry", 30)
+ .putStringToInt32Field("banana", 20)
+ .putStringToInt32Field("apple", 10)
+ .putInt32ToStringField(30, "cherry")
+ .putInt32ToStringField(20, "banana")
+ .putInt32ToStringField(10, "apple")
+ .build();
+ String text =
+ "int32_to_string_field {\n"
+ + " key: 10\n"
+ + " value: \"apple\"\n"
+ + "}\n"
+ + "int32_to_string_field {\n"
+ + " key: 20\n"
+ + " value: \"banana\"\n"
+ + "}\n"
+ + "int32_to_string_field {\n"
+ + " key: 30\n"
+ + " value: \"cherry\"\n"
+ + "}\n"
+ + "string_to_int32_field {\n"
+ + " key: \"apple\"\n"
+ + " value: 10\n"
+ + "}\n"
+ + "string_to_int32_field {\n"
+ + " key: \"banana\"\n"
+ + " value: 20\n"
+ + "}\n"
+ + "string_to_int32_field {\n"
+ + " key: \"cherry\"\n"
+ + " value: 30\n"
+ + "}\n";
+ assertEquals(text, TextFormat.printer().printToString(message));
+ }
}
diff --git a/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java b/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java
index 4a1d89b937..57e933f3a4 100755
--- a/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java
+++ b/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java
@@ -177,16 +177,20 @@ public final class Proto2MessageLiteInfoFactory implements MessageInfoFactory {
// To update this after a proto change, run protoc on proto2_message_lite.proto and copy over
// the content of the generated buildMessageInfo() method here.
java.lang.String info =
- "\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u0000\u0000\u0002\u0001\u0001\u0003"
- + "\u0002\u0002\u0004\u0003\u0003\u0005\u0004\u0004\u0006\u0005\u0005\u0007\u0006\u0006"
- + "\b\u0007\u0007\t\b\b\n\u0409\t\u000b\n\n\f\u000b\u000b\r\f\f\u000e\r\r\u000f\u000e"
- + "\u000e\u0010\u000f\u000f\u0011\u0010\u0010\u0012\u0012\u0013\u0013\u0014\u0014\u0015"
- + "\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c"
- + "\u001c\u001d\u001d\u001e\u001e\u001f\u001f !!\"\"##$$%%&&\'\'(())**++,,--..//00"
- + "1\u0011\u00113153\u000064\u000075\u000086\u000097\u0000:8\u0000;9\u0000<:\u0000="
- + ";\u0000>\u043c\u0000?=\u0000@>\u0000A@\u0000BA\u0000CB\u0000DC\u0000ED\u0000G\u0500"
- + "#H\u0501$I\u0502%J\u0503&K\u0504\'L\u0505(M\u0506)N\u0507*O\u0508+P\u0509,Q\u050a"
- + "-R\u050b.S\u050c/T\u050d0U\u050e1V\u050f2W\u05103X\u05114";
+ "\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u1000\u0000\u0002\u1001\u0001\u0003"
+ + "\u1002\u0002\u0004\u1003\u0003\u0005\u1004\u0004\u0006\u1005\u0005\u0007\u1006\u0006\b\u1007\u0007"
+ + "\t\u1008\b\n"
+ + "\u1409\t\u000b\u100a\n"
+ + "\f\u100b\u000b\r"
+ + "\u100c\f\u000e\u100d\r"
+ + "\u000f\u100e\u000e\u0010\u100f\u000f\u0011\u1010\u0010\u0012\u0012\u0013\u0013"
+ + "\u0014\u0014\u0015\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c\u001c\u001d\u001d\u001e\u001e\u001f\u001f"
+ + " !!\"\"##$$%%&&\'\'"
+ + "(())**++,,--..//001\u1011\u0011315\u1033\u00006\u1034\u00007\u1035\u00008\u1036\u0000"
+ + "9\u1037\u0000:\u1038\u0000;\u1039\u0000<\u103a\u0000=\u103b\u0000>\u143c\u0000?\u103d"
+ + "\u0000@\u103e\u0000A\u1040\u0000B\u1041\u0000C\u1042\u0000D\u1043\u0000E\u1044\u0000"
+ + "G\u1500#H\u1501$I\u1502%J\u1503&K\u1504\'L\u1505(M\u1506)N\u1507*O\u1508+P\u1509"
+ + ",Q\u150a-R\u150b.S\u150c/T\u150d0U\u150e1V\u150f2W\u15103X\u15114";
return new RawMessageInfo(Proto2MessageLite.getDefaultInstance(), info, objects);
}
diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
index 92458226ab..312d30fe22 100644
--- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
+++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
@@ -34,6 +34,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -49,7 +50,7 @@ import java.util.List;
/**
* Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
*/
-public class FieldMaskUtil {
+public final class FieldMaskUtil {
private static final String FIELD_PATH_SEPARATOR = ",";
private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
private static final String FIELD_SEPARATOR_REGEX = "\\.";
@@ -83,7 +84,7 @@ public class FieldMaskUtil {
*/
public static FieldMask fromString(String value) {
// TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead.
- return fromStringList(null, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
+ return fromStringList(Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
}
/**
@@ -103,14 +104,36 @@ public class FieldMaskUtil {
*/
// TODO(xiaofeng): Consider renaming fromStrings()
public static FieldMask fromStringList(Class extends Message> type, Iterable paths) {
+ return fromStringList(Internal.getDefaultInstance(type).getDescriptorForType(), paths);
+ }
+
+ /**
+ * Constructs a FieldMask for a list of field paths in a certain type.
+ *
+ * @throws IllegalArgumentException if any of the field path is not valid.
+ */
+ public static FieldMask fromStringList(Descriptor descriptor, Iterable paths) {
+ return fromStringList(Optional.of(descriptor), paths);
+ }
+
+ /**
+ * Constructs a FieldMask for a list of field paths in a certain type. Does not validate the given
+ * paths.
+ */
+ public static FieldMask fromStringList(Iterable paths) {
+ return fromStringList(Optional.absent(), paths);
+ }
+
+ private static FieldMask fromStringList(Optional descriptor, Iterable paths) {
FieldMask.Builder builder = FieldMask.newBuilder();
for (String path : paths) {
if (path.isEmpty()) {
// Ignore empty field paths.
continue;
}
- if (type != null && !isValid(type, path)) {
- throw new IllegalArgumentException(path + " is not a valid path for " + type);
+ if (descriptor.isPresent() && !isValid(descriptor.get(), path)) {
+ throw new IllegalArgumentException(
+ path + " is not a valid path for " + descriptor.get().getFullName());
}
builder.addPaths(path);
}
diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
index d9bcf8970a..67981435d1 100644
--- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
+++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
@@ -233,7 +233,7 @@ public class JsonFormat {
registry,
oldRegistry,
alwaysOutputDefaultValueFields,
- Collections.emptySet(),
+ includingDefaultValueFields,
preservingProtoFieldNames,
omittingInsignificantWhitespace,
true,
diff --git a/java/util/src/main/java/com/google/protobuf/util/Values.java b/java/util/src/main/java/com/google/protobuf/util/Values.java
index b3ade2ddfb..f03d70e0dc 100755
--- a/java/util/src/main/java/com/google/protobuf/util/Values.java
+++ b/java/util/src/main/java/com/google/protobuf/util/Values.java
@@ -71,8 +71,8 @@ public final class Values {
}
/**
- * Returns a Value with ListValue set to the appending the result of calling {@link #of(Object)}
- * on each element in the iterable.
+ * Returns a Value with ListValue set to the appending the result of calling {@link #of} on each
+ * element in the iterable.
*/
public static Value of(Iterable values) {
Value.Builder valueBuilder = Value.newBuilder();
diff --git a/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java b/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
index 1a99857053..78b470eda7 100644
--- a/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
+++ b/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
@@ -30,10 +30,12 @@
package com.google.protobuf.util;
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableList;
import com.google.protobuf.FieldMask;
import protobuf_unittest.UnittestProto.NestedTestAllTypes;
import protobuf_unittest.UnittestProto.TestAllTypes;
-
import junit.framework.TestCase;
/** Unit tests for {@link FieldMaskUtil}. */
@@ -172,6 +174,38 @@ public class FieldMaskUtilTest extends TestCase {
assertEquals("bar_baz", mask.getPaths(1));
}
+ public void testFromStringList() throws Exception {
+ FieldMask mask =
+ FieldMaskUtil.fromStringList(
+ NestedTestAllTypes.class, ImmutableList.of("payload.repeated_nested_message", "child"));
+ assertThat(mask)
+ .isEqualTo(
+ FieldMask.newBuilder()
+ .addPaths("payload.repeated_nested_message")
+ .addPaths("child")
+ .build());
+
+ mask =
+ FieldMaskUtil.fromStringList(
+ NestedTestAllTypes.getDescriptor(),
+ ImmutableList.of("payload.repeated_nested_message", "child"));
+ assertThat(mask)
+ .isEqualTo(
+ FieldMask.newBuilder()
+ .addPaths("payload.repeated_nested_message")
+ .addPaths("child")
+ .build());
+
+ mask =
+ FieldMaskUtil.fromStringList(ImmutableList.of("payload.repeated_nested_message", "child"));
+ assertThat(mask)
+ .isEqualTo(
+ FieldMask.newBuilder()
+ .addPaths("payload.repeated_nested_message")
+ .addPaths("child")
+ .build());
+ }
+
public void testUnion() throws Exception {
// Only test a simple case here and expect
// {@link FieldMaskTreeTest#testAddFieldPath} to cover all scenarios.
diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
index a06483192f..f9358e5221 100644
--- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
+++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
@@ -30,6 +30,7 @@
package com.google.protobuf.util;
+import com.google.common.collect.ImmutableSet;
import com.google.protobuf.Any;
import com.google.protobuf.BoolValue;
import com.google.protobuf.ByteString;
@@ -1784,4 +1785,16 @@ public class JsonFormatTest extends TestCase {
TestMap emptyMap = TestMap.getDefaultInstance();
assertEquals("{\n}", toSortedJsonString(emptyMap));
}
+
+ public void testPrintingEnumsAsIntsChainedAfterIncludingDefaultValueFields() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder().setOptionalBool(false).build();
+
+ assertEquals(
+ "{\n" + " \"optionalBool\": false\n" + "}",
+ JsonFormat.printer()
+ .includingDefaultValueFields(
+ ImmutableSet.of(message.getDescriptorForType().findFieldByName("optional_bool")))
+ .printingEnumsAsInts()
+ .print(message));
+ }
}
diff --git a/js/message_test.js b/js/message_test.js
index 3cac4c668d..3db8716b8c 100644
--- a/js/message_test.js
+++ b/js/message_test.js
@@ -1080,7 +1080,7 @@ describe('Message test suite', function() {
it('testMessageWithLargeFieldNumbers', function() {
var message = new proto.jspb.test.MessageWithLargeFieldNumbers;
-
+
message.setAString('string');
assertEquals('string', message.getAString());
diff --git a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
index e6362f2bfb..ea0edc5557 100644
--- a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
+++ b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
@@ -72,6 +72,7 @@ class Descriptor
->optional('oneof_index', \Google\Protobuf\Internal\GPBType::INT32, 9)
->optional('json_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FieldOptions')
+ ->optional('proto3_optional', \Google\Protobuf\Internal\GPBType::BOOL, 17)
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Type', \Google\Protobuf\Internal\Type::class)
diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
index b231c9e102..e00488e12e 100644
--- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
@@ -93,6 +93,20 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
*/
protected $options = null;
private $has_options = false;
+ /**
+ * If true, this is a proto3 "optional". When a proto3 field is optional, it
+ * tracks presence regardless of field type.
+ * For message fields this doesn't create any semantic change, since
+ * non-repeated message fields always track presence. However it still
+ * indicates the semantic detail of whether the user wrote "optional" or not.
+ * This can be useful for round-tripping the .proto file.
+ * Proto2 optional fields do not set this flag, because they already indicate
+ * optional with `LABEL_OPTIONAL`.
+ *
+ * Generated from protobuf field optional bool proto3_optional = 17;
+ */
+ protected $proto3_optional = false;
+ private $has_proto3_optional = false;
/**
* Constructor.
@@ -130,6 +144,15 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
* @type \Google\Protobuf\Internal\FieldOptions $options
+ * @type bool $proto3_optional
+ * If true, this is a proto3 "optional". When a proto3 field is optional, it
+ * tracks presence regardless of field type.
+ * For message fields this doesn't create any semantic change, since
+ * non-repeated message fields always track presence. However it still
+ * indicates the semantic detail of whether the user wrote "optional" or not.
+ * This can be useful for round-tripping the .proto file.
+ * Proto2 optional fields do not set this flag, because they already indicate
+ * optional with `LABEL_OPTIONAL`.
* }
*/
public function __construct($data = NULL) {
@@ -469,5 +492,51 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
return $this->has_options;
}
+ /**
+ * If true, this is a proto3 "optional". When a proto3 field is optional, it
+ * tracks presence regardless of field type.
+ * For message fields this doesn't create any semantic change, since
+ * non-repeated message fields always track presence. However it still
+ * indicates the semantic detail of whether the user wrote "optional" or not.
+ * This can be useful for round-tripping the .proto file.
+ * Proto2 optional fields do not set this flag, because they already indicate
+ * optional with `LABEL_OPTIONAL`.
+ *
+ * Generated from protobuf field optional bool proto3_optional = 17;
+ * @return bool
+ */
+ public function getProto3Optional()
+ {
+ return $this->proto3_optional;
+ }
+
+ /**
+ * If true, this is a proto3 "optional". When a proto3 field is optional, it
+ * tracks presence regardless of field type.
+ * For message fields this doesn't create any semantic change, since
+ * non-repeated message fields always track presence. However it still
+ * indicates the semantic detail of whether the user wrote "optional" or not.
+ * This can be useful for round-tripping the .proto file.
+ * Proto2 optional fields do not set this flag, because they already indicate
+ * optional with `LABEL_OPTIONAL`.
+ *
+ * Generated from protobuf field optional bool proto3_optional = 17;
+ * @param bool $var
+ * @return $this
+ */
+ public function setProto3Optional($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->proto3_optional = $var;
+ $this->has_proto3_optional = true;
+
+ return $this;
+ }
+
+ public function hasProto3Optional()
+ {
+ return $this->has_proto3_optional;
+ }
+
}
diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php
index 605d92bfda..892a6a8482 100644
--- a/php/src/Google/Protobuf/Internal/FileOptions.php
+++ b/php/src/Google/Protobuf/Internal/FileOptions.php
@@ -127,7 +127,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++.
*
- * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false];
+ * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = true];
*/
protected $cc_enable_arenas = false;
private $has_cc_enable_arenas = false;
@@ -732,7 +732,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++.
*
- * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false];
+ * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = true];
* @return bool
*/
public function getCcEnableArenas()
@@ -744,7 +744,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
* Enables the use of arenas for the proto messages in this file. This applies
* only to generated classes for C++.
*
- * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false];
+ * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = true];
* @param bool $var
* @return $this
*/
diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py
index 204f89b254..5ef81a2298 100755
--- a/python/google/protobuf/descriptor.py
+++ b/python/google/protobuf/descriptor.py
@@ -35,6 +35,7 @@ file, in types that make this information accessible in Python.
__author__ = 'robinson@google.com (Will Robinson)'
import threading
+import warnings
import six
from google.protobuf.internal import api_implementation
@@ -91,6 +92,25 @@ class _Lock(object):
_lock = threading.Lock()
+def _Deprecated(name):
+ if _Deprecated.count > 0:
+ _Deprecated.count -= 1
+ warnings.warn(
+ 'Call to deprecated create function %s(). Note: Create unlinked '
+ 'descriptors is going to go away. Please use get/find descriptors from '
+ 'generated code or query the descriptor_pool.'
+ % name,
+ category=DeprecationWarning, stacklevel=3)
+
+
+# Deprecated warnings will print 100 times at most which should be enough for
+# users to notice and do not cause timeout.
+_Deprecated.count = 100
+
+
+_internal_create_key = object()
+
+
class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""Descriptors base class.
@@ -271,7 +291,7 @@ class Descriptor(_NestedDescriptorBase):
serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
- syntax=None):
+ syntax=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindMessageTypeByName(full_name)
@@ -283,13 +303,16 @@ class Descriptor(_NestedDescriptorBase):
serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
- syntax=None):
+ syntax=None, create_key=None):
"""Arguments to __init__() are as described in the description
of Descriptor fields above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
+ if create_key is not _internal_create_key:
+ _Deprecated('Descriptor')
+
super(Descriptor, self).__init__(
options, 'MessageOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
@@ -515,7 +538,7 @@ class FieldDescriptor(DescriptorBase):
is_extension, extension_scope, options=None,
serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
_message.Message._CheckCalledFromGeneratedFile()
if is_extension:
return _message.default_pool.FindExtensionByName(full_name)
@@ -527,7 +550,7 @@ class FieldDescriptor(DescriptorBase):
is_extension, extension_scope, options=None,
serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
"""The arguments are as described in the description of FieldDescriptor
attributes above.
@@ -535,6 +558,9 @@ class FieldDescriptor(DescriptorBase):
(to deal with circular references between message types, for example).
Likewise for extension_scope.
"""
+ if create_key is not _internal_create_key:
+ _Deprecated('FieldDescriptor')
+
super(FieldDescriptor, self).__init__(
options, serialized_options, 'FieldOptions')
self.name = name
@@ -628,19 +654,22 @@ class EnumDescriptor(_NestedDescriptorBase):
def __new__(cls, name, full_name, filename, values,
containing_type=None, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None):
+ serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindEnumTypeByName(full_name)
def __init__(self, name, full_name, filename, values,
containing_type=None, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None):
+ serialized_start=None, serialized_end=None, create_key=None):
"""Arguments are as described in the attribute description above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumDescriptor')
+
super(EnumDescriptor, self).__init__(
options, 'EnumOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
@@ -684,7 +713,7 @@ class EnumValueDescriptor(DescriptorBase):
def __new__(cls, name, index, number,
type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None):
+ options=None, serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
# There is no way we can build a complete EnumValueDescriptor with the
# given parameters (the name of the Enum is not known, for example).
@@ -694,8 +723,11 @@ class EnumValueDescriptor(DescriptorBase):
def __init__(self, name, index, number,
type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None):
+ options=None, serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumValueDescriptor')
+
super(EnumValueDescriptor, self).__init__(
options, serialized_options, 'EnumValueOptions')
self.name = name
@@ -724,14 +756,17 @@ class OneofDescriptor(DescriptorBase):
def __new__(
cls, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None):
+ serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindOneofByName(full_name)
def __init__(
self, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None):
+ serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
+ if create_key is not _internal_create_key:
+ _Deprecated('OneofDescriptor')
+
super(OneofDescriptor, self).__init__(
options, serialized_options, 'OneofOptions')
self.name = name
@@ -765,13 +800,16 @@ class ServiceDescriptor(_NestedDescriptorBase):
def __new__(cls, name, full_name, index, methods, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None):
+ serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindServiceByName(full_name)
def __init__(self, name, full_name, index, methods, options=None,
serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None):
+ serialized_start=None, serialized_end=None, create_key=None):
+ if create_key is not _internal_create_key:
+ _Deprecated('ServiceDescriptor')
+
super(ServiceDescriptor, self).__init__(
options, 'ServiceOptions', name, full_name, file,
None, serialized_start=serialized_start,
@@ -826,17 +864,22 @@ class MethodDescriptor(DescriptorBase):
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor
def __new__(cls, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindMethodByName(full_name)
def __init__(self, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
"""The arguments are as described in the description of MethodDescriptor
attributes above.
Note that containing_service may be None, and may be set later if necessary.
"""
+ if create_key is not _internal_create_key:
+ _Deprecated('MethodDescriptor')
+
super(MethodDescriptor, self).__init__(
options, serialized_options, 'MethodOptions')
self.name = name
@@ -884,11 +927,11 @@ class FileDescriptor(DescriptorBase):
def __new__(cls, name, package, options=None,
serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None):
+ syntax=None, pool=None, create_key=None):
# FileDescriptor() is called from various places, not only from generated
# files, to register dynamic proto files and messages.
# pylint: disable=g-explicit-bool-comparison
- if serialized_pb == '':
+ if serialized_pb == b'':
# Cpp generated code must be linked in if serialized_pb is ''
try:
return _message.default_pool.FindFileByName(name)
@@ -902,8 +945,11 @@ class FileDescriptor(DescriptorBase):
def __init__(self, name, package, options=None,
serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None):
+ syntax=None, pool=None, create_key=None):
"""Constructor."""
+ if create_key is not _internal_create_key:
+ _Deprecated('FileDescriptor')
+
super(FileDescriptor, self).__init__(
options, serialized_options, 'FileOptions')
@@ -1042,9 +1088,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
for enum_proto in desc_proto.enum_type:
full_name = '.'.join(full_message_name + [enum_proto.name])
enum_desc = EnumDescriptor(
- enum_proto.name, full_name, None, [
- EnumValueDescriptor(enum_val.name, ii, enum_val.number)
- for ii, enum_val in enumerate(enum_proto.value)])
+ enum_proto.name, full_name, None, [
+ EnumValueDescriptor(enum_val.name, ii, enum_val.number,
+ create_key=_internal_create_key)
+ for ii, enum_val in enumerate(enum_proto.value)],
+ create_key=_internal_create_key)
enum_types[full_name] = enum_desc
# Create Descriptors for nested types
@@ -1083,10 +1131,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
field_proto.label, None, nested_desc, enum_desc, None, False, None,
options=_OptionsOrNone(field_proto), has_default_value=False,
- json_name=json_name)
+ json_name=json_name, create_key=_internal_create_key)
fields.append(field)
desc_name = '.'.join(full_message_name)
return Descriptor(desc_proto.name, desc_name, None, None, fields,
list(nested_types.values()), list(enum_types.values()), [],
- options=_OptionsOrNone(desc_proto))
+ options=_OptionsOrNone(desc_proto),
+ create_key=_internal_create_key)
diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py
index 078d39a9f5..de9100b09c 100644
--- a/python/google/protobuf/descriptor_pool.py
+++ b/python/google/protobuf/descriptor_pool.py
@@ -619,7 +619,7 @@ class DescriptorPool(object):
def FindAllExtensions(self, message_descriptor):
"""Gets all the known extensions of a given message.
- Extensions have to be registered to this pool by calling
+ Extensions have to be registered to this pool by build related
:func:`Add` or :func:`AddExtensionDescriptor`.
Args:
@@ -662,18 +662,7 @@ class DescriptorPool(object):
return
try:
- file_desc = self._ConvertFileProtoToFileDescriptor(file_proto)
- for extension in file_desc.extensions_by_name.values():
- self._extensions_by_number[extension.containing_type][
- extension.number] = extension
- self._extensions_by_name[extension.containing_type][
- extension.full_name] = extension
- for message_type in file_desc.message_types_by_name.values():
- for extension in message_type.extensions:
- self._extensions_by_number[extension.containing_type][
- extension.number] = extension
- self._extensions_by_name[extension.containing_type][
- extension.full_name] = extension
+ self._ConvertFileProtoToFileDescriptor(file_proto)
except:
warn_msg = ('Unable to load proto file %s for extension number %d.' %
(file_proto.name, number))
@@ -761,7 +750,9 @@ class DescriptorPool(object):
options=_OptionsOrNone(file_proto),
serialized_pb=file_proto.SerializeToString(),
dependencies=direct_deps,
- public_dependencies=public_deps)
+ public_dependencies=public_deps,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope = {}
# This loop extracts all the message and enum types from all the
@@ -820,7 +811,15 @@ class DescriptorPool(object):
self.Add(file_proto)
self._file_descriptors[file_proto.name] = file_descriptor
- return self._file_descriptors[file_proto.name]
+ # Add extensions to the pool
+ file_desc = self._file_descriptors[file_proto.name]
+ for extension in file_desc.extensions_by_name.values():
+ self._AddExtensionDescriptor(extension)
+ for message_type in file_desc.message_types_by_name.values():
+ for extension in message_type.extensions:
+ self._AddExtensionDescriptor(extension)
+
+ return file_desc
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
scope=None, syntax=None):
@@ -865,8 +864,11 @@ class DescriptorPool(object):
is_extension=True)
for index, extension in enumerate(desc_proto.extension)]
oneofs = [
+ # pylint: disable=g-complex-comprehension
descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
- index, None, [], desc.options)
+ index, None, [], desc.options,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for index, desc in enumerate(desc_proto.oneof_decl)]
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
if extension_ranges:
@@ -889,7 +891,9 @@ class DescriptorPool(object):
file=file_desc,
serialized_start=None,
serialized_end=None,
- syntax=syntax)
+ syntax=syntax,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for nested in desc.nested_types:
nested.containing_type = desc
for enum in desc.enum_types:
@@ -940,7 +944,9 @@ class DescriptorPool(object):
file=file_desc,
values=values,
containing_type=containing_type,
- options=_OptionsOrNone(enum_proto))
+ options=_OptionsOrNone(enum_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope['.%s' % enum_name] = desc
self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._enum_descriptors[enum_name] = desc
@@ -997,7 +1003,9 @@ class DescriptorPool(object):
is_extension=is_extension,
extension_scope=None,
options=_OptionsOrNone(field_proto),
- file=file_desc)
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _SetAllFieldTypes(self, package, desc_proto, scope):
"""Sets all the descriptor's fields's types.
@@ -1121,7 +1129,9 @@ class DescriptorPool(object):
index=index,
number=value_proto.number,
options=_OptionsOrNone(value_proto),
- type=None)
+ type=None,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
@@ -1146,12 +1156,15 @@ class DescriptorPool(object):
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
- desc = descriptor.ServiceDescriptor(name=service_proto.name,
- full_name=service_name,
- index=service_index,
- methods=methods,
- options=_OptionsOrNone(service_proto),
- file=file_desc)
+ desc = descriptor.ServiceDescriptor(
+ name=service_proto.name,
+ full_name=service_name,
+ index=service_index,
+ methods=methods,
+ options=_OptionsOrNone(service_proto),
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._service_descriptors[service_name] = desc
return desc
@@ -1175,13 +1188,16 @@ class DescriptorPool(object):
package, method_proto.input_type, scope)
output_type = self._GetTypeFromScope(
package, method_proto.output_type, scope)
- return descriptor.MethodDescriptor(name=method_proto.name,
- full_name=full_name,
- index=index,
- containing_service=None,
- input_type=input_type,
- output_type=output_type,
- options=_OptionsOrNone(method_proto))
+ return descriptor.MethodDescriptor(
+ name=method_proto.name,
+ full_name=full_name,
+ index=index,
+ containing_service=None,
+ input_type=input_type,
+ output_type=output_type,
+ options=_OptionsOrNone(method_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _ExtractSymbols(self, descriptors):
"""Pulls out all the symbols from descriptor protos.
diff --git a/python/google/protobuf/internal/decoder.py b/python/google/protobuf/internal/decoder.py
index c04df8e294..092dab5862 100755
--- a/python/google/protobuf/internal/decoder.py
+++ b/python/google/protobuf/internal/decoder.py
@@ -816,8 +816,12 @@ def MessageSetItemDecoder(descriptor):
if extension is not None:
value = field_dict.get(extension)
if value is None:
+ message_type = extension.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ message._FACTORY.GetPrototype(message_type)
value = field_dict.setdefault(
- extension, extension.message_type._concrete_class())
+ extension, message_type._concrete_class())
if value._InternalParse(buffer, message_start,message_end) != message_end:
# The only reason _InternalParse would return early is if it encountered
# an end-group tag.
diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py
index ad1eb653fd..fed82bfc7a 100644
--- a/python/google/protobuf/internal/descriptor_pool_test.py
+++ b/python/google/protobuf/internal/descriptor_pool_test.py
@@ -36,6 +36,7 @@ __author__ = 'matthewtoia@google.com (Matt Toia)'
import copy
import os
+import warnings
try:
import unittest2 as unittest #PY26
@@ -63,6 +64,9 @@ from google.protobuf import symbol_database
+warnings.simplefilter('error', DeprecationWarning)
+
+
class DescriptorPoolTestBase(object):
def testFindFileByName(self):
@@ -336,12 +340,10 @@ class DescriptorPoolTestBase(object):
'google.protobuf.python.internal.Factory2Message')
# An extension defined in a message.
one_more_field = factory2_message.extensions_by_name['one_more_field']
- self.pool.AddExtensionDescriptor(one_more_field)
# An extension defined at file scope.
factory_test2 = self.pool.FindFileByName(
'google/protobuf/internal/factory_test2.proto')
another_field = factory_test2.extensions_by_name['another_field']
- self.pool.AddExtensionDescriptor(another_field)
extensions = self.pool.FindAllExtensions(factory1_message)
expected_extension_numbers = set([one_more_field, another_field])
@@ -356,16 +358,9 @@ class DescriptorPoolTestBase(object):
def testFindExtensionByNumber(self):
factory1_message = self.pool.FindMessageTypeByName(
'google.protobuf.python.internal.Factory1Message')
- factory2_message = self.pool.FindMessageTypeByName(
- 'google.protobuf.python.internal.Factory2Message')
- # An extension defined in a message.
- one_more_field = factory2_message.extensions_by_name['one_more_field']
- self.pool.AddExtensionDescriptor(one_more_field)
- # An extension defined at file scope.
- factory_test2 = self.pool.FindFileByName(
+ # Build factory_test2.proto which will put extensions to the pool
+ self.pool.FindFileByName(
'google/protobuf/internal/factory_test2.proto')
- another_field = factory_test2.extensions_by_name['another_field']
- self.pool.AddExtensionDescriptor(another_field)
# An extension defined in a message.
extension = self.pool.FindExtensionByNumber(factory1_message, 1001)
@@ -533,13 +528,13 @@ class DescriptorPoolTestBase(object):
else:
pool = copy.deepcopy(self.pool)
file_descriptor = unittest_pb2.DESCRIPTOR
- pool.AddDescriptor(
+ pool._AddDescriptor(
file_descriptor.message_types_by_name['TestAllTypes'])
- pool.AddEnumDescriptor(
+ pool._AddEnumDescriptor(
file_descriptor.enum_types_by_name['ForeignEnum'])
- pool.AddServiceDescriptor(
+ pool._AddServiceDescriptor(
file_descriptor.services_by_name['TestService'])
- pool.AddExtensionDescriptor(
+ pool._AddExtensionDescriptor(
file_descriptor.extensions_by_name['optional_int32_extension'])
pool.Add(unittest_fd)
pool.Add(conflict_fd)
@@ -873,7 +868,7 @@ class AddDescriptorTest(unittest.TestCase):
def _TestMessage(self, prefix):
pool = descriptor_pool.DescriptorPool()
- pool.AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR)
+ pool._AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR)
self.assertEqual(
'protobuf_unittest.TestAllTypes',
pool.FindMessageTypeByName(
@@ -884,7 +879,7 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindMessageTypeByName(
prefix + 'protobuf_unittest.TestAllTypes.NestedMessage')
- pool.AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR)
+ pool._AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR)
self.assertEqual(
'protobuf_unittest.TestAllTypes.NestedMessage',
pool.FindMessageTypeByName(
@@ -909,7 +904,10 @@ class AddDescriptorTest(unittest.TestCase):
def _TestEnum(self, prefix):
pool = descriptor_pool.DescriptorPool()
- pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
+ if api_implementation.Type() == 'cpp':
+ pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
+ else:
+ pool._AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
self.assertEqual(
'protobuf_unittest.ForeignEnum',
pool.FindEnumTypeByName(
@@ -920,7 +918,10 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindEnumTypeByName(
prefix + 'protobuf_unittest.ForeignEnum.NestedEnum')
- pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
+ if api_implementation.Type() == 'cpp':
+ pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
+ else:
+ pool._AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
self.assertEqual(
'protobuf_unittest.TestAllTypes.NestedEnum',
pool.FindEnumTypeByName(
@@ -949,7 +950,7 @@ class AddDescriptorTest(unittest.TestCase):
pool = descriptor_pool.DescriptorPool()
with self.assertRaises(KeyError):
pool.FindServiceByName('protobuf_unittest.TestService')
- pool.AddServiceDescriptor(unittest_pb2._TESTSERVICE)
+ pool._AddServiceDescriptor(unittest_pb2._TESTSERVICE)
self.assertEqual(
'protobuf_unittest.TestService',
pool.FindServiceByName('protobuf_unittest.TestService').full_name)
@@ -958,7 +959,7 @@ class AddDescriptorTest(unittest.TestCase):
'With the cpp implementation, Add() must be called first')
def testFile(self):
pool = descriptor_pool.DescriptorPool()
- pool.AddFileDescriptor(unittest_pb2.DESCRIPTOR)
+ pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR)
self.assertEqual(
'google/protobuf/unittest.proto',
pool.FindFileByName(
@@ -1032,16 +1033,28 @@ class AddDescriptorTest(unittest.TestCase):
def testAddTypeError(self):
pool = descriptor_pool.DescriptorPool()
- with self.assertRaises(TypeError):
- pool.AddDescriptor(0)
- with self.assertRaises(TypeError):
- pool.AddEnumDescriptor(0)
- with self.assertRaises(TypeError):
- pool.AddServiceDescriptor(0)
- with self.assertRaises(TypeError):
- pool.AddExtensionDescriptor(0)
- with self.assertRaises(TypeError):
- pool.AddFileDescriptor(0)
+ if api_implementation.Type() == 'cpp':
+ with self.assertRaises(TypeError):
+ pool.AddDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool.AddEnumDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool.AddServiceDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool.AddExtensionDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool.AddFileDescriptor(0)
+ else:
+ with self.assertRaises(TypeError):
+ pool._AddDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool._AddEnumDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool._AddServiceDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool._AddExtensionDescriptor(0)
+ with self.assertRaises(TypeError):
+ pool._AddFileDescriptor(0)
TEST1_FILE = ProtoFile(
diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py
index bff2d5f548..5e3b0a9b4c 100755
--- a/python/google/protobuf/internal/descriptor_test.py
+++ b/python/google/protobuf/internal/descriptor_test.py
@@ -35,6 +35,7 @@
__author__ = 'robinson@google.com (Will Robinson)'
import sys
+import warnings
try:
import unittest2 as unittest #PY26
@@ -58,6 +59,9 @@ name: 'TestEmptyMessage'
"""
+warnings.simplefilter('error', DeprecationWarning)
+
+
class DescriptorTest(unittest.TestCase):
def setUp(self):
diff --git a/python/google/protobuf/internal/extension_dict.py b/python/google/protobuf/internal/extension_dict.py
index d08df4a8f9..b346cf283e 100644
--- a/python/google/protobuf/internal/extension_dict.py
+++ b/python/google/protobuf/internal/extension_dict.py
@@ -87,6 +87,10 @@ class _ExtensionDict(object):
if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
result = extension_handle._default_constructor(self._extended_message)
elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ message_type = extension_handle.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ self._extended_message._FACTORY.GetPrototype(message_type)
assert getattr(extension_handle.message_type, '_concrete_class', None), (
'Uninitialized concrete class found for field %r (message type %r)'
% (extension_handle.full_name,
diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py
index e3992f99ba..d5245f4786 100644
--- a/python/google/protobuf/internal/json_format_test.py
+++ b/python/google/protobuf/internal/json_format_test.py
@@ -821,6 +821,10 @@ class JsonFormatTest(JsonFormatBase):
def testFloatPrecision(self):
message = json_format_proto3_pb2.TestMessage()
message.float_value = 1.123456789
+ # Default to 8 valid digits.
+ text = '{\n "floatValue": 1.1234568\n}'
+ self.assertEqual(
+ json_format.MessageToJson(message), text)
# Set to 7 valid digits.
text = '{\n "floatValue": 1.123457\n}'
self.assertEqual(
diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py
index f12b531f8b..097c082c80 100755
--- a/python/google/protobuf/internal/message_test.py
+++ b/python/google/protobuf/internal/message_test.py
@@ -106,6 +106,9 @@ def IsNegInf(val):
return isinf(val) and (val < 0)
+warnings.simplefilter('error', DeprecationWarning)
+
+
@_parameterized.named_parameters(
('_proto2', unittest_pb2),
('_proto3', unittest_proto3_arena_pb2))
@@ -438,12 +441,19 @@ class MessageTest(unittest.TestCase):
self.assertEqual(str(message), 'optional_float: 2.0\n')
def testHighPrecisionFloatPrinting(self, message_module):
- message = message_module.TestAllTypes()
- message.optional_double = 0.12345678912345678
+ msg = message_module.TestAllTypes()
+ msg.optional_float = 0.12345678912345678
+ old_float = msg.optional_float
+ msg.ParseFromString(msg.SerializeToString())
+ self.assertEqual(old_float, msg.optional_float)
+
+ def testHighPrecisionDoublePrinting(self, message_module):
+ msg = message_module.TestAllTypes()
+ msg.optional_double = 0.12345678912345678
if sys.version_info >= (3,):
- self.assertEqual(str(message), 'optional_double: 0.12345678912345678\n')
+ self.assertEqual(str(msg), 'optional_double: 0.12345678912345678\n')
else:
- self.assertEqual(str(message), 'optional_double: 0.123456789123\n')
+ self.assertEqual(str(msg), 'optional_double: 0.123456789123\n')
def testUnknownFieldPrinting(self, message_module):
populated = message_module.TestAllTypes()
@@ -885,11 +895,13 @@ class MessageTest(unittest.TestCase):
def testOneofDefaultValues(self, message_module):
m = message_module.TestAllTypes()
self.assertIs(None, m.WhichOneof('oneof_field'))
+ self.assertFalse(m.HasField('oneof_field'))
self.assertFalse(m.HasField('oneof_uint32'))
# Oneof is set even when setting it to a default value.
m.oneof_uint32 = 0
self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field'))
+ self.assertTrue(m.HasField('oneof_field'))
self.assertTrue(m.HasField('oneof_uint32'))
self.assertFalse(m.HasField('oneof_string'))
diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py
index 8fb1946027..0691a4c94e 100755
--- a/python/google/protobuf/internal/python_message.py
+++ b/python/google/protobuf/internal/python_message.py
@@ -124,9 +124,16 @@ class GeneratedProtocolMessageType(type):
Returns:
Newly-allocated class.
+
+ Raises:
+ RuntimeError: Generated code only work with python cpp extension.
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
+ if isinstance(descriptor, str):
+ raise RuntimeError('The generated code only work with python cpp '
+ 'extension, but it is using pure python runtime.')
+
# If a concrete class already exists for this descriptor, don't try to
# create another. Doing so will break any messages that already exist with
# the existing class.
@@ -838,10 +845,9 @@ def _AddHasFieldMethod(message_descriptor, cls):
continue
hassable_fields[field.name] = field
- if not is_proto3:
- # Fields inside oneofs are never repeated (enforced by the compiler).
- for oneof in message_descriptor.oneofs:
- hassable_fields[oneof.name] = oneof
+ # Has methods are supported for oneof descriptors.
+ for oneof in message_descriptor.oneofs:
+ hassable_fields[oneof.name] = oneof
def HasField(self, field_name):
try:
diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py
index dace15447c..e67248fa62 100755
--- a/python/google/protobuf/internal/reflection_test.py
+++ b/python/google/protobuf/internal/reflection_test.py
@@ -40,6 +40,7 @@ import gc
import operator
import six
import struct
+import warnings
try:
import unittest2 as unittest #PY26
@@ -70,6 +71,9 @@ if six.PY3:
long = int # pylint: disable=redefined-builtin,invalid-name
+warnings.simplefilter('error', DeprecationWarning)
+
+
class _MiniDecoder(object):
"""Decodes a stream of values from a string.
@@ -1433,12 +1437,16 @@ class Proto2ReflectionTest(unittest.TestCase):
label=FieldDescriptor.LABEL_OPTIONAL, default_value=0,
containing_type=None, message_type=None, enum_type=None,
is_extension=False, extension_scope=None,
- options=descriptor_pb2.FieldOptions())
+ options=descriptor_pb2.FieldOptions(),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
mydescriptor = descriptor.Descriptor(
name='MyProto', full_name='MyProto', filename='ignored',
containing_type=None, nested_types=[], enum_types=[],
fields=[foo_field_descriptor], extensions=[],
- options=descriptor_pb2.MessageOptions())
+ options=descriptor_pb2.MessageOptions(),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
class MyProtoClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)):
DESCRIPTOR = mydescriptor
myproto_instance = MyProtoClass()
@@ -3168,22 +3176,34 @@ class ClassAPITest(unittest.TestCase):
'C++ implementation requires a call to MakeDescriptor()')
@testing_refleaks.SkipReferenceLeakChecker('MakeClass is not repeatable')
def testMakeClassWithNestedDescriptor(self):
- leaf_desc = descriptor.Descriptor('leaf', 'package.parent.child.leaf', '',
- containing_type=None, fields=[],
- nested_types=[], enum_types=[],
- extensions=[])
- child_desc = descriptor.Descriptor('child', 'package.parent.child', '',
- containing_type=None, fields=[],
- nested_types=[leaf_desc], enum_types=[],
- extensions=[])
- sibling_desc = descriptor.Descriptor('sibling', 'package.parent.sibling',
- '', containing_type=None, fields=[],
- nested_types=[], enum_types=[],
- extensions=[])
- parent_desc = descriptor.Descriptor('parent', 'package.parent', '',
- containing_type=None, fields=[],
- nested_types=[child_desc, sibling_desc],
- enum_types=[], extensions=[])
+ leaf_desc = descriptor.Descriptor(
+ 'leaf', 'package.parent.child.leaf', '',
+ containing_type=None, fields=[],
+ nested_types=[], enum_types=[],
+ extensions=[],
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
+ child_desc = descriptor.Descriptor(
+ 'child', 'package.parent.child', '',
+ containing_type=None, fields=[],
+ nested_types=[leaf_desc], enum_types=[],
+ extensions=[],
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
+ sibling_desc = descriptor.Descriptor(
+ 'sibling', 'package.parent.sibling',
+ '', containing_type=None, fields=[],
+ nested_types=[], enum_types=[],
+ extensions=[],
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
+ parent_desc = descriptor.Descriptor(
+ 'parent', 'package.parent', '',
+ containing_type=None, fields=[],
+ nested_types=[child_desc, sibling_desc],
+ enum_types=[], extensions=[],
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
reflection.MakeClass(parent_desc)
def _GetSerializedFileDescriptor(self, name):
@@ -3305,4 +3325,3 @@ class ClassAPITest(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
-
diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py
index 89520887ae..b7d2333b31 100755
--- a/python/google/protobuf/internal/text_format_test.py
+++ b/python/google/protobuf/internal/text_format_test.py
@@ -2194,5 +2194,23 @@ class WhitespaceTest(TextFormatBase):
}"""))
+class OptionalColonMessageToStringTest(unittest.TestCase):
+
+ def testForcePrintOptionalColon(self):
+ packed_message = unittest_pb2.OneString()
+ packed_message.data = 'string'
+ message = any_test_pb2.TestAny()
+ message.any_value.Pack(packed_message)
+ output = text_format.MessageToString(
+ message,
+ force_colon=True)
+ expected = ('any_value: {\n'
+ ' [type.googleapis.com/protobuf_unittest.OneString]: {\n'
+ ' data: "string"\n'
+ ' }\n'
+ '}\n')
+ self.assertEqual(expected, output)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/python/google/protobuf/internal/type_checkers.py b/python/google/protobuf/internal/type_checkers.py
index 8deba47507..f7690085f7 100755
--- a/python/google/protobuf/internal/type_checkers.py
+++ b/python/google/protobuf/internal/type_checkers.py
@@ -45,6 +45,11 @@ TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
__author__ = 'robinson@google.com (Will Robinson)'
+try:
+ import ctypes
+except Exception: # pylint: disable=broad-except
+ ctypes = None
+ import struct
import numbers
import six
@@ -257,9 +262,10 @@ class FloatValueChecker(object):
if converted_value < _FLOAT_MIN:
return _NEG_INF
- return converted_value
- # TODO(jieluo): convert to 4 bytes float (c style float) at setters:
- # return struct.unpack('f', struct.pack('f', converted_value))
+ if ctypes:
+ return ctypes.c_float(converted_value).value
+ else:
+ return struct.unpack('file()->syntax() == FileDescriptor::SYNTAX_PROTO3) {
- // HasField() for a oneof *itself* isn't supported.
- if (in_oneof) {
- PyErr_Format(PyExc_ValueError,
- "Can't test oneof field \"%s.%s\" for presence in proto3, "
- "use WhichOneof instead.", message_name.c_str(),
- field_descriptor->containing_oneof()->name().c_str());
- return false;
- }
-
- // ...but HasField() for fields *in* a oneof is supported.
+ // HasField() is supported for oneof fields.
if (field_descriptor->containing_oneof() != NULL) {
return true;
}
diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc
index 4bb35b3193..63d60b70e7 100644
--- a/python/google/protobuf/pyext/message_module.cc
+++ b/python/google/protobuf/pyext/message_module.cc
@@ -107,9 +107,12 @@ PyMODINIT_FUNC INITFUNC() {
}
// Adds the C++ API
- if (PyObject* api =
- PyCapsule_New(new ApiImplementation(),
- google::protobuf::python::PyProtoAPICapsuleName(), NULL)) {
+ if (PyObject* api = PyCapsule_New(
+ new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
+ [](PyObject* o) {
+ delete (ApiImplementation*)PyCapsule_GetPointer(
+ o, google::protobuf::python::PyProtoAPICapsuleName());
+ })) {
PyModule_AddObject(m, "proto_API", api);
} else {
return INITFUNC_ERRORVAL;
diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py
index bc9060bcfa..9c2b26720e 100755
--- a/python/google/protobuf/text_format.py
+++ b/python/google/protobuf/text_format.py
@@ -132,7 +132,8 @@ def MessageToString(message,
descriptor_pool=None,
indent=0,
message_formatter=None,
- print_unknown_fields=False):
+ print_unknown_fields=False,
+ force_colon=False):
# type: (...) -> str
"""Convert protobuf message to text format.
@@ -170,17 +171,28 @@ def MessageToString(message,
Custom formatter for selected sub-messages (usually based on message
type). Use to pretty print parts of the protobuf for easier diffing.
print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if the
+ field is a proto message.
Returns:
str: A string of the text formatted protocol buffer message.
"""
out = TextWriter(as_utf8)
- printer = _Printer(out, indent, as_utf8, as_one_line,
- use_short_repeated_primitives, pointy_brackets,
- use_index_order, float_format, double_format,
- use_field_number,
- descriptor_pool, message_formatter,
- print_unknown_fields=print_unknown_fields)
+ printer = _Printer(
+ out,
+ indent,
+ as_utf8,
+ as_one_line,
+ use_short_repeated_primitives,
+ pointy_brackets,
+ use_index_order,
+ float_format,
+ double_format,
+ use_field_number,
+ descriptor_pool,
+ message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
result = out.getvalue()
out.close()
@@ -218,7 +230,8 @@ def PrintMessage(message,
use_field_number=False,
descriptor_pool=None,
message_formatter=None,
- print_unknown_fields=False):
+ print_unknown_fields=False,
+ force_colon=False):
printer = _Printer(
out=out, indent=indent, as_utf8=as_utf8,
as_one_line=as_one_line,
@@ -230,7 +243,8 @@ def PrintMessage(message,
use_field_number=use_field_number,
descriptor_pool=descriptor_pool,
message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields)
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
@@ -246,13 +260,15 @@ def PrintField(field,
float_format=None,
double_format=None,
message_formatter=None,
- print_unknown_fields=False):
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field name/value pair."""
printer = _Printer(out, indent, as_utf8, as_one_line,
use_short_repeated_primitives, pointy_brackets,
use_index_order, float_format, double_format,
message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields)
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintField(field, value)
@@ -268,13 +284,15 @@ def PrintFieldValue(field,
float_format=None,
double_format=None,
message_formatter=None,
- print_unknown_fields=False):
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field value (not including name)."""
printer = _Printer(out, indent, as_utf8, as_one_line,
use_short_repeated_primitives, pointy_brackets,
use_index_order, float_format, double_format,
message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields)
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintFieldValue(field, value)
@@ -324,7 +342,8 @@ class _Printer(object):
use_field_number=False,
descriptor_pool=None,
message_formatter=None,
- print_unknown_fields=False):
+ print_unknown_fields=False,
+ force_colon=False):
"""Initialize the Printer.
Double values can be formatted compactly with 15 digits of precision
@@ -358,6 +377,8 @@ class _Printer(object):
to custom format selected sub-messages (usually based on message type).
Use to pretty print parts of the protobuf for easier diffing.
print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if
+ the field is a proto message.
"""
self.out = out
self.indent = indent
@@ -375,6 +396,7 @@ class _Printer(object):
self.descriptor_pool = descriptor_pool
self.message_formatter = message_formatter
self.print_unknown_fields = print_unknown_fields
+ self.force_colon = force_colon
def _TryPrintAsAnyMessage(self, message):
"""Serializes if message is a google.protobuf.Any field."""
@@ -384,7 +406,8 @@ class _Printer(object):
self.descriptor_pool)
if packed_message:
packed_message.MergeFromString(message.value)
- self.out.write('%s[%s] ' % (self.indent * ' ', message.type_url))
+ colon = ':' if self.force_colon else ''
+ self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
self._PrintMessageFieldValue(packed_message)
self.out.write(' ' if self.as_one_line else '\n')
return True
@@ -518,9 +541,11 @@ class _Printer(object):
else:
out.write(field.name)
- if field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
+ if (self.force_colon or
+ field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
# The colon is optional in this case, but our cross-language golden files
- # don't include it.
+ # don't include it. Here, the colon is only included if force_colon is
+ # set to True
out.write(':')
def PrintField(self, field, value):
@@ -531,6 +556,7 @@ class _Printer(object):
self.out.write(' ' if self.as_one_line else '\n')
def _PrintShortRepeatedPrimitivesValue(self, field, value):
+ """"Prints short repeated primitives value."""
# Note: this is called only when value has at least one element.
self._PrintFieldName(field)
self.out.write(' [')
@@ -539,6 +565,8 @@ class _Printer(object):
self.out.write(', ')
self.PrintFieldValue(field, value[-1])
self.out.write(']')
+ if self.force_colon:
+ self.out.write(':')
self.out.write(' ' if self.as_one_line else '\n')
def _PrintMessageFieldValue(self, value):
diff --git a/python/setup.py b/python/setup.py
index 327658a484..9aabbf7aaa 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -19,23 +19,17 @@ from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean
from distutils.spawn import find_executable
-
-current_dir = (os.path.dirname(__file__) or os.curdir)
-current_dir_relative = os.path.relpath(current_dir)
-src_dir = os.path.abspath(os.path.join(current_dir, "..", "src"))
-vsprojects_dir = os.path.abspath(os.path.join(current_dir, "..", "vsprojects"))
-
# Find the Protocol Compiler.
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
protoc = os.environ['PROTOC']
-elif os.path.exists(os.path.join(src_dir, "protoc")):
- protoc = os.path.join(src_dir, "protoc")
-elif os.path.exists(os.path.join(src_dir, "protoc.exe")):
- protoc = os.path.join(src_dir, "protoc.exe")
-elif os.path.exists(os.path.join(vsprojects_dir, "Debug", "protoc.exe")):
- protoc = os.path.join(vsprojects_dir, "Debug", "protoc.exe")
-elif os.path.exists(os.path.join(vsprojects_dir, "Release", "protoc.exe")):
- protoc = os.path.join(vsprojects_dir, "Release", "protoc.exe")
+elif os.path.exists("../src/protoc"):
+ protoc = "../src/protoc"
+elif os.path.exists("../src/protoc.exe"):
+ protoc = "../src/protoc.exe"
+elif os.path.exists("../vsprojects/Debug/protoc.exe"):
+ protoc = "../vsprojects/Debug/protoc.exe"
+elif os.path.exists("../vsprojects/Release/protoc.exe"):
+ protoc = "../vsprojects/Release/protoc.exe"
else:
protoc = find_executable("protoc")
@@ -46,7 +40,7 @@ def GetVersion():
Do not import google.protobuf.__init__ directly, because an installed
protobuf library may be loaded instead."""
- with open(os.path.join(current_dir, 'google', 'protobuf', '__init__.py')) as version_file:
+ with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals())
global __version__
return __version__
@@ -57,21 +51,15 @@ def generate_proto(source, require = True):
.proto file. Does nothing if the output already exists and is newer than
the input."""
- original_source = source
- source = source.replace("../src", src_dir)
-
if not require and not os.path.exists(source):
return
- output = os.path.join(
- current_dir,
- original_source.replace(".proto", "_pb2.py").replace("../src/", "")
- )
+ output = source.replace(".proto", "_pb2.py").replace("../src/", "")
if (not os.path.exists(output) or
(os.path.exists(source) and
os.path.getmtime(source) > os.path.getmtime(output))):
- print("Generating %s..." % os.path.relpath(output))
+ print("Generating %s..." % output)
if not os.path.exists(source):
sys.stderr.write("Can't find required file: %s\n" % source)
@@ -83,13 +71,7 @@ def generate_proto(source, require = True):
"or install the binary package.\n")
sys.exit(-1)
- protoc_command = [
- protoc,
- "-I{}".format(src_dir),
- "-I{}".format(current_dir),
- "--python_out={}".format(current_dir),
- source,
- ]
+ protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
if subprocess.call(protoc_command) != 0:
sys.exit(-1)
@@ -134,7 +116,7 @@ def GenerateUnittestProtos():
class clean(_clean):
def run(self):
# Delete generated files in the code tree.
- for (dirpath, dirnames, filenames) in os.walk(current_dir):
+ for (dirpath, dirnames, filenames) in os.walk("."):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
@@ -287,14 +269,7 @@ if __name__ == '__main__':
"Programming Language :: Python :: 3.7",
],
namespace_packages=['google'],
- # package_dir is required when setup.py is not run from the python/
- # directory (such as from the ReadTheDocs build). See
- # https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
- # package_dir must be a relative path. See:
- # https://stackoverflow.com/a/53547931/101923
- package_dir={"": current_dir_relative},
packages=find_packages(
- where=current_dir,
exclude=[
'import_test_package',
],
diff --git a/src/Makefile.am b/src/Makefile.am
index 7d5e779cee..3212a505ae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -510,6 +510,7 @@ protoc_inputs = \
google/protobuf/unittest_proto3_arena.proto \
google/protobuf/unittest_proto3_arena_lite.proto \
google/protobuf/unittest_proto3_lite.proto \
+ google/protobuf/unittest_proto3_optional.proto \
google/protobuf/unittest_well_known_types.proto \
google/protobuf/util/internal/testdata/anys.proto \
google/protobuf/util/internal/testdata/books.proto \
@@ -643,6 +644,8 @@ protoc_outputs = \
google/protobuf/unittest_proto3_arena_lite.pb.h \
google/protobuf/unittest_proto3_lite.pb.cc \
google/protobuf/unittest_proto3_lite.pb.h \
+ google/protobuf/unittest_proto3_optional.pb.cc \
+ google/protobuf/unittest_proto3_optional.pb.h \
google/protobuf/unittest_well_known_types.pb.cc \
google/protobuf/unittest_well_known_types.pb.h \
google/protobuf/util/internal/testdata/anys.pb.cc \
@@ -686,7 +689,7 @@ else
# relative to srcdir, which may not be the same as the current directory when
# building out-of-tree.
unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs)
- oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) )
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) --experimental_allow_proto3_optional )
touch unittest_proto_middleman
endif
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc
index 5d7ea1ccba..1eba999eba 100644
--- a/src/google/protobuf/any.pb.cc
+++ b/src/google/protobuf/any.pb.cc
@@ -69,9 +69,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
&scc_info_Any_google_2fprotobuf_2fany_2eproto.base,
};
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once;
-static bool descriptor_table_google_2fprotobuf_2fany_2eproto_initialized = false;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = {
- &descriptor_table_google_2fprotobuf_2fany_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205,
+ false, false, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205,
&descriptor_table_google_2fprotobuf_2fany_2eproto_once, descriptor_table_google_2fprotobuf_2fany_2eproto_sccs, descriptor_table_google_2fprotobuf_2fany_2eproto_deps, 1, 0,
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fany_2eproto::offsets,
file_level_metadata_google_2fprotobuf_2fany_2eproto, 1, file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, file_level_service_descriptors_google_2fprotobuf_2fany_2eproto,
@@ -102,23 +101,26 @@ class Any::_Internal {
public:
};
-Any::Any()
- : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr), _any_metadata_(&type_url_, &value_) {
+Any::Any(::PROTOBUF_NAMESPACE_ID::Arena* arena)
+ : ::PROTOBUF_NAMESPACE_ID::Message(arena),
+ _any_metadata_(&type_url_, &value_) {
SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.Any)
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Any)
}
Any::Any(const Any& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
- _internal_metadata_(nullptr),
_any_metadata_(&type_url_, &value_) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_type_url().empty()) {
- type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_);
+ type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_type_url(),
+ GetArena());
}
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_value().empty()) {
- value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_);
+ value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_value(),
+ GetArena());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
}
@@ -132,13 +134,21 @@ void Any::SharedCtor() {
Any::~Any() {
// @@protoc_insertion_point(destructor:google.protobuf.Any)
SharedDtor();
+ _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
void Any::SharedDtor() {
+ GOOGLE_DCHECK(GetArena() == nullptr);
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
+void Any::ArenaDtor(void* object) {
+ Any* _this = reinterpret_cast< Any* >(object);
+ (void)_this;
+}
+void Any::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
+}
void Any::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
@@ -154,13 +164,14 @@ void Any::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
- type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- _internal_metadata_.Clear();
+ type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
+ ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@@ -189,7 +200,9 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
ctx->SetLastTag(tag);
goto success;
}
- ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
+ ptr = UnknownFieldParse(tag,
+ _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
+ ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
@@ -227,7 +240,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
- _internal_metadata_.unknown_fields(), target, stream);
+ _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any)
return target;
@@ -282,17 +295,15 @@ void Any::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Any::MergeFrom(const Any& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any)
GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.type_url().size() > 0) {
-
- type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_);
+ _internal_set_type_url(from._internal_type_url());
}
if (from.value().size() > 0) {
-
- value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_);
+ _internal_set_value(from._internal_value());
}
}
@@ -316,11 +327,9 @@ bool Any::IsInitialized() const {
void Any::InternalSwap(Any* other) {
using std::swap;
- _internal_metadata_.Swap(&other->_internal_metadata_);
- type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
+ _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
+ type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const {
@@ -332,7 +341,7 @@ void Any::InternalSwap(Any* other) {
PROTOBUF_NAMESPACE_CLOSE
PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Any >(Arena* arena) {
- return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Any >(arena);
+ return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Any >(arena);
}
PROTOBUF_NAMESPACE_CLOSE
diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h
index 0ff9341b04..1b7dca0bdd 100644
--- a/src/google/protobuf/any.pb.h
+++ b/src/google/protobuf/any.pb.h
@@ -26,7 +26,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include // IWYU pragma: export
@@ -66,10 +66,10 @@ PROTOBUF_NAMESPACE_OPEN
// ===================================================================
-class PROTOBUF_EXPORT Any :
+class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ {
public:
- Any();
+ inline Any() : Any(nullptr) {};
virtual ~Any();
Any(const Any& from);
@@ -83,7 +83,7 @@ class PROTOBUF_EXPORT Any :
return *this;
}
inline Any& operator=(Any&& from) noexcept {
- if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
@@ -148,6 +148,15 @@ class PROTOBUF_EXPORT Any :
}
inline void Swap(Any* other) {
if (other == this) return;
+ if (GetArena() == other->GetArena()) {
+ InternalSwap(other);
+ } else {
+ ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
+ }
+ }
+ void UnsafeArenaSwap(Any* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@@ -182,13 +191,11 @@ class PROTOBUF_EXPORT Any :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Any";
}
+ protected:
+ explicit Any(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private:
- inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
- return nullptr;
- }
- inline void* MaybeArenaPtr() const {
- return nullptr;
- }
+ static void ArenaDtor(void* object);
+ inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@@ -218,6 +225,15 @@ class PROTOBUF_EXPORT Any :
std::string* mutable_type_url();
std::string* release_type_url();
void set_allocated_type_url(std::string* type_url);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_type_url();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_type_url(
+ std::string* type_url);
private:
const std::string& _internal_type_url() const;
void _internal_set_type_url(const std::string& value);
@@ -234,6 +250,15 @@ class PROTOBUF_EXPORT Any :
std::string* mutable_value();
std::string* release_value();
void set_allocated_value(std::string* value);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_value();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_value(
+ std::string* value);
private:
const std::string& _internal_value() const;
void _internal_set_value(const std::string& value);
@@ -244,7 +269,9 @@ class PROTOBUF_EXPORT Any :
private:
class _Internal;
- ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
+ template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
@@ -264,7 +291,7 @@ class PROTOBUF_EXPORT Any :
// string type_url = 1;
inline void Any::clear_type_url() {
- type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Any::type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
@@ -279,38 +306,40 @@ inline std::string* Any::mutable_type_url() {
return _internal_mutable_type_url();
}
inline const std::string& Any::_internal_type_url() const {
- return type_url_.GetNoArena();
+ return type_url_.Get();
}
inline void Any::_internal_set_type_url(const std::string& value) {
- type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Any::set_type_url(std::string&& value) {
- type_url_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ type_url_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
}
inline void Any::set_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
}
-inline void Any::set_type_url(const char* value, size_t size) {
+inline void Any::set_type_url(const char* value,
+ size_t size) {
- type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url)
}
inline std::string* Any::_internal_mutable_type_url() {
- return type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
- return type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) {
@@ -318,13 +347,33 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
} else {
}
- type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url);
+ type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
+inline std::string* Any::unsafe_arena_release_type_url() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.type_url)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Any::unsafe_arena_set_allocated_type_url(
+ std::string* type_url) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (type_url != nullptr) {
+
+ } else {
+
+ }
+ type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ type_url, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.type_url)
+}
// bytes value = 2;
inline void Any::clear_value() {
- value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
@@ -339,38 +388,40 @@ inline std::string* Any::mutable_value() {
return _internal_mutable_value();
}
inline const std::string& Any::_internal_value() const {
- return value_.GetNoArena();
+ return value_.Get();
}
inline void Any::_internal_set_value(const std::string& value) {
- value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Any::set_value(std::string&& value) {
- value_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ value_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
}
inline void Any::set_value(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
}
-inline void Any::set_value(const void* value, size_t size) {
+inline void Any::set_value(const void* value,
+ size_t size) {
- value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value)
}
inline std::string* Any::_internal_mutable_value() {
- return value_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return value_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
- return value_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) {
@@ -378,9 +429,29 @@ inline void Any::set_allocated_value(std::string* value) {
} else {
}
- value_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
}
+inline std::string* Any::unsafe_arena_release_value() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.value)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Any::unsafe_arena_set_allocated_value(
+ std::string* value) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (value != nullptr) {
+
+ } else {
+
+ }
+ value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ value, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.value)
+}
#ifdef __GNUC__
#pragma GCC diagnostic pop
diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc
index 0951c52436..816df1201c 100644
--- a/src/google/protobuf/api.pb.cc
+++ b/src/google/protobuf/api.pb.cc
@@ -159,9 +159,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
&scc_info_Mixin_google_2fprotobuf_2fapi_2eproto.base,
};
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once;
-static bool descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized = false;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = {
- &descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750,
+ false, false, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750,
&descriptor_table_google_2fprotobuf_2fapi_2eproto_once, descriptor_table_google_2fprotobuf_2fapi_2eproto_sccs, descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, 3, 2,
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fapi_2eproto::offsets,
file_level_metadata_google_2fprotobuf_2fapi_2eproto, 3, file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto,
@@ -190,30 +189,35 @@ void Api::clear_options() {
options_.Clear();
}
void Api::clear_source_context() {
- if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) {
+ if (GetArena() == nullptr && source_context_ != nullptr) {
delete source_context_;
}
source_context_ = nullptr;
}
-Api::Api()
- : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
+Api::Api(::PROTOBUF_NAMESPACE_ID::Arena* arena)
+ : ::PROTOBUF_NAMESPACE_ID::Message(arena),
+ methods_(arena),
+ options_(arena),
+ mixins_(arena) {
SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.Api)
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Api)
}
Api::Api(const Api& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
- _internal_metadata_(nullptr),
methods_(from.methods_),
options_(from.options_),
mixins_(from.mixins_) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
+ GetArena());
}
version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_version().empty()) {
- version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_);
+ version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_version(),
+ GetArena());
}
if (from._internal_has_source_context()) {
source_context_ = new PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_);
@@ -236,14 +240,22 @@ void Api::SharedCtor() {
Api::~Api() {
// @@protoc_insertion_point(destructor:google.protobuf.Api)
SharedDtor();
+ _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
void Api::SharedDtor() {
+ GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (this != internal_default_instance()) delete source_context_;
}
+void Api::ArenaDtor(void* object) {
+ Api* _this = reinterpret_cast< Api* >(object);
+ (void)_this;
+}
+void Api::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
+}
void Api::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
@@ -262,18 +274,19 @@ void Api::Clear() {
methods_.Clear();
options_.Clear();
mixins_.Clear();
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) {
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ if (GetArena() == nullptr && source_context_ != nullptr) {
delete source_context_;
}
source_context_ = nullptr;
syntax_ = 0;
- _internal_metadata_.Clear();
+ _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
+ ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@@ -354,7 +367,9 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
ctx->SetLastTag(tag);
goto success;
}
- ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
+ ptr = UnknownFieldParse(tag,
+ _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
+ ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
@@ -435,7 +450,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
- _internal_metadata_.unknown_fields(), target, stream);
+ _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Api)
return target;
@@ -524,7 +539,7 @@ void Api::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Api::MergeFrom(const Api& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api)
GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
@@ -532,12 +547,10 @@ void Api::MergeFrom(const Api& from) {
options_.MergeFrom(from.options_);
mixins_.MergeFrom(from.mixins_);
if (from.name().size() > 0) {
-
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ _internal_set_name(from._internal_name());
}
if (from.version().size() > 0) {
-
- version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_);
+ _internal_set_version(from._internal_version());
}
if (from.has_source_context()) {
_internal_mutable_source_context()->PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context());
@@ -567,16 +580,18 @@ bool Api::IsInitialized() const {
void Api::InternalSwap(Api* other) {
using std::swap;
- _internal_metadata_.Swap(&other->_internal_metadata_);
+ _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
methods_.InternalSwap(&other->methods_);
options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_);
- name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- swap(source_context_, other->source_context_);
- swap(syntax_, other->syntax_);
+ name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ ::PROTOBUF_NAMESPACE_ID::internal::memswap<
+ PROTOBUF_FIELD_OFFSET(Api, syntax_)
+ + sizeof(Api::syntax_)
+ - PROTOBUF_FIELD_OFFSET(Api, source_context_)>(
+ reinterpret_cast(&source_context_),
+ reinterpret_cast(&other->source_context_));
}
::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const {
@@ -595,27 +610,31 @@ class Method::_Internal {
void Method::clear_options() {
options_.Clear();
}
-Method::Method()
- : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
+Method::Method(::PROTOBUF_NAMESPACE_ID::Arena* arena)
+ : ::PROTOBUF_NAMESPACE_ID::Message(arena),
+ options_(arena) {
SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.Method)
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Method)
}
Method::Method(const Method& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
- _internal_metadata_(nullptr),
options_(from.options_) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
+ GetArena());
}
request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_request_type_url().empty()) {
- request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
+ request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_request_type_url(),
+ GetArena());
}
response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_response_type_url().empty()) {
- response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
+ response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_response_type_url(),
+ GetArena());
}
::memcpy(&request_streaming_, &from.request_streaming_,
static_cast(reinterpret_cast(&syntax_) -
@@ -636,14 +655,22 @@ void Method::SharedCtor() {
Method::~Method() {
// @@protoc_insertion_point(destructor:google.protobuf.Method)
SharedDtor();
+ _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
void Method::SharedDtor() {
+ GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
+void Method::ArenaDtor(void* object) {
+ Method* _this = reinterpret_cast< Method* >(object);
+ (void)_this;
+}
+void Method::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
+}
void Method::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
@@ -660,17 +687,18 @@ void Method::Clear() {
(void) cached_has_bits;
options_.Clear();
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::memset(&request_streaming_, 0, static_cast(
reinterpret_cast(&syntax_) -
reinterpret_cast(&request_streaming_)) + sizeof(syntax_));
- _internal_metadata_.Clear();
+ _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
+ ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@@ -743,7 +771,9 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int
ctx->SetLastTag(tag);
goto success;
}
- ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
+ ptr = UnknownFieldParse(tag,
+ _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
+ ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
@@ -822,7 +852,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
- _internal_metadata_.unknown_fields(), target, stream);
+ _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Method)
return target;
@@ -907,22 +937,19 @@ void Method::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Method::MergeFrom(const Method& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method)
GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
options_.MergeFrom(from.options_);
if (from.name().size() > 0) {
-
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ _internal_set_name(from._internal_name());
}
if (from.request_type_url().size() > 0) {
-
- request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
+ _internal_set_request_type_url(from._internal_request_type_url());
}
if (from.response_type_url().size() > 0) {
-
- response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
+ _internal_set_response_type_url(from._internal_response_type_url());
}
if (from.request_streaming() != 0) {
_internal_set_request_streaming(from._internal_request_streaming());
@@ -955,17 +982,17 @@ bool Method::IsInitialized() const {
void Method::InternalSwap(Method* other) {
using std::swap;
- _internal_metadata_.Swap(&other->_internal_metadata_);
+ _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
options_.InternalSwap(&other->options_);
- name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- swap(request_streaming_, other->request_streaming_);
- swap(response_streaming_, other->response_streaming_);
- swap(syntax_, other->syntax_);
+ name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ ::PROTOBUF_NAMESPACE_ID::internal::memswap<
+ PROTOBUF_FIELD_OFFSET(Method, syntax_)
+ + sizeof(Method::syntax_)
+ - PROTOBUF_FIELD_OFFSET(Method, request_streaming_)>(
+ reinterpret_cast(&request_streaming_),
+ reinterpret_cast(&other->request_streaming_));
}
::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const {
@@ -981,22 +1008,24 @@ class Mixin::_Internal {
public:
};
-Mixin::Mixin()
- : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
+Mixin::Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena)
+ : ::PROTOBUF_NAMESPACE_ID::Message(arena) {
SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.Mixin)
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Mixin)
}
Mixin::Mixin(const Mixin& from)
- : ::PROTOBUF_NAMESPACE_ID::Message(),
- _internal_metadata_(nullptr) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ : ::PROTOBUF_NAMESPACE_ID::Message() {
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
+ GetArena());
}
root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_root().empty()) {
- root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_);
+ root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_root(),
+ GetArena());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
}
@@ -1010,13 +1039,21 @@ void Mixin::SharedCtor() {
Mixin::~Mixin() {
// @@protoc_insertion_point(destructor:google.protobuf.Mixin)
SharedDtor();
+ _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
void Mixin::SharedDtor() {
+ GOOGLE_DCHECK(GetArena() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
+void Mixin::ArenaDtor(void* object) {
+ Mixin* _this = reinterpret_cast< Mixin* >(object);
+ (void)_this;
+}
+void Mixin::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
+}
void Mixin::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
@@ -1032,13 +1069,14 @@ void Mixin::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
- _internal_metadata_.Clear();
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
+ ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
@@ -1068,7 +1106,9 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte
ctx->SetLastTag(tag);
goto success;
}
- ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
+ ptr = UnknownFieldParse(tag,
+ _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
+ ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
@@ -1110,7 +1150,7 @@ failure:
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
- _internal_metadata_.unknown_fields(), target, stream);
+ _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Mixin)
return target;
@@ -1165,17 +1205,15 @@ void Mixin::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
void Mixin::MergeFrom(const Mixin& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin)
GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.name().size() > 0) {
-
- name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
+ _internal_set_name(from._internal_name());
}
if (from.root().size() > 0) {
-
- root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_);
+ _internal_set_root(from._internal_root());
}
}
@@ -1199,11 +1237,9 @@ bool Mixin::IsInitialized() const {
void Mixin::InternalSwap(Mixin* other) {
using std::swap;
- _internal_metadata_.Swap(&other->_internal_metadata_);
- name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
- root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- GetArenaNoVirtual());
+ _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
+ name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
+ root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const {
@@ -1215,13 +1251,13 @@ void Mixin::InternalSwap(Mixin* other) {
PROTOBUF_NAMESPACE_CLOSE
PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Api >(Arena* arena) {
- return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Api >(arena);
+ return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Api >(arena);
}
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Method >(Arena* arena) {
- return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Method >(arena);
+ return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Method >(arena);
}
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) {
- return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena);
+ return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena);
}
PROTOBUF_NAMESPACE_CLOSE
diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h
index ed49df1b1f..0d0ce4ab74 100644
--- a/src/google/protobuf/api.pb.h
+++ b/src/google/protobuf/api.pb.h
@@ -26,7 +26,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include // IWYU pragma: export
@@ -76,10 +76,10 @@ PROTOBUF_NAMESPACE_OPEN
// ===================================================================
-class PROTOBUF_EXPORT Api :
+class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ {
public:
- Api();
+ inline Api() : Api(nullptr) {};
virtual ~Api();
Api(const Api& from);
@@ -93,7 +93,7 @@ class PROTOBUF_EXPORT Api :
return *this;
}
inline Api& operator=(Api&& from) noexcept {
- if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
@@ -125,6 +125,15 @@ class PROTOBUF_EXPORT Api :
}
inline void Swap(Api* other) {
if (other == this) return;
+ if (GetArena() == other->GetArena()) {
+ InternalSwap(other);
+ } else {
+ ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
+ }
+ }
+ void UnsafeArenaSwap(Api* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@@ -159,13 +168,11 @@ class PROTOBUF_EXPORT Api :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Api";
}
+ protected:
+ explicit Api(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private:
- inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
- return nullptr;
- }
- inline void* MaybeArenaPtr() const {
- return nullptr;
- }
+ static void ArenaDtor(void* object);
+ inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@@ -254,6 +261,15 @@ class PROTOBUF_EXPORT Api :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_name();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_name(
+ std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@@ -270,6 +286,15 @@ class PROTOBUF_EXPORT Api :
std::string* mutable_version();
std::string* release_version();
void set_allocated_version(std::string* version);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_version();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_version(
+ std::string* version);
private:
const std::string& _internal_version() const;
void _internal_set_version(const std::string& value);
@@ -290,6 +315,9 @@ class PROTOBUF_EXPORT Api :
const PROTOBUF_NAMESPACE_ID::SourceContext& _internal_source_context() const;
PROTOBUF_NAMESPACE_ID::SourceContext* _internal_mutable_source_context();
public:
+ void unsafe_arena_set_allocated_source_context(
+ PROTOBUF_NAMESPACE_ID::SourceContext* source_context);
+ PROTOBUF_NAMESPACE_ID::SourceContext* unsafe_arena_release_source_context();
// .google.protobuf.Syntax syntax = 7;
void clear_syntax();
@@ -304,7 +332,9 @@ class PROTOBUF_EXPORT Api :
private:
class _Internal;
- ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
+ template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method > methods_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin > mixins_;
@@ -317,10 +347,10 @@ class PROTOBUF_EXPORT Api :
};
// -------------------------------------------------------------------
-class PROTOBUF_EXPORT Method :
+class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ {
public:
- Method();
+ inline Method() : Method(nullptr) {};
virtual ~Method();
Method(const Method& from);
@@ -334,7 +364,7 @@ class PROTOBUF_EXPORT Method :
return *this;
}
inline Method& operator=(Method&& from) noexcept {
- if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
@@ -366,6 +396,15 @@ class PROTOBUF_EXPORT Method :
}
inline void Swap(Method* other) {
if (other == this) return;
+ if (GetArena() == other->GetArena()) {
+ InternalSwap(other);
+ } else {
+ ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
+ }
+ }
+ void UnsafeArenaSwap(Method* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@@ -400,13 +439,11 @@ class PROTOBUF_EXPORT Method :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Method";
}
+ protected:
+ explicit Method(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private:
- inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
- return nullptr;
- }
- inline void* MaybeArenaPtr() const {
- return nullptr;
- }
+ static void ArenaDtor(void* object);
+ inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@@ -459,6 +496,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_name();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_name(
+ std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@@ -475,6 +521,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_request_type_url();
std::string* release_request_type_url();
void set_allocated_request_type_url(std::string* request_type_url);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_request_type_url();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_request_type_url(
+ std::string* request_type_url);
private:
const std::string& _internal_request_type_url() const;
void _internal_set_request_type_url(const std::string& value);
@@ -491,6 +546,15 @@ class PROTOBUF_EXPORT Method :
std::string* mutable_response_type_url();
std::string* release_response_type_url();
void set_allocated_response_type_url(std::string* response_type_url);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_response_type_url();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_response_type_url(
+ std::string* response_type_url);
private:
const std::string& _internal_response_type_url() const;
void _internal_set_response_type_url(const std::string& value);
@@ -528,7 +592,9 @@ class PROTOBUF_EXPORT Method :
private:
class _Internal;
- ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
+ template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_;
@@ -541,10 +607,10 @@ class PROTOBUF_EXPORT Method :
};
// -------------------------------------------------------------------
-class PROTOBUF_EXPORT Mixin :
+class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ {
public:
- Mixin();
+ inline Mixin() : Mixin(nullptr) {};
virtual ~Mixin();
Mixin(const Mixin& from);
@@ -558,7 +624,7 @@ class PROTOBUF_EXPORT Mixin :
return *this;
}
inline Mixin& operator=(Mixin&& from) noexcept {
- if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
@@ -590,6 +656,15 @@ class PROTOBUF_EXPORT Mixin :
}
inline void Swap(Mixin* other) {
if (other == this) return;
+ if (GetArena() == other->GetArena()) {
+ InternalSwap(other);
+ } else {
+ ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
+ }
+ }
+ void UnsafeArenaSwap(Mixin* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArena() == other->GetArena());
InternalSwap(other);
}
@@ -624,13 +699,11 @@ class PROTOBUF_EXPORT Mixin :
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
return "google.protobuf.Mixin";
}
+ protected:
+ explicit Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena);
private:
- inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
- return nullptr;
- }
- inline void* MaybeArenaPtr() const {
- return nullptr;
- }
+ static void ArenaDtor(void* object);
+ inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
public:
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
@@ -660,6 +733,15 @@ class PROTOBUF_EXPORT Mixin :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_name();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_name(
+ std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@@ -676,6 +758,15 @@ class PROTOBUF_EXPORT Mixin :
std::string* mutable_root();
std::string* release_root();
void set_allocated_root(std::string* root);
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ std::string* unsafe_arena_release_root();
+ GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
+ " string fields are deprecated and will be removed in a"
+ " future release.")
+ void unsafe_arena_set_allocated_root(
+ std::string* root);
private:
const std::string& _internal_root() const;
void _internal_set_root(const std::string& value);
@@ -686,7 +777,9 @@ class PROTOBUF_EXPORT Mixin :
private:
class _Internal;
- ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
+ template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
@@ -705,7 +798,7 @@ class PROTOBUF_EXPORT Mixin :
// string name = 1;
inline void Api::clear_name() {
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Api::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.name)
@@ -720,38 +813,40 @@ inline std::string* Api::mutable_name() {
return _internal_mutable_name();
}
inline const std::string& Api::_internal_name() const {
- return name_.GetNoArena();
+ return name_.Get();
}
inline void Api::_internal_set_name(const std::string& value) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Api::set_name(std::string&& value) {
- name_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ name_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
}
inline void Api::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.name)
}
-inline void Api::set_name(const char* value, size_t size) {
+inline void Api::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name)
}
inline std::string* Api::_internal_mutable_name() {
- return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name)
- return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) {
@@ -759,9 +854,29 @@ inline void Api::set_allocated_name(std::string* name) {
} else {
}
- name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
+ name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
}
+inline std::string* Api::unsafe_arena_release_name() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.name)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Api::unsafe_arena_set_allocated_name(
+ std::string* name) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (name != nullptr) {
+
+ } else {
+
+ }
+ name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ name, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.name)
+}
// repeated .google.protobuf.Method methods = 2;
inline int Api::_internal_methods_size() const {
@@ -840,7 +955,7 @@ Api::options() const {
// string version = 4;
inline void Api::clear_version() {
- version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Api::version() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.version)
@@ -855,38 +970,40 @@ inline std::string* Api::mutable_version() {
return _internal_mutable_version();
}
inline const std::string& Api::_internal_version() const {
- return version_.GetNoArena();
+ return version_.Get();
}
inline void Api::_internal_set_version(const std::string& value) {
- version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Api::set_version(std::string&& value) {
- version_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ version_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
}
inline void Api::set_version(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.version)
}
-inline void Api::set_version(const char* value, size_t size) {
+inline void Api::set_version(const char* value,
+ size_t size) {
- version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version)
}
inline std::string* Api::_internal_mutable_version() {
- return version_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return version_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version)
- return version_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) {
@@ -894,9 +1011,29 @@ inline void Api::set_allocated_version(std::string* version) {
} else {
}
- version_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version);
+ version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
+inline std::string* Api::unsafe_arena_release_version() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.version)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return version_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Api::unsafe_arena_set_allocated_version(
+ std::string* version) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (version != nullptr) {
+
+ } else {
+
+ }
+ version_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ version, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.version)
+}
// .google.protobuf.SourceContext source_context = 5;
inline bool Api::_internal_has_source_context() const {
@@ -914,7 +1051,27 @@ inline const PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.source_context)
return _internal_source_context();
}
+inline void Api::unsafe_arena_set_allocated_source_context(
+ PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
+ if (GetArena() == nullptr) {
+ delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
+ }
+ source_context_ = source_context;
+ if (source_context) {
+
+ } else {
+
+ }
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context)
+}
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
+ auto temp = unsafe_arena_release_source_context();
+ if (GetArena() != nullptr) {
+ temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp);
+ }
+ return temp;
+}
+inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_context() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
@@ -924,7 +1081,7 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() {
if (source_context_ == nullptr) {
- auto* p = CreateMaybeMessage(GetArenaNoVirtual());
+ auto* p = CreateMaybeMessage(GetArena());
source_context_ = p;
}
return source_context_;
@@ -934,12 +1091,13 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
return _internal_mutable_source_context();
}
inline void Api::set_allocated_source_context(PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
- ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual();
+ ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArena();
if (message_arena == nullptr) {
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
}
if (source_context) {
- ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = nullptr;
+ ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
+ reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)->GetArena();
if (message_arena != submessage_arena) {
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, source_context, submessage_arena);
@@ -1017,7 +1175,7 @@ inline void Api::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1;
inline void Method::clear_name() {
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Method::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.name)
@@ -1032,38 +1190,40 @@ inline std::string* Method::mutable_name() {
return _internal_mutable_name();
}
inline const std::string& Method::_internal_name() const {
- return name_.GetNoArena();
+ return name_.Get();
}
inline void Method::_internal_set_name(const std::string& value) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Method::set_name(std::string&& value) {
- name_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ name_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
}
inline void Method::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.name)
}
-inline void Method::set_name(const char* value, size_t size) {
+inline void Method::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name)
}
inline std::string* Method::_internal_mutable_name() {
- return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name)
- return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) {
@@ -1071,13 +1231,33 @@ inline void Method::set_allocated_name(std::string* name) {
} else {
}
- name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
+ name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
+inline std::string* Method::unsafe_arena_release_name() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.name)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Method::unsafe_arena_set_allocated_name(
+ std::string* name) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (name != nullptr) {
+
+ } else {
+
+ }
+ name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ name, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.name)
+}
// string request_type_url = 2;
inline void Method::clear_request_type_url() {
- request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Method::request_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url)
@@ -1092,38 +1272,40 @@ inline std::string* Method::mutable_request_type_url() {
return _internal_mutable_request_type_url();
}
inline const std::string& Method::_internal_request_type_url() const {
- return request_type_url_.GetNoArena();
+ return request_type_url_.Get();
}
inline void Method::_internal_set_request_type_url(const std::string& value) {
- request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Method::set_request_type_url(std::string&& value) {
- request_type_url_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ request_type_url_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
}
inline void Method::set_request_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url)
}
-inline void Method::set_request_type_url(const char* value, size_t size) {
+inline void Method::set_request_type_url(const char* value,
+ size_t size) {
- request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url)
}
inline std::string* Method::_internal_mutable_request_type_url() {
- return request_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return request_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Method::release_request_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
- return request_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) {
@@ -1131,9 +1313,29 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
} else {
}
- request_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url);
+ request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
+inline std::string* Method::unsafe_arena_release_request_type_url() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.request_type_url)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return request_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Method::unsafe_arena_set_allocated_request_type_url(
+ std::string* request_type_url) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (request_type_url != nullptr) {
+
+ } else {
+
+ }
+ request_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ request_type_url, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.request_type_url)
+}
// bool request_streaming = 3;
inline void Method::clear_request_streaming() {
@@ -1157,7 +1359,7 @@ inline void Method::set_request_streaming(bool value) {
// string response_type_url = 4;
inline void Method::clear_response_type_url() {
- response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Method::response_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url)
@@ -1172,38 +1374,40 @@ inline std::string* Method::mutable_response_type_url() {
return _internal_mutable_response_type_url();
}
inline const std::string& Method::_internal_response_type_url() const {
- return response_type_url_.GetNoArena();
+ return response_type_url_.Get();
}
inline void Method::_internal_set_response_type_url(const std::string& value) {
- response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Method::set_response_type_url(std::string&& value) {
- response_type_url_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ response_type_url_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
}
inline void Method::set_response_type_url(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url)
}
-inline void Method::set_response_type_url(const char* value, size_t size) {
+inline void Method::set_response_type_url(const char* value,
+ size_t size) {
- response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url)
}
inline std::string* Method::_internal_mutable_response_type_url() {
- return response_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return response_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Method::release_response_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
- return response_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) {
@@ -1211,9 +1415,29 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
} else {
}
- response_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url);
+ response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
+inline std::string* Method::unsafe_arena_release_response_type_url() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.response_type_url)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return response_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Method::unsafe_arena_set_allocated_response_type_url(
+ std::string* response_type_url) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (response_type_url != nullptr) {
+
+ } else {
+
+ }
+ response_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ response_type_url, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.response_type_url)
+}
// bool response_streaming = 5;
inline void Method::clear_response_streaming() {
@@ -1297,7 +1521,7 @@ inline void Method::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
// string name = 1;
inline void Mixin::clear_name() {
- name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Mixin::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
@@ -1312,38 +1536,40 @@ inline std::string* Mixin::mutable_name() {
return _internal_mutable_name();
}
inline const std::string& Mixin::_internal_name() const {
- return name_.GetNoArena();
+ return name_.Get();
}
inline void Mixin::_internal_set_name(const std::string& value) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Mixin::set_name(std::string&& value) {
- name_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ name_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
}
inline void Mixin::set_name(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name)
}
-inline void Mixin::set_name(const char* value, size_t size) {
+inline void Mixin::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name)
}
inline std::string* Mixin::_internal_mutable_name() {
- return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
- return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) {
@@ -1351,13 +1577,33 @@ inline void Mixin::set_allocated_name(std::string* name) {
} else {
}
- name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
+ name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
+inline std::string* Mixin::unsafe_arena_release_name() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.name)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Mixin::unsafe_arena_set_allocated_name(
+ std::string* name) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (name != nullptr) {
+
+ } else {
+
+ }
+ name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ name, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.name)
+}
// string root = 2;
inline void Mixin::clear_root() {
- root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline const std::string& Mixin::root() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
@@ -1372,38 +1618,40 @@ inline std::string* Mixin::mutable_root() {
return _internal_mutable_root();
}
inline const std::string& Mixin::_internal_root() const {
- return root_.GetNoArena();
+ return root_.Get();
}
inline void Mixin::_internal_set_root(const std::string& value) {
- root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
+ root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
}
inline void Mixin::set_root(std::string&& value) {
- root_.SetNoArena(
- &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ root_.Set(
+ &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
}
inline void Mixin::set_root(const char* value) {
GOOGLE_DCHECK(value != nullptr);
- root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
+ GetArena());
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root)
}
-inline void Mixin::set_root(const char* value, size_t size) {
+inline void Mixin::set_root(const char* value,
+ size_t size) {
- root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast(value), size));
+ root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast(value), size), GetArena());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root)
}
inline std::string* Mixin::_internal_mutable_root() {
- return root_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return root_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
- return root_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
+ return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
}
inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) {
@@ -1411,9 +1659,29 @@ inline void Mixin::set_allocated_root(std::string* root) {
} else {
}
- root_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root);
+ root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root,
+ GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
}
+inline std::string* Mixin::unsafe_arena_release_root() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.root)
+ GOOGLE_DCHECK(GetArena() != nullptr);
+
+ return root_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ GetArena());
+}
+inline void Mixin::unsafe_arena_set_allocated_root(
+ std::string* root) {
+ GOOGLE_DCHECK(GetArena() != nullptr);
+ if (root != nullptr) {
+
+ } else {
+
+ }
+ root_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
+ root, GetArena());
+ // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.root)
+}
#ifdef __GNUC__
#pragma GCC diagnostic pop
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h
index 2dcf817983..a67d478976 100644
--- a/src/google/protobuf/arena.h
+++ b/src/google/protobuf/arena.h
@@ -338,10 +338,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template
PROTOBUF_ALWAYS_INLINE static T* CreateArray(Arena* arena,
size_t num_elements) {
-#ifndef __INTEL_COMPILER // icc mis-evaluates some types as non-pod
static_assert(std::is_pod::value,
"CreateArray requires a trivially constructible type");
-#endif
static_assert(std::is_trivially_destructible::value,
"CreateArray requires a trivially destructible type");
GOOGLE_CHECK_LE(num_elements, std::numeric_limits::max() / sizeof(T))
@@ -455,7 +453,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return new (ptr) T(std::forward(args)...);
}
- static Arena* GetArena(const T* p) { return p->GetArenaNoVirtual(); }
+ static Arena* GetArena(const T* p) { return p->GetArena(); }
friend class Arena;
};
@@ -534,6 +532,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// the cookie is not null.
template
PROTOBUF_ALWAYS_INLINE void* AllocateInternal(bool skip_explicit_ownership) {
+ static_assert(alignof(T) <= 8, "T is overaligned, see b/151247138");
const size_t n = internal::AlignUpTo8(sizeof(T));
AllocHook(RTTI_TYPE_ID(T), n);
// Monitor allocation if needed.
@@ -618,24 +617,25 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// CreateInArenaStorage is used to implement map field. Without it,
// Map need to call generated message's protected arena constructor,
// which needs to declare Map as friend of generated message.
- template
- static void CreateInArenaStorage(T* ptr, Arena* arena) {
+ template
+ static void CreateInArenaStorage(T* ptr, Arena* arena, Args&&... args) {
CreateInArenaStorageInternal(ptr, arena,
- typename is_arena_constructable::type());
+ typename is_arena_constructable::type(),
+ std::forward(args)...);
RegisterDestructorInternal(
ptr, arena,
typename InternalHelper::is_destructor_skippable::type());
}
- template
+ template
static void CreateInArenaStorageInternal(T* ptr, Arena* arena,
- std::true_type) {
- InternalHelper::Construct(ptr, arena);
+ std::true_type, Args&&... args) {
+ InternalHelper::Construct(ptr, arena, std::forward(args)...);
}
- template
+ template
static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */,
- std::false_type) {
- new (ptr) T();
+ std::false_type, Args&&... args) {
+ new (ptr) T(std::forward(args)...);
}
template
@@ -667,7 +667,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// Implementation for GetArena(). Only message objects with
// InternalArenaConstructable_ tags can be associated with an arena, and such
- // objects must implement a GetArenaNoVirtual() method.
+ // objects must implement a GetArena() method.
template ::value, int>::type = 0>
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
@@ -694,6 +694,17 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
AllocHook(NULL, n);
return AllocateAlignedNoHook(internal::AlignUpTo8(n));
}
+ template
+ void* AllocateAlignedTo(size_t n) {
+ static_assert(Align > 0, "Alignment must be greater than 0");
+ static_assert((Align & (Align - 1)) == 0, "Alignment must be power of two");
+ if (Align <= 8) return AllocateAligned(n);
+ // TODO(b/151247138): if the pointer would have been aligned already,
+ // this is wasting space. We should pass the alignment down.
+ uintptr_t ptr = reinterpret_cast(AllocateAligned(n + Align - 8));
+ ptr = (ptr + Align - 1) & -Align;
+ return reinterpret_cast(ptr);
+ }
void* AllocateAlignedNoHook(size_t n);
diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h
index 528dc76428..1bc8dfca53 100644
--- a/src/google/protobuf/compiler/code_generator.h
+++ b/src/google/protobuf/compiler/code_generator.h
@@ -102,6 +102,16 @@ class PROTOC_EXPORT CodeGenerator {
GeneratorContext* generator_context,
std::string* error) const;
+ // Sync with plugin.proto.
+ enum Feature {
+ FEATURE_PROTO3_OPTIONAL = 1,
+ };
+
+ // Implement this to indicate what features this code generator supports.
+ // This should be a bitwise OR of features from the Features enum in
+ // plugin.proto.
+ virtual uint64 GetSupportedFeatures() const { return 0; }
+
// This is no longer used, but this class is part of the opensource protobuf
// library, so it has to remain to keep vtables the same for the current
// version of the library. When protobufs does a api breaking change, the
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index fd64d0f4a0..ab7a7d4bbd 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -773,16 +773,9 @@ const char* const CommandLineInterface::kPathSeparator = ":";
#endif
CommandLineInterface::CommandLineInterface()
- : mode_(MODE_COMPILE),
- print_mode_(PRINT_NONE),
- error_format_(ERROR_FORMAT_GCC),
- direct_dependencies_explicitly_set_(false),
- direct_dependencies_violation_msg_(
- kDefaultDirectDependenciesViolationMsg),
- imports_in_descriptor_set_(false),
- source_info_in_descriptor_set_(false),
- disallow_services_(false) {
-}
+ : direct_dependencies_violation_msg_(
+ kDefaultDirectDependenciesViolationMsg) {}
+
CommandLineInterface::~CommandLineInterface() {}
void CommandLineInterface::RegisterGenerator(const std::string& flag_name,
@@ -811,6 +804,39 @@ void CommandLineInterface::AllowPlugins(const std::string& exe_name_prefix) {
plugin_prefix_ = exe_name_prefix;
}
+namespace {
+
+bool ContainsProto3Optional(const Descriptor* desc) {
+ for (int i = 0; i < desc->field_count(); i++) {
+ if (desc->field(i)->has_optional_keyword()) {
+ return true;
+ }
+ }
+ for (int i = 0; i < desc->nested_type_count(); i++) {
+ if (ContainsProto3Optional(desc->nested_type(i))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool ContainsProto3Optional(const FileDescriptor* file) {
+ if (file->syntax() == FileDescriptor::SYNTAX_PROTO3) {
+ for (int i = 0; i < file->message_type_count(); i++) {
+ if (ContainsProto3Optional(file->message_type(i))) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+namespace {
+std::unique_ptr
+PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name);
+}
int CommandLineInterface::Run(int argc, const char* const argv[]) {
Clear();
@@ -827,16 +853,38 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
std::unique_ptr disk_source_tree;
std::unique_ptr error_collector;
std::unique_ptr descriptor_pool;
- std::unique_ptr descriptor_set_in_database;
+
+ // The SimpleDescriptorDatabases here are the constituents of the
+ // MergedDescriptorDatabase descriptor_set_in_database, so this vector is for
+ // managing their lifetimes. Its scope should match descriptor_set_in_database
+ std::vector>
+ databases_per_descriptor_set;
+ std::unique_ptr descriptor_set_in_database;
+
std::unique_ptr source_tree_database;
// Any --descriptor_set_in FileDescriptorSet objects will be used as a
// fallback to input_files on command line, so create that db first.
if (!descriptor_set_in_names_.empty()) {
- descriptor_set_in_database.reset(new SimpleDescriptorDatabase());
- if (!PopulateSimpleDescriptorDatabase(descriptor_set_in_database.get())) {
- return 1;
+ for (const std::string& name : descriptor_set_in_names_) {
+ std::unique_ptr database_for_descriptor_set =
+ PopulateSingleSimpleDescriptorDatabase(name);
+ if (!database_for_descriptor_set) {
+ return EXIT_FAILURE;
+ }
+ databases_per_descriptor_set.push_back(
+ std::move(database_for_descriptor_set));
+ }
+
+ std::vector raw_databases_per_descriptor_set;
+ raw_databases_per_descriptor_set.reserve(
+ databases_per_descriptor_set.size());
+ for (const std::unique_ptr& db :
+ databases_per_descriptor_set) {
+ raw_databases_per_descriptor_set.push_back(db.get());
}
+ descriptor_set_in_database.reset(
+ new MergedDescriptorDatabase(raw_databases_per_descriptor_set));
}
if (proto_path_.empty()) {
@@ -876,6 +924,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
}
+ for (auto fd : parsed_files) {
+ if (!AllowProto3Optional(*fd) && ContainsProto3Optional(fd)) {
+ std::cerr << fd->name()
+ << ": This file contains proto3 optional fields, but "
+ "--experimental_allow_proto3_optional was not set."
+ << std::endl;
+ return 1;
+ }
+ }
+
// We construct a separate GeneratorContext for each output location. Note
// that two code generators may output to the same location, in which case
// they should share a single GeneratorContext so that OpenForInsert() works.
@@ -1000,46 +1058,57 @@ bool CommandLineInterface::InitializeDiskSourceTree(
return true;
}
-bool CommandLineInterface::PopulateSimpleDescriptorDatabase(
- SimpleDescriptorDatabase* database) {
- for (int i = 0; i < descriptor_set_in_names_.size(); i++) {
- int fd;
- do {
- fd = open(descriptor_set_in_names_[i].c_str(), O_RDONLY | O_BINARY);
- } while (fd < 0 && errno == EINTR);
- if (fd < 0) {
- std::cerr << descriptor_set_in_names_[i] << ": " << strerror(ENOENT)
- << std::endl;
- return false;
- }
+namespace {
+std::unique_ptr
+PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name) {
+ int fd;
+ do {
+ fd = open(descriptor_set_name.c_str(), O_RDONLY | O_BINARY);
+ } while (fd < 0 && errno == EINTR);
+ if (fd < 0) {
+ std::cerr << descriptor_set_name << ": " << strerror(ENOENT) << std::endl;
+ return nullptr;
+ }
- FileDescriptorSet file_descriptor_set;
- bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
- if (close(fd) != 0) {
- std::cerr << descriptor_set_in_names_[i] << ": close: " << strerror(errno)
- << std::endl;
- return false;
- }
+ FileDescriptorSet file_descriptor_set;
+ bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
+ if (close(fd) != 0) {
+ std::cerr << descriptor_set_name << ": close: " << strerror(errno)
+ << std::endl;
+ return nullptr;
+ }
- if (!parsed) {
- std::cerr << descriptor_set_in_names_[i] << ": Unable to parse."
- << std::endl;
- return false;
- }
+ if (!parsed) {
+ std::cerr << descriptor_set_name << ": Unable to parse." << std::endl;
+ return nullptr;
+ }
- for (int j = 0; j < file_descriptor_set.file_size(); j++) {
- FileDescriptorProto previously_added_file_descriptor_proto;
- if (database->FindFileByName(file_descriptor_set.file(j).name(),
- &previously_added_file_descriptor_proto)) {
- // already present - skip
- continue;
- }
- if (!database->Add(file_descriptor_set.file(j))) {
- return false;
- }
+ std::unique_ptr database{
+ new SimpleDescriptorDatabase()};
+
+ for (int j = 0; j < file_descriptor_set.file_size(); j++) {
+ FileDescriptorProto previously_added_file_descriptor_proto;
+ if (database->FindFileByName(file_descriptor_set.file(j).name(),
+ &previously_added_file_descriptor_proto)) {
+ // already present - skip
+ continue;
+ }
+ if (!database->Add(file_descriptor_set.file(j))) {
+ return nullptr;
}
}
- return true;
+ return database;
+}
+
+} // namespace
+
+bool CommandLineInterface::AllowProto3Optional(
+ const FileDescriptor& file) const {
+ if (allow_proto3_optional_) return true;
+ if (file.name() == "google/protobuf/unittest_proto3_optional.proto") {
+ return true;
+ }
+ return false;
}
bool CommandLineInterface::VerifyInputFilesInDescriptors(
@@ -1068,10 +1137,26 @@ bool CommandLineInterface::ParseInputFiles(
DescriptorPool* descriptor_pool, DiskSourceTree* source_tree,
std::vector* parsed_files) {
- // Track unused imports in all source files
- for (const auto& input_file : input_files_) {
- descriptor_pool->AddUnusedImportTrackFile(input_file);
+ if (!proto_path_.empty()) {
+ // Track unused imports in all source files that were loaded from the
+ // filesystem. We do not track unused imports for files loaded from
+ // descriptor sets as they may be programmatically generated in which case
+ // exerting this level of rigor is less desirable. We're also making the
+ // assumption that the initial parse of the proto from the filesystem
+ // was rigorous in checking unused imports and that the descriptor set
+ // being parsed was produced then and that it was subsequent mutations
+ // of that descriptor set that left unused imports.
+ //
+ // Note that relying on proto_path exclusively is limited in that we may
+ // be loading descriptors from both the filesystem and descriptor sets
+ // depending on the invocation. At least for invocations that are
+ // exclusively reading from descriptor sets, we can eliminate this failure
+ // condition.
+ for (const auto& input_file : input_files_) {
+ descriptor_pool->AddUnusedImportTrackFile(input_file);
+ }
}
+
bool result = true;
// Parse each file.
for (const auto& input_file : input_files_) {
@@ -1139,6 +1224,7 @@ void CommandLineInterface::Clear() {
source_info_in_descriptor_set_ = false;
disallow_services_ = false;
direct_dependencies_explicitly_set_ = false;
+ allow_proto3_optional_ = false;
}
bool CommandLineInterface::MakeProtoProtoPathRelative(
@@ -1414,7 +1500,8 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name,
if (*name == "-h" || *name == "--help" || *name == "--disallow_services" ||
*name == "--include_imports" || *name == "--include_source_info" ||
*name == "--version" || *name == "--decode_raw" ||
- *name == "--print_free_field_numbers") {
+ *name == "--print_free_field_numbers" ||
+ *name == "--experimental_allow_proto3_optional") {
// HACK: These are the only flags that don't take a value.
// They probably should not be hard-coded like this but for now it's
// not worth doing better.
@@ -1621,6 +1708,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
} else if (name == "--disallow_services") {
disallow_services_ = true;
+ } else if (name == "--experimental_allow_proto3_optional") {
+ allow_proto3_optional_ = true;
+
} else if (name == "--encode" || name == "--decode" ||
name == "--decode_raw") {
if (mode_ != MODE_COMPILE) {
@@ -1921,6 +2011,28 @@ void CommandLineInterface::PrintHelpText() {
<< std::endl;
}
+bool CommandLineInterface::EnforceProto3OptionalSupport(
+ const std::string& codegen_name, uint64 supported_features,
+ const std::vector& parsed_files) const {
+ bool supports_proto3_optional =
+ supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL;
+ if (!supports_proto3_optional) {
+ for (const auto fd : parsed_files) {
+ if (ContainsProto3Optional(fd)) {
+ std::cerr << fd->name()
+ << ": is a proto3 file that contains optional fields, but "
+ "code generator "
+ << codegen_name
+ << " hasn't been updated to support optional fields in "
+ "proto3. Please ask the owner of this code generator to "
+ "support proto3 optional.";
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
bool CommandLineInterface::GenerateOutput(
const std::vector& parsed_files,
const OutputDirective& output_directive,
@@ -1955,6 +2067,12 @@ bool CommandLineInterface::GenerateOutput(
}
parameters.append(generator_parameters_[output_directive.name]);
}
+ if (!EnforceProto3OptionalSupport(
+ output_directive.name,
+ output_directive.generator->GetSupportedFeatures(), parsed_files)) {
+ return false;
+ }
+
if (!output_directive.generator->GenerateAll(parsed_files, parameters,
generator_context, &error)) {
// Generator returned an error.
@@ -2119,6 +2237,9 @@ bool CommandLineInterface::GeneratePluginOutput(
// Generator returned an error.
*error = response.error();
return false;
+ } else if (!EnforceProto3OptionalSupport(
+ plugin_name, response.supported_features(), parsed_files)) {
+ return false;
}
return true;
diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h
index a05c32ec90..3c95cd6ee9 100644
--- a/src/google/protobuf/compiler/command_line_interface.h
+++ b/src/google/protobuf/compiler/command_line_interface.h
@@ -226,6 +226,17 @@ class PROTOC_EXPORT CommandLineInterface {
bool MakeInputsBeProtoPathRelative(DiskSourceTree* source_tree,
DescriptorDatabase* fallback_database);
+ // Is this .proto file whitelisted, or do we have a command-line flag allowing
+ // us to use proto3 optional? This is a temporary control to avoid people from
+ // using proto3 optional until code generators have implemented it.
+ bool AllowProto3Optional(const FileDescriptor& file) const;
+
+ // Fails if these files use proto3 optional and the code generator doesn't
+ // support it. This is a permanent check.
+ bool EnforceProto3OptionalSupport(
+ const std::string& codegen_name, uint64 supported_features,
+ const std::vector& parsed_files) const;
+
// Return status for ParseArguments() and InterpretArgument().
enum ParseArgumentStatus {
@@ -269,9 +280,6 @@ class PROTOC_EXPORT CommandLineInterface {
// Verify that all the input files exist in the given database.
bool VerifyInputFilesInDescriptors(DescriptorDatabase* fallback_database);
- // Loads descriptor_set_in into the provided database
- bool PopulateSimpleDescriptorDatabase(SimpleDescriptorDatabase* database);
-
// Parses input_files_ into parsed_files
bool ParseInputFiles(DescriptorPool* descriptor_pool,
DiskSourceTree* source_tree,
@@ -373,21 +381,21 @@ class PROTOC_EXPORT CommandLineInterface {
MODE_PRINT, // Print mode: print info of the given .proto files and exit.
};
- Mode mode_;
+ Mode mode_ = MODE_COMPILE;
enum PrintMode {
PRINT_NONE, // Not in MODE_PRINT
PRINT_FREE_FIELDS, // --print_free_fields
};
- PrintMode print_mode_;
+ PrintMode print_mode_ = PRINT_NONE;
enum ErrorFormat {
ERROR_FORMAT_GCC, // GCC error output format (default).
ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs).
};
- ErrorFormat error_format_;
+ ErrorFormat error_format_ = ERROR_FORMAT_GCC;
std::vector >
proto_path_; // Search path for proto files.
@@ -396,7 +404,7 @@ class PROTOC_EXPORT CommandLineInterface {
// Names of proto files which are allowed to be imported. Used by build
// systems to enforce depend-on-what-you-import.
std::set direct_dependencies_;
- bool direct_dependencies_explicitly_set_;
+ bool direct_dependencies_explicitly_set_ = false;
// If there's a violation of depend-on-what-you-import, this string will be
// presented to the user. "%s" will be replaced with the violating import.
@@ -435,10 +443,13 @@ class PROTOC_EXPORT CommandLineInterface {
// True if --include_source_info was given, meaning that we should not strip
// SourceCodeInfo from the DescriptorSet.
- bool source_info_in_descriptor_set_;
+ bool source_info_in_descriptor_set_ = false;
// Was the --disallow_services flag used?
- bool disallow_services_;
+ bool disallow_services_ = false;
+
+ // Was the --experimental_allow_proto3_optional flag used?
+ bool allow_proto3_optional_ = false;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
};
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index a934d7a606..a51ad92d15 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -205,6 +205,17 @@ class CommandLineInterfaceTest : public testing::Test {
void ExpectFileContent(const std::string& filename,
const std::string& content);
+ // The default code generators support all features. Use this to create a
+ // code generator that omits the given feature(s).
+ void CreateGeneratorWithMissingFeatures(const std::string& name,
+ const std::string& description,
+ uint64 features) {
+ MockCodeGenerator* generator = new MockCodeGenerator(name);
+ generator->SuppressFeatures(features);
+ mock_generators_to_delete_.push_back(generator);
+ cli_.RegisterGenerator(name, generator, description);
+ }
+
private:
// The object we are testing.
CommandLineInterface cli_;
@@ -913,6 +924,58 @@ TEST_F(CommandLineInterfaceTest,
ExpectErrorSubstring("bar.proto: \"Baz\" is not defined.");
}
+TEST_F(CommandLineInterfaceTest,
+ InputsOnlyFromDescriptorSetIn_UnusedImportIsNotReported) {
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("unused.proto");
+ file_descriptor_proto->add_message_type()->set_name("Unused");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_dependency("unused.proto");
+ file_descriptor_proto->add_message_type()->set_name("Bar");
+
+ WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
+
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/unused_and_bar.bin unused.proto bar.proto");
+ ExpectNoErrors();
+}
+
+TEST_F(CommandLineInterfaceTest,
+ InputsFromDescriptorSetInAndFileSystem_UnusedImportIsReported) {
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("unused.proto");
+ file_descriptor_proto->add_message_type()->set_name("Unused");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_dependency("unused.proto");
+ file_descriptor_proto->add_message_type()->set_name("Bar");
+
+ WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
+
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "import \"bar.proto\";\n"
+ "message Foo {\n"
+ " optional Bar bar = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/unused_and_bar.bin "
+ "--proto_path=$tmpdir unused.proto bar.proto foo.proto");
+ // Reporting unused imports here is unfair, since it's unactionable. Notice
+ // the lack of a line number.
+ // TODO(b/144853061): If the file with unused import is from the descriptor
+ // set and not from the file system, suppress the warning.
+ ExpectWarningSubstring("bar.proto: warning: Import unused.proto is unused.");
+}
+
TEST_F(CommandLineInterfaceTest,
OnlyReportsUnusedImportsForFilesBeingGenerated) {
CreateTempFile("unused.proto",
@@ -975,7 +1038,6 @@ TEST_F(CommandLineInterfaceTest, ReportsTransitiveMisingImports_LeafLast) {
ExpectWarningSubstring(
"bar.proto:2:1: warning: Import unused.proto is unused.");
}
-
TEST_F(CommandLineInterfaceTest, CreateDirectory) {
// Test that when we output to a sub-directory, it is created.
@@ -2310,6 +2372,78 @@ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
ExpectErrorText("Missing value for flag: --test_out\n");
}
+TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowed) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " optional int32 i = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --proto_path=$tmpdir foo.proto -odescriptor.pb");
+
+ ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
+}
+
+TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedDescriptor) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " optional int32 i = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --experimental_allow_proto3_optional "
+ "--proto_path=$tmpdir foo.proto "
+ " -o$tmpdir/descriptor.pb");
+ ExpectNoErrors();
+
+ Run("protocol_compiler --descriptor_set_in=$tmpdir/descriptor.pb foo.proto "
+ "--test_out=$tmpdir");
+ ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
+}
+
+TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedGenCode) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " optional int32 i = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --proto_path=$tmpdir foo.proto --test_out=$tmpdir");
+
+ ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
+}
+
+TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedNoCodegenSupport) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " optional int32 i = 1;\n"
+ "}\n");
+
+ CreateGeneratorWithMissingFeatures("--no_proto3_optional_out",
+ "Doesn't support proto3 optional",
+ CodeGenerator::FEATURE_PROTO3_OPTIONAL);
+
+ Run("protocol_compiler --experimental_allow_proto3_optional "
+ "--proto_path=$tmpdir foo.proto --no_proto3_optional_out=$tmpdir");
+
+ ExpectErrorSubstring(
+ "code generator --no_proto3_optional_out hasn't been updated to support "
+ "optional fields in proto3");
+}
+
+TEST_F(CommandLineInterfaceTest, Proto3OptionalAllowWithFlag) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " optional int32 i = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --experimental_allow_proto3_optional "
+ "--proto_path=$tmpdir foo.proto --test_out=$tmpdir");
+ ExpectNoErrors();
+}
+
TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
index dbef855927..31fe5a6841 100755
--- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
@@ -76,8 +76,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) {
- strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line,
- column, message);
+ strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
+ message);
}
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc
index 8a661ea7c9..06da3f37c4 100644
--- a/src/google/protobuf/compiler/cpp/cpp_extension.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc
@@ -94,7 +94,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
variables_["constant_name"] = FieldConstantName(descriptor_);
variables_["field_type"] =
StrCat(static_cast(descriptor_->type()));
- variables_["packed"] = descriptor_->options().packed() ? "true" : "false";
+ variables_["packed"] = descriptor_->is_packed() ? "true" : "false";
std::string scope =
IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : "";
@@ -157,6 +157,11 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
StringReplace(variables_["scoped_name"], "::", "_", true) + "_default";
format("const std::string $1$($2$);\n", default_str,
DefaultValue(options_, descriptor_));
+ } else if (descriptor_->message_type()) {
+ // We have to initialize the default instance for extensions at registration
+ // time.
+ default_str =
+ FieldMessageTypeName(descriptor_, options_) + "::default_instance()";
} else {
default_str = DefaultValue(options_, descriptor_);
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index 7b08cdd7af..61f81429ca 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -411,11 +411,6 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* printer) {
IncludeFile("net/proto2/public/reflection_ops.h", printer);
IncludeFile("net/proto2/public/wire_format.h", printer);
}
- if (IsProto2MessageSetFile(file_, options_)) {
- format(
- // Implementation of proto1 MessageSet API methods.
- "#include \"net/proto2/internal/message_set_util.h\"\n");
- }
if (options_.proto_h) {
// Use the smaller .proto.h files.
@@ -898,18 +893,21 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
format("};\n");
// The DescriptorTable itself.
+ // Should be "bool eager = NeedsEagerDescriptorAssignment(file_, options_);"
+ // however this might cause a tsan failure in superroot b/148382879,
+ // so disable for now.
+ bool eager = false;
format(
"static ::$proto_ns$::internal::once_flag $desc_table$_once;\n"
- "static bool $desc_table$_initialized = false;\n"
"const ::$proto_ns$::internal::DescriptorTable $desc_table$ = {\n"
- " &$desc_table$_initialized, $1$, \"$filename$\", $2$,\n"
- " &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $3$, $4$,\n"
+ " false, $1$, $2$, \"$filename$\", $3$,\n"
+ " &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $4$, $5$,\n"
" schemas, file_default_instances, $tablename$::offsets,\n"
- " $file_level_metadata$, $5$, $file_level_enum_descriptors$, "
+ " $file_level_metadata$, $6$, $file_level_enum_descriptors$, "
"$file_level_service_descriptors$,\n"
"};\n\n",
- protodef_name, file_data.size(), sccs_.size(), num_deps,
- message_generators_.size());
+ eager ? "true" : "false", protodef_name, file_data.size(), sccs_.size(),
+ num_deps, message_generators_.size());
// For descriptor.proto we want to avoid doing any dynamic initialization,
// because in some situations that would otherwise pull in a lot of
@@ -1297,12 +1295,10 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
IncludeFile("net/proto2/public/generated_message_table_driven.h", printer);
IncludeFile("net/proto2/public/generated_message_util.h", printer);
IncludeFile("net/proto2/public/inlined_string_field.h", printer);
+ IncludeFile("net/proto2/public/metadata_lite.h", printer);
if (HasDescriptorMethods(file_, options_)) {
- IncludeFile("net/proto2/public/metadata.h", printer);
IncludeFile("net/proto2/public/generated_message_reflection.h", printer);
- } else {
- IncludeFile("net/proto2/public/metadata_lite.h", printer);
}
if (!message_generators_.empty()) {
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc
index 0d80ea2799..2c45ca8fa2 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc
@@ -93,6 +93,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.annotation_guard_name = options[i].second;
} else if (options[i].first == "speed") {
file_options.enforce_mode = EnforceOptimizeMode::kSpeed;
+ } else if (options[i].first == "code_size") {
+ file_options.enforce_mode = EnforceOptimizeMode::kCodeSize;
} else if (options[i].first == "lite") {
file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime;
} else if (options[i].first == "lite_implicit_weak_fields") {
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.h b/src/google/protobuf/compiler/cpp/cpp_generator.h
index c5ff28a70e..85a5aab1ec 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.h
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.h
@@ -81,7 +81,14 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
// implements CodeGenerator ----------------------------------------
bool Generate(const FileDescriptor* file, const std::string& parameter,
- GeneratorContext* generator_context, std::string* error) const;
+ GeneratorContext* generator_context,
+ std::string* error) const override;
+
+ uint64 GetSupportedFeatures() const override {
+ // We don't fully support this yet, but this is needed to unblock the tests,
+ // and we will have full support before the experimental flag is removed.
+ return FEATURE_PROTO3_OPTIONAL;
+ }
private:
bool opensource_runtime_ = true;
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index e15cd3a0c3..c3cd808295 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -43,10 +43,13 @@
#include
#include
+#include
+#include
#include
#include
#include
#include
+#include
#include
#include
#include
@@ -244,6 +247,31 @@ void SetCommonVars(const Options& options,
(*variables)["string"] = "std::string";
}
+void SetUnknkownFieldsVariable(const Descriptor* descriptor,
+ const Options& options,
+ std::map* variables) {
+ std::string proto_ns = ProtobufNamespace(options);
+ std::string unknown_fields_type;
+ if (UseUnknownFieldSet(descriptor->file(), options)) {
+ unknown_fields_type = "::" + proto_ns + "::UnknownFieldSet";
+ (*variables)["unknown_fields"] =
+ "_internal_metadata_.unknown_fields<" + unknown_fields_type + ">(" +
+ unknown_fields_type + "::default_instance)";
+ } else {
+ unknown_fields_type =
+ PrimitiveTypeName(options, FieldDescriptor::CPPTYPE_STRING);
+ (*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields<" +
+ unknown_fields_type + ">(::" + proto_ns +
+ "::internal::GetEmptyString)";
+ }
+ (*variables)["unknown_fields_type"] = unknown_fields_type;
+ (*variables)["have_unknown_fields"] =
+ "_internal_metadata_.have_unknown_fields()";
+ (*variables)["mutable_unknown_fields"] =
+ "_internal_metadata_.mutable_unknown_fields<" + unknown_fields_type +
+ ">()";
+}
+
std::string UnderscoresToCamelCase(const std::string& input,
bool cap_next_letter) {
std::string result;
@@ -334,6 +362,16 @@ std::string QualifiedClassName(const EnumDescriptor* d) {
return QualifiedClassName(d, Options());
}
+std::string QualifiedExtensionName(const FieldDescriptor* d,
+ const Options& options) {
+ GOOGLE_DCHECK(d->is_extension());
+ return QualifiedFileLevelSymbol(d->file(), FieldName(d), options);
+}
+
+std::string QualifiedExtensionName(const FieldDescriptor* d) {
+ return QualifiedExtensionName(d, Options());
+}
+
std::string Namespace(const std::string& package) {
if (package.empty()) return "";
return "::" + DotsToColons(package);
@@ -1345,11 +1383,14 @@ class ParseLoopGenerator {
format_.Set("GOOGLE_PROTOBUF", MacroPrefix(options_));
std::map vars;
SetCommonVars(options_, &vars);
+ SetUnknkownFieldsVariable(descriptor, options_, &vars);
format_.AddMap(vars);
std::vector ordered_fields;
for (auto field : FieldRange(descriptor)) {
- ordered_fields.push_back(field);
+ if (IsFieldUsed(field, options_)) {
+ ordered_fields.push_back(field);
+ }
}
std::sort(ordered_fields.begin(), ordered_fields.end(),
[](const FieldDescriptor* a, const FieldDescriptor* b) {
@@ -1375,12 +1416,13 @@ class ParseLoopGenerator {
}
if (descriptor->file()->options().cc_enable_arenas()) {
- format_("$p_ns$::Arena* arena = GetArenaNoVirtual(); (void)arena;\n");
+ format_("$p_ns$::Arena* arena = GetArena(); (void)arena;\n");
}
GenerateParseLoop(descriptor, ordered_fields);
format_.Outdent();
format_("success:\n");
if (hasbits_size) format_(" _has_bits_.Or(has_bits);\n");
+
format_(
" return ptr;\n"
"failure:\n"
@@ -1495,12 +1537,20 @@ class ParseLoopGenerator {
enum_validator =
StrCat(", ", QualifiedClassName(field->enum_type(), options_),
"_IsValid, &_internal_metadata_, ", field->number());
+ format_(
+ "ptr = "
+ "$pi_ns$::Packed$1$Parser<$unknown_fields_type$>(_internal_mutable_"
+ "$2$(), ptr, "
+ "ctx$3$);\n",
+ DeclaredTypeMethodName(field->type()), FieldName(field),
+ enum_validator);
+ } else {
+ format_(
+ "ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
+ "ctx$3$);\n",
+ DeclaredTypeMethodName(field->type()), FieldName(field),
+ enum_validator);
}
- format_(
- "ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
- "ctx$3$);\n",
- DeclaredTypeMethodName(field->type()), FieldName(field),
- enum_validator);
} else {
auto field_type = field->type();
switch (field_type) {
@@ -1518,7 +1568,9 @@ class ParseLoopGenerator {
if (HasFieldPresence(field->file()) &&
val->type() == FieldDescriptor::TYPE_ENUM) {
format_(
- "auto object = ::$proto_ns$::internal::InitEnumParseWrapper("
+ "auto object = "
+ "::$proto_ns$::internal::InitEnumParseWrapper<$unknown_"
+ "fields_type$>("
"&$1$_, $2$_IsValid, $3$, &_internal_metadata_);\n"
"ptr = ctx->ParseMessage(&object, ptr);\n",
FieldName(field), QualifiedClassName(val->enum_type()),
@@ -1533,8 +1585,7 @@ class ParseLoopGenerator {
"if (!_internal_has_$1$()) {\n"
" clear_$2$();\n"
" $2$_.$1$_ = ::$proto_ns$::Arena::CreateMessage<\n"
- " $pi_ns$::LazyField>("
- "GetArenaNoVirtual());\n"
+ " $pi_ns$::LazyField>(GetArena());\n"
" set_has_$1$();\n"
"}\n"
"ptr = ctx->ParseMessage($2$_.$1$_, ptr);\n",
@@ -1624,7 +1675,10 @@ class ParseLoopGenerator {
field->number());
}
} else {
- std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 || field->type() == FieldDescriptor::TYPE_UINT32) ? "32" : "64";
+ std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 ||
+ field->type() == FieldDescriptor::TYPE_UINT32)
+ ? "32"
+ : "64";
std::string zigzag;
if ((field->type() == FieldDescriptor::TYPE_SINT32 ||
field->type() == FieldDescriptor::TYPE_SINT64)) {
@@ -1807,7 +1861,10 @@ class ParseLoopGenerator {
"}\n");
}
format_(
- " ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);\n"
+ " ptr = UnknownFieldParse(tag,\n"
+ " _internal_metadata_.mutable_unknown_fields<$unknown_"
+ "fields_type$>(),\n"
+ " ptr, ctx);\n"
" CHK_(ptr != nullptr);\n"
" continue;\n");
}
@@ -1827,6 +1884,130 @@ void GenerateParserLoop(const Descriptor* descriptor, int num_hasbits,
generator.GenerateParserLoop(descriptor);
}
+static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file,
+ const Options& options,
+ bool* has_opt_codesize_extension) {
+ std::vector fields;
+ auto reflection = msg.GetReflection();
+ reflection->ListFields(msg, &fields);
+ for (auto field : fields) {
+ const auto* field_msg = field->message_type();
+ if (field_msg == nullptr) {
+ // It so happens that enums Is_Valid are still generated so enums work.
+ // Only messages have potential problems.
+ continue;
+ }
+ // If this option has an extension set AND that extension is defined in the
+ // same file we have bootstrap problem.
+ if (field->is_extension()) {
+ const auto* msg_extension_file = field->message_type()->file();
+ if (msg_extension_file == file) return true;
+ if (has_opt_codesize_extension &&
+ GetOptimizeFor(msg_extension_file, options) ==
+ FileOptions::CODE_SIZE) {
+ *has_opt_codesize_extension = true;
+ }
+ }
+ // Recurse in this field to see if there is a problem in there
+ if (field->is_repeated()) {
+ for (int i = 0; i < reflection->FieldSize(msg, field); i++) {
+ if (HasExtensionFromFile(reflection->GetRepeatedMessage(msg, field, i),
+ file, options, has_opt_codesize_extension)) {
+ return true;
+ }
+ }
+ } else {
+ if (HasExtensionFromFile(reflection->GetMessage(msg, field), file,
+ options, has_opt_codesize_extension)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static bool HasBootstrapProblem(const FileDescriptor* file,
+ const Options& options,
+ bool* has_opt_codesize_extension) {
+ static auto& cache = *new std::unordered_map;
+ auto it = cache.find(file);
+ if (it != cache.end()) return it->second;
+ // In order to build the data structures for the reflective parse, it needs
+ // to parse the serialized descriptor describing all the messages defined in
+ // this file. Obviously this presents a bootstrap problem for descriptor
+ // messages.
+ if (file->name() == "net/proto2/proto/descriptor.proto" ||
+ file->name() == "google/protobuf/descriptor.proto") {
+ return true;
+ }
+ // Unfortunately we're not done yet. The descriptor option messages allow
+ // for extensions. So we need to be able to parse these extensions in order
+ // to parse the file descriptor for a file that has custom options. This is a
+ // problem when these custom options extensions are defined in the same file.
+ FileDescriptorProto linkedin_fd_proto;
+ const DescriptorPool* pool = file->pool();
+ const Descriptor* fd_proto_descriptor =
+ pool->FindMessageTypeByName(linkedin_fd_proto.GetTypeName());
+ // Not all pools have descriptor.proto in them. In these cases there for sure
+ // are no custom options.
+ if (fd_proto_descriptor == nullptr) return false;
+
+ // It's easier to inspect file as a proto, because we can use reflection on
+ // the proto to iterate over all content.
+ file->CopyTo(&linkedin_fd_proto);
+
+ // linkedin_fd_proto is a generated proto linked in the proto compiler. As
+ // such it doesn't know the extensions that are potentially present in the
+ // descriptor pool constructed from the protos that are being compiled. These
+ // custom options are therefore in the unknown fields.
+ // By building the corresponding FileDescriptorProto in the pool constructed
+ // by the protos that are being compiled, ie. file's pool, the unknown fields
+ // are converted to extensions.
+ DynamicMessageFactory factory(pool);
+ Message* fd_proto = factory.GetPrototype(fd_proto_descriptor)->New();
+ fd_proto->ParseFromString(linkedin_fd_proto.SerializeAsString());
+
+ bool& res = cache[file];
+ res = HasExtensionFromFile(*fd_proto, file, options,
+ has_opt_codesize_extension);
+ delete fd_proto;
+ return res;
+}
+
+FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
+ const Options& options,
+ bool* has_opt_codesize_extension) {
+ if (has_opt_codesize_extension) *has_opt_codesize_extension = false;
+ switch (options.enforce_mode) {
+ case EnforceOptimizeMode::kSpeed:
+ return FileOptions::SPEED;
+ case EnforceOptimizeMode::kLiteRuntime:
+ return FileOptions::LITE_RUNTIME;
+ case EnforceOptimizeMode::kCodeSize:
+ if (file->options().optimize_for() == FileOptions::LITE_RUNTIME) {
+ return FileOptions::LITE_RUNTIME;
+ }
+ if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
+ return FileOptions::SPEED;
+ }
+ return FileOptions::CODE_SIZE;
+ case EnforceOptimizeMode::kNoEnforcement:
+ if (file->options().optimize_for() == FileOptions::CODE_SIZE) {
+ if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
+ GOOGLE_LOG(WARNING) << "Proto states optimize_for = CODE_SIZE, but we "
+ "cannot honor that because it contains custom option "
+ "extensions defined in the same proto.";
+ return FileOptions::SPEED;
+ }
+ }
+ return file->options().optimize_for();
+ }
+
+ GOOGLE_LOG(FATAL) << "Unknown optimization enforcement requested.";
+ // The phony return below serves to silence a warning from GCC 8.
+ return FileOptions::SPEED;
+}
+
} // namespace cpp
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index 28cf78e7e6..072d94955e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -83,6 +83,10 @@ extern const char kThinSeparator[];
void SetCommonVars(const Options& options,
std::map* variables);
+void SetUnknkownFieldsVariable(const Descriptor* descriptor,
+ const Options& options,
+ std::map* variables);
+
bool GetBootstrapBasename(const Options& options, const std::string& basename,
std::string* bootstrap_basename);
bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
@@ -130,6 +134,10 @@ inline std::string ClassName(const EnumDescriptor* descriptor, bool qualified) {
: ClassName(descriptor);
}
+std::string QualifiedExtensionName(const FieldDescriptor* d,
+ const Options& options);
+std::string QualifiedExtensionName(const FieldDescriptor* d);
+
// Type name of default instance.
std::string DefaultInstanceType(const Descriptor* descriptor,
const Options& options);
@@ -339,6 +347,12 @@ inline bool IsLazy(const FieldDescriptor* field, const Options& options) {
!options.opensource_runtime;
}
+// Returns true if "field" is used.
+inline bool IsFieldUsed(const FieldDescriptor* /*field*/,
+ const Options& /*options*/) {
+ return true;
+}
+
// Does the file contain any definitions that need extension_set.h?
bool HasExtensionsOrExtendableMessage(const FileDescriptor* file);
@@ -414,6 +428,12 @@ inline bool HasFieldPresence(const FileDescriptor* file) {
return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
}
+inline bool HasHasbit(const FieldDescriptor* field) {
+ // TODO(haberman): remove, and give some proto3 fields hasbits.
+ if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) return false;
+ return field->is_singular_with_presence();
+}
+
// Returns true if 'enum' semantics are such that unknown values are preserved
// in the enum field itself, rather than going to the UnknownFieldSet.
inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) {
@@ -475,16 +495,32 @@ inline std::string IncludeGuard(const FileDescriptor* file, bool pb_h,
}
}
+// Returns the OptimizeMode for this file, furthermore it updates a status
+// bool if has_opt_codesize_extension is non-null. If this status bool is true
+// it means this file contains an extension that itself is defined as
+// optimized_for = CODE_SIZE.
+FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
+ const Options& options,
+ bool* has_opt_codesize_extension);
inline FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
const Options& options) {
- switch (options.enforce_mode) {
- case EnforceOptimizeMode::kSpeed:
- return FileOptions::SPEED;
- case EnforceOptimizeMode::kLiteRuntime:
- return FileOptions::LITE_RUNTIME;
- case EnforceOptimizeMode::kNoEnforcement:
- default:
- return file->options().optimize_for();
+ return GetOptimizeFor(file, options, nullptr);
+}
+inline bool NeedsEagerDescriptorAssignment(const FileDescriptor* file,
+ const Options& options) {
+ bool has_opt_codesize_extension;
+ if (GetOptimizeFor(file, options, &has_opt_codesize_extension) ==
+ FileOptions::CODE_SIZE &&
+ has_opt_codesize_extension) {
+ // If this filedescriptor contains an extension from another file which
+ // is optimized_for = CODE_SIZE. We need to be careful in the ordering so
+ // we eagerly build the descriptors in the dependencies before building
+ // the descriptors of this file.
+ return true;
+ } else {
+ // If we have a generated code based parser we never need eager
+ // initialization of descriptors of our deps.
+ return false;
}
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index cc54f43e11..da4a38768e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -35,6 +35,7 @@
#include
#include
+#include
#include