public static void WriteSequence(bool copyMemory, SparseBufferGrowth growth) { using var writer = new SparseBufferWriter <byte>(128, growth); var sequence = ToReadOnlySequence(new ReadOnlyMemory <byte>(RandomBytes(5000)), 1000); writer.Write(in sequence, copyMemory); Equal(sequence.ToArray(), writer.ToReadOnlySequence().ToArray()); }
public string BuildStringUsingSparseBufferWriter() { using var writer = new SparseBufferWriter <char>(); for (var i = 0; i < 100; i++) { writer.Write(StringValue); writer.WriteInt32(int.MaxValue); writer.WriteLine(); } return(writer.BuildString()); }
public static void ExtractSingleSegment() { using var writer = new SparseBufferWriter <int>(); True(writer.IsSingleSegment); True(writer.TryGetWrittenContent(out var segment)); True(segment.IsEmpty); writer.Write(10); True(writer.IsSingleSegment); True(writer.TryGetWrittenContent(out segment)); Equal(10, segment.Span[0]); }
public static void StressTest(int totalSize) { using var writer = new SparseBufferWriter <byte>(); using var output = writer.AsStream(); var data = RandomBytes(2048); for (int remaining = totalSize, take; remaining > 0; remaining -= take) { take = Math.Min(remaining, data.Length); output.Write(data, 0, take); remaining -= take; } }
public void AddRangeToSparseBuffer() { using var writer = new SparseBufferWriter <int>(); writer.Write(inputArray); }
public void WriteToSparseBuffer() { using var buffer = new SparseBufferWriter <byte>(4096, SparseBufferGrowth.Exponential); using var ms = buffer.AsStream(false); Write(ms); }