pub struct Bucket<'a> { /* private fields */ }Expand description
A borrowed view over a single bucket: the parsed header plus the backing bytes, with slot-table resolution.
Bucket layout, reverse-engineered from libnsfdb_bucket.c:
+------------------+ offset 0
| header (66 B) |
+------------------+
| slot data ... | slot bytes live here, addressed by absolute
| | offset from the bucket start
+------------------+
| slot-index table | number_of_slots entries, 4 bytes each,
| | stored BACK-TO-FRONT: slot 0 occupies the last
| | 4 bytes before the footer. Each entry is
| | [u16 offset][u16 size] (offset at the lower
| | address, size at the higher).
+------------------+ size - footer_size
| footer |
+------------------+ sizeSlot indices on disk are 1-based (libnsfdb_bucket_get_slot
rejects index 0 and looks up slot_index - 1); RRV bucket-slot
entries carry the 1-based value, so Bucket::slot takes it as-is.
Implementations§
Source§impl<'a> Bucket<'a>
impl<'a> Bucket<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self, NsfError>
pub fn parse(bytes: &'a [u8]) -> Result<Self, NsfError>
Parse a bucket from a buffer positioned at the bucket’s file
offset. The buffer may extend past the bucket (e.g. it is the
remainder of the whole file); this constructor clamps the view to
the bucket’s declared size so slot resolution cannot read into a
neighbouring structure.
Sourcepub fn header(&self) -> &BucketHeader
pub fn header(&self) -> &BucketHeader
The parsed bucket header.
Sourcepub fn slot_count(&self) -> u32
pub fn slot_count(&self) -> u32
Number of slots the bucket declares.
Sourcepub fn slot_entry(&self, slot_index: u16) -> Result<BucketSlot, NsfError>
pub fn slot_entry(&self, slot_index: u16) -> Result<BucketSlot, NsfError>
Resolve the slot-index entry for a 1-based slot_index.
Returns NsfError::SlotIndexOutOfRange if the index is zero or
beyond the declared slot count, or NsfError::TooShort if the
bucket buffer does not actually contain the slot-index table the
header advertises (truncated / corrupt bucket).