Class MessagePackConverter
- Namespace
- Nerdbank.MessagePack
- Assembly
- Nerdbank.MessagePack.dll
A non-generic, object-based base class for all message pack converters.
public abstract class MessagePackConverter
- Inheritance
-
MessagePackConverter
- Derived
- Inherited Members
Properties
PreferAsyncSerialization
Gets a value indicating whether callers should prefer the async methods on this object.
public abstract bool PreferAsyncSerialization { get; }
Property Value
Remarks
Derived types that override the WriteObjectAsync(MessagePackAsyncWriter, object?, SerializationContext) and/or ReadObjectAsync(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.
public abstract 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
ReadObject(ref MessagePackReader, SerializationContext)
Deserializes an instance of an object.
public abstract object? ReadObject(ref MessagePackReader reader, SerializationContext context)
Parameters
reader
MessagePackReaderThe reader to use.
context
SerializationContextContext for the deserialization.
Returns
- object
The deserialized value.
ReadObjectAsync(MessagePackAsyncReader, SerializationContext)
Deserializes an instance of an object.
public abstract ValueTask<object?> ReadObjectAsync(MessagePackAsyncReader reader, SerializationContext context)
Parameters
reader
MessagePackAsyncReaderThe reader to use.
context
SerializationContextContext for the deserialization.
Returns
SkipToIndexValueAsync(MessagePackAsyncReader, object?, SerializationContext)
Skips ahead in the msgpack data to the point where the value at the specified index can be read.
public abstract ValueTask<bool> SkipToIndexValueAsync(MessagePackAsyncReader reader, object? index, SerializationContext context)
Parameters
reader
MessagePackAsyncReaderThe reader.
index
objectThe key or index of the value to be retrieved.
context
SerializationContextThe serialization context.
Returns
- ValueTask<bool>
true if the specified index was found in the data and the value is ready to be read; false otherwise.
Remarks
This method is used by DeserializeEnumerableAsync<T, TElement>(PipeReader, ITypeShape<T>, StreamingEnumerationOptions<T, TElement>, CancellationToken) to skip to the starting position of a sequence that should be asynchronously enumerated.
SkipToPropertyValueAsync(MessagePackAsyncReader, IPropertyShape, SerializationContext)
Skips ahead in the msgpack data to the point where the value of the specified property can be read.
public abstract ValueTask<bool> SkipToPropertyValueAsync(MessagePackAsyncReader reader, IPropertyShape propertyShape, SerializationContext context)
Parameters
reader
MessagePackAsyncReaderThe reader.
propertyShape
IPropertyShapeThe shape of the property whose value is to be skipped to.
context
SerializationContextThe serialization context.
Returns
- ValueTask<bool>
true if the specified property was found in the data and the value is ready to be read; false otherwise.
Remarks
WriteObject(ref MessagePackWriter, object?, SerializationContext)
Serializes an instance of an object.
public abstract void WriteObject(ref MessagePackWriter writer, object? value, SerializationContext context)
Parameters
writer
MessagePackWriterThe writer to use.
value
objectThe value to serialize.
context
SerializationContextContext for the serialization.
Remarks
Implementations of this method should not flush the writer.
WriteObjectAsync(MessagePackAsyncWriter, object?, SerializationContext)
Serializes an instance of an object.
public abstract ValueTask WriteObjectAsync(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.
Remarks
Implementations of this method should not flush the writer.