Home

Awesome

RawPacker

Simple binary packing/unpacking for RawArray in Godot.

About

RawPacker allows Variant arrays to be packed into and unpacked from a RawArray using a format string. The approach was inspired by Python's struct.pack and struct.unpack functions. Packing/unpacking RawArray is useful for sending and storing data in a compact form.

Installation

Simply drop the rawpacker directory in your godot/modules directory and build for the platfom of your choice.

Example

var raw_packer = RawPacker.new()
var raw_array = raw_packer.pack("?iis16fhv", [false,1,2,"fixed string",3.14,-42,"variable string"])
var array = raw_packer.unpack("?iis16fhv", raw_array)
print(array)

Output:

False, 1, 2, fixed string, 3.14, -42, variable string

Format Strings

FormatSerialized TypeGodot TypeSize (bytes)
ccharinteger1
bunsigned charinteger1
?unsigned charboolean1
hshortinteger2
Hunsigned shortinteger2
iintinteger4
Iunsigned intinteger4
qlong longinteger8
Qunsigned long longinteger8
ffloatreal4
ddoublereal8
s#char[]string#
vchar[]stringvariable

License

Copyright (c) 2015 James McLean
Licensed under the MIT license.