Skip to main content

ghast_protocol/
lib.rs

1//! Minecraft Java Edition network protocol for the ghast client library.
2//!
3//! Layers, bottom to top:
4//!
5//! - [`codec`]: bounds-checked [`Reader`] over [`bytes::Bytes`] (zero-copy byte arrays
6//!   and strings), [`McWrite`] for encoding, VarInt/VarLong.
7//! - [`types`], [`nbt`], [`chat`]: hand-written shared types — [`BlockPos`] with the
8//!   per-version bit layout, slots, lazily parsed NBT ([`nbt::RawNbt`]), chat JSON.
9//! - Generated packet modules per protocol version ([`v1_8`] = protocol 47,
10//!   [`v1_16_5`] = protocol 754), each with typed packet structs, one enum per state and
11//!   direction, and id constants. A [`Version`] marker type ties a version's packet sets
12//!   together so a version-agnostic layer can be written generically.
13//! - [`frame`]: length framing, zlib compression with partial inflation, the
14//!   AES-128-CFB8 hook ([`crypto`]), and the per-id [`PacketFilter`] that drops unwanted
15//!   packets before they are decoded.
16//! - [`io`] (feature `tokio`): async framed reader/writer.
17//!
18//! Decoding never panics on untrusted input: every failure is a [`DecodeError`] or
19//! [`FrameError`], and allocations are bounded by the input size.
20//!
21//! ```
22//! use ghast_protocol::{FrameDecoder, FrameEncoder, PacketSet, RawPacket};
23//! use ghast_protocol::v1_8::play::serverbound::{KeepAlive, ServerboundPlayPacket};
24//!
25//! let mut enc = FrameEncoder::new();
26//! enc.write_packet(&KeepAlive { keep_alive_id: 42 }).unwrap();
27//! let mut dec = FrameDecoder::new();
28//! dec.push(&enc.take());
29//! let raw: RawPacket = dec.next_packet().unwrap().unwrap();
30//! let p = ServerboundPlayPacket::decode_raw(&raw).unwrap();
31//! assert_eq!(p, ServerboundPlayPacket::KeepAlive(KeepAlive { keep_alive_id: 42 }));
32//! ```
33
34#![forbid(unsafe_code)]
35#![warn(missing_docs, unnameable_types)]
36
37pub mod chat;
38pub mod codec;
39pub mod crypto;
40pub mod error;
41pub mod frame;
42#[cfg(feature = "tokio")]
43pub mod io;
44pub mod nbt;
45pub mod packet;
46#[cfg(feature = "testgen")]
47pub mod testgen;
48pub mod types;
49
50#[cfg(feature = "v1_8")]
51#[path = "generated/v1_8/mod.rs"]
52pub mod v1_8;
53
54#[cfg(feature = "v1_16_5")]
55#[path = "generated/v1_16_5/mod.rs"]
56pub mod v1_16_5;
57
58pub use codec::{Decode, Encode, McWrite, Reader};
59pub use error::{DecodeError, EncodeError, FrameError};
60pub use frame::{FrameDecoder, FrameEncoder, FrameLimits};
61#[cfg(feature = "tokio")]
62pub use io::{FramedReader, FramedWriter};
63pub use packet::{Direction, Packet, PacketFilter, PacketSet, RawPacket, State, Version};
64pub use types::BlockPos;