private static boolean hasSecondVInt(byte b) { return WritableUtils.isNegativeVInt(b); }
private static boolean hasSecondVInt(byte b) { return WritableUtils.isNegativeVInt(b); }
private static boolean hasSecondVInt(byte b) { return WritableUtils.isNegativeVInt(b); }
/** * Similar to {@link WritableUtils#readVLong(DataInput)} but reads from a * {@link ByteBuffer}. */ public static long readVLong(ByteBuffer in) { byte firstByte = in.get(); int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = in.get(); i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
/** * Reads a zero-compressed encoded long from input buffer and returns it. * @param buffer Binary array * @param offset Offset into array at which vint begins. * @return deserialized long from buffer. */ public static long readAsVLong(final byte [] buffer, final int offset) { byte firstByte = buffer[offset]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = buffer[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
/** * @param buffer buffer to convert * @return vint bytes as an integer. */ public static long bytesToVint(final byte [] buffer) { int offset = 0; byte firstByte = buffer[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = buffer[offset++]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
/** * Read a zero-compressed encoded long from a byte array. * * @param bytes the byte array * @param offset the offset in the byte array where the VLong is stored * @return the long */ public static long readVLongFromByteArray(final byte[] bytes, int offset) { byte firstByte = bytes[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = bytes[offset++]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
/** * Reads a zero-compressed encoded long from input stream and returns it. * @param stream Binary input stream * @throws java.io.IOException * @return deserialized long from stream. */ public static long readVLong(DataInput stream) throws IOException { byte firstByte = stream.readByte(); int len = decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = stream.readByte(); i = i << 8; i = i | (b & 0xFF); } return (isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
/** * Reads a zero-compressed encoded long from a byte array and returns it. * * @param bytes * the byte array * @param offset * offset of the array to read from * @param vlong * storing the deserialized long and its size in byte */ public static void readVLong(byte[] bytes, int offset, VLong vlong) { byte firstByte = bytes[offset]; vlong.length = (byte) WritableUtils.decodeVIntSize(firstByte); if (vlong.length == 1) { vlong.value = firstByte; return; } long i = 0; for (int idx = 0; idx < vlong.length - 1; idx++) { byte b = bytes[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } vlong.value = (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
/** * Reads a zero-compressed encoded int from a byte array and returns it. * * @param bytes * the byte array * @param offset * offset of the array to read from * @param vInt * storing the deserialized int and its size in byte */ public static void readVInt(byte[] bytes, int offset, VInt vInt) { byte firstByte = bytes[offset]; vInt.length = (byte) WritableUtils.decodeVIntSize(firstByte); if (vInt.length == 1) { vInt.value = firstByte; return; } int i = 0; for (int idx = 0; idx < vInt.length - 1; idx++) { byte b = bytes[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } vInt.value = (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1) : i); }
/** * Similar to {@link WritableUtils#readVLong(java.io.DataInput)} but reads from a * {@link ByteBuff}. */ public static long readVLong(ByteBuff in) { byte firstByte = in.get(); int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = in.get(); i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
public long readVLong(Position readPos) { ponderNextBufferToRead(readPos); byte firstByte = readPos.buffer[readPos.offset++]; int length = (byte) WritableUtils.decodeVIntSize(firstByte) - 1; if (length == 0) { return firstByte; } long i = 0; if (isAllInOneReadBuffer(length, readPos)) { for (int idx = 0; idx < length; idx++) { i = (i << 8) | (readPos.buffer[readPos.offset + idx] & 0xFF); } readPos.offset += length; } else { for (int idx = 0; idx < length; idx++) { i = (i << 8) | (readNextByte(readPos) & 0xFF); } } return (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
i = i | (b & 0xFF); currMemstoreTS = (WritableUtils.isNegativeVInt(firstByte) ? ~i : i);
/** * Reads a long value from this reader's buffer, assuming the long was encoded as a * variable-length list of bytes. * * @return long value */ public long readVLong() { byte firstByte = data[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = data[offset++]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); } }
private static long readVInt(byte[] bytes, int start, int length) { long value = 0; for (int i = 1; i < length; i++) { value <<= 8; value |= (bytes[start + i] & 0xFF); } return WritableUtils.isNegativeVInt(bytes[start]) ? ~value : value; }
private static long readVInt(byte[] bytes, int start, int length) { long value = 0; for (int i = 1; i < length; i++) { value <<= 8; value |= (bytes[start + i] & 0xFF); } return WritableUtils.isNegativeVInt(bytes[start]) ? ~value : value; } }
/** * Decode a vint from the buffer pointed at to by ptr and * increment the offset of the ptr by the length of the * vint. * @param ptr a pointer to a byte array buffer * @return the decoded vint value as a long */ public static long vlongFromBytes(ImmutableBytesWritable ptr) { final byte [] buffer = ptr.get(); final int offset = ptr.getOffset(); byte firstByte = buffer[offset]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { ptr.set(buffer, offset+1, ptr.getLength()); return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = buffer[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } ptr.set(buffer, offset+len, ptr.getLength()); return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
private static boolean hasSecondVInt(byte b) { return WritableUtils.isNegativeVInt(b); }
private static boolean hasSecondVInt(byte b) { return WritableUtils.isNegativeVInt(b); }
/** * Decode a vint from the buffer pointed at to by ptr and * increment the offset of the ptr by the length of the * vint. * @param ptr a pointer to a byte array buffer * @return the decoded vint value as a long */ public static long vlongFromBytes(ImmutableBytesWritable ptr) { final byte [] buffer = ptr.get(); final int offset = ptr.getOffset(); byte firstByte = buffer[offset]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { ptr.set(buffer, offset+1, ptr.getLength()); return firstByte; } long i = 0; for (int idx = 0; idx < len-1; idx++) { byte b = buffer[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } ptr.set(buffer, offset+len, ptr.getLength()); return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }