Skip to main content

ghast_protocol/generated/v1_8/login/
clientbound.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 the NOTICE file
4// in crates/ghast-protocol/src/generated/.
5
6//! Clientbound packets of the login state.
7
8#![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
28/// Packet ids.
29pub mod id {
30    /// `disconnect`
31    pub const DISCONNECT: i32 = 0x00;
32    /// `encryption_begin`
33    pub const ENCRYPTION_BEGIN: i32 = 0x01;
34    /// `success`
35    pub const SUCCESS: i32 = 0x02;
36    /// `compress`
37    pub const COMPRESS: i32 = 0x03;
38}
39
40/// `disconnect` (clientbound login, id 0x00).
41pub type Disconnect = crate::defs::p47::login::clientbound::Disconnect<47>;
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
54/// `encryption_begin` (clientbound login, id 0x01).
55pub type EncryptionBegin = crate::defs::p47::login::clientbound::EncryptionBegin<47>;
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
68/// `success` (clientbound login, id 0x02).
69pub type Success = crate::defs::p47::login::clientbound::Success<47>;
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
82/// `compress` (clientbound login, id 0x03).
83pub type Compress = crate::defs::p47::login::clientbound::Compress<47>;
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/// Every Clientbound packet of the Login state.
97#[derive(Debug, Clone, PartialEq)]
98pub enum ClientboundLoginPacket {
99    /// `disconnect`
100    Disconnect(Disconnect),
101    /// `encryption_begin`
102    EncryptionBegin(EncryptionBegin),
103    /// `success`
104    Success(Success),
105    /// `compress`
106    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    /// All packet ids of this set, ascending.
158    pub const IDS: &'static [i32] = &[
159        id::DISCONNECT,
160        id::ENCRYPTION_BEGIN,
161        id::SUCCESS,
162        id::COMPRESS,
163    ];
164    /// Generates a random packet with the given id (test support).
165    #[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}