ghast-protocol 0.4.4

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.16.2/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(feature = "v1_16_5")]
/// `success` (clientbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct Success<const V: i32> {
    /// `uuid`
    pub uuid: Uuid,
    /// `username`
    pub username: ByteString,
}
#[cfg(feature = "v1_16_5")]
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()?;
            Self {
                uuid: v1,
                username: v2,
            }
        })
    }
}
#[cfg(feature = "v1_16_5")]
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)?;
        Ok(())
    }
}
#[cfg(feature = "v1_16_5")]
#[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();
            Self {
                uuid: v1,
                username: v2,
            }
        }
    }
}

#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
/// `login_plugin_request` (clientbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct LoginPluginRequest<const V: i32> {
    /// `messageId`
    pub message_id: i32,
    /// `channel`
    pub channel: ByteString,
    /// `data`
    pub data: Bytes,
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for LoginPluginRequest<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            let v2 = r.read_string()?;
            let v3 = r.read_rest();
            Self {
                message_id: v1,
                channel: v2,
                data: v3,
            }
        })
    }
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for LoginPluginRequest<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).message_id);
        w.put_string(&(*self).channel)?;
        w.put_slice(&(*self).data);
        Ok(())
    }
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for LoginPluginRequest<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v2 = g.string();
            let v3 = g.bytes();
            Self {
                message_id: v1,
                channel: v2,
                data: v3,
            }
        }
    }
}