Class JsonMessageFormatter
- Namespace
- StreamJsonRpc
- Assembly
- StreamJsonRpc.dll
Uses Newtonsoft.Json serialization to serialize JsonRpcMessage as JSON (text).
public class JsonMessageFormatter : FormatterBase, IJsonRpcFormatterState, IJsonRpcInstanceContainer, IDisposable, IJsonRpcAsyncMessageTextFormatter, IJsonRpcAsyncMessageFormatter, IJsonRpcMessageTextFormatter, IJsonRpcMessageFormatter, IJsonRpcMessageFactory
- Inheritance
-
JsonMessageFormatter
- Implements
- Inherited Members
Remarks
Each instance of this class may only be used with a single JsonRpc instance.
Constructors
JsonMessageFormatter()
Initializes a new instance of the JsonMessageFormatter class that uses JsonProgress (without the preamble) for its text encoding.
public JsonMessageFormatter()
JsonMessageFormatter(Encoding)
Initializes a new instance of the JsonMessageFormatter class.
public JsonMessageFormatter(Encoding encoding)
Parameters
encodingEncodingThe encoding to use for the JSON text.
Properties
Encoding
Gets or sets the encoding to use for transmitted messages.
public Encoding Encoding { get; set; }
Property Value
JsonSerializer
Gets the Newtonsoft.Json.JsonSerializer used when serializing and deserializing method arguments and return values.
public JsonSerializer JsonSerializer { get; }
Property Value
- JsonSerializer
MultiplexingStream
Gets or sets the MultiplexingStream that may be used to establish out of band communication (e.g. marshal IDuplexPipe arguments).
public MultiplexingStream? MultiplexingStream { get; set; }
Property Value
ProtocolVersion
Gets or sets the version of the JSON-RPC protocol emulated by this instance.
public Version ProtocolVersion { get; set; }
Property Value
- Version
The default value is 2.0.
Methods
Deserialize(JToken)
Deserializes a Newtonsoft.Json.Linq.JToken to a JsonRpcMessage.
public JsonRpcMessage Deserialize(JToken json)
Parameters
jsonJTokenThe JSON to deserialize.
Returns
- JsonRpcMessage
The deserialized message.
Deserialize(ReadOnlySequence<byte>)
Deserializes a JsonRpcMessage.
public JsonRpcMessage Deserialize(ReadOnlySequence<byte> contentBuffer)
Parameters
contentBufferReadOnlySequence<byte>A sequence of bytes to deserialize.
Returns
- JsonRpcMessage
The deserialized JsonRpcMessage.
Deserialize(ReadOnlySequence<byte>, Encoding)
Deserializes a sequence of bytes to a JsonRpcMessage.
public JsonRpcMessage Deserialize(ReadOnlySequence<byte> contentBuffer, Encoding encoding)
Parameters
contentBufferReadOnlySequence<byte>The bytes to deserialize.
encodingEncodingThe encoding to read the bytes in
contentBufferwith. Must not be null.
Returns
- JsonRpcMessage
The deserialized message.
DeserializeAsync(PipeReader, Encoding, CancellationToken)
Deserializes a sequence of bytes to a JsonRpcMessage.
public ValueTask<JsonRpcMessage> DeserializeAsync(PipeReader reader, Encoding encoding, CancellationToken cancellationToken)
Parameters
readerPipeReaderThe reader to deserialize from.
encodingEncodingThe encoding to read the bytes from
readerwith. Must not be null.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<JsonRpcMessage>
The deserialized message.
DeserializeAsync(PipeReader, CancellationToken)
Deserializes a JsonRpcMessage.
public ValueTask<JsonRpcMessage> DeserializeAsync(PipeReader reader, CancellationToken cancellationToken)
Parameters
readerPipeReaderThe reader to deserialize from.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<JsonRpcMessage>
The deserialized JsonRpcMessage.
Dispose(bool)
Disposes managed and native resources held by this instance.
protected override void Dispose(bool disposing)
Parameters
GetJsonText(JsonRpcMessage)
Gets a JSON representation for a given message for tracing purposes.
public object GetJsonText(JsonRpcMessage message)
Parameters
messageJsonRpcMessageThe message to be traced.
Returns
- object
Any object whose ToString() method will produce a human-readable JSON string, suitable for tracing.
Serialize(JsonRpcMessage)
Serializes a JsonRpcMessage to a Newtonsoft.Json.Linq.JToken.
public JToken Serialize(JsonRpcMessage message)
Parameters
messageJsonRpcMessageThe message to serialize.
Returns
- JToken
The JSON of the message.
Serialize(IBufferWriter<byte>, JsonRpcMessage)
Serializes a JsonRpcMessage.
public void Serialize(IBufferWriter<byte> contentBuffer, JsonRpcMessage message)
Parameters
contentBufferIBufferWriter<byte>messageJsonRpcMessageThe message to serialize.