@@ -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 ;
0 commit comments