Ejemplo n.º 1
0
        public static bool readVarInt32(IoBuffer ioBuffer, out int value)
        {
            byte tag = ioBuffer.ReadByte();

            // 1### #### (128 - (byte)0x80)
            if ((tag & FLAG_0X80) == 0)
            {
                value = tag & 0x7F;
                return(true);
            }

            int signal = tag & SIGNAL_MASK;

            if (ioBuffer.ReadSize < signal)
            {
                Debuger.LogError("readVarInt32 可读字节长度不足" + signal);
                value = 0;
                return(false);
            }

            if (signal > 4 || signal < 1)
            {
                Debuger.LogError("readVarInt32 字节数必须1~4");
                value = 0;
                return(false);
            }

            value = 0;
            for (int i = 8 * (signal - 1); i >= 0; i -= 8)
            {
                byte b = ioBuffer.ReadByte();
                value |= (b & 0xFF) << i;
            }
            return(true);
        }
Ejemplo n.º 2
0
        //反序列化
        public override void Deserialize(IoBuffer stream)
        {
            _value = stream.ReadByte();
#if SERIALIZE_DEBUG
            SerializeUtil.AddLog(this);
#endif
        }
Ejemplo n.º 3
0
        //反序列化
        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
        }
Ejemplo n.º 4
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.º 5
0
        public static Command valueOf(IoBuffer stream)
        {
            Command result = new Command();

            result.command = stream.ReadInt32();
            result.module  = stream.ReadByte();



            return(result);
        }
Ejemplo n.º 6
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.º 7
0
        public bool Decode(IoBuffer buffer, System.Type type, out object value)
        {
            byte flag = buffer.ReadByte();

            byte  t     = Proxy.getFlagTypes(flag);
            Proxy proxy = m_proxys.Get(t);

            if (proxy == null)
            {
                Debuger.LogError("找不到序列化类。flag:{0:x}", t);
                value = null;
                return(false);
            }


            return(proxy.getValue(buffer, type, flag, out value));
        }