Skip to content

Commit 10c241b

Browse files
committed
Use a config param for 8192
1 parent 72ceb0c commit 10c241b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ public static class PackerConfig
241241
*/
242242
public int smallStringOptimizationThreshold = 512;
243243

244+
/**
245+
* When the next payload size exceeds this threshold, MessagePacker will call MessageBufferOutput.flush() before
246+
* packing the data.
247+
*/
248+
public int bufferFlushThreshold = 8192;
249+
244250
/**
245251
* Create a packer that outputs the packed data to a given output
246252
*

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class MessagePacker
8686
{
8787
private final int smallStringOptimizationThreshold;
8888

89+
private final int bufferFlushThreshold;
90+
8991
protected MessageBufferOutput out;
9092

9193
private MessageBuffer buffer;
@@ -113,6 +115,7 @@ public MessagePacker(MessageBufferOutput out, MessagePack.PackerConfig config)
113115
this.out = checkNotNull(out, "MessageBufferOutput is null");
114116
// We must copy the configuration parameters here since the config object is mutable
115117
this.smallStringOptimizationThreshold = config.smallStringOptimizationThreshold;
118+
this.bufferFlushThreshold = config.bufferFlushThreshold;
116119
this.position = 0;
117120
this.totalFlushBytes = 0;
118121
}
@@ -703,7 +706,7 @@ public MessagePacker writePayload(byte[] src)
703706
public MessagePacker writePayload(byte[] src, int off, int len)
704707
throws IOException
705708
{
706-
if (buffer.size() - position < len || len > 8192) {
709+
if (buffer.size() - position < len || len > bufferFlushThreshold) {
707710
flush(); // call flush before write
708711
out.write(src, off, len);
709712
totalFlushBytes += len;
@@ -744,7 +747,7 @@ public MessagePacker addPayload(byte[] src)
744747
public MessagePacker addPayload(byte[] src, int off, int len)
745748
throws IOException
746749
{
747-
if (buffer.size() - position < len || len > 8192) {
750+
if (buffer.size() - position < len || len > bufferFlushThreshold) {
748751
flush(); // call flush before add
749752
out.add(src, off, len);
750753
totalFlushBytes += len;

0 commit comments

Comments
 (0)