Пример #1
0
        internal BufferWriter(SequencePool sequencePool, byte[] array)
        {
            buffered          = 0;
            bytesCommitted    = 0;
            this.sequencePool = sequencePool;
            rental            = default;
            output            = null;

            segment   = new ArraySegment <byte>(array);
            innerSpan = segment.AsSpan();
        }
Пример #2
0
        private void MigrateToSequence()
        {
            if (this.sequencePool == null)
            {
                return;
            }

            // 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;
            this.output    = output;

            sequencePool = default;
            rental       = default;

            var memory1 = this.output.GetMemory();

            if (memory1.IsEmpty)
            {
                throw new InvalidOperationException("The underlying IBufferWriter<byte>.GetMemory(int) method returned an empty memory block, which is not allowed. This is a bug in " + this.output.GetType().FullName);
            }
            var memory = memory1;

            MemoryMarshal.TryGetArray(memory, out segment);
            innerSpan = memory.Span;
        }