Revert var2bytes im python

Godot Version



Revert var2bytes using python

I need to migrate a Godot server to python, but I’m not finding a way to reverse the var2bytes variable process, the decompression issue is working, but pickle is unable to reconstruct the data made by var2bytes. If only I could find another way to store the data without having to use var2bytes, however the compress call only works on PoolbyteArray, which is the result of bytes2var… I need some light, because I can’t find anything on the internet about this, and these AIs understand almost nothing about gdscript…

Var2bytes isn’t a compression it’s just an encoding.

A poolbytearray can compress, but is just raw bytes at first.

It will be pretty hard to decode those in python unless you make custom decoders for each Godot type you want to pass.

For some types like integers python has the int.from_bytes() function. But that list will help you take the bytes and map to meaningful python types.

I just wanted to reverse this process…

func _ready():
	var teste:Dictionary = {"0":0,"1":1,"2":2}
	var t0:PoolByteArray = var2bytes(teste)
	var t1:PoolByteArray = t0.compress(2)

It’s the most economical way I found in Godot to store things…
The issue is that most of the time I store dictionary, but in some cases they are textures…