ghast_protocol/generated/v26_2/login/
clientbound.rs1#![allow(
9 unused_imports,
10 unused_variables,
11 unused_mut,
12 unused_parens,
13 unused_braces,
14 clippy::all,
15 clippy::pedantic,
16 non_camel_case_types,
17 non_snake_case
18)]
19use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
20use crate::error::{DecodeError, EncodeError};
21use crate::nbt::{AnonNbt, RawNbt};
22use crate::packet::{Direction, PacketSet, RawPacket, State};
23#[cfg(feature = "testgen")]
24use crate::testgen::{Gen, Generate};
25use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
26use bytes::{BufMut, Bytes, BytesMut};
27
28pub mod id {
30 pub const DISCONNECT: i32 = 0x00;
32 pub const ENCRYPTION_BEGIN: i32 = 0x01;
34 pub const SUCCESS: i32 = 0x02;
36 pub const COMPRESS: i32 = 0x03;
38 pub const LOGIN_PLUGIN_REQUEST: i32 = 0x04;
40 pub const COOKIE_REQUEST: i32 = 0x05;
42}
43
44pub use crate::defs::p775::login::clientbound::SuccessProperties;
45
46pub type Disconnect = crate::defs::p47::login::clientbound::Disconnect<776>;
48impl crate::packet::Packet for Disconnect {
49 const ID: i32 = id::DISCONNECT;
50 const NAME: &'static str = "disconnect";
51 const STATE: State = State::Login;
52 const DIRECTION: Direction = Direction::Clientbound;
53}
54impl From<Disconnect> for ClientboundLoginPacket {
55 fn from(p: Disconnect) -> Self {
56 Self::Disconnect(p)
57 }
58}
59
60pub type EncryptionBegin = crate::defs::p775::login::clientbound::EncryptionBegin<776>;
62impl crate::packet::Packet for EncryptionBegin {
63 const ID: i32 = id::ENCRYPTION_BEGIN;
64 const NAME: &'static str = "encryption_begin";
65 const STATE: State = State::Login;
66 const DIRECTION: Direction = Direction::Clientbound;
67}
68impl From<EncryptionBegin> for ClientboundLoginPacket {
69 fn from(p: EncryptionBegin) -> Self {
70 Self::EncryptionBegin(p)
71 }
72}
73
74pub type Success = crate::defs::p776::login::clientbound::Success<776>;
76impl crate::packet::Packet for Success {
77 const ID: i32 = id::SUCCESS;
78 const NAME: &'static str = "success";
79 const STATE: State = State::Login;
80 const DIRECTION: Direction = Direction::Clientbound;
81}
82impl From<Success> for ClientboundLoginPacket {
83 fn from(p: Success) -> Self {
84 Self::Success(p)
85 }
86}
87
88pub type Compress = crate::defs::p47::login::clientbound::Compress<776>;
90impl crate::packet::Packet for Compress {
91 const ID: i32 = id::COMPRESS;
92 const NAME: &'static str = "compress";
93 const STATE: State = State::Login;
94 const DIRECTION: Direction = Direction::Clientbound;
95}
96impl From<Compress> for ClientboundLoginPacket {
97 fn from(p: Compress) -> Self {
98 Self::Compress(p)
99 }
100}
101
102pub type LoginPluginRequest = crate::defs::p754::login::clientbound::LoginPluginRequest<776>;
104impl crate::packet::Packet for LoginPluginRequest {
105 const ID: i32 = id::LOGIN_PLUGIN_REQUEST;
106 const NAME: &'static str = "login_plugin_request";
107 const STATE: State = State::Login;
108 const DIRECTION: Direction = Direction::Clientbound;
109}
110impl From<LoginPluginRequest> for ClientboundLoginPacket {
111 fn from(p: LoginPluginRequest) -> Self {
112 Self::LoginPluginRequest(p)
113 }
114}
115
116pub type CookieRequest = crate::defs::p775::login::clientbound::CookieRequest<776>;
118impl crate::packet::Packet for CookieRequest {
119 const ID: i32 = id::COOKIE_REQUEST;
120 const NAME: &'static str = "cookie_request";
121 const STATE: State = State::Login;
122 const DIRECTION: Direction = Direction::Clientbound;
123}
124impl From<CookieRequest> for ClientboundLoginPacket {
125 fn from(p: CookieRequest) -> Self {
126 Self::CookieRequest(p)
127 }
128}
129
130#[derive(Debug, Clone, PartialEq)]
132pub enum ClientboundLoginPacket {
133 Disconnect(Disconnect),
135 EncryptionBegin(EncryptionBegin),
137 Success(Success),
139 Compress(Compress),
141 LoginPluginRequest(LoginPluginRequest),
143 CookieRequest(CookieRequest),
145}
146
147impl PacketSet for ClientboundLoginPacket {
148 const STATE: State = State::Login;
149 const DIRECTION: Direction = Direction::Clientbound;
150 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
151 match raw.id {
152 id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
153 id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
154 id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
155 id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
156 id::LOGIN_PLUGIN_REQUEST => decode_exact(&raw.body).map(Self::LoginPluginRequest),
157 id::COOKIE_REQUEST => decode_exact(&raw.body).map(Self::CookieRequest),
158 other => Err(DecodeError::UnknownPacketId(other)),
159 }
160 }
161 fn id(&self) -> i32 {
162 match *self {
163 Self::Disconnect(_) => id::DISCONNECT,
164 Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
165 Self::Success(_) => id::SUCCESS,
166 Self::Compress(_) => id::COMPRESS,
167 Self::LoginPluginRequest(_) => id::LOGIN_PLUGIN_REQUEST,
168 Self::CookieRequest(_) => id::COOKIE_REQUEST,
169 }
170 }
171 fn name(&self) -> &'static str {
172 match *self {
173 Self::Disconnect(_) => "disconnect",
174 Self::EncryptionBegin(_) => "encryption_begin",
175 Self::Success(_) => "success",
176 Self::Compress(_) => "compress",
177 Self::LoginPluginRequest(_) => "login_plugin_request",
178 Self::CookieRequest(_) => "cookie_request",
179 }
180 }
181 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
182 match *self {
183 Self::Disconnect(ref p) => p.encode(w),
184 Self::EncryptionBegin(ref p) => p.encode(w),
185 Self::Success(ref p) => p.encode(w),
186 Self::Compress(ref p) => p.encode(w),
187 Self::LoginPluginRequest(ref p) => p.encode(w),
188 Self::CookieRequest(ref p) => p.encode(w),
189 }
190 }
191 fn name_of(id: i32) -> Option<&'static str> {
192 match id {
193 id::DISCONNECT => Some("disconnect"),
194 id::ENCRYPTION_BEGIN => Some("encryption_begin"),
195 id::SUCCESS => Some("success"),
196 id::COMPRESS => Some("compress"),
197 id::LOGIN_PLUGIN_REQUEST => Some("login_plugin_request"),
198 id::COOKIE_REQUEST => Some("cookie_request"),
199 _ => None,
200 }
201 }
202}
203
204impl ClientboundLoginPacket {
205 pub const IDS: &'static [i32] = &[
207 id::DISCONNECT,
208 id::ENCRYPTION_BEGIN,
209 id::SUCCESS,
210 id::COMPRESS,
211 id::LOGIN_PLUGIN_REQUEST,
212 id::COOKIE_REQUEST,
213 ];
214 #[cfg(feature = "testgen")]
216 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
217 match id {
218 id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
219 id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
220 <EncryptionBegin as Generate>::generate(g),
221 )),
222 id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
223 id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
224 id::LOGIN_PLUGIN_REQUEST => Some(Self::LoginPluginRequest(
225 <LoginPluginRequest as Generate>::generate(g),
226 )),
227 id::COOKIE_REQUEST => Some(Self::CookieRequest(<CookieRequest as Generate>::generate(
228 g,
229 ))),
230 _ => None,
231 }
232 }
233}