//反序列化 public override void Deserialize(IoBuffer stream) { int changeCount = stream.ReadInt32(); #if SERIALIZE_DEBUG SerializeUtil.BeginParentLog(this, changeCount, false); #endif for (int i = 0; i < changeCount; ++i) { enSerializeChangeType type = (enSerializeChangeType)stream.ReadByte(); int idx = -1; if (type != enSerializeChangeType.clear) { idx = stream.ReadInt32(); } #if SERIALIZE_DEBUG SerializeUtil.BeginChangeLog(i, type, idx.ToString()); #endif if (type == enSerializeChangeType.add) { T item = (T)Activator.CreateInstance(typeof(T)); item.Parent = this; item.Idx = idx; item.Deserialize(stream); _list.Insert(item.Idx, item); } else if (type == enSerializeChangeType.remove) { _list.RemoveAt(idx); } else if (type == enSerializeChangeType.change) { _list[idx].Deserialize(stream); } else if (type == enSerializeChangeType.clear) { _list.Clear(); } #if SERIALIZE_DEBUG SerializeUtil.EndChangeLog(); #endif } #if SERIALIZE_DEBUG SerializeUtil.EndParentLog(this); #endif }
//反序列化 public override void Deserialize(IoBuffer stream) { enType t = (enType)stream.ReadByte(); SetType(t); if (_type == enType.Bool) { _value = stream.ReadBool(); } else if (_type == enType.Byte) { _value = stream.ReadByte(); } else if (_type == enType.Short) { _value = stream.ReadInt16(); } else if (_type == enType.Int) { _value = stream.ReadInt32(); } else if (_type == enType.Long) { _value = stream.ReadInt64(); } else if (_type == enType.Float) { _value = stream.ReadFloat(); } else if (_type == enType.Double) { _value = stream.ReadDouble(); } else if (_type == enType.String) { _value = stream.ReadStr(); } else { Debuger.LogError("未知的类型"); } #if SERIALIZE_DEBUG SerializeUtil.AddLog(this); #endif }
//序列化变化的部分,返回false说明没有任何改变 public override bool SerializeChange(IoBuffer stream) { if (!ValueChange) { return(false); } if (!OrderChange()) { ClearChange(); return(false); } stream.Write(_changes.Count);//变化数量 #if SERIALIZE_DEBUG SerializeUtil.BeginParentLog(this, _changes.Count, true); #endif ChangeCxt c; for (int i = 0; i < _changes.Count; ++i) { c = _changes[i]; if (c.type != enSerializeChangeType.change) { Debuger.LogError("逻辑错误,SObject的子节点只能被修改,不能增删。{0}", c.type); continue; } stream.Write(c.idx); #if SERIALIZE_DEBUG SerializeUtil.BeginChangeLog(i, enSerializeChangeType.change, _fieldsName[c.idx]); #endif if (!c.obj.SerializeChange(stream)) { Debuger.LogError("逻辑错误,一定会有要序列化的东西"); } #if SERIALIZE_DEBUG SerializeUtil.EndChangeLog(); #endif } ClearChange(); #if SERIALIZE_DEBUG SerializeUtil.EndParentLog(this); #endif return(true); }
//反序列化 public override void Deserialize(IoBuffer stream) { int changeCount = stream.ReadInt32(); #if SERIALIZE_DEBUG SerializeUtil.BeginParentLog(this, changeCount, false); #endif for (int i = 0; i < changeCount; ++i) { int idx = stream.ReadInt32(); #if SERIALIZE_DEBUG SerializeUtil.BeginChangeLog(i, enSerializeChangeType.change, _fieldsName[idx]); #endif _fields[idx].Deserialize(stream); #if SERIALIZE_DEBUG SerializeUtil.EndChangeLog(); #endif } #if SERIALIZE_DEBUG SerializeUtil.EndParentLog(this); #endif }
//序列化,返回false说明没有任何改变 public override bool SerializeChange(IoBuffer stream) { if (!ValueChange) { return(false); } if (!OrderChange()) { ClearChange(); return(false); } stream.Write(_changes.Count);//变化数量 #if SERIALIZE_DEBUG SerializeUtil.BeginParentLog(this, _changes.Count, true); #endif ChangeCxt c; for (int i = 0; i < _changes.Count; ++i) { c = _changes[i]; stream.Write((byte)c.type); if (c.type != enSerializeChangeType.clear) { stream.Write(c.idx); } #if SERIALIZE_DEBUG SerializeUtil.BeginChangeLog(i, c.type, c.idx.ToString()); #endif if (c.type == enSerializeChangeType.add) { if (!c.obj.SerializeChange(stream)) { Debuger.LogError("逻辑错误,一定会有要序列化的东西"); } } else if (c.type == enSerializeChangeType.remove) { } else if (c.type == enSerializeChangeType.change) { if (!c.obj.SerializeChange(stream)) { Debuger.LogError("逻辑错误,一定会有要序列化的东西"); } } else if (c.type == enSerializeChangeType.clear) { } #if SERIALIZE_DEBUG SerializeUtil.EndChangeLog(); #endif } ClearChange(); #if SERIALIZE_DEBUG SerializeUtil.EndParentLog(this); #endif return(true); }