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
CanWrite
Gets a value indicating whether this message handler can send messages.
bool CanWrite { get; }
Property Value
Formatter
Gets the formatter used for message serialization.
IJsonRpcMessageFormatter Formatter { get; }
Property Value
Methods
ReadAsync(CancellationToken)
Reads a distinct and complete message from the transport, waiting for one if necessary.
ValueTask<JsonRpcMessage?> ReadAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenA 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
- 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
JsonRpcMessageThe message to write.
cancellationToken
CancellationTokenA 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
- OperationCanceledException
Thrown if
cancellationToken
is canceled before message transmission begins.