Show / Hide Table of Contents

Class Message

A message that is exchanged between peers.

Inheritance
Object
Message
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
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 Source

ReadBytesAsync(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.

| Improve this Doc View Source

ReadStringAsync(Stream, CancellationToken)

Read the message as a String from the Stream.

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.

| Improve this Doc View Source

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.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX