public async Task SerializeToBinaryFormMemoryStream() { await using var output = new MemoryStream(1024); var writer = IAsyncBinaryWriter.Create(output, buffer); await writer.WriteInt32Async(data.Count, true); var context = new EncodingContext(Encoding.UTF8, true); foreach (var(key, value) in data) { await writer.WriteAsync(key.AsMemory(), context, LengthFormat.Plain); await writer.WriteAsync(value.AsMemory(), context, LengthFormat.Plain); } }
public static void EmptyObject() { var empty = IDataTransferObject.Empty; Equal(0L, empty.Length); True(empty.IsReusable); True(empty.TryGetMemory(out var memory)); True(memory.IsEmpty); Empty(empty.ToByteArrayAsync().Result); var writer = new ArrayBufferWriter <byte>(); True(empty.WriteToAsync(IAsyncBinaryWriter.Create(writer), CancellationToken.None).IsCompletedSuccessfully); Equal(0, writer.WrittenCount); }
public async Task SerializeToBinaryFormFileStream() { await using var output = new FileStream(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()), FileMode.CreateNew, FileAccess.Write, FileShare.None, 1024, FileOptions.SequentialScan | FileOptions.Asynchronous | FileOptions.DeleteOnClose); var writer = IAsyncBinaryWriter.Create(output, buffer); await writer.WriteInt32Async(data.Count, true); var context = new EncodingContext(Encoding.UTF8, true); foreach (var(key, value) in data) { await writer.WriteAsync(key.AsMemory(), context, LengthFormat.Plain); await writer.WriteAsync(value.AsMemory(), context, LengthFormat.Plain); } await output.FlushAsync(); }
public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(stream.AsBufferWriter(ArrayPool <byte> .Shared.ToAllocator()));
public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(stream, buffer);
public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(pipe.Writer, 1024, 128);
public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(pipe.Writer);