if (unpacker.hasNext() && unpacker.getNextFormat().getValueType().isArrayType())
/** * Create an exception for the case when an unexpected byte value is read * * @param expected * @param b * @return * @throws MessageFormatException */ private static MessagePackException unexpected(String expected, byte b) { MessageFormat format = MessageFormat.valueOf(b); if (format == MessageFormat.NEVER_USED) { return new MessageNeverUsedFormatException(String.format("Expected %s, but encountered 0xC1 \"NEVER_USED\" byte", expected)); } else { String name = format.getValueType().name(); String typeName = name.substring(0, 1) + name.substring(1).toLowerCase(); return new MessageTypeException(String.format("Expected %s, but got %s (%02x)", expected, typeName, b)); } }
/** * Returns format of the next value. * * <p> * Note that this method doesn't consume data from the internal buffer unlike the other unpack methods. * Calling this method twice will return the same value. * * <p> * To not throw {@link MessageInsufficientBufferException}, this method should be called only when * {@link #hasNext()} returns true. * * @return the next MessageFormat * @throws IOException when underlying input throws IOException * @throws MessageInsufficientBufferException when the end of file reached, i.e. {@link #hasNext()} == false. */ public MessageFormat getNextFormat() throws IOException { // makes sure that buffer has at least 1 byte if (!ensureBuffer()) { throw new MessageInsufficientBufferException(); } byte b = buffer.getByte(position); return MessageFormat.valueOf(b); }
MessageFormat f = MessageFormat.valueOf(b); switch (f) { case POSFIXINT:
ValueType type = format.getValueType(); int length; ExtensionTypeHeader extension;
private BElement unpackAny(MessageUnpacker unpacker) throws IOException { var format = unpacker.getNextFormat(); switch (format.getValueType()) { case ARRAY: return unpackArray(unpacker); case MAP: return unpackMap(unpacker); case BINARY: case BOOLEAN: case FLOAT: case INTEGER: case NIL: case STRING: return unpackValue(format, unpacker); case EXTENSION: default: break; } throw new InvalidTypeException("Cannot deserialize as BElement for format: " + format); }
ValueType type = format.getValueType(); int length; ExtensionTypeHeader extension;
ValueType valueType = messageUnpacker.getNextFormat().getValueType();
switch (mf.getValueType()) { case NIL: readByte();
private BValue unpackValue(MessageFormat format, MessageUnpacker unpacker) throws IOException { var value = this.getFactory().newValue(); switch (format.getValueType()) { case BINARY: int len = unpacker.unpackBinaryHeader();
switch (mf.getValueType()) { case NIL: readByte();