2025-06-13 16:02:37 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2025-06-10 23:39:08 +00:00
|
|
|
pub struct Chunk<'t> {
|
|
|
|
|
data: &'t [u8],
|
|
|
|
|
patch_uri: &'t str,
|
|
|
|
|
offset: u64,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 16:02:37 +00:00
|
|
|
impl fmt::Debug for Chunk<'_> {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
f.debug_struct("Chunk")
|
|
|
|
|
.field("patch_uri", &self.patch_uri)
|
|
|
|
|
.field("offset", &self.offset)
|
|
|
|
|
.field("data.len()", &self.data.len())
|
|
|
|
|
.finish_non_exhaustive()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 23:39:08 +00:00
|
|
|
impl<'t> Chunk<'t> {
|
|
|
|
|
pub fn new(data: &'t [u8], patch_uri: &'t str, offset: u64) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
data,
|
|
|
|
|
patch_uri,
|
|
|
|
|
offset,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_data(&self) -> &[u8] {
|
|
|
|
|
self.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_length(&self) -> u64 {
|
|
|
|
|
let len = self.data.len();
|
|
|
|
|
|
|
|
|
|
// BOOKMARK this might **panic** on platforms where `usize` has more than 64 bit.
|
|
|
|
|
// Also, you've allocated more than 2 EiB ... in ONE chunk.
|
|
|
|
|
// Whoa! Maybe just chill?
|
2025-06-11 00:06:08 +00:00
|
|
|
u64::try_from(len).unwrap_or_else(|e| panic!("usize={len} did not fit into u64: {e}"))
|
2025-06-10 23:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_patch_uri(&self) -> &str {
|
|
|
|
|
self.patch_uri
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_offset(&self) -> u64 {
|
|
|
|
|
self.offset
|
|
|
|
|
}
|
|
|
|
|
}
|