- Code: Select all
myVar1 = stateDataByteArray.readShort()
myVar2 = stateDataByteArray.readDouble();
myVar3 = stateDataByteArray.readInt();
However in C# it seems a bit more complicated, I've found 2 ways to extract the data:
- Code: Select all
myVar1 = BitConverter.ToInt32(stateDataByteArray, position);
myVar2 = BitConverter.ToInt32(stateDataByteArray, position +2);
- this one seems especially tedious, having to keep track of the position, and iterate it with irregular intervals(ie Bytes are position +1 but Integers are +4 shorts +2 etc ), which for complex data structures where there are more than one data type seems especially bothersome?
And this one, which has a more similar feel to Flash:
- Code: Select all
using (MemoryStream stream = new MemoryStream(stateDataByteArray)) {
using (BinaryReader reader = new BinaryReader(stream)) {
Console.WriteLine("myDouble: " + reader.ReadByte());
Console.WriteLine("myDouble: " + reader.ReadByte());
}}
any other suggestions or ideas? Whats your preferred way?