Alright guys I figured it out. For those who are curious, the packet specification is as follows:
- Offset: 0 - 4 = Packet length. The math is 4+4+len(data).
- Offset: 4 - 8 = Packet type. 4 tells GoDot this is string data.
- Offset: 8 - 12 = Data length. Length of python json (dictionary) data.
- Offset: 12 - Data Length = Actual data.
So if you've used buffers before and understand how they work, basically in the first four bytes you specify the entire packet length AFTER the first four bytes.
Then in the next four bytes you specify the packet type (4 = string). I'm sure their are other types but i didn't really look into them since I'm just using the string type to send and parse json data (via get_json(), parse_json() function calls in GoDot) between the client and server.
Then in the next four bytes you specify the actual data length, so if you're sending json from a (python) server like me you'll enter the length of the data here, i.e.: len(str(dictionary)) [python code].
Finally, in the next four bytes you'll store the actual data you are sending, in my case, this is where I placed the json data.
An example of my python server code implementation to send data to my GoDot client is as follows:
import struct
PACKET_STRING_TYPE = 4
dictionary = {"event": "someeventname", "value": "somevalue"}
dictionary = str(dictionary) # convert it into a 'json' string.
dictionary = dictionary.replace("'", '"') # required for GoDot parse_json() function
data_to_send = struct.pack("III", (4+4+len(dictionary)), PACKET_STRING_TYPE, len(dictionary)) + str(dictionary)
send_to_client(data_to_send)