wow_world_messages/world/shared/
smsg_resurrect_request_vanilla_tbc_wrath.rs

1use std::io::{Read, Write};
2
3use crate::Guid;
4
5/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/resurrect/smsg_resurrect_request.wowm:1`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/resurrect/smsg_resurrect_request.wowm#L1):
6/// ```text
7/// smsg SMSG_RESURRECT_REQUEST = 0x015B {
8///     Guid guid;
9///     SizedCString name;
10///     Bool player;
11/// }
12/// ```
13#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
14pub struct SMSG_RESURRECT_REQUEST {
15    pub guid: Guid,
16    pub name: String,
17    pub player: bool,
18}
19
20impl crate::private::Sealed for SMSG_RESURRECT_REQUEST {}
21impl SMSG_RESURRECT_REQUEST {
22    fn read_inner(mut r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseErrorKind> {
23        if !(14..=8013).contains(&body_size) {
24            return Err(crate::errors::ParseErrorKind::InvalidSize);
25        }
26
27        // guid: Guid
28        let guid = crate::util::read_guid(&mut r)?;
29
30        // name: SizedCString
31        let name = {
32            let name = crate::util::read_u32_le(&mut r)?;
33            let name = crate::util::read_sized_c_string_to_vec(&mut r, name)?;
34            String::from_utf8(name)?
35        };
36
37        // player: Bool
38        let player = crate::util::read_bool_u8(&mut r)?;
39
40        Ok(Self {
41            guid,
42            name,
43            player,
44        })
45    }
46
47}
48
49impl crate::Message for SMSG_RESURRECT_REQUEST {
50    const OPCODE: u32 = 0x015b;
51
52    #[cfg(feature = "print-testcase")]
53    fn message_name(&self) -> &'static str {
54        "SMSG_RESURRECT_REQUEST"
55    }
56
57    #[cfg(feature = "print-testcase")]
58    fn to_test_case_string(&self) -> Option<String> {
59        use std::fmt::Write;
60        use crate::traits::Message;
61
62        let mut s = String::new();
63
64        writeln!(s, "test SMSG_RESURRECT_REQUEST {{").unwrap();
65        // Members
66        writeln!(s, "    guid = {};", self.guid.guid()).unwrap();
67        writeln!(s, "    name = \"{}\";", self.name).unwrap();
68        writeln!(s, "    player = {};", if self.player { "TRUE" } else { "FALSE" }).unwrap();
69
70        writeln!(s, "}} [").unwrap();
71
72        let [a, b] = (u16::try_from(self.size() + 2).unwrap()).to_be_bytes();
73        writeln!(s, "    {a:#04X}, {b:#04X}, /* size */").unwrap();
74        let [a, b] = 347_u16.to_le_bytes();
75        writeln!(s, "    {a:#04X}, {b:#04X}, /* opcode */").unwrap();
76        let mut bytes: Vec<u8> = Vec::new();
77        self.write_into_vec(&mut bytes).unwrap();
78        let mut bytes = bytes.into_iter();
79
80        crate::util::write_bytes(&mut s, &mut bytes, 8, "guid", "    ");
81        crate::util::write_bytes(&mut s, &mut bytes, self.name.len() + 5, "name", "    ");
82        crate::util::write_bytes(&mut s, &mut bytes, 1, "player", "    ");
83
84
85        writeln!(s, "] {{").unwrap();
86        writeln!(s, "    versions = \"{}\";", std::env::var("WOWM_TEST_CASE_WORLD_VERSION").unwrap_or("1 2 3".to_string())).unwrap();
87        writeln!(s, "}}\n").unwrap();
88
89        Some(s)
90    }
91
92    fn size_without_header(&self) -> u32 {
93        self.size() as u32
94    }
95
96    fn write_into_vec(&self, mut w: impl Write) -> Result<(), std::io::Error> {
97        // guid: Guid
98        w.write_all(&self.guid.guid().to_le_bytes())?;
99
100        // name: SizedCString
101        w.write_all(&((self.name.len() + 1) as u32).to_le_bytes())?;
102        w.write_all(self.name.as_bytes())?;
103        // Null terminator
104        w.write_all(&[0])?;
105
106        // player: Bool
107        w.write_all(u8::from(self.player).to_le_bytes().as_slice())?;
108
109        Ok(())
110    }
111
112    fn read_body<S: crate::private::Sealed>(r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseError> {
113        Self::read_inner(r, body_size).map_err(|a| crate::errors::ParseError::new(347, "SMSG_RESURRECT_REQUEST", body_size, a))
114    }
115
116}
117
118#[cfg(feature = "vanilla")]
119impl crate::vanilla::ServerMessage for SMSG_RESURRECT_REQUEST {}
120
121#[cfg(feature = "tbc")]
122impl crate::tbc::ServerMessage for SMSG_RESURRECT_REQUEST {}
123
124#[cfg(feature = "wrath")]
125impl crate::wrath::ServerMessage for SMSG_RESURRECT_REQUEST {}
126
127impl SMSG_RESURRECT_REQUEST {
128    pub(crate) fn size(&self) -> usize {
129        8 // guid: Guid
130        + self.name.len() + 5 // name: SizedCString
131        + 1 // player: Bool
132    }
133}
134