2323import java .math .BigInteger ;
2424import org .msgpack .io .Input ;
2525import org .msgpack .io .StreamInput ;
26+ import org .msgpack .io .BufferReferer ;
2627import org .msgpack .MessagePack ;
2728import org .msgpack .MessageTypeException ;
2829import org .msgpack .packer .Unconverter ;
@@ -45,6 +46,7 @@ public class MessagePackUnpacker extends AbstractUnpacker {
4546 private final BigIntegerAccept bigIntegerAccept = new BigIntegerAccept ();
4647 private final DoubleAccept doubleAccept = new DoubleAccept ();
4748 private final ByteArrayAccept byteArrayAccept = new ByteArrayAccept ();
49+ private final StringAccept stringAccept = new StringAccept ();
4850 private final ArrayAccept arrayAccept = new ArrayAccept ();
4951 private final MapAccept mapAccept = new MapAccept ();
5052 private final ValueAccept valueAccept = new ValueAccept ();
@@ -110,9 +112,11 @@ final boolean readOneWithoutStack(Accept a) throws IOException {
110112 headByte = REQUIRE_TO_READ_HEAD ;
111113 return true ;
112114 }
113- readRawBody (count );
114- a .acceptRaw (raw );
115- raw = null ;
115+ if (!tryReferRawBody (a , count )) {
116+ readRawBody (count );
117+ a .acceptRaw (raw );
118+ raw = null ;
119+ }
116120 headByte = REQUIRE_TO_READ_HEAD ;
117121 return true ;
118122 }
@@ -210,9 +214,11 @@ final boolean readOneWithoutStack(Accept a) throws IOException {
210214 return true ;
211215 }
212216 in .advance ();
213- readRawBody (count );
214- a .acceptRaw (raw );
215- raw = null ;
217+ if (!tryReferRawBody (a , count )) {
218+ readRawBody (count );
219+ a .acceptRaw (raw );
220+ raw = null ;
221+ }
216222 headByte = REQUIRE_TO_READ_HEAD ;
217223 return true ;
218224 }
@@ -229,9 +235,11 @@ final boolean readOneWithoutStack(Accept a) throws IOException {
229235 return true ;
230236 }
231237 in .advance ();
232- readRawBody (count );
233- a .acceptRaw (raw );
234- raw = null ;
238+ if (!tryReferRawBody (a , count )) {
239+ readRawBody (count );
240+ a .acceptRaw (raw );
241+ raw = null ;
242+ }
235243 headByte = REQUIRE_TO_READ_HEAD ;
236244 return true ;
237245 }
@@ -289,6 +297,10 @@ final boolean readOneWithoutStack(Accept a) throws IOException {
289297 }
290298 }
291299
300+ private boolean tryReferRawBody (BufferReferer referer , int size ) throws IOException {
301+ return in .tryRefer (referer , size );
302+ }
303+
292304 private void readRawBody (int size ) throws IOException {
293305 raw = new byte [size ];
294306 rawFilled = 0 ;
@@ -421,11 +433,18 @@ public double readDouble() throws IOException {
421433 return doubleAccept .value ;
422434 }
423435
436+ @ Override
424437 public byte [] readByteArray () throws IOException {
425438 readOne (byteArrayAccept );
426439 return byteArrayAccept .value ;
427440 }
428441
442+ @ Override
443+ public String readString () throws IOException {
444+ readOne (stringAccept );
445+ return stringAccept .value ;
446+ }
447+
429448 @ Override
430449 public int readArrayBegin () throws IOException {
431450 readOne (arrayAccept );
0 commit comments