{"id":22393572,"url":"https://github.com/mubelotix/minecraft-protocol-derive","last_synced_at":"2025-07-31T10:32:10.242Z","repository":{"id":75703358,"uuid":"356231214","full_name":"Mubelotix/minecraft-protocol-derive","owner":"Mubelotix","description":"Procedural macros to make your Rust structs compatible with the Minecraft protocol.","archived":false,"fork":false,"pushed_at":"2023-10-28T13:17:36.000Z","size":36,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2023-10-28T14:34:51.200Z","etag":null,"topics":["derive","deserialization","minecraft","minecraft-protocol","parser","parsing","proc-macro","protocol","rust","serialization"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mubelotix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-09T10:29:33.000Z","updated_at":"2023-10-28T13:17:41.000Z","dependencies_parsed_at":"2023-02-27T00:30:51.698Z","dependency_job_id":null,"html_url":"https://github.com/Mubelotix/minecraft-protocol-derive","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mubelotix%2Fminecraft-protocol-derive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mubelotix%2Fminecraft-protocol-derive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mubelotix%2Fminecraft-protocol-derive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mubelotix%2Fminecraft-protocol-derive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mubelotix","download_url":"https://codeload.github.com/Mubelotix/minecraft-protocol-derive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228236627,"owners_count":17889562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["derive","deserialization","minecraft","minecraft-protocol","parser","parsing","proc-macro","protocol","rust","serialization"],"created_at":"2024-12-05T05:06:19.130Z","updated_at":"2024-12-05T05:06:28.266Z","avatar_url":"https://github.com/Mubelotix.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minecraft-protocol-derive\n\nProcedural macros to make your structs compatible with the Minecraft protocol. \n\nThis crate aims to make the development of Minecraft protocol libraries easier.  \nThere is already [a complete Minecraft protocol implementation](https://github.com/Mubelotix/minecraft-protocol) using this crate, but you could also [make your own](https://wiki.vg/Main_Page).\n\n## Usage\n\nThis crate requires you to declare a `MinecraftPacketPart` trait (see [tests](https://github.com/Mubelotix/minecraft-protocol-derive/tree/main/tests) for examples).  \nThe name of the derive macros is the same and can be used to implement the trait automatically.  \nIt can still be implemented manually for complex types.\n\n```rust\n#[derive(MinecraftPacketPart)]\nstruct Entity {\n    entity_id: VarInt,\n    x: f64,\n    y: f64,\n    z: f64,\n}\n```\n\nYou can also nest your different structures.\n\n```rust\n#[derive(MinecraftPacketPart)]\nstruct Entity {\n    entity_id: VarInt,\n    position: Position,\n}\n\n#[derive(MinecraftPacketPart)]\nstruct Position {\n    x: f64,\n    y: f64,\n    z: f64,\n}\n```\n\nNote that you need to implement the `MinecraftPacketPart` trait for all the primitive types.\nThe `VarInt` type is a common signed integer type.\nSee [the wiki](https://wiki.vg/Protocol#VarInt_and_VarLong) for help with the implementation.\n\n## Enums\n\nEnums are supported as long as you use named fields.\n\n```rust\n#[derive(MinecraftPacketPart)]\nenum Packet {\n    Login {\n        username: String,\n    },\n    MoveTo {\n        x: f64,\n        y: f64,\n        z: f64,\n    }\n    Ping,\n}\n```\n\nFor enums exclusively composed of unit variants, using `#[minecraft_enum]` is recommended since its implementation is more lightweight and optimized.\n\nSince numeric IDs represent enums in the protocol, each variant has an associated value (its corresponding ID).\nIt can be specified explicitly or inferred.\nA variant with no specified ID will take the ID of the previous variant, incremented by 1.\nThe first variant matches 0 if no ID is specified.\n\nYou can specify the type of the numeric ID in the macro parameters.\nIf missing, `VarInt` will be used.\n\n```rust\n#[minecraft_enum(u8)]\nenum EntityType {\n    Player,     // = 0 (inferred)\n    Villager,\n    Animal = 3, // Specify the corresponding ID like this.\n    Monster,    // = 4 (inferred, 3+1)\n    Minecart,\n}\n```\n\nIt is also possible to set the type and value of the numeric IDs with the derive syntax.\n\nThe same inference rules are applied.\n\n\n```rust\n#[derive(MinecraftPacketPart)]\n#[discriminant(u8)] // define the type of the numeric ID of the variants\nenum Packet {\n    Login {\n        username: String,\n    },\n    #[value = 5] // define the ID corresponding to the MoveTo variant\n    MoveTo {\n        x: f64,\n        y: f64,\n        z: f64,\n    }\n    Ping,\n}\n```\n\n## Lifetimes\n\nLifetimes are supported everywhere.\nThe only limitation is that you cannot have more than one lifetime.\n\nIt is easy to implement zero-copy deserialization by using references.\n\n```rust\n#[derive(MinecraftPacketPart)]\nstruct Player\u003c'a\u003e {\n    username: \u0026'a str,\n    data: \u0026'a [u8],\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmubelotix%2Fminecraft-protocol-derive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmubelotix%2Fminecraft-protocol-derive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmubelotix%2Fminecraft-protocol-derive/lists"}