Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,19 @@ private double readDouble()
public void skipValue()
throws IOException
{
int remainingValues = 1;
while (remainingValues > 0) {
skipValue(1);
}

/**
* Skip next values, then move the cursor at the end of the value
*
* @param count number of values to skip
* @throws IOException
*/
public void skipValue(int count)
throws IOException
{
while (count > 0) {
byte b = readByte();
MessageFormat f = MessageFormat.valueOf(b);
switch (f) {
Expand All @@ -377,12 +388,12 @@ public void skipValue()
break;
case FIXMAP: {
int mapLen = b & 0x0f;
remainingValues += mapLen * 2;
count += mapLen * 2;
break;
}
case FIXARRAY: {
int arrayLen = b & 0x0f;
remainingValues += arrayLen;
count += arrayLen;
break;
}
case FIXSTR: {
Expand Down Expand Up @@ -445,22 +456,22 @@ public void skipValue()
skipPayload(readNextLength32() + 1);
break;
case ARRAY16:
remainingValues += readNextLength16();
count += readNextLength16();
break;
case ARRAY32:
remainingValues += readNextLength32();
count += readNextLength32();
break;
case MAP16:
remainingValues += readNextLength16() * 2;
count += readNextLength16() * 2;
break;
case MAP32:
remainingValues += readNextLength32() * 2; // TODO check int overflow
count += readNextLength32() * 2; // TODO check int overflow
break;
case NEVER_USED:
throw new MessageNeverUsedFormatException("Encountered 0xC1 \"NEVER_USED\" byte");
}

remainingValues--;
count--;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ class MessageUnpackerTest extends MessagePackSpec {
}
}

time("bulk skip performance", repeat = 100) {
block("switch") {
val unpacker = MessagePack.newDefaultUnpacker(data)
unpacker.skipValue(N)
unpacker.hasNext shouldBe false
}
}

}

"parse int data" in {
Expand Down