/** * Write a zero-compressed encoded long to a byte array. * * @param bytes * the byte array/stream * @param l * the long */ public static int writeVLongToByteArray(byte[] bytes, long l) { return LazyBinaryUtils.writeVLongToByteArray(bytes, 0, l); }
/** * Given an integer representing nanoseconds, write its serialized * value to the byte array b at offset * * @param nanos * @param b * @param offset * @return */ private static boolean setNanosBytes(int nanos, byte[] b, int offset, boolean hasSecondVInt) { int decimal = 0; if (nanos != 0) { int counter = 0; while (counter < 9) { decimal *= 10; decimal += nanos % 10; nanos /= 10; counter++; } } if (hasSecondVInt || decimal != 0) { // We use the sign of the reversed-nanoseconds field to indicate that there is a second VInt // present. LazyBinaryUtils.writeVLongToByteArray(b, offset, hasSecondVInt ? (-decimal - 1) : decimal); } return decimal != 0; }
/** * Given an integer representing nanoseconds, write its serialized * value to the byte array b at offset * * @param nanos * @param b * @param offset * @return */ private static boolean setNanosBytes(int nanos, byte[] b, int offset, boolean hasSecondVInt) { int decimal = 0; if (nanos != 0) { int counter = 0; while (counter < 9) { decimal *= 10; decimal += nanos % 10; nanos /= 10; counter++; } } if (hasSecondVInt || decimal != 0) { // We use the sign of the reversed-nanoseconds field to indicate that there is a second VInt // present. LazyBinaryUtils.writeVLongToByteArray(b, offset, hasSecondVInt ? (-decimal - 1) : decimal); } return decimal != 0; }
/** * Given an integer representing nanoseconds, write its serialized * value to the byte array b at offset * * @param nanos * @param b * @param offset * @return */ private static boolean setNanosBytes(int nanos, byte[] b, int offset, boolean hasSecondVInt) { int decimal = 0; if (nanos != 0) { int counter = 0; while (counter < 9) { decimal *= 10; decimal += nanos % 10; nanos /= 10; counter++; } } if (hasSecondVInt || decimal != 0) { // We use the sign of the reversed-nanoseconds field to indicate that there is a second VInt // present. LazyBinaryUtils.writeVLongToByteArray(b, offset, hasSecondVInt ? (-decimal - 1) : decimal); } return decimal != 0; }
public static void writeVLong(RandomAccessOutput byteStream, long l) { byte[] vLongBytes = vLongBytesThreadLocal.get(); int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, l); byteStream.write(vLongBytes, 0, len); }
private void writeVInt(int v) { final int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, v); output.write(vLongBytes, 0, len); }
private void writeVLong(long v) { final int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, v); output.write(vLongBytes, 0, len); }
@Override public void writeKey(RandomAccessOutput dest) throws SerDeException { lastKey += 465623573; int len = LazyBinaryUtils.writeVLongToByteArray(buffer, lastKey); lastBuffer = Arrays.copyOf(buffer, len); keys.add(lastBuffer); writeLastBuffer(dest); }
/** * Writes a Timestamp's serialized value to byte array b at the given offset * @param t to convert to bytes * @param b destination byte array * @param offset destination offset in the byte array */ public static void convertTimestampToBytes(Timestamp t, byte[] b, int offset) { long millis = t.getTime(); int nanos = t.getNanos(); long seconds = TimestampUtils.millisToSeconds(millis); boolean hasSecondVInt = seconds < 0 || seconds > Integer.MAX_VALUE; boolean hasDecimal = setNanosBytes(nanos, b, offset+4, hasSecondVInt); int firstInt = (int) seconds; if (hasDecimal || hasSecondVInt) { firstInt |= DECIMAL_OR_SECOND_VINT_FLAG; } else { firstInt &= LOWEST_31_BITS_OF_SEC_MASK; } intToBytes(firstInt, b, offset); if (hasSecondVInt) { LazyBinaryUtils.writeVLongToByteArray(b, offset + 4 + WritableUtils.decodeVIntSize(b[offset + 4]), seconds >> 31); } }
private void populateBytes() { Arrays.fill(internalBytes, (byte) 0); long seconds = timestampTZ.getEpochSecond(); int nanos = timestampTZ.getNanos(); boolean hasSecondVInt = seconds < 0 || seconds > Integer.MAX_VALUE; boolean hasDecimal = setNanosBytes(nanos, internalBytes, offset + 4, hasSecondVInt); int firstInt = (int) seconds; if (hasDecimal || hasSecondVInt) { firstInt |= DECIMAL_OR_SECOND_VINT_FLAG; } intToBytes(firstInt, internalBytes, offset); if (hasSecondVInt) { LazyBinaryUtils.writeVLongToByteArray(internalBytes, offset + 4 + WritableUtils.decodeVIntSize(internalBytes[offset + 4]), seconds >> 31); } }
/** * Writes a Timestamp's serialized value to byte array b at the given offset * @param t to convert to bytes * @param b destination byte array * @param offset destination offset in the byte array */ public static void convertTimestampToBytes(Timestamp t, byte[] b, int offset) { long seconds = t.toEpochSecond(); int nanos = t.getNanos(); boolean hasSecondVInt = seconds < 0 || seconds > Integer.MAX_VALUE; boolean hasDecimal = setNanosBytes(nanos, b, offset+4, hasSecondVInt); int firstInt = (int) seconds; if (hasDecimal || hasSecondVInt) { firstInt |= DECIMAL_OR_SECOND_VINT_FLAG; } else { firstInt &= LOWEST_31_BITS_OF_SEC_MASK; } intToBytes(firstInt, b, offset); if (hasSecondVInt) { LazyBinaryUtils.writeVLongToByteArray(b, offset + 4 + WritableUtils.decodeVIntSize(b[offset + 4]), seconds >> 31); } }
/** * Given a byte[] that has binary sortable data, initialize the internal * structures to hold that data * @param bytes the byte array that holds the binary sortable representation * @param binSortOffset offset of the binary-sortable representation within the buffer. */ public void setBinarySortable(byte[] bytes, int binSortOffset) { // Flip the sign bit (and unused bits of the high-order byte) of the seven-byte long back. long seconds = readSevenByteLong(bytes, binSortOffset) ^ SEVEN_BYTE_LONG_SIGN_FLIP; int nanos = bytesToInt(bytes, binSortOffset + 7); int firstInt = (int) seconds; boolean hasSecondVInt = seconds < 0 || seconds > Integer.MAX_VALUE; if (nanos != 0 || hasSecondVInt) { firstInt |= DECIMAL_OR_SECOND_VINT_FLAG; } else { firstInt &= LOWEST_31_BITS_OF_SEC_MASK; } intToBytes(firstInt, internalBytes, 0); setNanosBytes(nanos, internalBytes, 4, hasSecondVInt); if (hasSecondVInt) { LazyBinaryUtils.writeVLongToByteArray(internalBytes, 4 + WritableUtils.decodeVIntSize(internalBytes[4]), seconds >> 31); } currentBytes = internalBytes; this.offset = 0; }
/** * Given a byte[] that has binary sortable data, initialize the internal * structures to hold that data * @param bytes the byte array that holds the binary sortable representation * @param binSortOffset offset of the binary-sortable representation within the buffer. */ public void setBinarySortable(byte[] bytes, int binSortOffset) { // Flip the sign bit (and unused bits of the high-order byte) of the seven-byte long back. long seconds = readSevenByteLong(bytes, binSortOffset) ^ SEVEN_BYTE_LONG_SIGN_FLIP; int nanos = bytesToInt(bytes, binSortOffset + 7); int firstInt = (int) seconds; boolean hasSecondVInt = seconds < 0 || seconds > Integer.MAX_VALUE; if (nanos != 0 || hasSecondVInt) { firstInt |= DECIMAL_OR_SECOND_VINT_FLAG; } else { firstInt &= LOWEST_31_BITS_OF_SEC_MASK; } intToBytes(firstInt, internalBytes, 0); setNanosBytes(nanos, internalBytes, 4, hasSecondVInt); if (hasSecondVInt) { LazyBinaryUtils.writeVLongToByteArray(internalBytes, 4 + WritableUtils.decodeVIntSize(internalBytes[4]), seconds >> 31); } currentBytes = internalBytes; this.offset = 0; }
/** * Write a zero-compressed encoded long to a byte array. * * @param bytes * the byte array/stream * @param l * the long */ public static int writeVLongToByteArray(byte[] bytes, long l) { return LazyBinaryUtils.writeVLongToByteArray(bytes, 0, l); }
/** * Write a zero-compressed encoded long to a byte array. * * @param bytes * the byte array/stream * @param l * the long */ public static int writeVLongToByteArray(byte[] bytes, long l) { return LazyBinaryUtils.writeVLongToByteArray(bytes, 0, l); }
/** * Write a zero-compressed encoded long to a byte array. * * @param bytes * the byte array/stream * @param l * the long */ public static int writeVLongToByteArray(byte[] bytes, long l) { return LazyBinaryUtils.writeVLongToByteArray(bytes, 0, l); }
public static void writeVLong(RandomAccessOutput byteStream, long l) { byte[] vLongBytes = vLongBytesThreadLocal.get(); int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, l); byteStream.write(vLongBytes, 0, len); }
public static void writeVLong(RandomAccessOutput byteStream, long l) { byte[] vLongBytes = vLongBytesThreadLocal.get(); int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, l); byteStream.write(vLongBytes, 0, len); }
public static void writeVLong(RandomAccessOutput byteStream, long l) { byte[] vLongBytes = vLongBytesThreadLocal.get(); int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, l); byteStream.write(vLongBytes, 0, len); }
public static void writeVLong(RandomAccessOutput byteStream, long l) { byte[] vLongBytes = vLongBytesThreadLocal.get(); int len = LazyBinaryUtils.writeVLongToByteArray(vLongBytes, l); byteStream.write(vLongBytes, 0, len); }