Interface IAsyncBinaryWriter
Providers a uniform way to encode the data.
Inherited Members
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 SourceBuffer
Gets buffer to modify.
Declaration
Memory<byte> Buffer { get; }
Property Value
Type | Description |
---|---|
Memory<byte> |
See Also
Methods
| Edit this page View SourceAdvanceAsync(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 |
|
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 |
|
ArgumentOutOfRangeException |
|
OperationCanceledException | The operation has been canceled. |
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 |
|
ArgumentOutOfRangeException |
|
OperationCanceledException | The operation has been canceled. |
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 |
|
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 |
|
ArgumentOutOfRangeException |
|
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 |
|
ArgumentException |
|
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 |
|
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 : notnull, 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 |
|
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 : notnull, 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 |
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. |
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 |
|
WriteAsync<T>(T, CancellationToken)
Encodes formattable value as a set of bytes.
Declaration
ValueTask WriteAsync<T>(T value, CancellationToken token = default) where T : notnull, 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. |
WriteBigEndianAsync<T>(T, CancellationToken)
Writes integer value in big-endian format.
Declaration
ValueTask WriteBigEndianAsync<T>(T value, CancellationToken token = default) where T : notnull, 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. |
WriteLittleEndianAsync<T>(T, CancellationToken)
Writes integer value in little-endian format.
Declaration
ValueTask WriteLittleEndianAsync<T>(T value, CancellationToken token = default) where T : notnull, 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. |