xtpor / godot-msgpack

A MessagePack serializer implemented in pure GDScript / msgpack.org[GDScript]
35 stars 6 forks source link
gdscript godot3 msgpack

godot-msgpack

A MessagePack serializer implemented in pure GDScript

Installation

Copy the msgpack.gd at the root of the repository into your godot project

Usage

var Msgpack = preload("res://msgpack.gd")

func _myfunc():
    var data = {"type": "wizard", "attack": 10, "weapon": ["dagger", "staff"]}

    var res = Msgpack.encode(data)
    print(res.result) # A PoolByteArray of the data encoded MessagePack

    var res2 = Msgpack.decode(res.result)
    print(res2.result) # Get back the original data

class Msgpack

static Dictionary encode(Variant value)

Convert a value (number, string, array and dictionary) into their counterparts in messagepack. Returns dictionary with three fields: result which is the packed data (a PoolByteArray); error which is the error code; and error_string which is a human readable error message

static Dictionary decode(PoolByteArray bytes)

Convert a packed data (a PoolByteArray) back into a value, the reverse of the encode function. The return value is similar to the one in the encode method

Limitation

Testcases

godot -s run_test.gd