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
36 changes: 33 additions & 3 deletions msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,37 @@ public void readPayload(ByteBuffer dst)
}
}

/**
* Reads payload bytes of binary, extension, or raw string types.
*
* <p>
* This consumes bytes, copies them to the specified buffer
* This is usually faster than readPayload(ByteBuffer) by using unsafe.copyMemory
*
* @param dst the Message buffer into which the data is read
* @param off the offset in the Message buffer
* @param len the number of bytes to read
* @throws IOException when underlying input throws IOException
*/
public void readPayload(MessageBuffer dst, int off, int len)
throws IOException
{
while (true) {
int bufferRemaining = buffer.size() - position;
if (bufferRemaining >= len) {
dst.putMessageBuffer(off, buffer, position, len);
position += len;
return;
}
dst.putMessageBuffer(off, buffer, position, bufferRemaining);
off += bufferRemaining;
len -= bufferRemaining;
position += bufferRemaining;

nextBuffer();
}
}

/**
* Reads payload bytes of binary, extension, or raw string types.
*
Expand Down Expand Up @@ -1541,8 +1572,7 @@ public byte[] readPayload(int length)
public void readPayload(byte[] dst, int off, int len)
throws IOException
{
// TODO optimize
readPayload(ByteBuffer.wrap(dst, off, len));
readPayload(MessageBuffer.wrap(dst), off, len);
}

/**
Expand All @@ -1566,7 +1596,7 @@ public MessageBuffer readPayloadAsReference(int length)
return slice;
}
MessageBuffer dst = MessageBuffer.allocate(length);
readPayload(dst.sliceAsByteBuffer());
readPayload(dst, 0, length);
return dst;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void copyTo(int index, MessageBuffer dst, int offset, int length)
@Override
public void putMessageBuffer(int index, MessageBuffer src, int srcOffset, int len)
{
putBytes(index, src.toByteArray(), srcOffset, len);
putByteBuffer(index, src.sliceAsByteBuffer(srcOffset, len), len);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class MessageUnpackerTest extends MessagePackSpec {
}
}

"be faster then msgpack-v6 skip" taggedAs ("cmp-skip") in {
"be faster than msgpack-v6 skip" taggedAs ("cmp-skip") in {

trait Fixture {
val unpacker: MessageUnpacker
Expand Down