Table of Contents

Class NerdbankMessagePackFormatter

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

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

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

Remarks

This formatter uses the Nerdbank.MessagePack serializer.

This formatter prioritizes being trim and NativeAOT safe. As such, it uses LoadTypeTrimSafe(string, string?) instead of LoadType(string, string?) to load exception types to be deserialized. This trim-friendly method should be overridden to return types that are particularly interesting to the application.

This formatter does not support general marshalable objects yet.

Constructors

NerdbankMessagePackFormatter()

Initializes a new instance of the NerdbankMessagePackFormatter class.

public NerdbankMessagePackFormatter()

Fields

DefaultSerializer

The default serializer to use for user data, and a good basis for any custom values for UserDataSerializer.

public static readonly MessagePackSerializer DefaultSerializer

Field Value

MessagePackSerializer

Remarks

This serializer is configured with Nerdbank.MessagePack.MessagePackSerializer.InternStrings set to true and various Nerdbank.MessagePack.MessagePackSerializer.Converters and Nerdbank.MessagePack.MessagePackSerializer.ConverterFactories.

When deviating from this default, doing so while preserving the converters and converter factories from the default is highly recommended. It should be done once and stored in a static field and reused for the lifetime of the application to avoid repeated startup costs associated with building up the converter tree.

Properties

TypeShapeProvider

Gets the shape provider for user data types.

public required ITypeShapeProvider TypeShapeProvider { get; init; }

Property Value

ITypeShapeProvider

UserDataSerializer

Gets the configured serializer to use for request arguments, result values and error data.

public MessagePackSerializer UserDataSerializer { get; init; }

Property Value

MessagePackSerializer

Remarks

When setting this property, basing the new value on DefaultSerializer is highly recommended.

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> bufferWriter, JsonRpcMessage message)

Parameters

bufferWriter IBufferWriter<byte>

The receiver of the serialized bytes.

message JsonRpcMessage

The message to serialize.