示例#1
0
 internal object Decode(Type t, byte[] msgbuf)
 {
     m_DataStream.SetLength(0);
     m_DataStream.Write(msgbuf, 0, msgbuf.Length);
     m_DataStream.Position = 0;
     try
     {
         object msg = m_Serializer.Deserialize(m_DataStream, null, t);
         if (msg == null)
         {
             LogSystem.Debug("decode message error:can't find {0} len({1}) !!!", t.Name, msgbuf.Length);
             return(null);
         }
         //LogSystem.Debug("decode message:id {0} len({1})[{2}]", id, msgbuf.Length - 2, jsonData.GetType().Name);
         return(msg);
     }
     catch (Exception ex)
     {
         LogSystem.Error("decode message error:{0} len({1}) {2}\n{3}\nData:\n{4}", t.Name, msgbuf.Length, ex.Message, ex.StackTrace, CrossEngineHelper.BinToHex(msgbuf));
         throw ex;
     }
 }
 private void OnDataReceived(byte[] data)
 {
     LogSystem.Debug("Receive Data Message:\n{0}", CrossEngineHelper.BinToHex(data));
 }
示例#3
0
        internal static object Decode(byte[] msgbuf)
        {
            int id = (int)(((int)msgbuf[0] << 8) | ((int)msgbuf[1]));

            if (id < 0)
            {
                LogSystem.Debug("decode message error:id({0}) len({1}) error !!!", id, msgbuf.Length - 2);
                return(null);
            }

            Type t;

            if (s_DicIDMsg.TryGetValue(id, out t))
            {
                DataStream.SetLength(0);
                DataStream.Write(msgbuf, 2, msgbuf.Length - 2);
                DataStream.Position = 0;
                try
                {
                    object msg = Serializer.Deserialize(DataStream, null, t);
                    if (msg == null)
                    {
                        LogSystem.Debug("decode message error:can't find id {0} len({1}) !!!", id, msgbuf.Length - 2);
                        return(null);
                    }
                    //LogSystem.Info("decode message:id {0} len({1})[{2}]", id, msgbuf.Length - 2, msg.GetType().Name);
                    return(msg);
                }
                catch (Exception ex)
                {
                    LogSystem.Error("decode message error:id({0}) len({1}) {2}\n{3}\nData:\n{4}", id, msgbuf.Length - 2, ex.Message, ex.StackTrace, CrossEngineHelper.BinToHex(msgbuf, 2));
                    throw ex;
                }
            }
            return(null);
        }