Skip to main content

ghast_protocol/generated/v1_8/login/
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 the NOTICE file
4// in crates/ghast-protocol/src/generated/.
5
6//! Serverbound 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    /// `login_start`
31    pub const LOGIN_START: i32 = 0x00;
32    /// `encryption_begin`
33    pub const ENCRYPTION_BEGIN: i32 = 0x01;
34}
35
36/// `login_start` (serverbound login, id 0x00).
37pub type LoginStart = crate::defs::p47::login::serverbound::LoginStart<47>;
38impl crate::packet::Packet for LoginStart {
39    const ID: i32 = id::LOGIN_START;
40    const NAME: &'static str = "login_start";
41    const STATE: State = State::Login;
42    const DIRECTION: Direction = Direction::Serverbound;
43}
44impl From<LoginStart> for ServerboundLoginPacket {
45    fn from(p: LoginStart) -> Self {
46        Self::LoginStart(p)
47    }
48}
49
50/// `encryption_begin` (serverbound login, id 0x01).
51pub type EncryptionBegin = crate::defs::p47::login::serverbound::EncryptionBegin<47>;
52impl crate::packet::Packet for EncryptionBegin {
53    const ID: i32 = id::ENCRYPTION_BEGIN;
54    const NAME: &'static str = "encryption_begin";
55    const STATE: State = State::Login;
56    const DIRECTION: Direction = Direction::Serverbound;
57}
58impl From<EncryptionBegin> for ServerboundLoginPacket {
59    fn from(p: EncryptionBegin) -> Self {
60        Self::EncryptionBegin(p)
61    }
62}
63
64/// Every Serverbound packet of the Login state.
65#[derive(Debug, Clone, PartialEq)]
66pub enum ServerboundLoginPacket {
67    /// `login_start`
68    LoginStart(LoginStart),
69    /// `encryption_begin`
70    EncryptionBegin(EncryptionBegin),
71}
72
73impl PacketSet for ServerboundLoginPacket {
74    const STATE: State = State::Login;
75    const DIRECTION: Direction = Direction::Serverbound;
76    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
77        match raw.id {
78            id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
79            id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
80            other => Err(DecodeError::UnknownPacketId(other)),
81        }
82    }
83    fn id(&self) -> i32 {
84        match *self {
85            Self::LoginStart(_) => id::LOGIN_START,
86            Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
87        }
88    }
89    fn name(&self) -> &'static str {
90        match *self {
91            Self::LoginStart(_) => "login_start",
92            Self::EncryptionBegin(_) => "encryption_begin",
93        }
94    }
95    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
96        match *self {
97            Self::LoginStart(ref p) => p.encode(w),
98            Self::EncryptionBegin(ref p) => p.encode(w),
99        }
100    }
101    fn name_of(id: i32) -> Option<&'static str> {
102        match id {
103            id::LOGIN_START => Some("login_start"),
104            id::ENCRYPTION_BEGIN => Some("encryption_begin"),
105            _ => None,
106        }
107    }
108}
109
110impl ServerboundLoginPacket {
111    /// All packet ids of this set, ascending.
112    pub const IDS: &'static [i32] = &[id::LOGIN_START, id::ENCRYPTION_BEGIN];
113    /// Generates a random packet with the given id (test support).
114    #[cfg(feature = "testgen")]
115    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
116        match id {
117            id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
118            id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
119                <EncryptionBegin as Generate>::generate(g),
120            )),
121            _ => None,
122        }
123    }
124}