public ReadOnlyByteBuffer(IByteBuffer buffer) : base(buffer is object?buffer.MaxCapacity: AbstractByteBufferAllocator.DefaultMaxCapacity) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } switch (buffer) { case ReadOnlyByteBuffer _: case UnpooledDuplicatedByteBuffer _: _buffer = buffer.Unwrap(); break; default: _buffer = buffer; break; } _ = SetIndex(buffer.ReaderIndex, buffer.WriterIndex); }
internal static void SetBytes(AbstractByteBuffer buf, byte *addr, int index, IByteBuffer src, int srcIndex, int length) { Contract.Requires(src != null); if (MathUtil.IsOutOfBounds(srcIndex, length, src.Capacity)) { ThrowHelper.ThrowIndexOutOfRangeException_SrcIndex(srcIndex); } if (length != 0) { if (src.HasMemoryAddress) { IntPtr ptr = src.AddressOfPinnedMemory(); if (ptr != IntPtr.Zero) { PlatformDependent.CopyMemory((byte *)(ptr + srcIndex), addr, length); } else { fixed(byte *source = &src.GetPinnableMemoryAddress()) { PlatformDependent.CopyMemory(source + srcIndex, addr, length); } } } else if (src.HasArray) { PlatformDependent.CopyMemory(src.Array, src.ArrayOffset + srcIndex, addr, length); } else { src.GetBytes(srcIndex, buf, index, length); } } }
public override IByteBuffer SetBytes(int index, IByteBuffer src, int srcIndex, int length) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override IByteBuffer SetBytes(int index, byte[] src) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override IByteBuffer DiscardSomeReadBytes() => throw ThrowHelper.GetReadOnlyBufferException();
public override IByteBuffer EnsureWritable(int minWritableBytes) => throw ThrowHelper.GetReadOnlyBufferException();
public override IByteBuffer AdjustCapacity(int newCapacity) => throw ThrowHelper.GetReadOnlyBufferException();
public override IByteBuffer SetZero(int index, int length) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override int SetString(int index, string value, Encoding encoding) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override int SetCharSequence(int index, ICharSequence sequence, Encoding encoding) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override IByteBuffer SetBoolean(int index, bool value) { throw ThrowHelper.GetReadOnlyBufferException(); }
protected internal override void _SetShortLE(int index, int value) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override IByteBuffer SetShortLE(int index, int value) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override IByteBuffer SetLongLE(int index, long value) { throw ThrowHelper.GetReadOnlyBufferException(); }
protected internal override void _SetLong(int index, long value) { throw ThrowHelper.GetReadOnlyBufferException(); }
public override Task <int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken) { throw ThrowHelper.GetReadOnlyBufferException(); }