Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Implementation of the Messagepack specification for Godot 4 written in pure GDSCript.
Godot 4 MessagePack implementation
MessagePack is a binary serialization format. Similar to JSON but lighter and faster. You can read the specification here.
messagepack.gd contains an implementation of the spec written in pure GDScript for Godot 4.
Installation
Copy the messagepack.gd file into your project to start using it with the Messagepack class.
Usage
The Messagepack class contains two main static methods for serialization: encode and decode:
encode(variant: Variant) -> Dictionary
Converts a Godot Variant into MessagePack binary format.
Returns:
A dictionary with:
status (bool):trueif successful,falseon errorvalue (PackedByteArray): Encoded binary data
decode(data: PackedByteArray) -> Dictionary
Converts MessagePack binary data back into Godot Variants.
Returns:
A dictionary with:
status (bool):trueif successful,falseon errorvalue (Variant): Decoded data
Example
Both methods are static so you can simply call them with Messagepack.encode() and Messagepack.decode().
# Encoding
var to_encode = {
"hp": 200,
"speed": 8.5,
"is_invincible": false,
"actions": ["jump","dash","attack"]
}
var encoded = Messagepack.encode(to_encode)
if encoded.status != null: # Check for status to verify encoding issues
printerr(encoded.status)
else:
print(encoded.value)
# Decoding
var to_decode = encoded.value
var decoded = Messagepack.decode(to_decode)
if decoded.status != null: # Check for status to verify decoding issues
printerr(decoded.status)
else:
print(decoded.value)
Acknowledgements & Attribution
This implementation is based on the work by xtpor.
The project is distributed under the MIT license.
Implementation of the Messagepack specification for Godot 4 written in pure GDSCript.
Reviews
Quick Information
Implementation of the Messagepack specification for Godot 4 written in pure GDSCript.