Commit 642f7003 authored by Wink Saville's avatar Wink Saville

Merge commit 'f65ee555' into fix-merge-conflict

* commit 'f65ee555':

Change-Id: Ic1216c50b608f1609fd8a1a1a50209c4486f30a4
parents f812e7f2 2666d4df
...@@ -38,7 +38,7 @@ import java.io.IOException; ...@@ -38,7 +38,7 @@ import java.io.IOException;
* @author wink@google.com Wink Saville * @author wink@google.com Wink Saville
*/ */
public abstract class MessageNano { public abstract class MessageNano {
protected volatile int cachedSize = -1; protected int cachedSize = -1;
/** /**
* Get the number of bytes required to encode this message. * Get the number of bytes required to encode this message.
...@@ -61,17 +61,8 @@ public abstract class MessageNano { ...@@ -61,17 +61,8 @@ public abstract class MessageNano {
* using getCachedSize(). * using getCachedSize().
*/ */
public int getSerializedSize() { 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. // This is overridden if the generated message has serialized fields.
cachedSize = 0;
return 0; return 0;
} }
......
...@@ -105,12 +105,6 @@ public class NanoTest extends TestCase { ...@@ -105,12 +105,6 @@ public class NanoTest extends TestCase {
assertEquals(456, newMsg.d); assertEquals(456, newMsg.d);
assertEquals(2, msg.nestedMsg.bb); assertEquals(2, msg.nestedMsg.bb);
assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum); assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum);
msg.nestedMsg = null;
assertTrue(msgSerializedSize != msg.getSerializedSize());
msg.clear();
assertEquals(0, msg.getSerializedSize());
} }
public void testRecursiveMessageNano() throws Exception { public void testRecursiveMessageNano() throws Exception {
...@@ -149,12 +143,6 @@ public class NanoTest extends TestCase { ...@@ -149,12 +143,6 @@ public class NanoTest extends TestCase {
assertEquals(3, newMsg.repeatedRecursiveMessageNano[0].id); 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 { public void testNanoRequiredInt32() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano(); TestAllTypesNano msg = new TestAllTypesNano();
msg.id = 123; msg.id = 123;
...@@ -2910,20 +2898,6 @@ public class NanoTest extends TestCase { ...@@ -2910,20 +2898,6 @@ public class NanoTest extends TestCase {
assertTrue(Arrays.equals(enums, message.getExtension(RepeatedExtensions.repeatedEnum))); 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 { public void testUnknownFields() throws Exception {
// Check that we roundtrip (serialize and deserialize) unrecognized fields. // Check that we roundtrip (serialize and deserialize) unrecognized fields.
AnotherMessage message = new AnotherMessage(); AnotherMessage message = new AnotherMessage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment