Interface IMessagePackConverter
- Namespace
- Nerdbank.MessagePack
- Assembly
- Nerdbank.MessagePack.dll
A non-generic, object-based interface for all message pack converters.
public interface IMessagePackConverter
Properties
PreferAsyncSerialization
Gets a value indicating whether callers should prefer the async methods on this object.
bool PreferAsyncSerialization { get; }
Property Value
Remarks
Derived types that override the WriteAsync(MessagePackAsyncWriter, object?, SerializationContext) and/or ReadAsync(MessagePackAsyncReader, SerializationContext) methods should also override this property and have it return true.
Methods
GetJsonSchema(JsonSchemaContext, ITypeShape)
Gets the JSON schema that resembles the data structure that this converter can serialize and deserialize.
JsonObject? GetJsonSchema(JsonSchemaContext context, ITypeShape typeShape)
Parameters
context
JsonSchemaContextA means to obtain schema fragments for inclusion when your converter delegates to other converters.
typeShape
ITypeShapeThe shape of the type
T
, in case it provides useful metadata for constructing the schema.
Returns
- JsonObject
The fragment of JSON schema that describes the value written by this converter, or null if this method has not been overridden.
Remarks
Implementations should return a new instance of JsonObject that represents the JSON schema fragment for every caller. A shared instance may be used to call DeepClone() and the result returned.
The type
property should not include "null" on account of the converted type being a reference type.
It is the consumer of the object that will determine whether null is an acceptable value of the object.
Custom converters that do not override this method will lead to a JSON schema that does not describe the written data, and allows any data as input.
If the converter delegates to other converters, the schemas for those sub-values can be obtained for inclusion in the returned schema
by calling GetJsonSchema(ITypeShape) on the context
.
- See Also
Read(ref MessagePackReader, SerializationContext)
Deserializes an instance of an object.
object? Read(ref MessagePackReader reader, SerializationContext context)
Parameters
reader
MessagePackReaderThe reader to use.
context
SerializationContextContext for the deserialization.
Returns
- object
The deserialized value.
ReadAsync(MessagePackAsyncReader, SerializationContext)
Deserializes an instance of an object.
ValueTask<object?> ReadAsync(MessagePackAsyncReader reader, SerializationContext context)
Parameters
reader
MessagePackAsyncReaderThe reader to use.
context
SerializationContextContext for the deserialization.
Returns
Write(ref MessagePackWriter, object?, SerializationContext)
Serializes an instance of an object.
void Write(ref MessagePackWriter writer, object? value, SerializationContext context)
Parameters
writer
MessagePackWriterThe writer to use.
value
objectThe value to serialize.
context
SerializationContextContext for the serialization.
WriteAsync(MessagePackAsyncWriter, object?, SerializationContext)
Serializes an instance of an object.
ValueTask WriteAsync(MessagePackAsyncWriter writer, object? value, SerializationContext context)
Parameters
writer
MessagePackAsyncWriterThe writer to use.
value
objectThe value to serialize.
context
SerializationContextContext for the serialization.
Returns
- ValueTask
A task that tracks the asynchronous operation.