示例#1
0
        public static byte[] TakeAsArray(this IBufferReader reader, int bytes)
        {
            var segments = reader.Take(bytes).ToList();
            var len      = segments.Sum(x => x.Count);
            var buffer   = new byte[len];
            int bi       = 0;

            foreach (var arraySegment in segments)
            {
                for (int i = 0; i < arraySegment.Count; i++)
                {
                    buffer[bi++] = arraySegment.Array[arraySegment.Offset + i];
                }
            }
            return(buffer);
        }