-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathIBObject.cs
More file actions
48 lines (43 loc) · 1.98 KB
/
Copy pathIBObject.cs
File metadata and controls
48 lines (43 loc) · 1.98 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.IO;
using System.IO.Pipelines;
using System.Threading;
using System.Threading.Tasks;
namespace BencodeNET.Objects
{
/// <summary>
/// Represent a bencode value that can be encoded to bencode.
/// </summary>
public interface IBObject
{
/// <summary>
/// Calculates the (encoded) size of the object in bytes.
/// </summary>
int GetSizeInBytes();
/// <summary>
/// Writes the object as bencode to the specified stream.
/// </summary>
/// <typeparam name="TStream">The type of stream.</typeparam>
/// <param name="stream">The stream to write to.</param>
/// <returns>The used stream.</returns>
TStream EncodeTo<TStream>(TStream stream) where TStream : Stream;
/// <summary>
/// Writes the object as bencode to the specified <see cref="PipeWriter"/> without flushing the writer,
/// you should do that manually.
/// </summary>
/// <param name="writer">The writer to write to.</param>
void EncodeTo(PipeWriter writer);
/// <summary>
/// Writes the object as bencode to the specified <see cref="PipeWriter"/> and flushes the writer afterwards.
/// </summary>
/// <param name="writer">The writer to write to.</param>
/// <param name="cancellationToken"></param>
ValueTask<FlushResult> EncodeToAsync(PipeWriter writer, CancellationToken cancellationToken = default);
/// <summary>
/// Writes the object asynchronously as bencode to the specified <see cref="Stream"/> using a <see cref="PipeWriter"/>.
/// </summary>
/// <param name="stream">The stream to write to.</param>
/// <param name="writerOptions">The options for the <see cref="PipeWriter"/>.</param>
/// <param name="cancellationToken"></param>
ValueTask<FlushResult> EncodeToAsync(Stream stream, StreamPipeWriterOptions writerOptions = null, CancellationToken cancellationToken = default);
}
}