Show / Hide Table of Contents

Interface IAsyncBinaryWriter

Providers a uniform way to encode the data.

Inherited Members
ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>.Invoke(ReadOnlyMemory<byte>, CancellationToken)
IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>.ToDelegate()
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public interface IAsyncBinaryWriter : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>

Properties

| Edit this page View Source

Buffer

Gets buffer to modify.

Declaration
Memory<byte> Buffer { get; }
Property Value
Type Description
Memory<byte>
See Also
AdvanceAsync(int, CancellationToken)

Methods

| Edit this page View Source

AdvanceAsync(int, CancellationToken)

Instructs the writer that the specified number of bytes of Buffer is modified.

Declaration
ValueTask AdvanceAsync(int bytesWritten, CancellationToken token = default)
Parameters
Type Name Description
int bytesWritten

The number of written bytes to Buffer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Exceptions
Type Condition
ArgumentOutOfRangeException

bytesWritten is negative.

| Edit this page View Source

CopyFromAsync(PipeReader, long?, CancellationToken)

Writes the content from the specified pipe.

Declaration
ValueTask CopyFromAsync(PipeReader source, long? count = null, CancellationToken token = default)
Parameters
Type Name Description
PipeReader source

The pipe to read from.

long? count

The number of bytes to read from the source.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Exceptions
Type Condition
ArgumentNullException

source is null.

ArgumentOutOfRangeException

count is negative.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

CopyFromAsync(Stream, long?, CancellationToken)

Writes the content from the specified stream.

Declaration
ValueTask CopyFromAsync(Stream source, long? count = null, CancellationToken token = default)
Parameters
Type Name Description
Stream source

The stream to read from the source.

long? count

The number of bytes to read from the source.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Exceptions
Type Condition
ArgumentNullException

source is null.

ArgumentOutOfRangeException

count is negative.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

Create(IBufferWriter<byte>)

Creates default implementation of binary writer for the buffer writer.

Declaration
public static IAsyncBinaryWriter Create(IBufferWriter<byte> writer)
Parameters
Type Name Description
IBufferWriter<byte> writer

The buffer writer.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Exceptions
Type Condition
ArgumentNullException

writer is null.

| Edit this page View Source

Create(PipeWriter, long)

Creates default implementation of binary writer for the pipe.

Declaration
public static IAsyncBinaryWriter Create(PipeWriter output, long bufferSize = 0)
Parameters
Type Name Description
PipeWriter output

The stream instance.

long bufferSize

The maximum numbers of bytes that can be buffered in the memory without flushing.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Exceptions
Type Condition
ArgumentNullException

output is null.

ArgumentOutOfRangeException

bufferSize or is less than or equal to zero.

| Edit this page View Source

Create(Stream, Memory<byte>)

Creates default implementation of binary writer for the stream.

Declaration
public static IAsyncBinaryWriter Create(Stream output, Memory<byte> buffer)
Parameters
Type Name Description
Stream output

The stream instance.

Memory<byte> buffer

The buffer used for encoding binary data.

Returns
Type Description
IAsyncBinaryWriter

The stream writer.

Remarks

It is recommended to use extension methods from StreamExtensions class for encoding data to the stream. This method is intended for situation when you need an object implementing IAsyncBinaryWriter interface.

Exceptions
Type Condition
ArgumentNullException

output is null.

ArgumentException

buffer is empty.

| Edit this page View Source

EncodeAsync(ReadOnlyMemory<char>, EncodingContext, LengthFormat?, CancellationToken)

Encodes a block of characters using the specified encoding.

Declaration
ValueTask<long> EncodeAsync(ReadOnlyMemory<char> chars, EncodingContext context, LengthFormat? lengthFormat = null, CancellationToken token = default)
Parameters
Type Name Description
ReadOnlyMemory<char> chars

The characters to encode.

EncodingContext context

The context describing encoding of characters.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<long>

The number of written bytes.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

FormatAsync<T>(T, EncodingContext, LengthFormat?, string?, IFormatProvider?, MemoryAllocator<char>?, CancellationToken)

Encodes formattable value as a set of characters using the specified encoding.

Declaration
ValueTask<long> FormatAsync<T>(T value, EncodingContext context, LengthFormat? lengthFormat = null, string? format = null, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null, CancellationToken token = default) where T : ISpanFormattable
Parameters
Type Name Description
T value

The value to be written as string.

EncodingContext context

The context describing encoding of characters.

LengthFormat? lengthFormat

String length encoding format.

string format

The format of the value.

IFormatProvider provider

The format provider.

MemoryAllocator<char> allocator

Characters buffer allocator.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<long>

The number of written bytes.

Type Parameters
Name Description
T

The type of formattable value.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

FormatAsync<T>(T, LengthFormat?, string?, IFormatProvider?, CancellationToken)

Converts the value to UTF-8 encoded characters.

Declaration
ValueTask<int> FormatAsync<T>(T value, LengthFormat? lengthFormat, string? format = null, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanFormattable
Parameters
Type Name Description
T value

The value to convert.

LengthFormat? lengthFormat

String length encoding format.

string format

The format of the value.

IFormatProvider provider

The format provider.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<int>

The number of written bytes.

Type Parameters
Name Description
T

The type of the value to convert.

Exceptions
Type Condition
InternalBufferOverflowException

The internal buffer cannot place all UTF-8 bytes exposed by value.

| Edit this page View Source

TryGetBufferWriter()

Attempts to get synchronous writer.

Declaration
IBufferWriter<byte>? TryGetBufferWriter()
Returns
Type Description
IBufferWriter<byte>

Synchronous writer wrapped by this asynchronous writer; or null if underlying I/O is fully asynchronous.

| Edit this page View Source

WriteAsync(ReadOnlyMemory<byte>, LengthFormat?, CancellationToken)

Encodes a block of memory, optionally prefixed with the length encoded as a sequence of bytes according with the specified format.

Declaration
ValueTask WriteAsync(ReadOnlyMemory<byte> input, LengthFormat? lengthFormat = null, CancellationToken token = default)
Parameters
Type Name Description
ReadOnlyMemory<byte> input

A block of memory.

LengthFormat? lengthFormat

Indicates how the length of the BLOB must be encoded; or null to prevent length encoding.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

WriteAsync<T>(T, CancellationToken)

Encodes formattable value as a set of bytes.

Declaration
ValueTask WriteAsync<T>(T value, CancellationToken token = default) where T : IBinaryFormattable<T>
Parameters
Type Name Description
T value

The value to be written as a sequence of bytes.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Type Parameters
Name Description
T

The type of formattable value.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

WriteBigEndianAsync<T>(T, CancellationToken)

Writes integer value in big-endian format.

Declaration
ValueTask WriteBigEndianAsync<T>(T value, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters
Type Name Description
T value

The value to be written in big-endian format.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Type Parameters
Name Description
T

The integer type.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

WriteLittleEndianAsync<T>(T, CancellationToken)

Writes integer value in little-endian format.

Declaration
ValueTask WriteLittleEndianAsync<T>(T value, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters
Type Name Description
T value

The value to be written in little-endian format.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Type Parameters
Name Description
T

The integer type.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)

See Also

IAsyncBinaryReader
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾