Ejemplo n.º 1
0
        //序列化,返回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.key);
                }
#if SERIALIZE_DEBUG
                SerializeUtil.BeginChangeLog(i, c.type, c.key);
#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);
        }
Ejemplo n.º 2
0
        //反序列化
        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);
                    _dict[item.Idx] = item;
                }
                else if (type == enSerializeChangeType.remove)
                {
                    if (!_dict.Remove(idx))
                    {
                        Debuger.LogError("同步失败");
                    }
                }
                else if (type == enSerializeChangeType.change)
                {
                    T item = _dict.Get(idx);
                    if (item == null)
                    {
                        Debuger.LogError("同步失败2");
                    }
                    item.Deserialize(stream);
                }
                else if (type == enSerializeChangeType.clear)
                {
                    _dict.Clear();
                }
#if SERIALIZE_DEBUG
                SerializeUtil.EndChangeLog();
#endif
            }
#if SERIALIZE_DEBUG
            SerializeUtil.EndParentLog(this);
#endif
        }
Ejemplo n.º 3
0
        //反序列化
        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
        }
Ejemplo n.º 4
0
        //序列化变化的部分,返回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);
        }
Ejemplo n.º 5
0
        //反序列化
        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
        }