public void SerializeInto(BinaryWriter writer) { writer.Write(new char[] { 'F', 'S', 'O', 'v' }); Context.SerializeInto(writer); writer.Write(Entities.Length); foreach (var ent in Entities) { byte type = (byte)((ent is VMAvatarMarshal) ? 1 : 0); writer.Write(type); ent.SerializeInto(writer); } writer.Write(Threads.Length); foreach (var thr in Threads) { thr.SerializeInto(writer); } writer.Write(MultitileGroups.Length); foreach (var grp in MultitileGroups) { grp.SerializeInto(writer); } writer.Write(GlobalState.Length); foreach (var val in GlobalState) { writer.Write(val); } writer.Write(ObjectId); }
public void SerializeInto(BinaryWriter writer) { writer.Write(new char[] { 'F', 'S', 'O', 'v' }); writer.Write(Version); writer.Write(Compressed); var uWriter = writer; MemoryStream cStream = null; if (Compressed) { cStream = new MemoryStream(); writer = new BinaryWriter(cStream); } var timer = new System.Diagnostics.Stopwatch(); timer.Start(); Context.SerializeInto(writer); //Console.WriteLine("== SERIAL: Context done... " + timer.ElapsedMilliseconds + " ms =="); writer.Write(Entities.Length); foreach (var ent in Entities) { byte type = (byte)((ent is VMAvatarMarshal) ? 1 : 0); writer.Write(type); ent.SerializeInto(writer); } //Console.WriteLine("== SERIAL: Ents done... " + timer.ElapsedMilliseconds + " ms =="); writer.Write(Threads.Length); foreach (var thr in Threads) { thr.SerializeInto(writer); } //Console.WriteLine("== SERIAL: Threads done... " + timer.ElapsedMilliseconds + " ms =="); writer.Write(MultitileGroups.Length); foreach (var grp in MultitileGroups) { grp.SerializeInto(writer); } //Console.WriteLine("== SERIAL: Groups done... " + timer.ElapsedMilliseconds + " ms =="); writer.Write(GlobalState.Length); foreach (var val in GlobalState) { writer.Write(val); } PlatformState.SerializeInto(writer); //Console.WriteLine("== SERIAL: Globals done... " + timer.ElapsedMilliseconds + " ms =="); writer.Write(ObjectId); if (Compressed) { writer.Close(); //zipStream.Close(); var data = cStream.ToArray(); var zipMStream = new MemoryStream(); var zipStream = new GZipStream(zipMStream, CompressionMode.Compress); zipStream.Write(data, 0, data.Length); zipStream.Close(); var cData = zipMStream.ToArray(); uWriter.Write(cData.Length); uWriter.Write(cData); cStream.Close(); zipMStream.Close(); } }