コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(stream.AsBufferWriter(ArrayPool <byte> .Shared.ToAllocator()));
コード例 #5
0
 public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(stream, buffer);
コード例 #6
0
 public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(pipe.Writer, 1024, 128);
コード例 #7
0
 public IAsyncBinaryWriter CreateWriter() => IAsyncBinaryWriter.Create(pipe.Writer);