Skip to content

Commit c695c86

Browse files
committed
Make MessageUnpacker.hasNext overridable
In a case when a client knows the exact number of elements, it can use an optimized overriden MessageUnpacker which always returns true
1 parent fb6a213 commit c695c86

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ private static int utf8MultibyteCharacterSize(byte firstByte)
263263
*/
264264
public boolean hasNext()
265265
throws IOException
266+
{
267+
return ensureBuffer();
268+
}
269+
270+
private boolean ensureBuffer()
271+
throws IOException
266272
{
267273
while (buffer.size() <= position) {
268274
MessageBuffer next = in.next();
@@ -290,7 +296,7 @@ public MessageFormat getNextFormat()
290296
throws IOException
291297
{
292298
// makes sure that buffer has at leat 1 byte
293-
if (!hasNext()) {
299+
if (!ensureBuffer()) {
294300
throw new MessageInsufficientBufferException();
295301
}
296302
byte b = buffer.getByte(position);

0 commit comments

Comments
 (0)