예제 #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);
        }
예제 #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());
        }
예제 #3
0
        public override ByteBuf GetBytes(int index, sbyte[] dst, int dstIndex, int length)
        {
            CheckDstIndex(index, length, dstIndex, dst.Length);
            if (length == 0)
            {
                return(this);
            }

            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));
                s.GetBytes(index - adjustment, dst, dstIndex, localLength);
                index    += localLength;
                dstIndex += localLength;
                length   -= localLength;
                i++;
            }
            return(this);
        }
예제 #4
0
        public override ByteBuf SetBytes(int index, ByteBuf src, int srcIndex, int length)
        {
            CheckSrcIndex(index, length, srcIndex, src.Capacity);
            if (length == 0)
            {
                return(this);
            }

            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));
                s.SetBytes(index - adjustment, src, srcIndex, localLength);
                index    += localLength;
                srcIndex += localLength;
                length   -= localLength;
                i++;
            }
            return(this);
        }
예제 #5
0
 public override ByteBuf SetBytes(int index, ByteBuf src, int srcIndex, int length)
 {
     _buffer.SetBytes(index, src, srcIndex, length);
     return(this);
 }
예제 #6
0
 public override ByteBuf SetBytes(int index, ByteBuf src, int srcIndex, int length)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 protected AbstractByteBufAllocator(bool preferDirect)
 {
     _directByDefault = preferDirect;       // TODO PlatformDependent needed??
     _emptyBuf        = new EmptyByteBuf(); // alloc not used
 }
예제 #8
0
 public override bool Equals(ByteBuf other)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public override ByteBuf WriteBytes(ByteBuf src, int length)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 public override ByteBuf SetBytes(int index, ByteBuf src, int srcIndex, int length)
 {
     CheckIndex(index, length);
     _buffer.SetBytes(index + _adjustment, src, srcIndex, length);
     return(this);
 }
예제 #11
0
 public CompositeByteBuf AddComponent(ByteBuf buffer)
 {
     AddComponent0(_components.Count, buffer);
     ConsolidateIfNeeded();
     return(this);
 }
예제 #12
0
 internal Component(ByteBuf buf)
 {
     _buf    = buf;
     _length = buf.ReadableBytes;
 }