List of utility methods to do ByteBuffer to Long
int | readUBEInt16(ByteBuffer b) read UBE Int int result = 0; result += readUInt8(b) << 8; result += readUInt8(b); return result; |
int | readUInt16(ByteBuffer bb) read U Int return (bb.getShort() & 0xffff);
|
int | readUInt16BE(ByteBuffer bb) read U Int BE int result = 0; result += byte2int(bb.get()); result += byte2int(bb.get()) << 8; return result; |
long | readUInt32(ByteBuffer buf, int length) read U Int if ((buf.position() + length) <= buf.limit() && length <= 4) { long r = 0; for (int i = 0; i < length; i++) { r |= (((long) (buf.get() & 0xff)) << (i << 3)); return r; return 0; ... |
BigInteger | readUInt64(ByteBuffer bb) read U Int byte[] data = new byte[8]; bb.get(data); long l1 = (((long) data[0] & 0xff) << 0) | (((long) data[1] & 0xff) << 8) | (((long) data[2] & 0xff) << 16) | (((long) data[3] & 0xff) << 24); long l2 = (((long) data[4] & 0xff) << 0) | (((long) data[5] & 0xff) << 8) | (((long) data[6] & 0xff) << 16) | (((long) data[7] & 0xff) << 24); return BigInteger.valueOf((l1 << 0) | (l2 << 32)); |
long | readUInt64(ByteBuffer byteBuffer) read U Int long result = 0; result += readUInt32(byteBuffer) << 32; if (result < 0) { throw new RuntimeException( "I don't know how to deal with UInt64! long is not sufficient and I don't want to use BigInt"); result += readUInt32(byteBuffer); return result; ... |
byte | readUInt8(ByteBuffer bb) Read an 8-bit unsigned integer from the byte buffer. return bb.get();
|
long | readVarLong(ByteBuffer buff) Read a variable size long. long x = buff.get(); if (x >= 0) { return x; x &= 0x7f; for (int s = 7; s < 64; s += 7) { long b = buff.get(); x |= (b & 0x7f) << s; ... |
long | readVarlong(ByteBuffer buffer) Read a long stored in variable-length format using zig-zag decoding from Google Protocol Buffers. long value = 0L; int i = 0; long b; while (((b = buffer.get()) & 0x80) != 0) { value |= (b & 0x7f) << i; i += 7; if (i > 63) throw illegalVarlongException(value); ... |
long | toLong(ByteBuffer buffer) to Long return toByteBuffer(buffer, Long.BYTES).getLong();
|