public override int Read(byte[] buffer, int offset, int count) { var remaining = _length - _position; if (remaining < count) { count = (int)remaining; } if (count <= 0) { return(0); } MemoryUtils.PinAndCopyMemory(_buffer, (int)_position, buffer, offset, count); _position += count; return(count); }
public byte[] FullBuffer() { var data = new byte[_length]; var page = _first; int position = 0; fixed(byte *b = data) while (page != null) { var length = (*page).Used; MemoryUtils.CopyMemory(BufferHeader.Data(page), b + position, length); position += length; page = (*page).Next; } return(data); }
public override void Write(byte[] buffer, int offset, int count) { var initialCount = count; fixed(byte *src = buffer) while (true) { int capacity = EnsureCapacity(); int toCopy = Math.Min(count, capacity); MemoryUtils.CopyMemory(src + offset, BufferHeader.Data(_current) + (*_current).Used, toCopy); (*_current).Used += toCopy; count -= toCopy; if (count == 0) { break; } offset += toCopy; } _length += initialCount; }