Skip to main content

nurtex_protocol/types/
chat_mode.rs

1use nurtex_codec::{Buffer, VarInt};
2
3/// Режим чата
4#[derive(Debug, Clone, PartialEq, PartialOrd)]
5pub enum ChatMode {
6  Enabled,
7  CommandsOnly,
8  Hidden,
9}
10
11impl Buffer for ChatMode {
12  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
13    let id = i32::read_varint(buffer)?;
14
15    Some(match id {
16      0 => Self::Enabled,
17      1 => Self::CommandsOnly,
18      2 => Self::Hidden,
19      _ => return None,
20    })
21  }
22
23  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
24    let id = match self {
25      Self::Enabled => 0,
26      Self::CommandsOnly => 1,
27      Self::Hidden => 2,
28    };
29
30    id.write_varint(buffer)
31  }
32}