ghast-protocol 0.4.3

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/26.1/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 = "v26_1", feature = "v26_2"))]
/// `login_start` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct LoginStart<const V: i32> {
    /// `username`
    pub username: ByteString,
    /// `playerUUID`
    pub player_uuid: Uuid,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for LoginStart<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = r.read_uuid()?;
            Self {
                username: v1,
                player_uuid: v2,
            }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for LoginStart<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).username)?;
        w.put_uuid(&(*self).player_uuid);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for LoginStart<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = g.uuid();
            Self {
                username: v1,
                player_uuid: v2,
            }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `login_acknowledged` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct LoginAcknowledged<const V: i32> {}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for LoginAcknowledged<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({ Self {} })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for LoginAcknowledged<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for LoginAcknowledged<V> {
    fn generate(g: &mut Gen) -> Self {
        { Self {} }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `cookie_response` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct CookieResponse<const V: i32> {
    /// `key`
    pub key: ByteString,
    /// `value`
    pub value: Option<Bytes>,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for CookieResponse<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = if r.read_bool()? {
                Some(r.read_byte_array()?)
            } else {
                None
            };
            Self { key: v1, value: v2 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for CookieResponse<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).key)?;
        match &(*self).value {
            Some(v1) => {
                w.put_u8(1);
                w.put_byte_array(&(*v1))?;
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CookieResponse<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = if g.bool() { Some(g.bytes()) } else { None };
            Self { key: v1, value: v2 }
        }
    }
}