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); }
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); }
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(); }
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(); } }
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(); } }
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); }
private IByteBuffer createFlushByteBuf() { return(byteBufAllocator.DirectBuffer(this.mtu)); }
public IByteBuffer DirectBuffer() => _allocator.DirectBuffer();