ghast-protocol 0.4.5

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

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

#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `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,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
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()?;
            Self {
                server_id: v1,
                public_key: v2,
                verify_token: v3,
            }
        })
    }
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
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)?;
        Ok(())
    }
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[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();
            Self {
                server_id: v1,
                public_key: v2,
                verify_token: v3,
            }
        }
    }
}

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

#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1",
    feature = "v26_2"
))]
/// `compress` (clientbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct Compress<const V: i32> {
    /// `threshold`
    pub threshold: i32,
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1",
    feature = "v26_2"
))]
impl<const V: i32> Decode for Compress<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            Self { threshold: v1 }
        })
    }
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1",
    feature = "v26_2"
))]
impl<const V: i32> Encode for Compress<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).threshold);
        Ok(())
    }
}
#[cfg(any(
    feature = "v1_8",
    feature = "v1_12_2",
    feature = "v1_16_5",
    feature = "v26_1",
    feature = "v26_2"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Compress<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            Self { threshold: v1 }
        }
    }
}