wow_world_messages/world/wrath/
cmsg_calendar_guild_filter.rs

1use std::io::{Read, Write};
2
3use crate::shared::level_vanilla_tbc_wrath::Level;
4
5/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/calendar/cmsg_calendar_guild_filter.wowm:1`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/calendar/cmsg_calendar_guild_filter.wowm#L1):
6/// ```text
7/// cmsg CMSG_CALENDAR_GUILD_FILTER = 0x042B {
8///     Level32 minimum_level;
9///     Level32 maximum_level;
10///     u32 minimum_rank;
11/// }
12/// ```
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
14pub struct CMSG_CALENDAR_GUILD_FILTER {
15    pub minimum_level: Level,
16    pub maximum_level: Level,
17    pub minimum_rank: u32,
18}
19
20impl crate::private::Sealed for CMSG_CALENDAR_GUILD_FILTER {}
21impl CMSG_CALENDAR_GUILD_FILTER {
22    fn read_inner(mut r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseErrorKind> {
23        if body_size != 12 {
24            return Err(crate::errors::ParseErrorKind::InvalidSize);
25        }
26
27        // minimum_level: Level32
28        let minimum_level = Level::new(crate::util::read_u32_le(&mut r)? as u8);
29
30        // maximum_level: Level32
31        let maximum_level = Level::new(crate::util::read_u32_le(&mut r)? as u8);
32
33        // minimum_rank: u32
34        let minimum_rank = crate::util::read_u32_le(&mut r)?;
35
36        Ok(Self {
37            minimum_level,
38            maximum_level,
39            minimum_rank,
40        })
41    }
42
43}
44
45impl crate::Message for CMSG_CALENDAR_GUILD_FILTER {
46    const OPCODE: u32 = 0x042b;
47
48    #[cfg(feature = "print-testcase")]
49    fn message_name(&self) -> &'static str {
50        "CMSG_CALENDAR_GUILD_FILTER"
51    }
52
53    #[cfg(feature = "print-testcase")]
54    fn to_test_case_string(&self) -> Option<String> {
55        use std::fmt::Write;
56        use crate::traits::Message;
57
58        let mut s = String::new();
59
60        writeln!(s, "test CMSG_CALENDAR_GUILD_FILTER {{").unwrap();
61        // Members
62        writeln!(s, "    minimum_level = {};", self.minimum_level.as_int()).unwrap();
63        writeln!(s, "    maximum_level = {};", self.maximum_level.as_int()).unwrap();
64        writeln!(s, "    minimum_rank = {};", self.minimum_rank).unwrap();
65
66        writeln!(s, "}} [").unwrap();
67
68        let [a, b] = 16_u16.to_be_bytes();
69        writeln!(s, "    {a:#04X}, {b:#04X}, /* size */").unwrap();
70        let [a, b, c, d] = 1067_u32.to_le_bytes();
71        writeln!(s, "    {a:#04X}, {b:#04X}, {c:#04X}, {d:#04X}, /* opcode */").unwrap();
72        let mut bytes: Vec<u8> = Vec::new();
73        self.write_into_vec(&mut bytes).unwrap();
74        let mut bytes = bytes.into_iter();
75
76        crate::util::write_bytes(&mut s, &mut bytes, 4, "minimum_level", "    ");
77        crate::util::write_bytes(&mut s, &mut bytes, 4, "maximum_level", "    ");
78        crate::util::write_bytes(&mut s, &mut bytes, 4, "minimum_rank", "    ");
79
80
81        writeln!(s, "] {{").unwrap();
82        writeln!(s, "    versions = \"{}\";", std::env::var("WOWM_TEST_CASE_WORLD_VERSION").unwrap_or("3.3.5".to_string())).unwrap();
83        writeln!(s, "}}\n").unwrap();
84
85        Some(s)
86    }
87
88    fn size_without_header(&self) -> u32 {
89        12
90    }
91
92    fn write_into_vec(&self, mut w: impl Write) -> Result<(), std::io::Error> {
93        // minimum_level: Level32
94        w.write_all(&u32::from(self.minimum_level.as_int()).to_le_bytes())?;
95
96        // maximum_level: Level32
97        w.write_all(&u32::from(self.maximum_level.as_int()).to_le_bytes())?;
98
99        // minimum_rank: u32
100        w.write_all(&self.minimum_rank.to_le_bytes())?;
101
102        Ok(())
103    }
104
105    fn read_body<S: crate::private::Sealed>(r: &mut &[u8], body_size: u32) -> Result<Self, crate::errors::ParseError> {
106        Self::read_inner(r, body_size).map_err(|a| crate::errors::ParseError::new(1067, "CMSG_CALENDAR_GUILD_FILTER", body_size, a))
107    }
108
109}
110
111#[cfg(feature = "wrath")]
112impl crate::wrath::ClientMessage for CMSG_CALENDAR_GUILD_FILTER {}
113