List of utility methods to do ByteBuffer Read
int | readSmart(ByteBuffer buffer) Reads a 'smart' (either a byte or short depending on the value) from the specified buffer. int peek = buffer.get(buffer.position()) & 0xFF; if (peek < 128) { return buffer.get() & 0xFF; return (buffer.getShort() & 0xFFFF) - 32768; |
byte[] | readToBytes(ByteBuffer byteBuffer) read To Bytes int remain = byteBuffer.remaining(); byte[] data = new byte[remain]; byteBuffer.get(data); return data; |
long | readTs(ByteBuffer is) read Ts return (((long) is.get() & 0x0e) << 29) | ((is.get() & 0xff) << 22) | (((is.get() & 0xff) >> 1) << 15) | ((is.get() & 0xff) << 7) | ((is.get() & 0xff) >> 1); |
long | readTs(ByteBuffer is, int c) read Ts return (((long) c & 0x0e) << 29) | ((is.get() & 0xff) << 22) | (((is.get() & 0xff) >> 1) << 15) | ((is.get() & 0xff) << 7) | ((is.get() & 0xff) >> 1); |
UUID | readUUID(ByteBuffer buffer) read UUID long most = buffer.getLong(); long least = buffer.getLong(); return new UUID(most, least); |
int | readVariableLength(ByteBuffer buf) read Variable Length int length = 0; int cur; if (buf.hasRemaining()) do { cur = buf.get(); length |= (cur & 0x7F); if ((cur & 0x80) != 0) length <<= 7; ... |
int | readVInt(ByteBuffer bb) read V Int return (int) readVLong(bb); |
int | readVInt(ByteBuffer bb) Reads an int stored in variable-length format. byte b = bb.get(); int i = b & 0x7F; if ((b & 0x80) == 0) return i; b = bb.get(); i |= (b & 0x7F) << 7; if ((b & 0x80) == 0) return i; ... |
List | readVL(ByteBuffer byteBuffer) read VL List<Long> ret = new ArrayList<Long>(); int size = byteBuffer.getInt(); for (int i = 0; i < size; ++i) { ret.add(byteBuffer.getLong()); return ret; |
String | readZeroTermStr(ByteBuffer bb) read Zero Term Str int off = bb.position(); while (bb.hasRemaining()) { byte b = bb.get(); if (b == 0) { break; int len = bb.position() - off; ... |