Example #1
0
        static IByteBuffer NewCompositeBuffer(IByteBufferAllocator alloc)
        {
            CompositeByteBuffer compositeByteBuf = alloc.CompositeBuffer();

            compositeByteBuf.AddComponent(true, alloc.DirectBuffer(4).WriteInt(100));
            compositeByteBuf.AddComponent(true, alloc.DirectBuffer(8).WriteLong(123));
            compositeByteBuf.AddComponent(true, alloc.DirectBuffer(8).WriteLong(456));
            Assert.Equal(ExpectedBytes, compositeByteBuf.ReadableBytes);
            return(compositeByteBuf);
        }
Example #2
0
        public static Segment createSegment(IByteBufferAllocator byteBufAllocator, int size)
        {
            Segment seg = RECYCLER.Take();

            if (size == 0)
            {
                seg.data = byteBufAllocator.DirectBuffer(0, 0);
            }
            else
            {
                seg.data = byteBufAllocator.DirectBuffer(size);
            }
            return(seg);
        }
Example #3
0
        public void UnsafeHeapBufferAndUnsafeDirectBuffer()
        {
            IByteBufferAllocator allocator    = this.NewUnpooledAllocator();
            IByteBuffer          directBuffer = allocator.DirectBuffer();

            AssertInstanceOf <UnpooledUnsafeDirectByteBuffer>(directBuffer);
            directBuffer.Release();

            IByteBuffer heapBuffer = allocator.HeapBuffer();

            AssertInstanceOf <UnpooledHeapByteBuffer>(heapBuffer);
            heapBuffer.Release();
        }
Example #4
0
        public void DirectBuffer(bool preferDirect)
        {
            IByteBufferAllocator allocator = this.NewAllocator(preferDirect);
            IByteBuffer          buffer    = allocator.DirectBuffer(1);

            try
            {
                AssertBuffer(buffer, true, 1, this.DefaultMaxCapacity);
            }
            finally
            {
                buffer.Release();
            }
        }
Example #5
0
        public void DirectBufferWithCapacity(bool preferDirect, int maxCapacity)
        {
            IByteBufferAllocator allocator = this.NewAllocator(preferDirect);
            IByteBuffer          buffer    = allocator.DirectBuffer(1, maxCapacity);

            try
            {
                AssertBuffer(buffer, true, 1, maxCapacity);
            }
            finally
            {
                buffer.Release();
            }
        }
Example #6
0
 protected override IByteBuffer ComposeFirst(IByteBufferAllocator allocator, IByteBuffer first)
 {
     if (first is CompositeByteBuffer composite)
     {
         first = allocator.DirectBuffer(composite.ReadableBytes);
         try
         {
             first.WriteBytes(composite);
         }
         catch (Exception cause)
         {
             first.Release();
             ExceptionDispatchInfo.Capture(cause).Throw();
         }
         composite.Release();
     }
     return(first);
 }
Example #7
0
 private IByteBuffer createFlushByteBuf()
 {
     return(byteBufAllocator.DirectBuffer(this.mtu));
 }
Example #8
0
 public IByteBuffer DirectBuffer() => _allocator.DirectBuffer();