Sending binary data instead of JSON


I have procedural maps generated when a match starts on nakama. I would like to send this map to my Godot client. The map is a 500x500 tile map. I compress the map using a custom compression algorithm which brings the size down to ~2500 bytes from 250000 bytes. Is there a way to transmit this without json marshalling? When I marshal it (I’m using go lang) the size jumps to ~55000 bytes and really just messes up my data by converting it to strings I believe.

So, my question is, can you transmit raw binary data in Nakama to a Godot client, or is there another way you suggest transmitting this data?

A few options I have thought of:

  • generate a png file where each pixel represents a tile and just transmit the png file.
  • Chunk my map data and only send the map data for the area directly around the player.
  • just use Nakama for authentication, chat and instantiate Godot servers for the actual match play. I just think a Golang server would be so much more efficient than a Godot Server. The big advantage here would be I only need to pass the seed to the client and the map could be reproduced from it.

Any input would be greatly appreciated.

What if you base64 encode the 2500 bytes and then transmit that single string using Nakama’s API:s?

That’s a really good idea. I’ll give it a try.

Thank you.

I had bit similar problem with Nakama, Godot and JSON. I worked around problem in other ways but I came up one way to compress data that might work in Godot side:

JSON:encode(game_state) → use this compression library GitHub - Rochet2/lualzw: A relatively fast LZW compression algorithm in pure lua compress() → broadacast JSON from match → on Godot side String.to_ascii(compressed_json) to get PoolByteArray → PoolByteArray.decompress(size, COMPRESSION_FASTLZ) and PoolByteArray.get_string_from_utf8()JSON.parse(byte_array).

This is totally untested and I’ll have to look into it more if my workaround stops working. I haven’t looked into using Golang as problem is limited support of decompression tools in Godot.

One other way is to split data into multiple pieces and reconstruct it in Godot after all pieces have been broadcasted.

Also keep in mind that at least last time I tested Godot client silently disconnects if server tries to send too big Websocket message. I made issue about it 6 months ago but it hasn’t received any activity Improve error reporting and disconnect detection · Issue #84 · heroiclabs/nakama-godot · GitHub

Thank you for the input. For now I’ve just chunked my map up to keep the transfer sizes down. I will definitely implement compression at some point in the future.
I also noticed that Godot silently disconnects if the Websocket message is too big.