Show / Hide Table of Contents

Interface IDataTransferObject

Represents the structured data unit that can be transferred over wire.

Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public interface IDataTransferObject
Remarks

Typically, this interface is used for variable-length data units while IBinaryFormattable<TSelf> can be used for simple fixed-length structures.

Properties

| Edit this page View Source

Empty

Gets empty data transfer object.

Declaration
public static IDataTransferObject Empty { get; }
Property Value
Type Description
IDataTransferObject
| Edit this page View Source

IsReusable

Indicates that the content of this object can be copied to the output stream or pipe multiple times.

Declaration
bool IsReusable { get; }
Property Value
Type Description
bool
| Edit this page View Source

Length

Gets length of the object payload, in bytes.

Declaration
long? Length { get; }
Property Value
Type Description
long?
Remarks

If value is null then length of the payload cannot be determined.

Methods

| Edit this page View Source

TransformAsync<TResult, TTransformation>(PipeReader, TTransformation, CancellationToken)

Decodes the data using pipe reader.

Declaration
protected static ValueTask<TResult> TransformAsync<TResult, TTransformation>(PipeReader input, TTransformation transformation, CancellationToken token) where TTransformation : IDataTransferObject.ITransformation<TResult>
Parameters
Type Name Description
PipeReader input

The pipe reader used for decoding.

TTransformation transformation

The decoder.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<TResult>

The decoded stream.

Type Parameters
Name Description
TResult

The type of result.

TTransformation

The type of parser.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

TransformAsync<TResult, TTransformation>(Stream, TTransformation, bool, MemoryAllocator<byte>?, CancellationToken)

Decodes the stream.

Declaration
protected static ValueTask<TResult> TransformAsync<TResult, TTransformation>(Stream input, TTransformation transformation, bool resetStream, MemoryAllocator<byte>? allocator, CancellationToken token) where TTransformation : IDataTransferObject.ITransformation<TResult>
Parameters
Type Name Description
Stream input

The stream to decode.

TTransformation transformation

The decoder.

bool resetStream

true to reset stream position after decoding.

MemoryAllocator<byte> allocator

The allocator of temporary buffer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<TResult>

The decoded stream.

Type Parameters
Name Description
TResult

The type of result.

TTransformation

The type of parser.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

TransformAsync<TResult, TTransformation>(Stream, TTransformation, bool, Memory<byte>, CancellationToken)

Decodes the stream.

Declaration
protected static ValueTask<TResult> TransformAsync<TResult, TTransformation>(Stream input, TTransformation transformation, bool resetStream, Memory<byte> buffer, CancellationToken token) where TTransformation : IDataTransferObject.ITransformation<TResult>
Parameters
Type Name Description
Stream input

The stream to decode.

TTransformation transformation

The decoder.

bool resetStream

true to reset stream position after decoding.

Memory<byte> buffer

The temporary buffer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<TResult>

The decoded stream.

Type Parameters
Name Description
TResult

The type of result.

TTransformation

The type of parser.

Exceptions
Type Condition
ArgumentException

buffer is empty.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

TransformAsync<TResult, TTransformation>(Stream, TTransformation, bool, CancellationToken)

Decodes the stream.

Declaration
protected static ValueTask<TResult> TransformAsync<TResult, TTransformation>(Stream input, TTransformation transformation, bool resetStream, CancellationToken token) where TTransformation : IDataTransferObject.ITransformation<TResult>
Parameters
Type Name Description
Stream input

The stream to decode.

TTransformation transformation

The decoder.

bool resetStream

true to reset stream position after decoding.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<TResult>

The decoded stream.

Type Parameters
Name Description
TResult

The type of result.

TTransformation

The type of parser.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

TransformAsync<TResult, TTransformation>(TTransformation, CancellationToken)

Converts the data transfer object to another type.

Declaration
ValueTask<TResult> TransformAsync<TResult, TTransformation>(TTransformation transformation, CancellationToken token = default) where TTransformation : IDataTransferObject.ITransformation<TResult>
Parameters
Type Name Description
TTransformation transformation

The parser instance.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<TResult>

The converted DTO content.

Type Parameters
Name Description
TResult

The type of result.

TTransformation

The type of parser.

Remarks

The default implementation copies the content into memory before parsing.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

TryGetMemory(out ReadOnlyMemory<byte>)

Attempts to retrieve the contents of this object as a memory block synchronously.

Declaration
bool TryGetMemory(out ReadOnlyMemory<byte> memory)
Parameters
Type Name Description
ReadOnlyMemory<byte> memory

The memory block containing the contents of this object.

Returns
Type Description
bool

true if this object is representable as a memory block; otherwise, false.

| Edit this page View Source

WriteToAsync<TWriter>(TWriter, CancellationToken)

Transforms this object to serialized form.

Declaration
ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken token) where TWriter : IAsyncBinaryWriter
Parameters
Type Name Description
TWriter writer

The binary writer.

CancellationToken token

The toke that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing state of asynchronous execution.

Type Parameters
Name Description
TWriter

The type of writer.

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>)
DataTransferObject.ToByteArrayAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.ToMemoryAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.ToStringAsync<TObject>(TObject, Encoding, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.TransformAsync<TResult, TObject>(TObject, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>>, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, IBufferWriter<byte>, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, PipeWriter, long, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, Stream, int, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, Stream, Memory<byte>, CancellationToken)
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
IAsyncBinaryWriter
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾