Beispiel #1
0
        public override MemoryStream NioBuffer(int index, int length)
        {
            if (_components.Count == 1)
            {
                ByteBuf buf = _components[0]._buf;
                if (buf.NioBufferCount() == 1)
                {
                    return(_components[0]._buf.NioBuffer(index, length));
                }
            }
            MemoryStream merged = Convenient.Allocate(length); // little-endian

            MemoryStream[] buffers = NioBuffers(index, length);

            for (int i = 0; i < buffers.Length; i++)
            {
                merged.Put(buffers[i]);
            }

            merged.Flip();
            return(merged);
        }
Beispiel #2
0
        public override MemoryStream[] NioBuffers(int index, int length)
        {
            CheckIndex(index, length);
            if (length == 0)
            {
                return(new MemoryStream[0]); // EMPTY_BYTE_BUFFERS
            }

            var buffers = new List <MemoryStream>(_components.Count);
            int i       = ToComponentIndex(index);

            while (length > 0)
            {
                Component c           = _components[i];
                ByteBuf   s           = c._buf;
                int       adjustment  = c._offset;
                int       localLength = Math.Min(length, s.Capacity - (index - adjustment));
                switch (s.NioBufferCount())
                {
                case 0:
                    throw new NotSupportedException();

                case 1:
                    buffers.Add(s.NioBuffer(index - adjustment, localLength));
                    break;

                default:
                    buffers.AddRange(s.NioBuffers(index - adjustment, localLength));
                    break;
                }

                index  += localLength;
                length -= localLength;
                i++;
            }

            return(buffers.ToArray());
        }
 public override int NioBufferCount()
 {
     return(_buffer.NioBufferCount());
 }