Skip to content

Commit

Permalink
fixed typo and used ArrayBufferWriter on test
Browse files Browse the repository at this point in the history
  • Loading branch information
j0nimost committed Oct 28, 2023
1 parent 48dd134 commit 7044fc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ Behind the curtains Kafa is using `KafaPooledWriter` a pooled IBufferWriter to w
`Write<T>(IBufferWriter<byte> bufferWriter, List<T> entities, KafaOptions options = null)` Method.

```c#
var csvs = new List<CSVDataWithAttributes>()
var csvs = new List<CsvData>()
{
new CSVDataWithAttributes{ Date = DateTime.Parse("10/10/2023 4:08:38 PM"), Open=12.45, Close=12.99, High=13.00, Low=12.1, Name="AMZN", Volume=1233435512},
new CSVDataWithAttributes{ Date = DateTime.Parse("10/10/2023 4:08:38 PM"), Open=12.45, Close=12.99, High=13.00, Low=12.1, Name="AMZN", Volume=1233435512}
new CsvData{ Date = DateTime.Parse("10/10/2023 4:08:38 PM"), Open=12.45, Close=12.99, High=13.00, Low=12.1, Name="AMZN", Volume=1233435512},
new CsvData{ Date = DateTime.Parse("10/10/2023 4:08:38 PM"), Open=12.45, Close=12.99, High=13.00, Low=12.1, Name="AMZN", Volume=1233435512}
};

// get a ReadOnlySpan<bytes>
Expand All @@ -122,9 +122,9 @@ Behind the curtains Kafa is using `KafaPooledWriter` a pooled IBufferWriter to w
// or
// Write to a IBufferWriter<byte> for zero allocation writes
using var pooledWriter = new KafaPooledWriter();
Kafa.Write<CsvData>(pooledWriter, csvs);
var str = Encoding.UTF8.GetString(pooledWriter.WrittenAsSpan);
var arrayWriter = new ArrayBufferWriter<byte>();
Kafa.Write<CsvData>(arrayWriter, csvs);
var str = Encoding.UTF8.GetString(arrayWriter.WrittenSpan);

// or
// write directly to a file
Expand Down
11 changes: 6 additions & 5 deletions src/KafaTests/KafaWriteTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using nyingi.Kafa.Writer;
using System.Buffers;
using nyingi.Kafa.Writer;

namespace KafaTests
{
Expand Down Expand Up @@ -112,10 +113,10 @@ public async Task WriteToBufferWriter()
{
expected = "Date,Open,High,Low,Close,Volume,Name\r\n10/10/2023 4:08:38 PM,12.45,13,12.1,12.99,1233435512,AMZN\r\n10/10/2023 4:08:38 PM,12.45,13,12.1,12.99,1233435512,AMZN\r\n";
}
using var pooledWriter = new KafaPooledWriter();
Kafa.Write<CsvData>(pooledWriter, csvs);
var str = Encoding.UTF8.GetString(pooledWriter.WrittenAsSpan);

var arrayWriter = new ArrayBufferWriter<byte>();
Kafa.Write<CsvData>(arrayWriter, csvs);
var str = Encoding.UTF8.GetString(arrayWriter.WrittenSpan);
Assert.Equal(expected, str);
}
}
Expand Down

0 comments on commit 7044fc7

Please sign in to comment.