Table of Contents

Class JsonRpcPipeChannel

Namespace
Nerdbank.JsonRpc
Assembly
Nerdbank.JsonRpc.dll

Provides an abstract channel for transporting JSON-RPC messages over a duplex pipe, enabling asynchronous message exchange between endpoints.

public abstract class JsonRpcPipeChannel : Channel<JsonRpcMessage>, IAsyncDisposable
Inheritance
JsonRpcPipeChannel
Implements
Derived
Inherited Members

Remarks

Derived classes select the encoding and implement serialization, deserialization, and any framing. This base class manages the pipe and message queues without choosing a wire format.

Constructors

JsonRpcPipeChannel(IDuplexPipe, Channel<JsonRpcMessage>, Channel<JsonRpcMessage>)

Initializes a new instance of the JsonRpcPipeChannel class with deferred transport startup.

protected JsonRpcPipeChannel(IDuplexPipe pipe, Channel<JsonRpcMessage> inboundChannel, Channel<JsonRpcMessage> outboundChannel)

Parameters

pipe IDuplexPipe

The connected duplex pipe.

inboundChannel Channel<JsonRpcMessage>

The queue for received messages.

outboundChannel Channel<JsonRpcMessage>

The queue for messages to send.

Properties

Encoding

Gets the encoding used by this transport.

public abstract JsonRpcEncoding Encoding { get; }

Property Value

JsonRpcEncoding

Logger

protected ILogger Logger { get; }

Property Value

ILogger

MaximumMessageSize

Gets the configured maximum size, in bytes, of a message.

protected int MaximumMessageSize { get; }

Property Value

int

Serializer

Gets the serializer selected by this channel for application values.

public abstract JsonRpcSerializer Serializer { get; }

Property Value

JsonRpcSerializer

Methods

CreateInboundChannel(int?)

protected static Channel<JsonRpcMessage> CreateInboundChannel(int? capacity)

Parameters

capacity int?

Returns

Channel<JsonRpcMessage>

CreateOutboundChannel(int?)

protected static Channel<JsonRpcMessage> CreateOutboundChannel(int? capacity)

Parameters

capacity int?

Returns

Channel<JsonRpcMessage>

DisposeAsync()

Stops transport processing and completes both sides of the pipe.

public ValueTask DisposeAsync()

Returns

ValueTask

The bounded transport cleanup operation.

Exceptions

OperationCanceledException

A transport processor did not stop within the one-second cleanup budget.

ReceiveMessagesAsync(PipeReader, CancellationToken)

protected abstract IAsyncEnumerable<JsonRpcMessage> ReceiveMessagesAsync(PipeReader reader, CancellationToken cancellationToken)

Parameters

reader PipeReader
cancellationToken CancellationToken

Returns

IAsyncEnumerable<JsonRpcMessage>

SendMessageAsync(PipeWriter, JsonRpcMessage, CancellationToken)

protected abstract ValueTask SendMessageAsync(PipeWriter writer, JsonRpcMessage message, CancellationToken cancellationToken)

Parameters

writer PipeWriter
message JsonRpcMessage
cancellationToken CancellationToken

Returns

ValueTask

Start()

Starts transport processing after the channel and its owning JsonRpc instance have been configured.

public void Start()

Remarks

Start() calls this method automatically. Call it directly only when using the channel without a JsonRpc instance.