aboutsummaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorUlas Kirazci <ulas@google.com>2013-07-29 11:08:34 -0700
committerUlas Kirazci <ulas@google.com>2013-07-31 14:15:10 -0700
commit1c277f9c68b81b594701d0c5cd90e74170bbab21 (patch)
tree837302d8f7b55bd867a8b8acc38ff205ed2da1e7 /java/src
parenta91e2fc467033f975211e8d88582a3d706ee862d (diff)
downloadprotobuf-1c277f9c68b81b594701d0c5cd90e74170bbab21.tar.gz
protobuf-1c277f9c68b81b594701d0c5cd90e74170bbab21.tar.bz2
protobuf-1c277f9c68b81b594701d0c5cd90e74170bbab21.zip
Fixed packed repeated serialization.
Remove buggy memoization. Memoization also is too fragile for the api because the repeated field is public. Change-Id: I538b8426d274b22df2eeea5935023abbe7df49fe
Diffstat (limited to 'java/src')
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 0ea80d40..edb0a208 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -46,6 +46,7 @@ import com.google.protobuf.nano.UnittestImportNano;
import junit.framework.TestCase;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -1955,6 +1956,24 @@ public class NanoTest extends TestCase {
assertEquals(TestAllTypesNano.BAR, msg.repeatedPackedNestedEnum[1]);
}
+ public void testNanoRepeatedPackedSerializedSize() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedPackedInt32 = new int[] { 123, 789, 456 };
+ int msgSerializedSize = msg.getSerializedSize();
+ byte [] result = MessageNano.toByteArray(msg);
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano msg2 = new TestAllTypesNano();
+ msg2.repeatedPackedInt32 = new int[] { 123, 789, 456 };
+ byte [] result2 = new byte[msgSerializedSize];
+ MessageNano.toByteArray(msg2, result2, 0, msgSerializedSize);
+
+ // Check equal size and content.
+ assertEquals(msgSerializedSize, msg2.getSerializedSize());
+ assertTrue(Arrays.equals(result, result2));
+ }
+
public void testNanoRepeatedInt32ReMerge() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano();
msg.repeatedInt32 = new int[] { 234 };