I have created an example code of a byte array, and im creating slices and converting slices to the field types in a struct.
The idea is i receive a TCP message as a byte array, the first index tells me the overall message length, then from that i slice up the byte data to add to my struct.
It works, but if i have thousands of connected TCP clients all sending messages, this obviously needs to be as performant as possible.
Here is the playground code: https://play.golang.org/p/FJ8klMQR2k
I created a buffer and added some data. In this case the message reads as:
 = messageSize
[1…4] = userkey (uint32) //4bytes
[5…8] = userID (uint32) //4bytes
[9:messageSize] = username (string) //the remaining bytes
Can i improve this at all ?