private int readNextLength8() throws IOException { byte u8 = readByte(); return u8 & 0xff; }
/** * Reads a Nil byte. * * @throws MessageTypeException when value is not MessagePack Nil type * @throws IOException when underlying input throws IOException */ public void unpackNil() throws IOException { byte b = readByte(); if (b == Code.NIL) { return; } throw unexpected("Nil", b); }
/** * Reads true or false. * * @return the read value * @throws MessageTypeException when value is not MessagePack Boolean type * @throws IOException when underlying input throws IOException */ public boolean unpackBoolean() throws IOException { byte b = readByte(); if (b == Code.FALSE) { return false; } else if (b == Code.TRUE) { return true; } throw unexpected("boolean", b); }
throws IOException byte b = readByte(); if (Code.isFixInt(b)) { return BigInteger.valueOf((long) b); byte u8 = readByte(); return BigInteger.valueOf((long) (u8 & 0xff)); case Code.UINT16: // unsigned int 16 byte i8 = readByte(); return BigInteger.valueOf((long) i8); case Code.INT16: // signed int 16
/** * Reads a double. * * @return the read value * @throws MessageTypeException when value is not MessagePack Float type * @throws IOException when underlying input throws IOException */ public double unpackDouble() throws IOException { byte b = readByte(); switch (b) { case Code.FLOAT32: // float float fv = readFloat(); return (double) fv; case Code.FLOAT64: // double double dv = readDouble(); return dv; } throw unexpected("Float", b); }
/** * Reads a float. * * This method rounds value to the range of float when precision of the read value is larger than the range of float. This may happen when {@link #getNextFormat()} returns FLOAT64. * * @return the read value * @throws MessageTypeException when value is not MessagePack Float type * @throws IOException when underlying input throws IOException */ public float unpackFloat() throws IOException { byte b = readByte(); switch (b) { case Code.FLOAT32: // float float fv = readFloat(); return fv; case Code.FLOAT64: // double double dv = readDouble(); return (float) dv; } throw unexpected("Float", b); }
/** * Peeks a Nil byte and reads it if next byte is a nil value. * * The difference from {@link unpackNil} is that unpackNil throws an exception if the next byte is not nil value * while this tryUnpackNil method returns false without changing position. * * @return true if a nil value is read * @throws MessageInsufficientBufferException when the end of file reached * @throws IOException when underlying input throws IOException */ public boolean tryUnpackNil() throws IOException { // makes sure that buffer has at least 1 byte if (!ensureBuffer()) { throw new MessageInsufficientBufferException(); } byte b = buffer.getByte(position); if (b == Code.NIL) { readByte(); return true; } return false; }
public int unpackRawStringHeader() throws IOException { byte b = readByte(); if (Code.isFixedRaw(b)) { // FixRaw return b & 0x1f; } int len = tryReadStringHeader(b); if (len >= 0) { return len; } if (allowReadingBinaryAsString) { len = tryReadBinaryHeader(b); if (len >= 0) { return len; } } throw unexpected("String", b); }
public ExtensionTypeHeader unpackExtensionTypeHeader() throws IOException byte b = readByte(); switch (b) { case Code.FIXEXT1: { byte type = readByte(); return new ExtensionTypeHeader(type, 1); byte type = readByte(); return new ExtensionTypeHeader(type, 2); byte type = readByte(); return new ExtensionTypeHeader(type, 4); byte type = readByte(); return new ExtensionTypeHeader(type, 8); byte type = readByte(); return new ExtensionTypeHeader(type, 16);
throws IOException byte b = readByte(); if (Code.isFixedMap(b)) { // fixmap return b & 0x0f;
throws IOException byte b = readByte(); if (Code.isFixedArray(b)) { // fixarray return b & 0x0f;
throws IOException byte b = readByte(); if (Code.isFixedRaw(b)) { // FixRaw return b & 0x1f;
/** * Read a byte value at the cursor and proceed the cursor. * * @return * @throws IOException */ private byte readByte() throws IOException { if (buffer.size() > position) { byte b = buffer.getByte(position); position++; return b; } else { nextBuffer(); if (buffer.size() > 0) { byte b = buffer.getByte(0); position = 1; return b; } return readByte(); } }
switch (mf.getValueType()) { case NIL: readByte(); var.setNilValue(); return var;
switch (mf.getValueType()) { case NIL: readByte(); return ValueFactory.newNil(); case BOOLEAN:
byte b = readByte(); MessageFormat f = MessageFormat.valueOf(b); switch (f) {