From 6c780a56f1156ede5f4a4027f13ba92ac3b9c27f Mon Sep 17 00:00:00 2001 From: widberg Date: Sun, 22 Oct 2023 10:26:34 -0400 Subject: [PATCH] Add a size method to Resource. --- bff/src/bigfile/resource.rs | 11 +++++++++++ bff/src/crc/blacksheep32.rs | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bff/src/bigfile/resource.rs b/bff/src/bigfile/resource.rs index c5038e0..d8d59a3 100644 --- a/bff/src/bigfile/resource.rs +++ b/bff/src/bigfile/resource.rs @@ -20,3 +20,14 @@ pub struct Resource { pub name: Name, pub data: ResourceData, } + +impl Resource { + pub fn size(&self) -> usize { + match &self.data { + ResourceData::Data(data) | ResourceData::CompressibleData { data, .. } => data.len(), + ResourceData::ExtendedData { + link_header, body, .. + } => link_header.len() + body.len(), + } + } +} diff --git a/bff/src/crc/blacksheep32.rs b/bff/src/crc/blacksheep32.rs index 966c543..41f021c 100644 --- a/bff/src/crc/blacksheep32.rs +++ b/bff/src/crc/blacksheep32.rs @@ -1,6 +1,9 @@ use crate::traits::NameHashFunction; -// IEEE 802.3 CRC32 Lookup Table +// This algorithm is also used by Ubisoft + +// Appears to be the same as FreeBSD +// https://github.com/lattera/freebsd/blob/401a161083850a9a4ce916f37520c084cff1543b/sys/libkern/crc32.c#L51-L95 const CRC32_TABLE: [u32; 256] = [ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, @@ -40,7 +43,7 @@ pub const fn blacksheep32(bytes: &[u8]) -> i32 { blacksheep32_options(bytes, 0) } -// IEEE 802.3 CRC32 +// https://github.com/lattera/freebsd/blob/401a161083850a9a4ce916f37520c084cff1543b/sys/libkern/crc32.c#L103-L113 pub const fn blacksheep32_options(bytes: &[u8], starting: i32) -> i32 { let mut hash = !starting as u32; let mut i: usize = 0;