has variable of the non-allowed type: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Is PlayerIO have an analog for this class or I should convert to any other type?
by fair_wind_ » December 27th, 2017, 10:51 am
has variable of the non-allowed type: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
by Henrik » January 1st, 2018, 8:41 pm
by pasEnixan » March 26th, 2019, 12:57 pm
Henrik wrote:For what purpose do you want to serialize a dictionary? BigDB or Multiplayer Messages?
by jasonredhawk » March 22nd, 2020, 4:15 pm
by Henrik » March 23rd, 2020, 11:38 pm
by jasonredhawk » March 24th, 2020, 2:16 pm
{
mapName: "MapName",
size: 128,
elevation: [
0:[
0: 407,
1: 548,
2: etc etc
]
1:[
0: 407,
1: 548,
2: etc etc
]
2:[
0: 407,
1: 548,
2: etc etc
]
],
fuelCode: [
0:[
0: 99,
1: 98,
2: etc etc
]
1:[
0: 99,
1: 98,
2: etc etc
]
2:[
0: 99,
1: 98,
2: etc etc
]
],
}
by Henrik » March 27th, 2020, 6:18 am
byte[] result;
using (var ms = new MemoryStream(128*3*2)) { //128 items, three shorts in each, each short is 2 bytes.
using (var bw = new BinaryWriter(ms)) {
foreach (var el in elevations) {
bw.Write(el[0]);
bw.Write(el[1]);
bw.Write(el[2]);
}
}
result = ms.ToArray();
}
var result = new short[128][]; //128 items
using (var br = new BinaryReader(new MemoryStream(input))) {
for (int i = 0; i < 128; i++) {
result[i] = new short[3]; //3 shorts in each
for (int j = 0; j < 3; j++) {
result[i][j] = br.ReadInt16(); //Read each short
}
}
}
by jasonredhawk » March 28th, 2020, 8:39 pm
[Serializable]
public class MapSection{
public short[,] elevation;
public short[,] fuelCode;
public short[,] vegetationCode;
}
public static byte[] MapSectionToByteArray(MapSection mapSection)
{
byte[] result;
using (var ms = new MemoryStream(128*128*3*2)) {
using (var bw = new BinaryWriter(ms)) {
for (var i = 0; i < 128; i++) {
for (var j = 0; j < 128; j++) {
bw.Write(mapSection.elevation[i,j]);
bw.Write(mapSection.fuelCode[i,j]);
bw.Write(mapSection.vegetationCode[i,j]);
}
}
}
result = ms.ToArray();
}
return result;
}
public static MapSection ByteArrayToMapSection(byte[] arrBytes)
{
MapSection mapSection = new MapSection();
mapSection.elevation = new short[128,128];
mapSection.fuelCode = new short[128,128];
mapSection.vegetationCode = new short[128,128];
using (var br = new BinaryReader(new MemoryStream(arrBytes))) {
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 128; j++) {
mapSection.elevation[i,j] = br.ReadInt16(); //Read each short
mapSection.fuelCode[i,j] = br.ReadInt16(); //Read each short
mapSection.vegetationCode[i,j] = br.ReadInt16(); //Read each short
}
}
}
return mapSection;
}