ghast-protocol 0.4.1

Minecraft Java Edition network protocol for the ghast client library: generated per-version packets, framing, compression, encryption, NBT
Documentation
// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/1.8/protocol.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
// in crates/ghast-protocol/src/generated/.

//! Serverbound packets of the login state.

#![allow(
    unused_imports,
    unused_variables,
    unused_mut,
    unused_parens,
    unused_braces,
    clippy::all,
    clippy::pedantic,
    non_camel_case_types,
    non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::{AnonNbt, RawNbt};
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
use bytes::{BufMut, Bytes, BytesMut};

#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `login_start` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct LoginStart<const V: i32> {
    /// `username`
    pub username: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for LoginStart<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            Self { username: v1 }
        })
    }
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for LoginStart<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).username)?;
        Ok(())
    }
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for LoginStart<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            Self { username: v1 }
        }
    }
}

#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1"
))]
/// `encryption_begin` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct EncryptionBegin<const V: i32> {
    /// `sharedSecret`
    pub shared_secret: Bytes,
    /// `verifyToken`
    pub verify_token: Bytes,
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1"
))]
impl<const V: i32> Decode for EncryptionBegin<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_byte_array()?;
            let v2 = r.read_byte_array()?;
            Self {
                shared_secret: v1,
                verify_token: v2,
            }
        })
    }
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1"
))]
impl<const V: i32> Encode for EncryptionBegin<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_byte_array(&(*self).shared_secret)?;
        w.put_byte_array(&(*self).verify_token)?;
        Ok(())
    }
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EncryptionBegin<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.bytes();
            let v2 = g.bytes();
            Self {
                shared_secret: v1,
                verify_token: v2,
            }
        }
    }
}