private static SequenceBuilder ToBuilder(IEnumerable <byte> data) { var sb = new SequenceBuilder(MemoryPool <byte> .Shared); foreach (var b in data) { var m = sb.Request(1); m.Span[0] = b; } return(sb); }
public void Append(SequenceBuilder other) { if (other.disposed) { throw new ObjectDisposedException(nameof(other), "Cannot append a disposed SequenceBuilder"); } // current instance is empty; just clone the other builder if (current == null) { start = other.start; current = other.current; segmentSize = other.segmentSize; length = other.length; } else { // the other one is empty, quit var otherSegment = other.start ?? other.current; if (otherSegment == null) { return; // 'other' is empty, there is nothing to append } // append the other builder's list to ours // our current will be their current if (start == null) { start = current; } current.SetNext(otherSegment); // find the end of their list while (otherSegment != null) { current = otherSegment; otherSegment = otherSegment.NextSegment; } length += other.length; segmentSize = Math.Max(segmentSize, other.segmentSize); } // the other builder cannot be used anymore other.Clear(); }
public SegmentedStream(SequenceBuilder builder) { this.builder = builder; }