1use super::FileId;
2use binrw::prelude::*;
3use modular_bitfield::prelude::*;
4
5#[binrw::binrw]
6#[derive(Debug)]
7pub struct LockRequest {
8 #[bw(calc = 48)]
9 #[br(assert(_structure_size == 48))]
10 _structure_size: u16,
11 #[bw(try_calc = locks.len().try_into())]
12 lock_count: u16,
13 pub lock_sequence: LockSequence,
14 pub file_id: FileId,
15 #[br(count = lock_count)]
16 pub locks: Vec<LockElement>,
17}
18
19#[bitfield]
20#[derive(BinWrite, BinRead, Debug, Default, Clone, Copy, PartialEq, Eq)]
21#[bw(map = |&x| Self::into_bytes(x))]
22#[br(map = Self::from_bytes)]
23pub struct LockSequence {
24 pub number: B4,
25 pub index: B28,
26}
27
28#[binrw::binrw]
29#[derive(Debug)]
30pub struct LockElement {
31 pub offset: u64,
32 pub length: u64,
33 pub flags: LockFlag,
34 #[bw(calc = 0)]
35 #[br(assert(_reserved == 0))]
36 _reserved: u32,
37}
38
39#[bitfield]
40#[derive(BinWrite, BinRead, Debug, Default, Clone, Copy, PartialEq, Eq)]
41#[bw(map = |&x| Self::into_bytes(x))]
42#[br(map = Self::from_bytes)]
43pub struct LockFlag {
44 pub shared: bool,
45 pub exclusive: bool,
46 pub unlock: bool,
47 pub fail_immediately: bool,
48 #[skip]
49 __: B28,
50}
51
52#[binrw::binrw]
53#[derive(Debug)]
54pub struct LockResponse {
55 #[bw(calc = 4)]
56 #[br(assert(_structure_size == 4))]
57 pub _structure_size: u16,
58 #[bw(calc = 0)]
59 #[br(assert(_reserved == 0))]
60 pub _reserved: u16,
61}
62
63#[cfg(test)]
64mod tests {
65
66 }