ghast_protocol/generated/v1_12_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}
39
40pub type Disconnect = crate::defs::p47::login::clientbound::Disconnect<340>;
42impl crate::packet::Packet for Disconnect {
43 const ID: i32 = id::DISCONNECT;
44 const NAME: &'static str = "disconnect";
45 const STATE: State = State::Login;
46 const DIRECTION: Direction = Direction::Clientbound;
47}
48impl From<Disconnect> for ClientboundLoginPacket {
49 fn from(p: Disconnect) -> Self {
50 Self::Disconnect(p)
51 }
52}
53
54pub type EncryptionBegin = crate::defs::p47::login::clientbound::EncryptionBegin<340>;
56impl crate::packet::Packet for EncryptionBegin {
57 const ID: i32 = id::ENCRYPTION_BEGIN;
58 const NAME: &'static str = "encryption_begin";
59 const STATE: State = State::Login;
60 const DIRECTION: Direction = Direction::Clientbound;
61}
62impl From<EncryptionBegin> for ClientboundLoginPacket {
63 fn from(p: EncryptionBegin) -> Self {
64 Self::EncryptionBegin(p)
65 }
66}
67
68pub type Success = crate::defs::p47::login::clientbound::Success<340>;
70impl crate::packet::Packet for Success {
71 const ID: i32 = id::SUCCESS;
72 const NAME: &'static str = "success";
73 const STATE: State = State::Login;
74 const DIRECTION: Direction = Direction::Clientbound;
75}
76impl From<Success> for ClientboundLoginPacket {
77 fn from(p: Success) -> Self {
78 Self::Success(p)
79 }
80}
81
82pub type Compress = crate::defs::p47::login::clientbound::Compress<340>;
84impl crate::packet::Packet for Compress {
85 const ID: i32 = id::COMPRESS;
86 const NAME: &'static str = "compress";
87 const STATE: State = State::Login;
88 const DIRECTION: Direction = Direction::Clientbound;
89}
90impl From<Compress> for ClientboundLoginPacket {
91 fn from(p: Compress) -> Self {
92 Self::Compress(p)
93 }
94}
95
96#[derive(Debug, Clone, PartialEq)]
98pub enum ClientboundLoginPacket {
99 Disconnect(Disconnect),
101 EncryptionBegin(EncryptionBegin),
103 Success(Success),
105 Compress(Compress),
107}
108
109impl PacketSet for ClientboundLoginPacket {
110 const STATE: State = State::Login;
111 const DIRECTION: Direction = Direction::Clientbound;
112 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
113 match raw.id {
114 id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
115 id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
116 id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
117 id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
118 other => Err(DecodeError::UnknownPacketId(other)),
119 }
120 }
121 fn id(&self) -> i32 {
122 match *self {
123 Self::Disconnect(_) => id::DISCONNECT,
124 Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
125 Self::Success(_) => id::SUCCESS,
126 Self::Compress(_) => id::COMPRESS,
127 }
128 }
129 fn name(&self) -> &'static str {
130 match *self {
131 Self::Disconnect(_) => "disconnect",
132 Self::EncryptionBegin(_) => "encryption_begin",
133 Self::Success(_) => "success",
134 Self::Compress(_) => "compress",
135 }
136 }
137 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
138 match *self {
139 Self::Disconnect(ref p) => p.encode(w),
140 Self::EncryptionBegin(ref p) => p.encode(w),
141 Self::Success(ref p) => p.encode(w),
142 Self::Compress(ref p) => p.encode(w),
143 }
144 }
145 fn name_of(id: i32) -> Option<&'static str> {
146 match id {
147 id::DISCONNECT => Some("disconnect"),
148 id::ENCRYPTION_BEGIN => Some("encryption_begin"),
149 id::SUCCESS => Some("success"),
150 id::COMPRESS => Some("compress"),
151 _ => None,
152 }
153 }
154}
155
156impl ClientboundLoginPacket {
157 pub const IDS: &'static [i32] = &[
159 id::DISCONNECT,
160 id::ENCRYPTION_BEGIN,
161 id::SUCCESS,
162 id::COMPRESS,
163 ];
164 #[cfg(feature = "testgen")]
166 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
167 match id {
168 id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
169 id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
170 <EncryptionBegin as Generate>::generate(g),
171 )),
172 id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
173 id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
174 _ => None,
175 }
176 }
177}