aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/main/java/com/google/protobuf/nano/MessageNano.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/main/java/com/google/protobuf/nano/MessageNano.java')
-rw-r--r--java/src/main/java/com/google/protobuf/nano/MessageNano.java17
1 files changed, 13 insertions, 4 deletions
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 82dc6cc..d6288c9 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 int cachedSize = -1;
+ protected volatile int cachedSize = -1;
/**
* Get the number of bytes required to encode this message.
@@ -61,9 +61,18 @@ public abstract class MessageNano {
* using getCachedSize().
*/
public int getSerializedSize() {
- // This is overridden if the generated message has serialized fields.
- cachedSize = 0;
- return 0;
+ 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;
}
/**