func checkPreamble()

in hll/utils.go [145:181]


func checkPreamble(preamble []byte) (curMode, error) {
	if len(preamble) == 0 {
		return 0, fmt.Errorf("preamble cannot be nil or empty")
	}
	preInts := extractPreInts(preamble)
	if len(preamble) < (preInts * 4) {
		return 0, fmt.Errorf("preamble length mismatch: %d, %d", len(preamble), preInts)
	}
	serVer := extractSerVer(preamble)
	famId := extractFamilyID(preamble)
	curMode := extractCurMode(preamble)

	if famId != internal.FamilyEnum.HLL.Id {
		return 0, fmt.Errorf("possible Corruption: Invalid Family: %d", famId)
	}
	if serVer != 1 {
		return 0, fmt.Errorf("possible Corruption: Invalid Serialization Version: %d", serVer)
	}

	if preInts != listPreInts && preInts != hashSetPreInts && preInts != hllPreInts {
		return 0, fmt.Errorf("possible Corruption: Invalid Preamble Ints: %d", preInts)
	}

	if curMode == curModeList && preInts != listPreInts {
		return 0, fmt.Errorf("possible Corruption: Invalid Preamble Ints: %d", preInts)
	}

	if curMode == curModeSet && preInts != hashSetPreInts {
		return 0, fmt.Errorf("possible Corruption: Invalid Preamble Ints: %d", preInts)
	}

	if curMode == curModeHll && preInts != hllPreInts {
		return 0, fmt.Errorf("possible Corruption: Invalid Preamble Ints: %d", preInts)
	}

	return curMode, nil
}