public final boolean hasDecimal() { return hasDecimalOrSecondVInt() || currentBytes[offset + 4] != -1; // If the first byte of the VInt is -1, the VInt itself is -1, indicating that there is a // second VInt but the nanoseconds field is actually 0. }
private final boolean hasDecimalOrSecondVInt() { return hasDecimalOrSecondVInt(currentBytes[offset]); }
/** * * @return nanoseconds in this TimestampWritable */ public int getNanos() { if (!timestampEmpty) { return timestamp.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt() ? TimestampWritable.getNanos(currentBytes, offset + 4) : 0; } else { throw new IllegalStateException("Both timestamp and bytes are empty"); } }
public static void setTimestamp(Timestamp t, byte[] bytes, int offset) { long seconds = getSeconds(bytes, offset); t.setTime(seconds * 1000); if (hasDecimalOrSecondVInt(bytes[offset])) { t.setNanos(getNanos(bytes, offset + 4)); } else { t.setNanos(0); } }
public void readFields(DataInput in) throws IOException { in.readFully(internalBytes, 0, 4); if (TimestampWritable.hasDecimalOrSecondVInt(internalBytes[0])) { in.readFully(internalBytes, 4, 1); int len = (byte) WritableUtils.decodeVIntSize(internalBytes[4]); if (len > 1) { in.readFully(internalBytes, 5, len-1); } long vlong = LazyBinaryUtils.readVLongFromByteArray(internalBytes, 4); if (vlong < -1000000000 || vlong > 999999999) { throw new IOException( "Invalid first vint value (encoded nanoseconds) of a TimestampWritable: " + vlong + ", expected to be between -1000000000 and 999999999."); // Note that -1000000000 is a valid value corresponding to a nanosecond timestamp // of 999999999, because if the second VInt is present, we use the value // (-reversedNanoseconds - 1) as the second VInt. } if (vlong < 0) { // This indicates there is a second VInt containing the additional bits of the seconds // field. in.readFully(internalBytes, 4 + len, 1); int secondVIntLen = (byte) WritableUtils.decodeVIntSize(internalBytes[4 + len]); if (secondVIntLen > 1) { in.readFully(internalBytes, 5 + len, secondVIntLen - 1); } } } currentBytes = internalBytes; this.offset = 0; }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }
public final boolean hasDecimal() { return hasDecimalOrSecondVInt() || currentBytes[offset + 4] != -1; // If the first byte of the VInt is -1, the VInt itself is -1, indicating that there is a // second VInt but the nanoseconds field is actually 0. }
public final boolean hasDecimal() { return hasDecimalOrSecondVInt() || currentBytes[offset + 4] != -1; // If the first byte of the VInt is -1, the VInt itself is -1, indicating that there is a // second VInt but the nanoseconds field is actually 0. }
public final boolean hasDecimal() { return hasDecimalOrSecondVInt() || currentBytes[offset + 4] != -1; // If the first byte of the VInt is -1, the VInt itself is -1, indicating that there is a // second VInt but the nanoseconds field is actually 0. }
public final boolean hasDecimal() { return hasDecimalOrSecondVInt() || currentBytes[offset + 4] != -1; // If the first byte of the VInt is -1, the VInt itself is -1, indicating that there is a // second VInt but the nanoseconds field is actually 0. }
private final boolean hasDecimalOrSecondVInt() { return hasDecimalOrSecondVInt(currentBytes[offset]); }
private final boolean hasDecimalOrSecondVInt() { return hasDecimalOrSecondVInt(currentBytes[offset]); }
/** * * @return nanoseconds in this TimestampWritable */ public int getNanos() { if (!timestampEmpty) { return timestamp.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt() ? TimestampWritable.getNanos(currentBytes, offset + 4) : 0; } else { throw new IllegalStateException("Both timestamp and bytes are empty"); } }
/** * * @return nanoseconds in this TimestampWritable */ public int getNanos() { if (!timestampEmpty) { return timestamp.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt() ? TimestampWritable.getNanos(currentBytes, offset + 4) : 0; } else { throw new IllegalStateException("Both timestamp and bytes are empty"); } }
/** * * @return nanoseconds in this TimestampWritable */ public int getNanos() { if (!timestampEmpty) { return timestamp.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt() ? TimestampWritable.getNanos(currentBytes, offset + 4) : 0; } else { throw new IllegalStateException("Both timestamp and bytes are empty"); } }
public static void setTimestamp(Timestamp t, byte[] bytes, int offset) { long seconds = getSeconds(bytes, offset); t.setTime(seconds * 1000); if (hasDecimalOrSecondVInt(bytes[offset])) { t.setNanos(getNanos(bytes, offset + 4)); } else { t.setNanos(0); } }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }