2

I'm using Unity to make a little network game, and I need to send a list (of structs) over to the other players. Since Unity can't send lists, nor binary data, I though to convert it to a string. It doesn't have to be human-readable. Since I need to send this list over pretty much every frame, I was wondering, how can I convert it to an as small as possible string?

So, I have a List<myStruct> and would like a string, one that's very small. Fast conversion, both from and to the string, is also important.

Note that I'm using c# to script everything.

Thoughts?

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
The Oddler
  • 6,314
  • 7
  • 51
  • 94
  • 3
    Use JSON serialization. Example: http://msdn.microsoft.com/en-us/library/bb412179.aspx – Rui Jarimba Aug 12 '13 at 14:43
  • 5
    This question might be of interest: http://stackoverflow.com/questions/9944994/fast-serialization-deserialization-of-structs – Findus Aug 12 '13 at 14:44

1 Answers1

3

A very compact method of communicating data via strings is Protocol Buffers. This is one of the main mechanisms that Google uses so if it can work on that scale it should be fine for you.

The basic idea is that data is known ahead of time and then sent with the information in a set sequence (index). That way you know that element 1 will be the name, element 2 will be the age and so on.

It just so happens that there is already a .NET implementation called ProtoBuf.NET and well worth checking out.

Of course, you could always borrow the idea and just parse your List<myStruct> into 0:Name|1:Age|2:Something Else etc and process on the other side.

Belogix
  • 8,129
  • 1
  • 27
  • 32