Skip to main content

ghast_protocol/generated/v1_16_5/status/
clientbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.16.2/protocol.json, Minecraft 1.16.5). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see ../NOTICE.
4
5//! Clientbound packets of the status state.
6
7#![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_16_5::types;
26use bytes::{BufMut, Bytes, BytesMut};
27
28/// Packet ids.
29pub mod id {
30    /// `server_info`
31    pub const SERVER_INFO: i32 = 0x00;
32    /// `ping`
33    pub const PING: i32 = 0x01;
34}
35
36/// `server_info` (clientbound status, id 0x00).
37#[derive(Debug, Clone, PartialEq)]
38pub struct ServerInfo {
39    /// `response`
40    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/// `ping` (clientbound status, id 0x01).
78#[derive(Debug, Clone, PartialEq)]
79pub struct Ping {
80    /// `time`
81    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/// Every Clientbound packet of the Status state.
119#[derive(Debug, Clone, PartialEq)]
120pub enum ClientboundStatusPacket {
121    /// `server_info`
122    ServerInfo(ServerInfo),
123    /// `ping`
124    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    /// All packet ids of this set, ascending.
166    pub const IDS: &'static [i32] = &[id::SERVER_INFO, id::PING];
167    /// Generates a random packet with the given id (test support).
168    #[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}