Exemple #1
0
 public static HB32Header ReadFromBytes(byte[] bytes)
 {
     int[] array = BytesConverter.ParseIntArray(bytes, 0, 32);
     return(new HB32Header()
     {
         Flag = (SocketPacketFlag)array[0],
         I1 = array[1],
         I2 = array[2],
         I3 = array[3],
         PacketCount = array[4],
         TotalByteLength = array[5],
         PacketIndex = array[6],
         ValidByteLength = array[7],
     });
 }
Exemple #2
0
        public static byte[] ListToBytes(List <SocketFileInfo> socketFileInfos)
        {
            List <byte[]> byteList   = new List <byte[]>();
            int           bytesCount = 0;

            foreach (SocketFileInfo info in socketFileInfos)
            {
                byte[] _bytes = ToBytes(info);
                byteList.Add(_bytes);
                bytesCount += _bytes.Length;
            }

            byte[] bytes = new byte[bytesCount + 4];
            int    idx   = 0;

            bytes = BytesConverter.WriteInt(bytes, byteList.Count, ref idx);
            foreach (byte[] _bytes in byteList)
            {
                Array.Copy(_bytes, 0, bytes, idx, _bytes.Length);
                idx += _bytes.Length;
            }
            return(bytes);
        }