Show / Hide Table of Contents

Interface IAsyncBinaryWriter

Providers a uniform way to encode the data.

Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public interface IAsyncBinaryWriter

Methods

| Improve this Doc View Source

CopyFromAsync(PipeReader, CancellationToken)

Writes the content from the specified pipe.

Declaration
virtual Task CopyFromAsync(PipeReader input, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
PipeReader input

The pipe to read from.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing state of asynchronous execution.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

CopyFromAsync(Stream, CancellationToken)

Writes the content from the specified stream.

Declaration
virtual Task CopyFromAsync(Stream input, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Stream input

The stream to read from.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing state of asynchronous execution.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

CopyFromAsync<TArg>(Func<TArg, CancellationToken, ValueTask<ReadOnlyMemory<Byte>>>, TArg, CancellationToken)

Writes the content from the delegate supplying memory blocks.

Declaration
virtual Task CopyFromAsync<TArg>(Func<TArg, CancellationToken, ValueTask<ReadOnlyMemory<byte>>> supplier, TArg arg, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Func<TArg, CancellationToken, ValueTask<ReadOnlyMemory<Byte>>> supplier

The delegate supplying memory blocks.

TArg arg

The argument to be passed to the supplier.

CancellationToken token

The token that can be used to cancel operation.

Returns
Type Description
Task

The task representing state of asynchronous execution.

Type Parameters
Name Description
TArg

The type of the argument to be passed to the supplier.

Remarks

Copy process will be stopped when supplier returns empty ReadOnlyMemory<T>.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

Create(PipeWriter)

Creates default implementation of binary writer for the pipe.

Declaration
static IAsyncBinaryWriter Create(PipeWriter output)
Parameters
Type Name Description
PipeWriter output

The stream instance.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Remarks

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

Exceptions
Type Condition
ArgumentNullException

output is null.

| Improve this Doc View Source

Create(PipeWriter, Int32, Int32)

Creates default implementation of binary writer for the pipe.

Declaration
static IAsyncBinaryWriter Create(PipeWriter output, int stringLengthThreshold, int encodingBufferSize)
Parameters
Type Name Description
PipeWriter output

The stream instance.

Int32 stringLengthThreshold

The threshold for the number of characters. If the number of characters is less than or equal to this threshold then writer encodes the whole sequence of characters in memory and then flushes the pipe; otherwise, the pipe flushes multiple times for each portion of the sequence.

Int32 encodingBufferSize

The size of internal buffer used to encode characters.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Exceptions
Type Condition
ArgumentNullException

output is null.

ArgumentOutOfRangeException

encodingBufferSize or stringLengthThreshold is less than zero.

| Improve this Doc View Source

Create(Stream, Memory<Byte>)

Creates default implementation of binary writer for the stream.

Declaration
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.

| Improve this Doc View Source

Create<TWriter>(TWriter)

Creates default implementation of binary writer for the buffer writer.

Declaration
static IAsyncBinaryWriter Create<TWriter>(TWriter writer)

    where TWriter : class, IBufferWriter<byte>, IFlushable
Parameters
Type Name Description
TWriter writer

The buffer writer.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Type Parameters
Name Description
TWriter

The type of the buffer writer.

Exceptions
Type Condition
ArgumentNullException

writer is null.

| Improve this Doc View Source

WriteAsync(ReadOnlySequence<Byte>, CancellationToken)

Writes the content from the specified sequence of bytes.

Declaration
virtual Task WriteAsync(ReadOnlySequence<byte> input, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
ReadOnlySequence<Byte> input

The sequence of bytes to read from.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing state of asynchronous execution.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

Encodes a block of memory.

Declaration
ValueTask WriteAsync(ReadOnlyMemory<byte> input, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
ReadOnlyMemory<Byte> input

A block of memory.

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.

| Improve this Doc View Source

WriteAsync(ReadOnlyMemory<Char>, EncodingContext, Nullable<StringLengthEncoding>, CancellationToken)

Encodes a block of characters using the specified encoding.

Declaration
ValueTask WriteAsync(ReadOnlyMemory<char> chars, EncodingContext context, StringLengthEncoding? lengthFormat, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
ReadOnlyMemory<Char> chars

The characters to encode.

EncodingContext context

The context describing encoding of characters.

Nullable<StringLengthEncoding> 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

The task representing state of asynchronous execution.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Improve this Doc View Source

WriteAsync<T>(T, CancellationToken)

Encodes value of blittable type.

Declaration
virtual ValueTask WriteAsync<T>(T value, CancellationToken token = default(CancellationToken))

    where T : struct
Parameters
Type Name Description
T value

The value to encode.

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 the value to encode.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

WriteByteAsync(Byte, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes 8-bit unsigned integer as a string.

Declaration
virtual ValueTask WriteByteAsync(byte value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Byte value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteDateTimeAsync(DateTime, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes DateTime as a string.

Declaration
virtual ValueTask WriteDateTimeAsync(DateTime value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
DateTime value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom date/time format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteDateTimeOffsetAsync(DateTimeOffset, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes DateTimeOffset as a string.

Declaration
virtual ValueTask WriteDateTimeOffsetAsync(DateTimeOffset value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
DateTimeOffset value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom date/time format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteDecimalAsync(Decimal, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes Decimal as a string.

Declaration
virtual ValueTask WriteDecimalAsync(decimal value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Decimal value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteDoubleAsync(Double, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes double-precision floating-point number as a string.

Declaration
virtual ValueTask WriteDoubleAsync(double value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Double value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteGuidAsync(Guid, StringLengthEncoding, EncodingContext, String, CancellationToken)

Encodes Guid as a string.

Declaration
virtual ValueTask WriteGuidAsync(Guid value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Guid value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom GUID format string.

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.

| Improve this Doc View Source

WriteInt16Async(Int16, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes 16-bit signed integer as a string.

Declaration
virtual ValueTask WriteInt16Async(short value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int16 value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteInt16Async(Int16, Boolean, CancellationToken)

Encodes 16-bit signed integer asynchronously.

Declaration
virtual ValueTask WriteInt16Async(short value, bool littleEndian, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int16 value

The value to encode.

Boolean littleEndian

true to use little-endian encoding; false to use big-endian 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.

| Improve this Doc View Source

WriteInt32Async(Int32, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes 32-bit signed integer as a string.

Declaration
virtual ValueTask WriteInt32Async(int value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int32 value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteInt32Async(Int32, Boolean, CancellationToken)

Encodes 32-bit signed integer asynchronously.

Declaration
virtual ValueTask WriteInt32Async(int value, bool littleEndian, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int32 value

The value to encode.

Boolean littleEndian

true to use little-endian encoding; false to use big-endian 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.

| Improve this Doc View Source

WriteInt64Async(Int64, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes 64-bit signed integer as a string.

Declaration
virtual ValueTask WriteInt64Async(long value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int64 value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteInt64Async(Int64, Boolean, CancellationToken)

Encodes 64-bit signed integer asynchronously.

Declaration
virtual ValueTask WriteInt64Async(long value, bool littleEndian, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Int64 value

The value to encode.

Boolean littleEndian

true to use little-endian encoding; false to use big-endian 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.

| Improve this Doc View Source

WriteSingleAsync(Single, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes single-precision floating-point number as a string.

Declaration
virtual ValueTask WriteSingleAsync(float value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
Single value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom numeric format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

| Improve this Doc View Source

WriteTimeSpanAsync(TimeSpan, StringLengthEncoding, EncodingContext, String, IFormatProvider, CancellationToken)

Encodes TimeSpan as a string.

Declaration
virtual ValueTask WriteTimeSpanAsync(TimeSpan value, StringLengthEncoding lengthFormat, EncodingContext context, string format = null, IFormatProvider provider = null, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan value

The value to encode.

StringLengthEncoding lengthFormat

String length encoding format.

EncodingContext context

The context describing encoding of characters.

String format

A standard or custom date/time format string.

IFormatProvider provider

An object that supplies culture-specific formatting information.

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.

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)

See Also

IAsyncBinaryReader
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX