Skip to main content

ghast_protocol/generated/v1_8/status/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.8/protocol.json, Minecraft 1.8.9). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see ../NOTICE.
4
5//! Serverbound 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_8::types;
26use bytes::{BufMut, Bytes, BytesMut};
27
28/// Packet ids.
29pub mod id {
30    /// `ping_start`
31    pub const PING_START: i32 = 0x00;
32    /// `ping`
33    pub const PING: i32 = 0x01;
34}
35
36/// `ping_start` (serverbound status, id 0x00).
37#[derive(Debug, Clone, PartialEq)]
38pub struct PingStart {}
39impl crate::packet::Packet for PingStart {
40    const ID: i32 = id::PING_START;
41    const NAME: &'static str = "ping_start";
42    const STATE: State = State::Status;
43    const DIRECTION: Direction = Direction::Serverbound;
44}
45impl Decode for PingStart {
46    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
47        Ok({ PingStart {} })
48    }
49}
50impl Encode for PingStart {
51    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
52        Ok(())
53    }
54}
55#[cfg(feature = "testgen")]
56impl Generate for PingStart {
57    fn generate(g: &mut Gen) -> Self {
58        { PingStart {} }
59    }
60}
61impl From<PingStart> for ServerboundStatusPacket {
62    fn from(p: PingStart) -> Self {
63        Self::PingStart(p)
64    }
65}
66
67/// `ping` (serverbound status, id 0x01).
68#[derive(Debug, Clone, PartialEq)]
69pub struct Ping {
70    /// `time`
71    pub time: i64,
72}
73impl crate::packet::Packet for Ping {
74    const ID: i32 = id::PING;
75    const NAME: &'static str = "ping";
76    const STATE: State = State::Status;
77    const DIRECTION: Direction = Direction::Serverbound;
78}
79impl Decode for Ping {
80    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
81        Ok({
82            let v15 = r.read_i64()?;
83            Ping { time: v15 }
84        })
85    }
86}
87impl Encode for Ping {
88    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
89        w.put_i64((*self).time);
90        Ok(())
91    }
92}
93#[cfg(feature = "testgen")]
94impl Generate for Ping {
95    fn generate(g: &mut Gen) -> Self {
96        {
97            let v16 = g.i64();
98            Ping { time: v16 }
99        }
100    }
101}
102impl From<Ping> for ServerboundStatusPacket {
103    fn from(p: Ping) -> Self {
104        Self::Ping(p)
105    }
106}
107
108/// Every Serverbound packet of the Status state.
109#[derive(Debug, Clone, PartialEq)]
110pub enum ServerboundStatusPacket {
111    /// `ping_start`
112    PingStart(PingStart),
113    /// `ping`
114    Ping(Ping),
115}
116
117impl PacketSet for ServerboundStatusPacket {
118    const STATE: State = State::Status;
119    const DIRECTION: Direction = Direction::Serverbound;
120    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
121        match raw.id {
122            id::PING_START => decode_exact(&raw.body).map(Self::PingStart),
123            id::PING => decode_exact(&raw.body).map(Self::Ping),
124            other => Err(DecodeError::UnknownPacketId(other)),
125        }
126    }
127    fn id(&self) -> i32 {
128        match *self {
129            Self::PingStart(_) => id::PING_START,
130            Self::Ping(_) => id::PING,
131        }
132    }
133    fn name(&self) -> &'static str {
134        match *self {
135            Self::PingStart(_) => "ping_start",
136            Self::Ping(_) => "ping",
137        }
138    }
139    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
140        match *self {
141            Self::PingStart(ref p) => p.encode(w),
142            Self::Ping(ref p) => p.encode(w),
143        }
144    }
145    fn name_of(id: i32) -> Option<&'static str> {
146        match id {
147            id::PING_START => Some("ping_start"),
148            id::PING => Some("ping"),
149            _ => None,
150        }
151    }
152}
153
154impl ServerboundStatusPacket {
155    /// All packet ids of this set, ascending.
156    pub const IDS: &'static [i32] = &[id::PING_START, id::PING];
157    /// Generates a random packet with the given id (test support).
158    #[cfg(feature = "testgen")]
159    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
160        match id {
161            id::PING_START => Some(Self::PingStart(<PingStart as Generate>::generate(g))),
162            id::PING => Some(Self::Ping(<Ping as Generate>::generate(g))),
163            _ => None,
164        }
165    }
166}