Пример #1
0
        public void Init(NetConfiguration configuration)
        {
            byteOrder = configuration.byteOrder;
            //NetDebug.Log("NetCustomSerializer: init");
            Type[] types = ReflectionTool.FastGetChildTypes(typeof(INetSerializable));
            foreach (var t in types)
            {
                //NetDebug.Log("Add Msg Type:" + t.Name);
                typeDic.Add(t.Name, t);
            }

            //reader = new NetDataReader(byteOrder);
            //writer = new NetDataWriter(byteOrder);
        }
Пример #2
0
        private void AddAllCompressFun()
        {
            if (isAddAllCompressFun)
            {
                return;
            }
            isAddAllCompressFun = true;

            Type[] types = ReflectionTool.FastGetChildTypes(typeof(MsgCompressBase), false);
            foreach (var t in types)
            {
                MsgCompressBase obj = (MsgCompressBase)ReflectionTool.CreateDefultInstance(t);
                compressFun.Add(obj.CompressType, obj);
            }
        }
Пример #3
0
        //private NetDataReader reader = null;
        public object Deserialize(byte[] datas, out object msgType)
        {
            //NetDebug.Log("Deserialize收到消息:" + datas.Length);
            NetDataReader reader = new NetDataReader(byteOrder);

            reader.SetSource(datas, 0);
            msgType = reader.GetString();
            string msgT = msgType.ToString();

            if (!typeDic.ContainsKey(msgT))
            {
                NetDebug.LogError("No msgType:" + msgType);
                return(null);
            }
            Type             type         = typeDic[msgT];
            INetSerializable serializable = (INetSerializable)ReflectionTool.CreateDefultInstance(type);

            serializable.Deserialize(reader);
            return(serializable);
        }