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 SourceEmpty
Gets empty data transfer object.
Declaration
public static IDataTransferObject Empty { get; }
Property Value
| Type | Description |
|---|---|
| IDataTransferObject |
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 |
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 SourceTransformAsync<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. |
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. |
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 |
|
| OperationCanceledException | The operation has been canceled. |
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. |
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. |
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. |
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. |