@@ -17,16 +17,35 @@ package org.msgpack.core
1717
1818import java .io ._
1919import java .nio .ByteBuffer
20+ import java .nio .charset .StandardCharsets
2021
22+ import org .msgpack .core .MessageUnpackerTest .SplitMessageBufferInput
2123import org .msgpack .core .buffer ._
2224import org .msgpack .value .ValueType
2325import xerial .core .io .IOUtil
2426
2527import scala .util .Random
2628
27- /**
28- * Created on 2014/05/07.
29- */
29+ object MessageUnpackerTest {
30+ class SplitMessageBufferInput (array : Array [Array [Byte ]]) extends MessageBufferInput {
31+ var cursor = 0
32+ override def next (): MessageBuffer = {
33+ if (cursor < array.length) {
34+ val a = array(cursor)
35+ cursor += 1
36+ MessageBuffer .wrap(a)
37+ }
38+ else {
39+ null
40+ }
41+ }
42+
43+ override def close (): Unit = {}
44+ }
45+ }
46+
47+ import MessageUnpackerTest ._
48+
3049class MessageUnpackerTest extends MessagePackSpec {
3150
3251 def testData : Array [Byte ] = {
@@ -246,21 +265,6 @@ class MessageUnpackerTest extends MessagePackSpec {
246265
247266 }
248267
249- class SplitMessageBufferInput (array : Array [Array [Byte ]]) extends MessageBufferInput {
250- var cursor = 0
251- override def next (): MessageBuffer = {
252- if (cursor < array.length) {
253- val a = array(cursor)
254- cursor += 1
255- MessageBuffer .wrap(a)
256- }
257- else {
258- null
259- }
260- }
261-
262- override def close (): Unit = {}
263- }
264268
265269 " read data at the buffer boundary" taggedAs (" boundary" ) in {
266270
@@ -703,5 +707,18 @@ class MessageUnpackerTest extends MessagePackSpec {
703707 Seq (8185 , 8186 , 8187 , 8188 , 16377 , 16378 , 16379 , 16380 ).foreach { n => check(s, n)}
704708 }
705709 }
710+
711+ " read value length at buffer boundary" taggedAs(" number-boundary" ) in {
712+ val input = new SplitMessageBufferInput (Array (
713+ Array [Byte ](MessagePack .Code .STR16 ),
714+ Array [Byte ](0x00 ),
715+ Array [Byte ](0x05 ), // STR16 length at the boundary
716+ " hello" .getBytes(MessagePack .UTF8 ))
717+ )
718+ val unpacker = MessagePack .newDefaultUnpacker(input)
719+ while (unpacker.hasNext) {
720+ unpacker.unpackValue()
721+ }
722+ }
706723 }
707724}
0 commit comments