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/.

//! Clientbound 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"))]
/// `encryption_begin` (clientbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct EncryptionBegin<const V: i32> {
    /// `serverId`
    pub server_id: ByteString,
    /// `publicKey`
    pub public_key: Bytes,
    /// `verifyToken`
    pub verify_token: Bytes,
    /// `shouldAuthenticate`
    pub should_authenticate: bool,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for EncryptionBegin<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = r.read_byte_array()?;
            let v3 = r.read_byte_array()?;
            let v4 = r.read_bool()?;
            Self {
                server_id: v1,
                public_key: v2,
                verify_token: v3,
                should_authenticate: v4,
            }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for EncryptionBegin<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).server_id)?;
        w.put_byte_array(&(*self).public_key)?;
        w.put_byte_array(&(*self).verify_token)?;
        w.put_bool((*self).should_authenticate);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EncryptionBegin<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = g.bytes();
            let v3 = g.bytes();
            let v4 = g.bool();
            Self {
                server_id: v1,
                public_key: v2,
                verify_token: v3,
                should_authenticate: v4,
            }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct SuccessProperties {
    /// `name`
    pub name: ByteString,
    /// `value`
    pub value: ByteString,
    /// `signature`
    pub signature: Option<ByteString>,
}

#[cfg(feature = "v26_1")]
/// `success` (clientbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct Success<const V: i32> {
    /// `uuid`
    pub uuid: Uuid,
    /// `username`
    pub username: ByteString,
    /// `properties`
    pub properties: Vec<crate::defs::p775::login::clientbound::SuccessProperties>,
}
#[cfg(feature = "v26_1")]
impl<const V: i32> Decode for Success<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_uuid()?;
            let v2 = r.read_string()?;
            let v3 = {
                let v4 = {
                    let c = r.read_varint()?;
                    r.check_count(i64::from(c), 3)?
                };
                let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v4 {
                    v5.push({
                        let v6 = r.read_string()?;
                        let v7 = r.read_string()?;
                        let v8 = if r.read_bool()? {
                            Some(r.read_string()?)
                        } else {
                            None
                        };
                        crate::defs::p775::login::clientbound::SuccessProperties {
                            name: v6,
                            value: v7,
                            signature: v8,
                        }
                    });
                }
                v5
            };
            Self {
                uuid: v1,
                username: v2,
                properties: v3,
            }
        })
    }
}
#[cfg(feature = "v26_1")]
impl<const V: i32> Encode for Success<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_uuid(&(*self).uuid);
        w.put_string(&(*self).username)?;
        w.put_len_varint((*self).properties.len())?;
        for v1 in (*self).properties.iter() {
            w.put_string(&(*v1).name)?;
            w.put_string(&(*v1).value)?;
            match &(*v1).signature {
                Some(v2) => {
                    w.put_u8(1);
                    w.put_string(&(*v2))?;
                }
                None => w.put_u8(0),
            }
        }
        Ok(())
    }
}
#[cfg(feature = "v26_1")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Success<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.uuid();
            let v2 = g.string();
            let v3 = {
                let v4 = g.count();
                let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v4 {
                    v5.push({
                        let v6 = g.string();
                        let v7 = g.string();
                        let v8 = if g.bool() { Some(g.string()) } else { None };
                        crate::defs::p775::login::clientbound::SuccessProperties {
                            name: v6,
                            value: v7,
                            signature: v8,
                        }
                    });
                }
                v5
            };
            Self {
                uuid: v1,
                username: v2,
                properties: v3,
            }
        }
    }
}

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