jimage_rs/
raw_jimage.rs

1use memmap2::Mmap;
2
3/// A low-level view into the underlying memory-mapped JImage.
4#[derive(Debug)]
5pub struct RawJImage<'a> {
6    mmap: &'a Mmap,
7}
8
9impl<'a> RawJImage<'a> {
10    /// Creates a new `RawJImage` instance from a memory-mapped file.
11    pub(crate) fn new(mmap: &'a Mmap) -> Self {
12        Self { mmap }
13    }
14
15    /// Returns total length of the mapped file in bytes.
16    #[inline]
17    pub fn len(&self) -> usize {
18        self.mmap.len()
19    }
20
21    /// Returns a pointer to the start of the memory-mapped data.
22    ///
23    /// # Safety
24    /// The caller must ensure that the pointer is not used after the `JImage` instance.
25    /// Dereferencing this pointer is unsafe; it is valid for `self.len()` bytes.
26    #[inline]
27    pub fn as_ptr(&self) -> *const u8 {
28        self.mmap.as_ptr()
29    }
30
31    /// Returns the entire memory-mapped data as a byte slice.
32    #[inline]
33    pub fn as_slice(&self) -> &'a [u8] {
34        &self.mmap
35    }
36}