1use zerocopy::{little_endian, AsBytes, FromBytes, FromZeroes};
2
3pub type Magic = [u8; 8];
5
6pub const MAGIC: Magic = *b"TAPEFILE";
8
9#[derive(Debug, AsBytes, FromBytes, FromZeroes)]
11#[repr(C)]
12pub struct Version {
13 pub major: u8,
14 pub minor: u8,
15}
16
17pub const VERSION: Version = Version { major: 0, minor: 1 };
18
19#[derive(Debug, AsBytes, FromBytes, FromZeroes)]
24#[repr(transparent)]
25pub struct ChapterSize(pub u8);
26
27impl Into<usize> for ChapterSize {
28 fn into(self) -> usize {
29 1 << self.0 as usize
30 }
31}
32
33#[derive(Debug, AsBytes, FromBytes, FromZeroes)]
35#[repr(C)]
36pub struct Intro {
37 pub magic: [u8; 8],
38 pub version: Version,
39 pub chapter_size: ChapterSize,
40 _padding: [u8; 5],
41 pub timestamp_base: little_endian::I128,
42}
43
44impl Intro {
45 pub fn new(chapter_size: u8, timestamp_base: i128) -> Self {
46 Self {
47 magic: MAGIC,
48 version: VERSION,
49 chapter_size: ChapterSize(chapter_size),
50 _padding: [0; 5],
51 timestamp_base: timestamp_base.into(),
52 }
53 }
54}
55
56#[test]
57fn test_intro_size() {
58 assert_eq!(std::mem::size_of::<Intro>(), 32);
59}