ghast_protocol/generated/v1_8/login/
serverbound.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 LOGIN_START: i32 = 0x00;
32 pub const ENCRYPTION_BEGIN: i32 = 0x01;
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub struct LoginStart {
39 pub username: ByteString,
41}
42impl crate::packet::Packet for LoginStart {
43 const ID: i32 = id::LOGIN_START;
44 const NAME: &'static str = "login_start";
45 const STATE: State = State::Login;
46 const DIRECTION: Direction = Direction::Serverbound;
47}
48impl Decode for LoginStart {
49 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
50 Ok({
51 let v31 = r.read_string()?;
52 LoginStart { username: v31 }
53 })
54 }
55}
56impl Encode for LoginStart {
57 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
58 w.put_string(&(*self).username)?;
59 Ok(())
60 }
61}
62#[cfg(feature = "testgen")]
63impl Generate for LoginStart {
64 fn generate(g: &mut Gen) -> Self {
65 {
66 let v32 = g.string();
67 LoginStart { username: v32 }
68 }
69 }
70}
71impl From<LoginStart> for ServerboundLoginPacket {
72 fn from(p: LoginStart) -> Self {
73 Self::LoginStart(p)
74 }
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub struct EncryptionBegin {
80 pub shared_secret: Bytes,
82 pub verify_token: Bytes,
84}
85impl crate::packet::Packet for EncryptionBegin {
86 const ID: i32 = id::ENCRYPTION_BEGIN;
87 const NAME: &'static str = "encryption_begin";
88 const STATE: State = State::Login;
89 const DIRECTION: Direction = Direction::Serverbound;
90}
91impl Decode for EncryptionBegin {
92 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
93 Ok({
94 let v33 = r.read_byte_array()?;
95 let v34 = r.read_byte_array()?;
96 EncryptionBegin {
97 shared_secret: v33,
98 verify_token: v34,
99 }
100 })
101 }
102}
103impl Encode for EncryptionBegin {
104 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
105 w.put_byte_array(&(*self).shared_secret)?;
106 w.put_byte_array(&(*self).verify_token)?;
107 Ok(())
108 }
109}
110#[cfg(feature = "testgen")]
111impl Generate for EncryptionBegin {
112 fn generate(g: &mut Gen) -> Self {
113 {
114 let v35 = g.bytes();
115 let v36 = g.bytes();
116 EncryptionBegin {
117 shared_secret: v35,
118 verify_token: v36,
119 }
120 }
121 }
122}
123impl From<EncryptionBegin> for ServerboundLoginPacket {
124 fn from(p: EncryptionBegin) -> Self {
125 Self::EncryptionBegin(p)
126 }
127}
128
129#[derive(Debug, Clone, PartialEq)]
131pub enum ServerboundLoginPacket {
132 LoginStart(LoginStart),
134 EncryptionBegin(EncryptionBegin),
136}
137
138impl PacketSet for ServerboundLoginPacket {
139 const STATE: State = State::Login;
140 const DIRECTION: Direction = Direction::Serverbound;
141 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
142 match raw.id {
143 id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
144 id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
145 other => Err(DecodeError::UnknownPacketId(other)),
146 }
147 }
148 fn id(&self) -> i32 {
149 match *self {
150 Self::LoginStart(_) => id::LOGIN_START,
151 Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
152 }
153 }
154 fn name(&self) -> &'static str {
155 match *self {
156 Self::LoginStart(_) => "login_start",
157 Self::EncryptionBegin(_) => "encryption_begin",
158 }
159 }
160 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
161 match *self {
162 Self::LoginStart(ref p) => p.encode(w),
163 Self::EncryptionBegin(ref p) => p.encode(w),
164 }
165 }
166 fn name_of(id: i32) -> Option<&'static str> {
167 match id {
168 id::LOGIN_START => Some("login_start"),
169 id::ENCRYPTION_BEGIN => Some("encryption_begin"),
170 _ => None,
171 }
172 }
173}
174
175impl ServerboundLoginPacket {
176 pub const IDS: &'static [i32] = &[id::LOGIN_START, id::ENCRYPTION_BEGIN];
178 #[cfg(feature = "testgen")]
180 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
181 match id {
182 id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
183 id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
184 <EncryptionBegin as Generate>::generate(g),
185 )),
186 _ => None,
187 }
188 }
189}