Esempio n. 1
0
    private string _DecodeFmt(byte[] bytes)
    {
        string        tmp_fmt   = m_fmt;
        int           fmt_start = 0;
        int           fmt_len   = 0;
        int           byte_ind  = 0;
        int           tmp;
        List <object> str_lens = new List <object> ();

        Debug.Log("[Header][_DecodeFmt] all bytelen is " + bytes.Length);
        while (true)
        {
            int tag_ind = tmp_fmt.IndexOf('{');
            if (tag_ind == -1)
            {
                break;
            }
            fmt_len = tag_ind - fmt_start;
            string sub_fmt = tmp_fmt.Substring(fmt_start, fmt_len);
            Debug.Log("[Header][_DecodeFmt] " + sub_fmt);
            int tmp_sz = (int)Proto.calsize(sub_fmt);
            Debug.Log("[Header][_DecodeFmt] sz is " + tmp_sz);
            byte_ind += tmp_sz;
            int    len_sz   = (int)Proto.calsize("i");
            byte[] tmp_byte = new byte[len_sz];
            Array.Copy(bytes, byte_ind, tmp_byte, 0, len_sz);
            ArrayList arr = Proto.unpack("i", tmp_byte, out tmp);
            if (arr == null || arr.Count != 1)
            {
                Debug.Log("[Header][_DecodeFmt] errir arr is nil or len is not one");
                return(null);
            }
            str_lens.Add(arr[0]);
            byte_ind = byte_ind + (int)arr[0] + len_sz;
            Debug.Log("[Header][_DecodeFmt] " + byte_ind);
            tag_ind = tmp_fmt.IndexOf('}');
            //Debug.Log ("[Header][_DecodeFmt] index is " + tag_ind + " tmp_len is "+tmp_fmt.Length);
            if (tag_ind + 1 >= tmp_fmt.Length)
            {
                break;
            }
            int sub_start = tag_ind + 2;
            tmp_fmt = tmp_fmt.Substring(sub_start, tmp_fmt.Length - sub_start);
        }
        Debug.Log("[Header][_DecodeFmt] fmt is " + string.Format(m_fmt, str_lens.ToArray()));
        return(string.Format(m_fmt, str_lens.ToArray()));
    }
Esempio n. 2
0
 //通过hid发送对应的bytes给对应的监听者
 private void ParseHeader(int hLen)
 {
     lock (locker){
         int       ind;
         ArrayList arrL = Proto.unpack("iH", m_recvBytes, out ind);
         if (arrL == null || arrL.Count != 2)
         {
             return;
         }
         //Debug.Log("hLen is " + hLen);
         int    hid      = (ushort)arrL[1];
         byte[] tmpBytes = new byte[hLen];
         ind = ind - (int)Proto.calsize("H");
         Array.Copy(m_recvBytes, ind, tmpBytes, 0, hLen);
         int tot_len = hLen + (int)Proto.calsize("i");
         m_recvcount -= tot_len;
         byte[] tmp = new byte[m_recvcount];
         Array.Copy(m_recvBytes, tot_len, tmp, 0, m_recvcount);
         m_recvBytes = tmp;
         //发送数据
         Debug.Log("pass hid is " + hid);
         NetDelegate.GetIns().DispatchEvent((ushort)hid, tmpBytes);
     }
 }