internal void DeserializeImp(SimpleDataSerializer s) { try { LogCalled(); for (ushort i = 0; i < SegmentBuffer.Length; ++i) { SegmentBuffer[i].Deserialize(s); } for (int i = 0; i < SegmentEndBuffer.Length; ++i) { SegmentEndBuffer[i].Deserialize(s); } //for (ushort i = 0; i < NodeBuffer.Length; ++i) { // NodeBuffer[i].Serialize(s); //} uint n = s.ReadUInt32(); for (uint i = 0; i < n; ++i) { uint laneID = s.ReadUInt32(); LaneBuffer[laneID].Deserialize(s); } } catch (Exception ex) { ex.Log(); } }
public void Serialize(SimpleDataSerializer s) { try { LogCalled(); for (ushort i = 0; i < SegmentBuffer.Length; ++i) { SegmentBuffer[i].Serialize(s); } for (int i = 0; i < SegmentEndBuffer.Length; ++i) { SegmentEndBuffer[i].Serialize(s); } //for (ushort i = 0; i < NodeBuffer.Length; ++i) { // NodeBuffer[i].Serialize(s); //} uint n = (uint)LaneBuffer.LongCount(_l => !_l.IsEmpty); s.WriteUInt32(n); for (uint i = 0; i < LaneBuffer.Length; ++i) { if (LaneBuffer[i].IsEmpty) { continue; } s.WriteUInt32(i); LaneBuffer[i].Serialize(s); } } catch (Exception ex) { ex.Log(); } }
public static void Deserialize(SimpleDataSerializer s) { try { instance_ = new NetworkExtensionManager(); if (s != null) { instance_.DeserializeImp(s); } } catch (Exception ex) { ex.Log(); } }
public override void OnSaveData() { try { Log.Info("OnSaveData() ...", true); var man = NetworkExtensionManager.Instance; Assertion.AssertNotNull(DataVersion, "DataVersion"); var s = SimpleDataSerializer.Writer(DataVersion, man.SerializationCapacity); man.Serialize(s); serializableDataManager.SaveData(DATA_ID, s.GetBytes()); Log.Info("OnSaveData() was successful!", true); } catch (Exception ex) { ex.Log(); } }
public override void OnLoadData() { try { Log.Info("SerializableDataExtension.OnLoadData() ...", true); byte[] data = serializableDataManager.LoadData(DATA_ID); if (data == null) { NetworkExtensionManager.Deserialize(null); } else { var s = SimpleDataSerializer.Reader(data); NetworkExtensionManager.Deserialize(s); } Log.Info("SerializableDataExtension.OnLoadData() was successful!", true); } catch (Exception ex) { ex.Log(); } }
public void Serialize(SimpleDataSerializer s) { try { Assertion.NotNull(s); LogCalled("s.version=" + s.Version); for (ushort i = 0; i < SegmentBuffer.Length; ++i) { SegmentBuffer[i].Serialize(s); } } catch (Exception ex) { ex.Log(); } try { for (int i = 0; i < SegmentEndBuffer.Length; ++i) { SegmentEndBuffer[i].Serialize(s); } } catch (Exception ex) { ex.Log(); } try { for (ushort i = 0; i < NodeBuffer.Length; ++i) { NodeBuffer[i].Serialize(s); } } catch (Exception ex) { ex.Log(); } try { var n0 = LaneBuffer.LongCount(_l => !_l.IsEmpty); uint n = (uint)(ulong)n0; Assertion.GT((uint)LaneBuffer.Length, n, $"LaneBuffer.Length > n | n0 = {n0}"); s.WriteUInt32(n); Log.Debug($"Serializing {n} lanes"); for (uint i = 0; i < LaneBuffer.Length; ++i) { if (LaneBuffer[i].IsEmpty) { continue; } s.WriteUInt32(i); LaneBuffer[i].Serialize(s); } } catch (Exception ex) { ex.Log(); } }
static void Test() { return; LogCalled(); byte[] data; { var man = NetworkExtensionManager.CreateNew(); man.LaneBuffer[1].m_flags = NetLaneExt.Flags.Custom0; Log.Debug("Serialize lane flags:" + man.LaneBuffer[1].m_flags); var s = SimpleDataSerializer.Writer(new Version(1, 1), 100); man.Serialize(s); data = s.GetBytes(); } { var man = NetworkExtensionManager.CreateNew(); Log.Debug("Before Deserialize lane flags :" + man.LaneBuffer[1].m_flags); var s = SimpleDataSerializer.Reader(data); man.DeserializeImp(s); Log.Debug("After Deserialize lane flags :" + man.LaneBuffer[1].m_flags); } }
internal void DeserializeImp(SimpleDataSerializer s) { try { Assertion.NotNull(s); LogCalled("s.version=" + s.Version); for (ushort i = 0; i < SegmentBuffer.Length; ++i) { SegmentBuffer[i].Deserialize(s); } } catch (Exception ex) { ex.Log("failed to deserialize segments"); } try { for (int i = 0; i < SegmentEndBuffer.Length; ++i) { SegmentEndBuffer[i].Deserialize(s); } } catch (Exception ex) { ex.Log("failed to deserialize segment ends"); } try { for (ushort i = 0; i < NodeBuffer.Length; ++i) { NodeBuffer[i].Deserialize(s); } } catch (Exception ex) { ex.Log("failed to deserialize nodes"); } try { uint n = s.ReadUInt32(); Assertion.GT((uint)LaneBuffer.Length, n, "LaneBuffer.Length > n"); Log.Debug($"deserializing {n} lanes"); for (uint i = 0; i < n; ++i) { uint laneID = s.ReadUInt32(); Assertion.GT((uint)LaneBuffer.Length, laneID, "LaneBuffer.Length > laneID"); LaneBuffer[laneID].Deserialize(s); } } catch (Exception ex) { ex.Log($"failed to deserialize lanes"); } }
static SimpleDataSerializer GetWriter() => SimpleDataSerializer.Writer(version, 100);
static SimpleDataSerializer GetReader(byte [] data) => SimpleDataSerializer.Reader(data);
public void Deserialize(SimpleDataSerializer s) => m_flags = (m_flags & ~Flags.CustomsMask) | (Flags)(s.ReadInt32() << CUSTOM_FLAG_SHIFT);
public void Serialize(SimpleDataSerializer s) => s.WriteInt32( ((int)(Flags.CustomsMask & m_flags)) >> CUSTOM_FLAG_SHIFT);