Skip to content

Commit edb9623

Browse files
committed
Move a configuration parameter to MessagePack.Config
1 parent 2d73708 commit edb9623

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public static class Config {
3636
public int STRING_DECODER_BUFFER_SIZE = 8192;
3737

3838
public int PACKER_BUFFER_SIZE = 8192;
39+
40+
public int PACKER_FLUSH_THRESHOLD = 512;
3941
}
4042

4143
/**

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public void flush() throws IOException {
9999
position = 0;
100100
}
101101

102+
private void flushBuffer(MessageBuffer b) throws IOException {
103+
out.flush(b, 0, b.size());
104+
}
105+
102106
public void close() throws IOException {
103107
try {
104108
flush();
@@ -437,20 +441,18 @@ public MessagePacker packRawStringHeader(int len) throws IOException {
437441
return this;
438442
}
439443

440-
private final int FLUSH_THRESHOLD = 512;
441444

442445
public MessagePacker writePayload(ByteBuffer src) throws IOException {
443-
if(src.remaining() >= FLUSH_THRESHOLD) {
446+
if(src.remaining() >= config.PACKER_FLUSH_THRESHOLD) {
444447
// Use the source ByteBuffer directly to avoid memory copy
445448

446449
// First, flush the current buffer contents
447450
flush();
448451

449452
// Wrap the input source as a MessageBuffer
450-
// TODO Create MessageBuffer.wrap(ByteBuffer, offset, length);
451-
MessageBuffer wrapped = MessageBuffer.wrap(src);
453+
MessageBuffer wrapped = MessageBuffer.wrap(src).slice(src.position(), src.remaining());
452454
// Then, dump the source data to the output
453-
out.flush(wrapped, src.position(), src.remaining());
455+
flushBuffer(wrapped);
454456
src.position(src.limit());
455457
}
456458
else {
@@ -471,16 +473,16 @@ public MessagePacker writePayload(byte[] src) throws IOException {
471473
}
472474

473475
public MessagePacker writePayload(byte[] src, int off, int len) throws IOException {
474-
if(len >= FLUSH_THRESHOLD) {
476+
if(len >= config.PACKER_FLUSH_THRESHOLD) {
475477
// Use the input array directory to avoid memory copy
476478

477479
// Flush the current buffer contents
478480
flush();
479481

480482
// Wrap the input array as a MessageBuffer
481-
MessageBuffer wrapped = MessageBuffer.wrap(src);
483+
MessageBuffer wrapped = MessageBuffer.wrap(src).slice(off, len);
482484
// Dump the source data to the output
483-
out.flush(wrapped, off, len);
485+
flushBuffer(wrapped);
484486
}
485487
else {
486488
int cursor = 0;

msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBufferOutput.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public interface MessageBufferOutput extends Closeable {
1919

2020
public void flush(MessageBuffer buf, int offset, int len) throws IOException;
2121

22-
2322
}
2423

2524

0 commit comments

Comments
 (0)