diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-11-12 18:13:33 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-11-12 18:13:33 +0000 |
commit | 6493368285ce77792f6076954d4311a9a457a826 (patch) | |
tree | 9c77f15e07c2b7918f8a4bfc78d67a1017daf717 /java/src/main | |
parent | 6ba3df0d326e6478101c8cd0bb9bce6c7cc87488 (diff) | |
download | protobuf-6493368285ce77792f6076954d4311a9a457a826.tar.gz protobuf-6493368285ce77792f6076954d4311a9a457a826.tar.bz2 protobuf-6493368285ce77792f6076954d4311a9a457a826.zip |
CodedInputStream.getTotalBytesRead(); patch from Michael Kucharski.
Diffstat (limited to 'java/src/main')
-rw-r--r-- | java/src/main/java/com/google/protobuf/CodedInputStream.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/java/src/main/java/com/google/protobuf/CodedInputStream.java b/java/src/main/java/com/google/protobuf/CodedInputStream.java index 9125957d..f339c00e 100644 --- a/java/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/src/main/java/com/google/protobuf/CodedInputStream.java @@ -467,7 +467,9 @@ public final class CodedInputStream { /** * The total number of bytes read before the current buffer. The total * bytes read up to the current position can be computed as - * {@code totalBytesRetired + bufferPos}. + * {@code totalBytesRetired + bufferPos}. This value may be negative if + * reading started in the middle of the current buffer (e.g. if the + * constructor that takes a byte array and an offset was used). */ private int totalBytesRetired; @@ -489,6 +491,7 @@ public final class CodedInputStream { this.buffer = buffer; bufferSize = off + len; bufferPos = off; + totalBytesRetired = -off; input = null; } @@ -496,6 +499,7 @@ public final class CodedInputStream { buffer = new byte[BUFFER_SIZE]; bufferSize = 0; bufferPos = 0; + totalBytesRetired = 0; this.input = input; } @@ -546,7 +550,7 @@ public final class CodedInputStream { * Resets the current size counter to zero (see {@link #setSizeLimit(int)}). */ public void resetSizeCounter() { - totalBytesRetired = 0; + totalBytesRetired = -bufferPos; } /** @@ -616,6 +620,14 @@ public final class CodedInputStream { } /** + * The total bytes read up to the current position. Calling + * {@link #resetSizeCounter()} resets this value to zero. + */ + public int getTotalBytesRead() { + return totalBytesRetired + bufferPos; + } + + /** * Called with {@code this.buffer} is empty to read more bytes from the * input. If {@code mustSucceed} is true, refillBuffer() gurantees that * either there will be at least one byte in the buffer when it returns |