Exemplo n.º 1
0
 public BufferResult FirstPage()
 {
     return(new BufferResult()
     {
         Length = (*_first).Used, Buffer = (IntPtr)BufferHeader.Data(_first)
     });
 }
Exemplo n.º 2
0
        public override void WriteByte(byte value)
        {
            EnsureCapacity();
            var data = BufferHeader.Data(_current) + (*_current).Used;

            (*data) = value;
            ++(*_current).Used;
        }
Exemplo n.º 3
0
        public BufferResult NextPage(BufferResult result)
        {
            var current = (BufferHeader *)((byte *)result.Buffer - BufferHeader.BufferHeaderSize);
            var next    = (*current).Next;

            if (next == null)
            {
                return(new BufferResult());
            }

            return(new BufferResult()
            {
                Length = (*next).Used, Buffer = (IntPtr)BufferHeader.Data(next)
            });
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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;
        }