A pure-GML implementation of the MessagePack protocol. Is able to encode or decode ds_map and ds_list into/from msgpack structures stored in buffers.
MessagePack is a light-weight binary serialization format with wide language support, often described as "like JSON, but more binary". See https://msgpack.org for more details.
This set of scripts uses pure GML to do the conversion, making it safer for cross-platform use as it does not depend on external DLLs. However, the consequence of this, and due to some of the limitations of GML's datastructures, it is slower than the native json_encode/decode.
The function msgpack_encode() takes a buffer and a ds_map. It encodes the map as binary data inside the buffer. The buffer can then be transmitted or saved to file.
var buffer = buffer_create(100, buffer_grow, 1); msgpack_encode(buffer, map); buffer_resize(buffer, buffer_tell(buffer)); // resize to exactly the right size buffer_save(buffer, "save.bin");
The function msgpack_decode() takes a buffer and returns a ds_map or ds_list depending on what is contained within the messagepack.
var map= msgpack_decode(buffer);