aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorWink Saville <wink@google.com>2014-05-07 14:37:31 -0700
committerWink Saville <wink@google.com>2014-05-07 14:37:31 -0700
commitf65ee55561e2a5f53be6db2ce03e518e249c9e80 (patch)
treeebec75f7ede9150939c836d1695e8a9b08bc30ef /java
parentd89b3060b40d8485d02e48d11056750495ecb577 (diff)
parente887563af628efea8f49b1393d30c33107b198e0 (diff)
downloadexternal_protobuf-f65ee55561e2a5f53be6db2ce03e518e249c9e80.zip
external_protobuf-f65ee55561e2a5f53be6db2ce03e518e249c9e80.tar.gz
external_protobuf-f65ee55561e2a5f53be6db2ce03e518e249c9e80.tar.bz2
Merge commit 'e887563a' into fix-merge-conclict
* commit 'e887563a': Revert "am 5b931dc7: am ec0b12c3: Merge "Don\'t reset cachedSize to 0 in getSerializedSize"" Change-Id: I1222ae20e6caef67c5a00ac481e10fe7b7d2a91c
Diffstat (limited to 'java')
-rw-r--r--java/README.txt9
-rw-r--r--java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java3
-rw-r--r--java/src/main/java/com/google/protobuf/nano/MessageNano.java17
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java26
4 files changed, 6 insertions, 49 deletions
diff --git a/java/README.txt b/java/README.txt
index c693313..96b042f 100644
--- a/java/README.txt
+++ b/java/README.txt
@@ -437,15 +437,6 @@ and the runtime overhead. An overview of Nano features:
MessageNano.
- The 'bytes' type translates to the Java type byte[].
-The generated messages are not thread-safe for writes, but may be
-used simultaneously from multiple threads in a read-only manner.
-In other words, an appropriate synchronization mechanism (such as
-a ReadWriteLock) must be used to ensure that a message, its
-ancestors, and descendants are not accessed by any other threads
-while the message is being modified. Field reads, getter methods,
-toByteArray(...), writeTo(...), getCachedSize(), and
-getSerializedSize() are all considered read-only operations.
-
IMPORTANT: If you have fields with defaults and opt out of accessors
How fields with defaults are serialized has changed. Because we don't
diff --git a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
index 63c8afc..839f21c 100644
--- a/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
@@ -47,7 +47,7 @@ public abstract class ExtendableMessageNano<M extends ExtendableMessageNano<M>>
protected List<UnknownFieldData> unknownFieldData;
@Override
- protected int computeSerializedSize() {
+ public int getSerializedSize() {
int size = 0;
int unknownFieldCount = unknownFieldData == null ? 0 : unknownFieldData.size();
for (int i = 0; i < unknownFieldCount; i++) {
@@ -55,6 +55,7 @@ public abstract class ExtendableMessageNano<M extends ExtendableMessageNano<M>>
size += CodedOutputByteBufferNano.computeRawVarint32Size(unknownField.tag);
size += unknownField.bytes.length;
}
+ cachedSize = size;
return size;
}
diff --git a/java/src/main/java/com/google/protobuf/nano/MessageNano.java b/java/src/main/java/com/google/protobuf/nano/MessageNano.java
index d6288c9..82dc6cc 100644
--- a/java/src/main/java/com/google/protobuf/nano/MessageNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/MessageNano.java
@@ -38,7 +38,7 @@ import java.io.IOException;
* @author wink@google.com Wink Saville
*/
public abstract class MessageNano {
- protected volatile int cachedSize = -1;
+ protected int cachedSize = -1;
/**
* Get the number of bytes required to encode this message.
@@ -61,18 +61,9 @@ public abstract class MessageNano {
* using getCachedSize().
*/
public int getSerializedSize() {
- int size = computeSerializedSize();
- cachedSize = size;
- return size;
- }
-
- /**
- * Computes the number of bytes required to encode this message. This does not update the
- * cached size.
- */
- protected int computeSerializedSize() {
- // This is overridden if the generated message has serialized fields.
- return 0;
+ // This is overridden if the generated message has serialized fields.
+ cachedSize = 0;
+ return 0;
}
/**
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 00e2597..9987cac 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -105,12 +105,6 @@ public class NanoTest extends TestCase {
assertEquals(456, newMsg.d);
assertEquals(2, msg.nestedMsg.bb);
assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum);
-
- msg.nestedMsg = null;
- assertTrue(msgSerializedSize != msg.getSerializedSize());
-
- msg.clear();
- assertEquals(0, msg.getSerializedSize());
}
public void testRecursiveMessageNano() throws Exception {
@@ -149,12 +143,6 @@ public class NanoTest extends TestCase {
assertEquals(3, newMsg.repeatedRecursiveMessageNano[0].id);
}
- public void testMessageNoFields() {
- SingleMessageNano msg = new SingleMessageNano();
- assertEquals(0, msg.getSerializedSize());
- assertEquals(0, MessageNano.toByteArray(msg).length);
- }
-
public void testNanoRequiredInt32() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano();
msg.id = 123;
@@ -2910,20 +2898,6 @@ public class NanoTest extends TestCase {
assertTrue(Arrays.equals(enums, message.getExtension(RepeatedExtensions.repeatedEnum)));
}
- public void testNullExtensions() throws Exception {
- // Check that clearing the extension on an empty message is a no-op.
- Extensions.ExtendableMessage message = new Extensions.ExtendableMessage();
- message.setExtension(SingularExtensions.someMessage, null);
- assertEquals(0, MessageNano.toByteArray(message).length);
-
- // Check that the message is empty after setting and clearing an extension.
- AnotherMessage another = new AnotherMessage();
- message.setExtension(SingularExtensions.someMessage, another);
- assertTrue(MessageNano.toByteArray(message).length > 0);
- message.setExtension(SingularExtensions.someMessage, null);
- assertEquals(0, MessageNano.toByteArray(message).length);
- }
-
public void testUnknownFields() throws Exception {
// Check that we roundtrip (serialize and deserialize) unrecognized fields.
AnotherMessage message = new AnotherMessage();