|
27 | 27 | import org.msgpack.MessagePack; |
28 | 28 | import org.msgpack.MessageTypeException; |
29 | 29 | import org.msgpack.packer.Unconverter; |
| 30 | +import org.msgpack.type.ValueType; |
30 | 31 |
|
31 | 32 | public class MessagePackUnpacker extends AbstractUnpacker { |
32 | 33 | private static final byte REQUIRE_TO_READ_HEAD = (byte) 0xc6; |
@@ -581,6 +582,55 @@ public void skip() throws IOException { |
581 | 582 | } |
582 | 583 | } |
583 | 584 |
|
| 585 | + public ValueType getNextType() throws IOException { |
| 586 | + final int b = (int) getHeadByte(); |
| 587 | + if ((b & 0x80) == 0) { // Positive Fixnum |
| 588 | + return ValueType.INTEGER; |
| 589 | + } |
| 590 | + if ((b & 0xe0) == 0xe0) { // Negative Fixnum |
| 591 | + return ValueType.INTEGER; |
| 592 | + } |
| 593 | + if ((b & 0xe0) == 0xa0) { // FixRaw |
| 594 | + return ValueType.RAW; |
| 595 | + } |
| 596 | + if ((b & 0xf0) == 0x90) { // FixArray |
| 597 | + return ValueType.ARRAY; |
| 598 | + } |
| 599 | + if ((b & 0xf0) == 0x80) { // FixMap |
| 600 | + return ValueType.MAP; |
| 601 | + } |
| 602 | + switch (b & 0xff) { |
| 603 | + case 0xc0: // nil |
| 604 | + return ValueType.NIL; |
| 605 | + case 0xc2: // false |
| 606 | + case 0xc3: // true |
| 607 | + return ValueType.BOOLEAN; |
| 608 | + case 0xca: // float |
| 609 | + case 0xcb: // double |
| 610 | + return ValueType.FLOAT; |
| 611 | + case 0xcc: // unsigned int 8 |
| 612 | + case 0xcd: // unsigned int 16 |
| 613 | + case 0xce: // unsigned int 32 |
| 614 | + case 0xcf: // unsigned int 64 |
| 615 | + case 0xd0: // signed int 8 |
| 616 | + case 0xd1: // signed int 16 |
| 617 | + case 0xd2: // signed int 32 |
| 618 | + case 0xd3: // signed int 64 |
| 619 | + return ValueType.INTEGER; |
| 620 | + case 0xda: // raw 16 |
| 621 | + case 0xdb: // raw 32 |
| 622 | + return ValueType.RAW; |
| 623 | + case 0xdc: // array 16 |
| 624 | + case 0xdd: // array 32 |
| 625 | + return ValueType.ARRAY; |
| 626 | + case 0xde: // map 16 |
| 627 | + case 0xdf: // map 32 |
| 628 | + return ValueType.MAP; |
| 629 | + default: |
| 630 | + throw new IOException("Invalid byte: " + b); // TODO error FormatException |
| 631 | + } |
| 632 | + } |
| 633 | + |
584 | 634 | public void reset() { |
585 | 635 | raw = null; |
586 | 636 | stack.clear(); |
|
0 commit comments