Once again I’m receiving structs via UDP from a C++ programm,
Now I ported the structs to C#, Example:
[Serializable]
struct sample
{
public int in;
public byte[] arr;
public int[] arr2;
public float fl;
}
Ok so how does the Deserializer know when one array ends and the other begins?
Can specify somehow how big the array is?
I don’t want to use fixed, since this makes my code unsafe, and I also can’t use a Constructor since structs are not allowed to contain constructors without parameters.
Any suggestions?
//edit:
the arrays are known to be 32 and 4 long.
the problem is that I don’t know how to pass this information to the deserialiser
then sender is C++ an works like this:
char* pr = &sample;
int i=0;
while (i<sizeof(sample))
{
udp.send(*(pr+i))
i++;
}
Now that you have told us that the lengths are of pre-defined length, then the following statement becomes clearer:
In fact, it becomes moot. There is no pre-defined serializer that is going to help you here. You have two options:
A: write your own serializer, and process the data now that you know the format – perhaps using
BinaryReader:B: buffer 56 bytes, and use really nasty
unsafe/fixed/ pointer-banging codeI strongly suggest the first. In particular, this will also allow you to address endianness if required.
IN THE NAME OF EVERYTHING SACRED TO YOU, DO NOT DO THIS:
For larger buffers, you can treat
ptras an unsafe array of multiplesample, accessed by index:(etc)
But honestly… there are so many things “evil” with that, I honestly don’t know where to begin… just… unless you know absolutely what every line in there is doing, have done it before, and understand all the traps… DON’T EVEN THINK ABOUT IT