Further testing has indicated that mapped memory accessors will throw an
exception if the position argument is already at the end, even if zero bytes
are read.
The methods mentioned previously therefore become:
public override ByteBuffer Get(byte[] dst, int offset, int length)
{
CheckBounds(offset, length, dst.Length);
if (length > Remaining)
throw new BufferUnderflowException();
// we need to check for 0-length reads, since ReadArray
will throw an ArgumentOutOfRange exception if position is at the end
// even when nothing is read
if (length > 0)
_accessor.ReadArray(Ix(NextGetIndex(length)), dst,
offset, length);
return this;
}
And
public override ByteBuffer Put(byte[] src, int offset, int length)
{
CheckBounds(offset, length, src.Length);
if (length > Remaining)
throw new BufferOverflowException();
// we need to check for 0-length writes, since ReadArray
will throw an ArgumentOutOfRange exception if position is at the end
// even when nothing is read
if (length > 0)
_accessor.WriteArray(Ix(NextPutIndex(length)), src,
offset, length);
return this;
}
Vincent