deepslate_protocol/packet/
status.rs1use bytes::{Buf, BufMut};
4
5use crate::types::{self, ProtocolError};
6
7use super::Packet;
8
9#[derive(Debug, Clone)]
12pub struct StatusRequestPacket;
13
14impl Packet for StatusRequestPacket {
15 const PACKET_ID: i32 = 0x00;
16
17 fn decode(_buf: &mut impl Buf) -> Result<Self, ProtocolError> {
18 Ok(Self)
19 }
20
21 fn encode(&self, _buf: &mut impl BufMut) {}
22}
23
24#[derive(Debug, Clone)]
26pub struct StatusResponsePacket {
27 pub json: String,
29}
30
31impl Packet for StatusResponsePacket {
32 const PACKET_ID: i32 = 0x00;
33
34 fn decode(buf: &mut impl Buf) -> Result<Self, ProtocolError> {
35 let json = types::read_string(buf)?;
36 Ok(Self { json })
37 }
38
39 fn encode(&self, buf: &mut impl BufMut) {
40 types::write_string(buf, &self.json);
41 }
42}
43
44#[derive(Debug, Clone)]
46pub struct PingRequestPacket {
47 pub payload: i64,
49}
50
51impl Packet for PingRequestPacket {
52 const PACKET_ID: i32 = 0x01;
53
54 fn decode(buf: &mut impl Buf) -> Result<Self, ProtocolError> {
55 if buf.remaining() < 8 {
56 return Err(ProtocolError::UnexpectedEof);
57 }
58 Ok(Self {
59 payload: buf.get_i64(),
60 })
61 }
62
63 fn encode(&self, buf: &mut impl BufMut) {
64 buf.put_i64(self.payload);
65 }
66}
67
68#[derive(Debug, Clone)]
70pub struct PongResponsePacket {
71 pub payload: i64,
73}
74
75impl Packet for PongResponsePacket {
76 const PACKET_ID: i32 = 0x01;
77
78 fn decode(buf: &mut impl Buf) -> Result<Self, ProtocolError> {
79 if buf.remaining() < 8 {
80 return Err(ProtocolError::UnexpectedEof);
81 }
82 Ok(Self {
83 payload: buf.get_i64(),
84 })
85 }
86
87 fn encode(&self, buf: &mut impl BufMut) {
88 buf.put_i64(self.payload);
89 }
90}