Example #1
0
        /// <summary>
        /// 读取数据的包头,将数据解析成分段数据
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public static List <EnvelopePart> EnvlopeDataToPart(List <EnvelopeData> datas)
        {
            if (datas == null)
            {
                return(null);
            }
            int c = datas.Count;
            List <EnvelopePart> parts = new List <EnvelopePart>();

            for (int i = 0; i < c; i++)
            {
                var dat = datas[i].data;
                if (dat.Length == 0)
                {
                    continue;
                }
                EnvelopePart part = new EnvelopePart();
                var          buf  = ReadPart(dat, out part.head);
                if (buf != null)
                {
                    part.data = buf;
                    parts.Add(part);
                }
            }
            return(parts);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buff">源数据</param>
        /// <param name="len">数据长度</param>
        /// <param name="buffer">缓存数据</param>
        /// <param name="remain"></param>
        /// <param name="fs"></param>
        /// <returns></returns>
        public static List <EnvelopePart> UnpackPart(byte[] buff, int len, byte[] buffer, ref int remain, int fs)
        {
            fs -= EnvelopeHeadSize;
            List <EnvelopePart> list = new List <EnvelopePart>();
            int s = remain;

            for (int i = 0; i < len; i++)
            {
                buffer[s] = buff[i];
                s++;
            }
            len += remain;
            int index = 0;

            for (int i = 0; i < 1024; i++)
            {
                EnvelopeHead head = ReadHead(buffer, index);
                if (head.PartLen > fs)
                {
                    remain = 0;
                    break;
                }
                if (index + EnvelopeHeadSize + head.PartLen > len)
                {
                    remain = len - index;
                    for (int j = 0; j < len; j++)
                    {
                        buffer[j] = buffer[index];
                        index++;
                    }
                    return(list);
                }
                index += EnvelopeHeadSize;
                if (head.Lenth > 2)
                {
                    EnvelopePart part = new EnvelopePart();
                    part.head = head;
                    int l   = (int)head.PartLen;
                    var buf = new byte[l];
                    int a   = index;
                    for (int j = 0; j < l; j++)
                    {
                        buf[j] = buffer[a]; a++;
                    }
                    part.data = buf;
                    list.Add(part);
                }
                index += head.PartLen;
                if (index >= len)
                {
                    remain = 0;
                    break;
                }
            }
            return(list);
        }
Example #3
0
        /// <summary>
        /// 读取数据的包头,将数据解析成分段数据
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public static List <EnvelopePart> EnvlopeDataToPart(List <byte[]> datas)
        {
            if (datas == null)
            {
                return(null);
            }
            int c = datas.Count;
            List <EnvelopePart> parts = new List <EnvelopePart>();

            for (int i = 0; i < c; i++)
            {
                EnvelopePart part = new EnvelopePart();
                var          buf  = ReadPart(datas[i], out part.head);
                if (buf != null)
                {
                    part.data = buf;
                    parts.Add(part);
                }
            }
            return(parts);
        }