notfilippo commented on code in PR #91:
URL: https://github.com/apache/datasketches-rust/pull/91#discussion_r2805613338


##########
datasketches/src/bloom/sketch.rs:
##########
@@ -432,27 +430,30 @@ impl BloomFilter {
             .map_err(|_| Error::insufficient_data("flags"))?;
 
         // Validate
-        if family_id != BLOOM_FAMILY_ID {
-            return Err(Error::invalid_family(
-                BLOOM_FAMILY_ID,
-                family_id,
-                "BloomFilter",
-            ));
-        }
+        Family::BLOOMFILTER.validate_id(family_id)?;
         if serial_version != SERIAL_VERSION {
             return Err(Error::unsupported_serial_version(
                 SERIAL_VERSION,
                 serial_version,
             ));
         }
-        if preamble_longs != PREAMBLE_LONGS_EMPTY && preamble_longs != 
PREAMBLE_LONGS_STANDARD {
-            return Err(Error::invalid_preamble_longs(
-                PREAMBLE_LONGS_STANDARD,
-                preamble_longs,
-            ));
+        if 
!(Family::BLOOMFILTER.min_pre_longs..=Family::BLOOMFILTER.max_pre_longs)
+            .contains(&preamble_longs)
+        {
+            return Err(Error::deserial(format!(
+                "invalid preamble longs: expected [{}, {}], got {}",
+                Family::BLOOMFILTER.min_pre_longs,
+                Family::BLOOMFILTER.max_pre_longs,
+                preamble_longs
+            )));
         }
 
         let is_empty = (flags & EMPTY_FLAG_MASK) != 0;
+        if is_empty {
+            debug_assert_eq!(preamble_longs, 
Family::BLOOMFILTER.min_pre_longs);

Review Comment:
   Why do we use `debug_assert_eq` here? Are we worried about performance?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to