https://github.com/spockbotmc/mcd2c
Generate C serialization/deserialization code from the minecraft-data protodef protocol spec
https://github.com/spockbotmc/mcd2c
c minecraft minecraft-data protodef spockbot
Last synced: about 1 year ago
JSON representation
Generate C serialization/deserialization code from the minecraft-data protodef protocol spec
- Host: GitHub
- URL: https://github.com/spockbotmc/mcd2c
- Owner: SpockBotMC
- License: zlib
- Created: 2019-12-01T22:21:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-22T12:39:51.000Z (almost 6 years ago)
- Last Synced: 2025-03-25T16:08:12.616Z (about 1 year ago)
- Topics: c, minecraft, minecraft-data, protodef, spockbot
- Language: C
- Size: 1.63 MB
- Stars: 8
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: License
Awesome Lists containing this project
README
# mcd2c
Generate C serialization/deserialization code from the minecraft-data protodef protocol spec
Requires [python-minecraft-data](https://github.com/SpockBotMC/python-minecraft-data)
## Usage
`python mcd2c.py [version]`
Will generate two files: `[version]_proto.c` and `[version]_proto.h`
The header file is pretty self explanatory, each packet gets four or five functions:
`int walk_[packet_name](char *source, size_t max_len)`
Validates a packet's layout in a buffer, returns `-1` on invalid or improper layout and the total size of the packet on success. Walk should always be called on a buffer before calling a decode function, because decode doesn't do any bounds checking.
`size_t size_[packet_name]([packet_type] packet)`
Calculates the size of the packet when serialized, so you can know the amount of free space you need in the destination buffer. Size should always be called on a packet before calling an encode function, because encode doesn't do any bounds checking.
`char * enc_[packet_name](char *dest, [packet_type] packet)`
Serializes the packet into the destination buffer, returns a pointer to the end of the serialized packet.
`char * dec_[packet_name]([packet_type] *dest, char *source)`
Deserializes the buffer into the destination packet, returns a pointer to the end of the deserialized buffer.
`void free_[packet_name]([packet_type] packet)`
Frees dynamically allocated memory for packets that have dynamic-memory types, not present for packets that don't require dynamic memory allocation.