diff --git a/milli/src/heed_codec/roaring_bitmap/bo_roaring_bitmap_codec.rs b/milli/src/heed_codec/roaring_bitmap/bo_roaring_bitmap_codec.rs index 7ceb69f9a..25c8afe2f 100644 --- a/milli/src/heed_codec/roaring_bitmap/bo_roaring_bitmap_codec.rs +++ b/milli/src/heed_codec/roaring_bitmap/bo_roaring_bitmap_codec.rs @@ -1,4 +1,6 @@ use std::borrow::Cow; +use std::mem::size_of; + use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use roaring::RoaringBitmap; @@ -7,9 +9,14 @@ pub struct BoRoaringBitmapCodec; impl heed::BytesDecode<'_> for BoRoaringBitmapCodec { type DItem = RoaringBitmap; - fn bytes_decode(mut bytes: &[u8]) -> Option { + fn bytes_decode(bytes: &[u8]) -> Option { let mut bitmap = RoaringBitmap::new(); - while let Ok(integer) = bytes.read_u32::() { + let num_u32 = bytes.len() / size_of::(); + for i in 0..num_u32 { + let start = i * size_of::(); + let end = (i + 1) * size_of::(); + let mut bytes = bytes.get(start..end)?; + let integer = bytes.read_u32::().ok()?; bitmap.insert(integer); } Some(bitmap)