示例#1
0
        internal BufferWriter(SequencePool sequencePool, byte[] array)
        {
            _buffered       = 0;
            _bytesCommitted = 0;
            _sequencePool   = sequencePool ?? throw new ArgumentNullException(nameof(sequencePool));
            _rental         = default;
            _output         = null;

            _segment = new ArraySegment <byte>(array);
            _span    = _segment.AsSpan();
        }
示例#2
0
 private void MigrateToSequence()
 {
     if (this._sequencePool != null)
     {
         // We were writing to our private scratch memory, so we have to copy it into the actual writer.
         _rental = _sequencePool.Rent();
         _output = _rental.Value;
         var realSpan = _output.GetSpan(_buffered);
         _segment.AsSpan(0, _buffered).CopyTo(realSpan);
         _sequencePool = null;
     }
 }
示例#3
0
        public BufferWriter(IBufferWriter <byte> output)
        {
            _buffered       = 0;
            _bytesCommitted = 0;
            _output         = output ?? throw new ArgumentNullException(nameof(output));

            _sequencePool = default;
            _rental       = default;

            var memory = _output.GetMemoryCheckResult();

            MemoryMarshal.TryGetArray(memory, out _segment);
            _span = memory.Span;
        }
示例#4
0
 internal Rental(SequencePool owner, Sequence <byte> value)
 {
     this.owner = owner;
     this.Value = value;
 }