Skip to content

Commit f762b10

Browse files
committed
Fix flushedBytes computation in writePayload
1 parent ad7b194 commit f762b10

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ else if(len < (1 << 16)) {
549549

550550

551551
public MessagePacker writePayload(ByteBuffer src) throws IOException {
552-
flushedBytes += src.remaining();
553-
if(src.remaining() >= config.getPackerRawDataCopyingThreshold()) {
552+
int len = src.remaining();
553+
if(len >= config.getPackerRawDataCopyingThreshold()) {
554554
// Use the source ByteBuffer directly to avoid memory copy
555555

556556
// First, flush the current buffer contents
@@ -561,6 +561,7 @@ public MessagePacker writePayload(ByteBuffer src) throws IOException {
561561
// Then, dump the source data to the output
562562
out.flush(wrapped);
563563
src.position(src.limit());
564+
flushedBytes += len;
564565
}
565566
else {
566567
// If the input source is small, simply copy the contents to the buffer
@@ -593,6 +594,7 @@ public MessagePacker writePayload(byte[] src, int off, int len) throws IOExcepti
593594
MessageBuffer wrapped = MessageBuffer.wrap(src).slice(off, len);
594595
// Dump the source data to the output
595596
out.flush(wrapped);
597+
flushedBytes += len;
596598
}
597599
else {
598600
int cursor = 0;

0 commit comments

Comments
 (0)