MCPcopy Create free account
hub / github.com/OpenTSDB/opentsdb / fixFloatingPointValue

Method fixFloatingPointValue

src/core/Internal.java:577–591  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 7

fixFloatingPointValueMethod · 0.95
checkForFixupMethod · 0.95
getCopyOfCurrentValueMethod · 0.95
extractDataPointsMethod · 0.95

Calls 2

toStringMethod · 0.45

Tested by 4

fixFloatingPointValueMethod · 0.76