fix parsing COUNT envelopes without "hll".

This commit is contained in:
fiatjaf 2024-12-07 00:21:58 -03:00
parent 142da7344f
commit e8d9464938

View File

@ -166,7 +166,12 @@ func (v *CountEnvelope) UnmarshalJSON(data []byte) error {
}
if err := json.Unmarshal([]byte(arr[2].Raw), &countResult); err == nil && countResult.Count != nil {
v.Count = countResult.Count
v.HyperLogLog, _ = hex.DecodeString(countResult.HLL)
if len(countResult.HLL) == 512 {
v.HyperLogLog, err = hex.DecodeString(countResult.HLL)
if err != nil {
return fmt.Errorf("invalid \"hll\" value in COUNT message: %w", err)
}
}
return nil
}