Table of Contents

Class NewLineDelimitedMessageHandler

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

A JSON-RPC message handler that delimits messages with new lines.

public class NewLineDelimitedMessageHandler : PipeMessageHandler, IJsonRpcMessageHandler, IDisposableObservable, IDisposable, IAsyncDisposable, IJsonRpcMessageBufferManager
Inheritance
NewLineDelimitedMessageHandler
Implements
Inherited Members

Remarks

When reading messages, either \n or \r\n character sequences are permitted for new lines. When writing messages the NewLine property controls which character sequence is used to terminate each message.

Constructors

NewLineDelimitedMessageHandler(IDuplexPipe, IJsonRpcMessageTextFormatter)

Initializes a new instance of the NewLineDelimitedMessageHandler class.

public NewLineDelimitedMessageHandler(IDuplexPipe pipe, IJsonRpcMessageTextFormatter formatter)

Parameters

pipe IDuplexPipe

The reader and writer to use for receiving/transmitting messages.

formatter IJsonRpcMessageTextFormatter

The formatter used to serialize messages. Only UTF-8 formatters are supported.

NewLineDelimitedMessageHandler(PipeWriter?, PipeReader?, IJsonRpcMessageTextFormatter)

Initializes a new instance of the NewLineDelimitedMessageHandler class.

public NewLineDelimitedMessageHandler(PipeWriter? writer, PipeReader? reader, IJsonRpcMessageTextFormatter formatter)

Parameters

writer PipeWriter

The writer to use for transmitting messages.

reader PipeReader

The reader to use for receiving messages.

formatter IJsonRpcMessageTextFormatter

The formatter used to serialize messages. Only UTF-8 formatters are supported.

NewLineDelimitedMessageHandler(Stream, Stream, IJsonRpcMessageTextFormatter)

Initializes a new instance of the NewLineDelimitedMessageHandler class.

public NewLineDelimitedMessageHandler(Stream writer, Stream reader, IJsonRpcMessageTextFormatter formatter)

Parameters

writer Stream

The stream to use for transmitting messages.

reader Stream

The stream to use for receiving messages.

formatter IJsonRpcMessageTextFormatter

The formatter used to serialize messages. Only UTF-8 formatters are supported.

Properties

Formatter

Gets the formatter used for message serialization.

public IJsonRpcMessageTextFormatter Formatter { get; }

Property Value

IJsonRpcMessageTextFormatter

NewLine

Gets or sets the new line sequence to use to terminate a JSON-RPC message.

public NewLineDelimitedMessageHandler.NewLineStyle NewLine { get; set; }

Property Value

NewLineDelimitedMessageHandler.NewLineStyle

Methods

ReadCoreAsync(CancellationToken)

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

protected override ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to cancel the read request.

Returns

ValueTask<JsonRpcMessage>

A task whose result is the received message. A null string indicates the stream has ended. An empty string should never be returned.

Write(JsonRpcMessage, CancellationToken)

Writes a message to the pipe.

protected override void Write(JsonRpcMessage content, CancellationToken cancellationToken)

Parameters

content JsonRpcMessage

The message to write.

cancellationToken CancellationToken

A token to cancel the transmission.

Remarks

Implementations may assume the method is never called before the previous call has completed. They can assume their caller will invoke FlushAsync(CancellationToken) on their behalf after writing is completed.