public IByteBuffer ToByteBuffer() { CompositeByteBuffer compositeBuffer = ArrayPooled.CompositeBuffer(); _ = compositeBuffer.AddComponents(this.value); _ = compositeBuffer.SetWriterIndex(this.size); _ = compositeBuffer.SetReaderIndex(0); return compositeBuffer; }
public override void AddContent(IByteBuffer buffer, bool last) { if (buffer is object) { long localsize = buffer.ReadableBytes; CheckSize(Size + localsize, MaxSize); if (DefinedSize > 0 && DefinedSize < Size + localsize) { ThrowHelper.ThrowIOException_OutOfSize(Size + localsize, DefinedSize); } Size += localsize; if (_byteBuf is null) { _byteBuf = buffer; } else if (_byteBuf is CompositeByteBuffer buf) { _ = buf.AddComponent(true, buffer); _ = buf.SetWriterIndex((int)Size); } else { CompositeByteBuffer compositeBuffer = ArrayPooled.CompositeBuffer(int.MaxValue); _ = compositeBuffer.AddComponents(true, _byteBuf, buffer); _ = compositeBuffer.SetWriterIndex((int)Size); _byteBuf = compositeBuffer; } } if (last) { SetCompleted(); } else { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } } }