atom_macho/load_command/
uuid.rs

1use crate::io::{Endian, ReadExt as _, WriteExt as _};
2use std::io::{Read, Write};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct UuidCommand {
6    pub cmd: u32,
7    pub cmdsize: u32,
8    pub uuid: [u8; 16],
9}
10
11impl UuidCommand {
12    pub const TYPE: u32 = 0x1b;
13
14    pub const SIZE: u32 = 0x18; // 24
15
16    pub fn read_from_in<R: Read>(read: &mut R, endian: Endian) -> Self {
17        let cmd = read.read_u32_in(endian);
18        assert_eq!(cmd, Self::TYPE);
19
20        let cmdsize = read.read_u32_in(endian);
21        assert_eq!(cmdsize, Self::SIZE);
22
23        let mut uuid = [0; 16];
24        read.read_exact(&mut uuid).unwrap();
25
26        UuidCommand {
27            cmd,
28            cmdsize,
29            uuid,
30        }
31    }
32
33    pub fn write_into<W: Write>(&self, write: &mut W) {
34        write.write_u32_native(self.cmd);
35        write.write_u32_native(self.cmdsize);
36        write.write_all(&self.uuid).unwrap();
37    }
38}