Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Godot 4 MessagePack

An asset by luiherch
The page banner background of a mountain and forest
Godot 4 MessagePack hero image

Quick Information

0 ratings
Godot 4 MessagePack icon image
luiherch
Godot 4 MessagePack

Implementation of the Messagepack specification for Godot 4 written in pure GDSCript.

Supported Engine Version
4.0
Version String
0.1
License Version
MIT
Support Level
community
Modified Date
2 months ago
Git URL
Issue URL

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): true if successful, false on error
  • value (PackedByteArray): Encoded binary data

decode(data: PackedByteArray) -> Dictionary

Converts MessagePack binary data back into Godot Variants.

Returns:

A dictionary with:

  • status (bool): true if successful, false on error
  • value (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

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Godot 4 MessagePack icon image
luiherch
Godot 4 MessagePack

Implementation of the Messagepack specification for Godot 4 written in pure GDSCript.

Supported Engine Version
4.0
Version String
0.1
License Version
MIT
Support Level
community
Modified Date
2 months ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers