aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/main/java')
-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.java19
2 files changed, 7 insertions, 15 deletions
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 3119c93..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.
@@ -60,19 +60,10 @@ public abstract class MessageNano {
* The size is cached and the cached result can be retrieved
* using getCachedSize().
*/
- public final 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;
+ public int getSerializedSize() {
+ // This is overridden if the generated message has serialized fields.
+ cachedSize = 0;
+ return 0;
}
/**