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

//! 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_16_5", feature = "v26_1", feature = "v26_2"))]
/// `login_plugin_response` (serverbound login).
#[derive(Debug, Clone, PartialEq)]
pub struct LoginPluginResponse<const V: i32> {
    /// `messageId`
    pub message_id: i32,
    /// `data`
    pub data: Option<Bytes>,
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for LoginPluginResponse<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            let v2 = if r.read_bool()? {
                Some(r.read_rest())
            } else {
                None
            };
            Self {
                message_id: v1,
                data: v2,
            }
        })
    }
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for LoginPluginResponse<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).message_id);
        match &(*self).data {
            Some(v1) => {
                w.put_u8(1);
                w.put_slice(&(*v1));
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(any(feature = "v1_16_5", feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for LoginPluginResponse<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v2 = if g.bool() { Some(g.bytes()) } else { None };
            Self {
                message_id: v1,
                data: v2,
            }
        }
    }
}