Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
64933682
Commit
64933682
authored
Nov 12, 2009
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CodedInputStream.getTotalBytesRead(); patch from Michael Kucharski.
parent
6ba3df0d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
CONTRIBUTORS.txt
CONTRIBUTORS.txt
+2
-0
CodedInputStream.java
java/src/main/java/com/google/protobuf/CodedInputStream.java
+14
-2
CodedInputStreamTest.java
...c/test/java/com/google/protobuf/CodedInputStreamTest.java
+7
-0
No files found.
CONTRIBUTORS.txt
View file @
64933682
...
@@ -78,3 +78,5 @@ Patch contributors:
...
@@ -78,3 +78,5 @@ Patch contributors:
* Detect whether zlib is new enough in configure script.
* Detect whether zlib is new enough in configure script.
Evan Jones <evanj@mit.edu>
Evan Jones <evanj@mit.edu>
* Optimize Java serialization code when writing a small message to a stream.
* Optimize Java serialization code when writing a small message to a stream.
Michael Kucharski <m.kucharski@gmail.com>
* Added CodedInputStream.getTotalBytesRead().
java/src/main/java/com/google/protobuf/CodedInputStream.java
View file @
64933682
...
@@ -467,7 +467,9 @@ public final class CodedInputStream {
...
@@ -467,7 +467,9 @@ public final class CodedInputStream {
/**
/**
* The total number of bytes read before the current buffer. The total
* The total number of bytes read before the current buffer. The total
* bytes read up to the current position can be computed as
* 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
;
private
int
totalBytesRetired
;
...
@@ -489,6 +491,7 @@ public final class CodedInputStream {
...
@@ -489,6 +491,7 @@ public final class CodedInputStream {
this
.
buffer
=
buffer
;
this
.
buffer
=
buffer
;
bufferSize
=
off
+
len
;
bufferSize
=
off
+
len
;
bufferPos
=
off
;
bufferPos
=
off
;
totalBytesRetired
=
-
off
;
input
=
null
;
input
=
null
;
}
}
...
@@ -496,6 +499,7 @@ public final class CodedInputStream {
...
@@ -496,6 +499,7 @@ public final class CodedInputStream {
buffer
=
new
byte
[
BUFFER_SIZE
];
buffer
=
new
byte
[
BUFFER_SIZE
];
bufferSize
=
0
;
bufferSize
=
0
;
bufferPos
=
0
;
bufferPos
=
0
;
totalBytesRetired
=
0
;
this
.
input
=
input
;
this
.
input
=
input
;
}
}
...
@@ -546,7 +550,7 @@ public final class CodedInputStream {
...
@@ -546,7 +550,7 @@ public final class CodedInputStream {
* Resets the current size counter to zero (see {@link #setSizeLimit(int)}).
* Resets the current size counter to zero (see {@link #setSizeLimit(int)}).
*/
*/
public
void
resetSizeCounter
()
{
public
void
resetSizeCounter
()
{
totalBytesRetired
=
0
;
totalBytesRetired
=
-
bufferPos
;
}
}
/**
/**
...
@@ -615,6 +619,14 @@ public final class CodedInputStream {
...
@@ -615,6 +619,14 @@ public final class CodedInputStream {
return
bufferPos
==
bufferSize
&&
!
refillBuffer
(
false
);
return
bufferPos
==
bufferSize
&&
!
refillBuffer
(
false
);
}
}
/**
* 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
* Called with {@code this.buffer} is empty to read more bytes from the
* input. If {@code mustSucceed} is true, refillBuffer() gurantees that
* input. If {@code mustSucceed} is true, refillBuffer() gurantees that
...
...
java/src/test/java/com/google/protobuf/CodedInputStreamTest.java
View file @
64933682
...
@@ -434,6 +434,7 @@ public class CodedInputStreamTest extends TestCase {
...
@@ -434,6 +434,7 @@ public class CodedInputStreamTest extends TestCase {
new
SmallBlockInputStream
(
new
byte
[
256
],
8
));
new
SmallBlockInputStream
(
new
byte
[
256
],
8
));
input
.
setSizeLimit
(
16
);
input
.
setSizeLimit
(
16
);
input
.
readRawBytes
(
16
);
input
.
readRawBytes
(
16
);
assertEquals
(
16
,
input
.
getTotalBytesRead
());
try
{
try
{
input
.
readRawByte
();
input
.
readRawByte
();
...
@@ -443,7 +444,10 @@ public class CodedInputStreamTest extends TestCase {
...
@@ -443,7 +444,10 @@ public class CodedInputStreamTest extends TestCase {
}
}
input
.
resetSizeCounter
();
input
.
resetSizeCounter
();
assertEquals
(
0
,
input
.
getTotalBytesRead
());
input
.
readRawByte
();
// No exception thrown.
input
.
readRawByte
();
// No exception thrown.
input
.
resetSizeCounter
();
assertEquals
(
0
,
input
.
getTotalBytesRead
());
try
{
try
{
input
.
readRawBytes
(
16
);
// Hits limit again.
input
.
readRawBytes
(
16
);
// Hits limit again.
...
@@ -477,10 +481,13 @@ public class CodedInputStreamTest extends TestCase {
...
@@ -477,10 +481,13 @@ public class CodedInputStreamTest extends TestCase {
public
void
testReadFromSlice
()
throws
Exception
{
public
void
testReadFromSlice
()
throws
Exception
{
byte
[]
bytes
=
bytes
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
byte
[]
bytes
=
bytes
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
CodedInputStream
in
=
CodedInputStream
.
newInstance
(
bytes
,
3
,
5
);
CodedInputStream
in
=
CodedInputStream
.
newInstance
(
bytes
,
3
,
5
);
assertEquals
(
0
,
in
.
getTotalBytesRead
());
for
(
int
i
=
3
;
i
<
8
;
i
++)
{
for
(
int
i
=
3
;
i
<
8
;
i
++)
{
assertEquals
(
i
,
in
.
readRawByte
());
assertEquals
(
i
,
in
.
readRawByte
());
assertEquals
(
i
-
2
,
in
.
getTotalBytesRead
());
}
}
// eof
// eof
assertEquals
(
0
,
in
.
readTag
());
assertEquals
(
0
,
in
.
readTag
());
assertEquals
(
5
,
in
.
getTotalBytesRead
());
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment