ghast_protocol/generated/v1_8/status/
clientbound.rs1#![allow(
8 unused_imports,
9 unused_variables,
10 unused_mut,
11 unused_parens,
12 unused_braces,
13 clippy::all,
14 clippy::pedantic,
15 non_camel_case_types,
16 non_snake_case
17)]
18use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
19use crate::error::{DecodeError, EncodeError};
20use crate::nbt::RawNbt;
21use crate::packet::{Direction, PacketSet, RawPacket, State};
22#[cfg(feature = "testgen")]
23use crate::testgen::{Gen, Generate};
24use crate::types::{BlockPos, ByteString, PositionLayout, Uuid};
25use crate::v1_8::types;
26use bytes::{BufMut, Bytes, BytesMut};
27
28pub mod id {
30 pub const SERVER_INFO: i32 = 0x00;
32 pub const PING: i32 = 0x01;
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub struct ServerInfo {
39 pub response: ByteString,
41}
42impl crate::packet::Packet for ServerInfo {
43 const ID: i32 = id::SERVER_INFO;
44 const NAME: &'static str = "server_info";
45 const STATE: State = State::Status;
46 const DIRECTION: Direction = Direction::Clientbound;
47}
48impl Decode for ServerInfo {
49 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
50 Ok({
51 let v11 = r.read_string()?;
52 ServerInfo { response: v11 }
53 })
54 }
55}
56impl Encode for ServerInfo {
57 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
58 w.put_string(&(*self).response)?;
59 Ok(())
60 }
61}
62#[cfg(feature = "testgen")]
63impl Generate for ServerInfo {
64 fn generate(g: &mut Gen) -> Self {
65 {
66 let v12 = g.string();
67 ServerInfo { response: v12 }
68 }
69 }
70}
71impl From<ServerInfo> for ClientboundStatusPacket {
72 fn from(p: ServerInfo) -> Self {
73 Self::ServerInfo(p)
74 }
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub struct Ping {
80 pub time: i64,
82}
83impl crate::packet::Packet for Ping {
84 const ID: i32 = id::PING;
85 const NAME: &'static str = "ping";
86 const STATE: State = State::Status;
87 const DIRECTION: Direction = Direction::Clientbound;
88}
89impl Decode for Ping {
90 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
91 Ok({
92 let v13 = r.read_i64()?;
93 Ping { time: v13 }
94 })
95 }
96}
97impl Encode for Ping {
98 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
99 w.put_i64((*self).time);
100 Ok(())
101 }
102}
103#[cfg(feature = "testgen")]
104impl Generate for Ping {
105 fn generate(g: &mut Gen) -> Self {
106 {
107 let v14 = g.i64();
108 Ping { time: v14 }
109 }
110 }
111}
112impl From<Ping> for ClientboundStatusPacket {
113 fn from(p: Ping) -> Self {
114 Self::Ping(p)
115 }
116}
117
118#[derive(Debug, Clone, PartialEq)]
120pub enum ClientboundStatusPacket {
121 ServerInfo(ServerInfo),
123 Ping(Ping),
125}
126
127impl PacketSet for ClientboundStatusPacket {
128 const STATE: State = State::Status;
129 const DIRECTION: Direction = Direction::Clientbound;
130 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
131 match raw.id {
132 id::SERVER_INFO => decode_exact(&raw.body).map(Self::ServerInfo),
133 id::PING => decode_exact(&raw.body).map(Self::Ping),
134 other => Err(DecodeError::UnknownPacketId(other)),
135 }
136 }
137 fn id(&self) -> i32 {
138 match *self {
139 Self::ServerInfo(_) => id::SERVER_INFO,
140 Self::Ping(_) => id::PING,
141 }
142 }
143 fn name(&self) -> &'static str {
144 match *self {
145 Self::ServerInfo(_) => "server_info",
146 Self::Ping(_) => "ping",
147 }
148 }
149 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
150 match *self {
151 Self::ServerInfo(ref p) => p.encode(w),
152 Self::Ping(ref p) => p.encode(w),
153 }
154 }
155 fn name_of(id: i32) -> Option<&'static str> {
156 match id {
157 id::SERVER_INFO => Some("server_info"),
158 id::PING => Some("ping"),
159 _ => None,
160 }
161 }
162}
163
164impl ClientboundStatusPacket {
165 pub const IDS: &'static [i32] = &[id::SERVER_INFO, id::PING];
167 #[cfg(feature = "testgen")]
169 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
170 match id {
171 id::SERVER_INFO => Some(Self::ServerInfo(<ServerInfo as Generate>::generate(g))),
172 id::PING => Some(Self::Ping(<Ping as Generate>::generate(g))),
173 _ => None,
174 }
175 }
176}