CopyTo() public method

public CopyTo ( byte segmentBuffer, int currentSegmentIndex, int spaceToWrite, int additionalOffset ) : void
segmentBuffer byte
currentSegmentIndex int
spaceToWrite int
additionalOffset int
return void
Esempio n. 1
0
        private void WriteImpl(ref ByteSlice slice)
        {
            var offset       = 0;
            var bytesLeft    = _capacity - _position;
            var bytesToAlloc = slice.Count - bytesLeft;

            if (bytesToAlloc > 0)
            {
                var numberOfSegments = Calculator.GetSegmentIndex(bytesToAlloc) + 1;
                AddSegments(numberOfSegments);
            }

            // find initial segment to write
            var index = Calculator.GetSegmentIndex(_position);

            var currentSegment = FindSegment(index);

            // intial segment selected, do writing
            var toWrite = slice.Count;

            do
            {
                var currentSegmentIndex = Calculator.GetIndexInSegment(_position);
                var segmentBuffer       = currentSegment->Buffer;
                var spaceToWrite        = currentSegment->Length - currentSegmentIndex;

                spaceToWrite = spaceToWrite > toWrite ? toWrite : spaceToWrite;
                if (spaceToWrite > 0)
                {
                    slice.CopyTo(segmentBuffer, currentSegmentIndex, spaceToWrite, offset);
                }

                toWrite       -= spaceToWrite;
                _position     += spaceToWrite;
                offset        += spaceToWrite;
                currentSegment = currentSegment->Next;
            } while (toWrite > 0);

            if (_position > _length)
            {
                _length = _position;
            }
        }
Esempio n. 2
0
        private void WriteImpl(ref ByteSlice slice)
        {
            var offset = 0;
            var bytesLeft = _capacity - _position;
            var bytesToAlloc = slice.Count - bytesLeft;
            if (bytesToAlloc > 0)
            {
                var numberOfSegments = Calculator.GetSegmentIndex(bytesToAlloc) + 1;
                AddSegments(numberOfSegments);
            }

            // find initial segment to write
            var index = Calculator.GetSegmentIndex(_position);

            var currentSegment = FindSegment(index);

            // intial segment selected, do writing
            var toWrite = slice.Count;
            do
            {
                var currentSegmentIndex = Calculator.GetIndexInSegment(_position);
                var segmentBuffer = currentSegment->Buffer;
                var spaceToWrite = currentSegment->Length - currentSegmentIndex;

                spaceToWrite = spaceToWrite > toWrite ? toWrite : spaceToWrite;
                if (spaceToWrite > 0)
                {
                    slice.CopyTo(segmentBuffer, currentSegmentIndex, spaceToWrite, offset);
                }

                toWrite -= spaceToWrite;
                _position += spaceToWrite;
                offset += spaceToWrite;
                currentSegment = currentSegment->Next;
            } while (toWrite > 0);

            if (_position > _length)
            {
                _length = _position;
            }
        }