-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathIDataPackageHandler.cs
More file actions
32 lines (29 loc) · 1.9 KB
/
IDataPackageHandler.cs
File metadata and controls
32 lines (29 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Socket.DataHandlers;
/// <summary>
/// Defines an interface for adapting data packages to and from a TCP socket connection.
/// </summary>
/// <remarks>Implementations of this interface are responsible for converting raw data received from a TCP socket
/// into structured data packages and vice versa. This allows for custom serialization and deserialization logic
/// tailored to specific application protocols.</remarks>
public interface IDataPackageHandler
{
/// <summary>
/// Gets or sets the callback function to be invoked when data is received asynchronously.
/// </summary>
Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack { get; set; }
/// <summary>
/// Asynchronously receives data and processes it.
/// </summary>
/// <remarks>The method is designed for asynchronous operations and may be used in scenarios where
/// efficient handling of data streams is required. Ensure that the <paramref name="data"/> parameter contains valid
/// data for processing, and handle potential cancellation using the <paramref name="token"/>.</remarks>
/// <param name="data">The data to be received, represented as a read-only memory block of bytes.</param>
/// <param name="token">A cancellation token that can be used to cancel the operation. Defaults to <see langword="default"/> if not
/// provided.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> containing <see langword="true"/> if the data was successfully received and
/// processed; otherwise, <see langword="false"/>.</returns>
ValueTask HandlerAsync(ReadOnlyMemory<byte> data, CancellationToken token = default);
}