Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP2:Update
protobuf.29292
protobuf-58d4420e2dd8a3cd354fff9db0052881c25369...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File protobuf-58d4420e2dd8a3cd354fff9db0052881c25369ce.patch of Package protobuf.29292
From 58d4420e2dd8a3cd354fff9db0052881c25369ce Mon Sep 17 00:00:00 2001 From: Rafi Kamal <rafikamal@google.com> Date: Mon, 11 Nov 2019 17:06:56 -0800 Subject: [PATCH] Down Integrate Internal Changes --- java/core/src/main/java/com/google/protobuf/ByteString.java | 10 ++- java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java | 2 java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java | 3 - java/core/src/main/java/com/google/protobuf/MessageLiteToString.java | 2 java/core/src/main/java/com/google/protobuf/MessageSchema.java | 8 +- java/core/src/main/java/com/google/protobuf/RopeByteString.java | 28 +++++++--- java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java | 9 +-- java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java | 25 ++++++++ java/lite/proguard.pgcfg | 3 + 9 files changed, 68 insertions(+), 22 deletions(-) create mode 100755 java/lite/proguard.pgcfg --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -57,13 +57,17 @@ import java.util.Locale; import java.util.NoSuchElementException; /** - * Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable - * underlying bytes. Concatenation is likewise supported without copying (long strings) by building - * a tree of pieces in {@link RopeByteString}. + * Immutable sequence of bytes. Provides conversions to and from {@code byte[]}, {@link + * java.lang.String}, {@link ByteBuffer}, {@link InputStream}, {@link OutputStream}. Also provides a + * conversion to {@link CodedInputStream}. * * <p>Like {@link String}, the contents of a {@link ByteString} can never be observed to change, not * even in the presence of a data race or incorrect API usage in the client code. * + * <p>Substring is supported by sharing the reference to the immutable underlying bytes. + * Concatenation is likewise supported without copying (long strings) by building a tree of pieces + * in {@link RopeByteString}. + * * @author crazybob@google.com Bob Lee * @author kenton@google.com Kenton Varda * @author carlanton@google.com Carl Haverl --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -1023,7 +1023,7 @@ public abstract class GeneratedMessageLi } /** Clear an extension. */ - public final <Type> BuilderType clearExtension(final ExtensionLite<MessageType, ?> extension) { + public final BuilderType clearExtension(final ExtensionLite<MessageType, ?> extension) { GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension); verifyExtensionContainingType(extensionLite); --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -1498,8 +1498,7 @@ public abstract class GeneratedMessageV3 } /** Clear an extension. */ - public final <Type> BuilderType clearExtension( - final ExtensionLite<MessageType, ?> extensionLite) { + public final BuilderType clearExtension(final ExtensionLite<MessageType, ?> extensionLite) { Extension<MessageType, ?> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); --- a/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java @@ -88,7 +88,7 @@ final class MessageLiteToString { } for (String getter : getters) { - String suffix = getter.replaceFirst("get", ""); + String suffix = getter.startsWith("get") ? getter.substring(3) : getter; if (suffix.endsWith(LIST_SUFFIX) && !suffix.endsWith(BUILDER_LIST_SUFFIX) // Sometimes people have fields named 'list' that aren't repeated. --- a/java/core/src/main/java/com/google/protobuf/MessageSchema.java +++ b/java/core/src/main/java/com/google/protobuf/MessageSchema.java @@ -1173,12 +1173,10 @@ final class MessageSchema<T> implements mergeSingleField(message, other, i); } - if (!proto3) { - SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); + SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); - if (hasExtensions) { - SchemaUtil.mergeExtensions(extensionSchema, message, other); - } + if (hasExtensions) { + SchemaUtil.mergeExtensions(extensionSchema, message, other); } } --- a/java/core/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java @@ -211,7 +211,7 @@ final class RopeByteString extends ByteS // Fine, we'll add a node and increase the tree depth--unless we rebalance ;^) int newDepth = Math.max(left.getTreeDepth(), right.getTreeDepth()) + 1; - if (newLength >= minLengthByDepth[newDepth]) { + if (newLength >= minLength(newDepth)) { // The tree is shallow enough, so don't rebalance return new RopeByteString(left, right); } @@ -251,6 +251,22 @@ final class RopeByteString extends ByteS } /** + * Returns the minimum length for which a tree of the given depth is considered balanced according + * to BAP95, which means the tree is flat-enough with respect to the bounds. Defaults to {@code + * Integer.MAX_VALUE} if {@code depth >= minLengthByDepth.length} in order to avoid an {@code + * ArrayIndexOutOfBoundsException}. + * + * @param depth tree depth + * @return minimum balanced length + */ + static int minLength(int depth) { + if (depth >= minLengthByDepth.length) { + return Integer.MAX_VALUE; + } + return minLengthByDepth[depth]; + } + + /** * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for * backwards-compatibility reasons although it would more properly be {@link * IndexOutOfBoundsException}. @@ -328,7 +344,7 @@ final class RopeByteString extends ByteS */ @Override protected boolean isBalanced() { - return totalLength >= minLengthByDepth[treeDepth]; + return totalLength >= minLength(treeDepth); } /** @@ -656,7 +672,7 @@ final class RopeByteString extends ByteS */ private void insert(ByteString byteString) { int depthBin = getDepthBinForLength(byteString.size()); - int binEnd = minLengthByDepth[depthBin + 1]; + int binEnd = minLength(depthBin + 1); // BAP95: Concatenate all trees occupying bins representing the length of // our new piece or of shorter pieces, to the extent that is possible. @@ -665,7 +681,7 @@ final class RopeByteString extends ByteS if (prefixesStack.isEmpty() || prefixesStack.peek().size() >= binEnd) { prefixesStack.push(byteString); } else { - int binStart = minLengthByDepth[depthBin]; + int binStart = minLength(depthBin); // Concatenate the subtrees of shorter length ByteString newTree = prefixesStack.pop(); @@ -680,7 +696,7 @@ final class RopeByteString extends ByteS // Continue concatenating until we land in an empty bin while (!prefixesStack.isEmpty()) { depthBin = getDepthBinForLength(newTree.size()); - binEnd = minLengthByDepth[depthBin + 1]; + binEnd = minLength(depthBin + 1); if (prefixesStack.peek().size() < binEnd) { ByteString left = prefixesStack.pop(); newTree = new RopeByteString(left, newTree); @@ -816,7 +832,7 @@ final class RopeByteString extends ByteS * * <p>Note that {@link InputStream#read(byte[], int, int)} and {@link * ByteArrayInputStream#read(byte[], int, int)} behave inconsistently when reading 0 bytes at - * EOF; the interface defines the return value to be 0 and the latter returns -1. We use the + * EOF; the interface defines the return value to be 0 and the latter returns -1. We use the * latter behavior so that all ByteString streams are consistent. * * @return -1 if at EOF, otherwise the actual number of bytes read. --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java @@ -62,18 +62,19 @@ public class RopeByteStringTest extends expectedHashCode = -1214197238; } - public void testMinLengthByDepth() { - // minLengthByDepth should match the Fibonacci sequence + public void testMinLength() { + // minLength should match the Fibonacci sequence int a = 1; int b = 1; int i; for (i = 0; a > 0; i++) { - assertEquals(a, RopeByteString.minLengthByDepth[i]); + assertEquals(a, RopeByteString.minLength(i)); int c = a + b; a = b; b = c; } - assertEquals(Integer.MAX_VALUE, RopeByteString.minLengthByDepth[i]); + assertEquals(Integer.MAX_VALUE, RopeByteString.minLength(i)); + assertEquals(Integer.MAX_VALUE, RopeByteString.minLength(i + 1)); assertEquals(i + 1, RopeByteString.minLengthByDepth.length); } --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java @@ -38,6 +38,7 @@ import protobuf_unittest.UnittestProto.T import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; +import proto3_unittest.UnittestProto3; import java.util.Arrays; import java.util.Map; import junit.framework.TestCase; @@ -379,4 +380,28 @@ public class UnknownFieldSetTest extends } // ================================================================= + + public void testProto3RoundTrip() throws Exception { + ByteString data = getBizarroData(); + + UnittestProto3.TestEmptyMessage message = + UnittestProto3.TestEmptyMessage.parseFrom(data, ExtensionRegistryLite.getEmptyRegistry()); + assertEquals(data, message.toByteString()); + + message = UnittestProto3.TestEmptyMessage.newBuilder().mergeFrom(message).build(); + assertEquals(data, message.toByteString()); + + assertEquals( + data, + UnittestProto3.TestMessageWithDummy.parseFrom( + data, ExtensionRegistryLite.getEmptyRegistry()) + .toBuilder() + // force copy-on-write + .setDummy(true) + .build() + .toBuilder() + .clearDummy() + .build() + .toByteString()); + } } --- /dev/null +++ b/java/lite/proguard.pgcfg @@ -0,0 +1,3 @@ +-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite { + <fields>; +}
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor