Table of Contents

Interface IJsonRpcMessageHandler

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

The contract for sending and receiving JSON-RPC messages.

public interface IJsonRpcMessageHandler

Properties

CanRead

Gets a value indicating whether this message handler can receive messages.

bool CanRead { get; }

Property Value

bool

CanWrite

Gets a value indicating whether this message handler can send messages.

bool CanWrite { get; }

Property Value

bool

Formatter

Gets the formatter used for message serialization.

IJsonRpcMessageFormatter Formatter { get; }

Property Value

IJsonRpcMessageFormatter

Methods

ReadAsync(CancellationToken)

Reads a distinct and complete message from the transport, waiting for one if necessary.

ValueTask<JsonRpcMessage?> ReadAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to cancel the read request.

Returns

ValueTask<JsonRpcMessage>

The received message, or null if the underlying transport ends before beginning another message.

Remarks

Implementations may assume this method is never called before any async result from a prior call to this method has completed.

Exceptions

InvalidOperationException

Thrown when CanRead returns false.

EndOfStreamException

Thrown if the transport ends while reading a message.

OperationCanceledException

Thrown if cancellationToken is canceled before a new message is received.

WriteAsync(JsonRpcMessage, CancellationToken)

Writes a JSON-RPC message to the transport and flushes.

ValueTask WriteAsync(JsonRpcMessage jsonRpcMessage, CancellationToken cancellationToken)

Parameters

jsonRpcMessage JsonRpcMessage

The message to write.

cancellationToken CancellationToken

A token to cancel the write request.

Returns

ValueTask

A task that represents the asynchronous operation.

Remarks

Implementations should expect this method to be invoked concurrently and use a queue to preserve message order as they are transmitted one at a time.

Exceptions

InvalidOperationException

Thrown when CanWrite returns false.

OperationCanceledException

Thrown if cancellationToken is canceled before message transmission begins.