static CurMode checkPreamble()

in src/main/java/org/apache/datasketches/hll/HllUtil.java [97:116]


  static CurMode checkPreamble(final Memory mem) {
    checkBounds(0, 8, mem.getCapacity()); //need min 8 bytes
    final int preInts = extractPreInts(mem);
    checkBounds(0, (long)preInts * Integer.BYTES, mem.getCapacity());
    final int serVer = extractSerVer(mem);
    final int famId = extractFamilyId(mem);
    final CurMode curMode = extractCurMode(mem);
    if (
      (famId != Family.HLL.getID())
      || (serVer != 1)
      || ((preInts != LIST_PREINTS) && (preInts != HASH_SET_PREINTS) && (preInts != HLL_PREINTS))
      || ((curMode == CurMode.LIST) && (preInts != LIST_PREINTS))
      || ((curMode == CurMode.SET) && (preInts != HASH_SET_PREINTS))
      || ((curMode == CurMode.HLL) && (preInts != HLL_PREINTS))
    ) {
      throw new SketchesArgumentException("Possible Corruption, Invalid Preamble:"
          + PreambleUtil.toString(mem));
    }
    return curMode;
  }