Returns a corrected value if this is a floating point value to fix. OpenTSDB used to encode all floating point values as `float' (4 bytes) but actually store them on 8 bytes, with 4 leading 0 bytes, and flags correctly stating the value was on 4 bytes. This function detects such values and r
(final byte flags,
final byte[] value)
| 575 | * @throws IllegalDataException if the value is malformed. |
| 576 | */ |
| 577 | public static byte[] fixFloatingPointValue(final byte flags, |
| 578 | final byte[] value) { |
| 579 | if (floatingPointValueToFix(flags, value)) { |
| 580 | // The first 4 bytes should really be zeros. |
| 581 | if (value[0] == 0 && value[1] == 0 && value[2] == 0 && value[3] == 0) { |
| 582 | // Just keep the last 4 bytes. |
| 583 | return new byte[] { value[4], value[5], value[6], value[7] }; |
| 584 | } else { // Very unlikely. |
| 585 | throw new IllegalDataException("Corrupted floating point value: " |
| 586 | + Arrays.toString(value) + " flags=0x" + Integer.toHexString(flags) |
| 587 | + " -- first 4 bytes are expected to be zeros."); |
| 588 | } |
| 589 | } |
| 590 | return value; |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Determines if the qualifier is in milliseconds or not |