Esempio n. 1
0
    public static NetCmdBase ByteToCmd(byte[] byteData, int offset, int length)
    {
        if (length < 4)
        {
            return(null);
        }
        int t1 = (int)byteData[offset + 3];
        int t2 = (int)byteData[offset + 2];

        t1 = t1 << 8 | t2;

        NetCmdType cmdType = (NetCmdType)(t1);

        if (cmdType >= NetCmdType.CMD_MAX)
        {
            return(null);
        }
        NetTypeInfo typeInfo = NetCmdMapping.GetTypeInfo(cmdType);

        if (typeInfo == null)
        {
            LogMgr.Log("未注册的命令:" + cmdType.ToString());
            return(null);
        }
        if (length < typeInfo.StructSize)
        {
            LogMgr.Log("命令大小与结构体大小不匹配:" + length.ToString() + " : " + typeInfo.StructSize.ToString() + " :" + cmdType.ToString());
            return(null);
        }
        NetCmdBase cmd = (NetCmdBase)TypeReflector.BytesToObj(
            typeInfo.TypeHashCode,
            byteData,
            offset,
            length
            );

        return(cmd);
    }