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
pipeIDuplexPipeThe reader and writer to use for receiving/transmitting messages.
formatterIJsonRpcMessageTextFormatterThe 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
writerPipeWriterThe writer to use for transmitting messages.
readerPipeReaderThe reader to use for receiving messages.
formatterIJsonRpcMessageTextFormatterThe 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
writerStreamThe stream to use for transmitting messages.
readerStreamThe stream to use for receiving messages.
formatterIJsonRpcMessageTextFormatterThe 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
NewLine
Gets or sets the new line sequence to use to terminate a JSON-RPC message.
public NewLineDelimitedMessageHandler.NewLineStyle NewLine { get; set; }
Property Value
Methods
ReadCoreAsync(CancellationToken)
Reads a distinct and complete message, waiting for one if necessary.
protected override ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA 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
contentJsonRpcMessageThe message to write.
cancellationTokenCancellationTokenA 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.