1 个不稳定版本

0.1.0 2023年12月9日

#1505 in 游戏开发

每月 23 下载
用于 4 crates

MIT/Apache

50KB
945

minecrevy_io

一个用于读取和写入Minecraft协议类型的库。

不带 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:

一个类似 serde 风格的库,用于编码/解码Minecraft数据包和数据类型。

示例

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,
}

重新导出重要的特性和函数。

依赖

~3–4.5MB
~112K SLoC