Class Message
A message that is exchanged between peers.
Inherited Members
Namespace: PeerTalk.Protocols
Assembly: PeerTalk.dll
Syntax
public static class Message
Remarks
A message consists of
- A Varint length prefix
- The payload
- A terminating newline
Methods
| Improve this Doc View SourceReadBytesAsync(Stream, CancellationToken)
Read the message as a sequence of bytes from the Stream.
Declaration
public static Task<byte[]> ReadBytesAsync(Stream stream, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream to a peer. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Byte[]> | A task that represents the asynchronous operation. The task's result is the byte representation of the message's payload. |
Exceptions
Type | Condition |
---|---|
InvalidDataException | When the message is invalid. |
ReadStringAsync(Stream, CancellationToken)
Declaration
public static Task<string> ReadStringAsync(Stream stream, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream to a peer. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<String> | A task that represents the asynchronous operation. The task's result is the string representation of the message's payload. |
Remarks
The return value has the length prefix and terminating newline removed.
Exceptions
Type | Condition |
---|---|
InvalidDataException | When the message is invalid. |
WriteAsync(String, Stream, CancellationToken)
Writes the binary representation of the message to the specified Stream.
Declaration
public static Task WriteAsync(string message, Stream stream, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | message | The message to write. A newline is automatically appended. |
Stream | stream | The Stream to a peer. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |