Table of Contents

Class MessagePackFormatter

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

Serializes JSON-RPC messages using MessagePack (a fast, compact binary format).

public class MessagePackFormatter : FormatterBase, IJsonRpcFormatterState, IJsonRpcInstanceContainer, IDisposable, IJsonRpcMessageFormatter, IJsonRpcFormatterTracingCallbacks, IJsonRpcMessageFactory
Inheritance
MessagePackFormatter
Implements
Inherited Members

Remarks

The MessagePack implementation used here comes from https://github.com/neuecc/MessagePack-CSharp. The README on that project site describes use cases and its performance compared to alternative .NET MessagePack implementations and this one appears to be the best by far.

Constructors

MessagePackFormatter()

Initializes a new instance of the MessagePackFormatter class.

public MessagePackFormatter()

Properties

DefaultUserDataSerializationOptions

Gets the default MessagePack.MessagePackSerializerOptions used for user data (arguments, return values and errors) in RPC calls prior to any call to SetMessagePackSerializerOptions(MessagePackSerializerOptions).

public static MessagePackSerializerOptions DefaultUserDataSerializationOptions { get; }

Property Value

MessagePackSerializerOptions

This is MessagePack.Resolvers.StandardResolverAllowPrivate.Options modified to use the MessagePack.MessagePackSecurity.UntrustedData security setting.

InternStrings

Gets or sets a value indicating whether user data should be deserialized with string interning.

public bool InternStrings { get; set; }

Property Value

bool

The default value is true.

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

MultiplexingStream

TraceParentAsW3CString

Gets a value indicating whether the W3C traceparent property should be serialized as a string instead of a more compact binary format.

public bool TraceParentAsW3CString { get; init; }

Property Value

bool

The default value is false.

Methods

Deserialize(ReadOnlySequence<byte>)

Deserializes a JsonRpcMessage.

public JsonRpcMessage Deserialize(ReadOnlySequence<byte> contentBuffer)

Parameters

contentBuffer ReadOnlySequence<byte>

A sequence of bytes to deserialize.

Returns

JsonRpcMessage

The deserialized JsonRpcMessage.

GetJsonText(JsonRpcMessage)

Gets a JSON representation for a given message for tracing purposes.

public object GetJsonText(JsonRpcMessage message)

Parameters

message JsonRpcMessage

The message to be traced.

Returns

object

Any object whose ToString() method will produce a human-readable JSON string, suitable for tracing.

Serialize(IBufferWriter<byte>, JsonRpcMessage)

Serializes a JsonRpcMessage.

public void Serialize(IBufferWriter<byte> contentBuffer, JsonRpcMessage message)

Parameters

contentBuffer IBufferWriter<byte>
message JsonRpcMessage

The message to serialize.

SetMessagePackSerializerOptions(MessagePackSerializerOptions)

Sets the MessagePack.MessagePackSerializerOptions to use for serialization of user data.

public void SetMessagePackSerializerOptions(MessagePackSerializerOptions options)

Parameters

options MessagePackSerializerOptions

The options to use. Before this call, the options used come from DefaultUserDataSerializationOptions.