#minecraft #minecraft-server #packets #protocols #bevy #packet

minecrevy_io

A library for reading and writing Minecraft protocol types

1 unstable release

0.1.0 Dec 9, 2023

#2004 in Encoding

21 downloads per month
Used in 4 crates

MIT/Apache

50KB
945 lines

minecrevy_io

A library for reading and writing Minecraft protocol types.

Example without derive

use std::io;
use minecrevy_io::{
    args::{IntArgs, StringArgs},
    McRead,
};

#[derive(Clone, PartialEq, Debug)]
pub struct Handshake {
    pub protocol_version: i32,
    pub server_address: String,
    pub server_port: u16,
    pub next_state: i32,
}

impl McRead for Handshake {
    type Args = ();

    fn read(mut reader: impl io::Read, (): Self::Args) -> io::Result<Self> {
        Ok(Self {
            protocol_version: i32::read(&mut reader, IntArgs { varint: true })?,
            server_address: String::read(&mut reader, StringArgs { max_len: Some(255) })?,
            server_port: u16::read(&mut reader, ())?,
            next_state: i32::read(&mut reader, IntArgs { varint: true })?,
        })
    }
}

lib.rs:

A library for encoding/decoding Minecraft packets and data types in the style of serde.

Example

use minecrevy_io::{McRead, McWrite};

#[derive(McRead, McWrite)]
pub struct Handshake {
    #[args(varint = true)]
    pub version: i32,
    #[args(max_len = 255)]
    pub address: String,
    pub port: u16,
    #[args(varint = true)]
    pub next: i32,
}

Re-exports important traits, types, and functions.

Dependencies

~3–4MB
~109K SLoC