Skip to main content

nurtex_protocol/types/
intention.rs

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