1pub(crate) mod detect;
2pub(crate) mod legacy;
3pub(crate) mod modern;
4
5mod read;
6
7pub use read::BdatFile;
8
9const BDAT_MAGIC: [u8; 4] = [b'B', b'D', b'A', b'T'];
10
11pub type SwitchEndian = byteorder::LittleEndian;
14pub type WiiEndian = byteorder::BigEndian;
16
17#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub enum BdatVersion {
21 Legacy(LegacyVersion),
23 Modern,
25}
26
27#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub enum LegacyVersion {
37 Wii,
39 New3ds,
41 Switch,
43 X,
45}
46
47impl BdatVersion {
48 pub fn is_legacy(&self) -> bool {
49 *self != BdatVersion::Modern
50 }
51
52 pub fn is_modern(&self) -> bool {
53 !self.is_legacy()
54 }
55
56 pub fn are_labels_hashed(&self) -> bool {
58 self.is_modern()
59 }
60}
61
62impl LegacyVersion {
63 pub(crate) const fn table_header_size(&self) -> usize {
65 if self.is_wii_table_format() {
66 legacy::HEADER_SIZE_WII
67 } else {
68 legacy::HEADER_SIZE
69 }
70 }
71
72 pub(crate) const fn is_wii_table_format(&self) -> bool {
73 matches!(self, Self::Wii | Self::New3ds)
74 }
75}
76
77impl From<LegacyVersion> for BdatVersion {
78 fn from(value: LegacyVersion) -> Self {
79 Self::Legacy(value)
80 }
81}