Class MessagePackInputFormatter
- Namespace
- Nerdbank.MessagePack.AspNetCoreMvcFormatter
- Assembly
- Nerdbank.MessagePack.AspNetCoreMvcFormatter.dll
An input formatter for ASP.NET Core MVC that deserializes MessagePack content into strongly-typed objects.
public class MessagePackInputFormatter : InputFormatter, IInputFormatter, IApiRequestFormatMetadataProvider
- Inheritance
-
MessagePackInputFormatter
- Implements
- Inherited Members
Remarks
This formatter supports the "application/x-msgpack" media type and uses the provided ITypeShapeProvider to resolve type shapes for deserialization with the specified MessagePackSerializer.
Constructors
MessagePackInputFormatter(ITypeShapeProvider)
Initializes a new instance of the MessagePackInputFormatter class.
public MessagePackInputFormatter(ITypeShapeProvider typeShapeProvider)
Parameters
typeShapeProviderITypeShapeProvider- The type shape provider used to resolve type shapes for deserialization. This may be Default but is recommended to be a source generated type shape provider for better startup performance.
Remarks
The MessagePackSerializer this constructor initializes includes converters commonly useful to ASP.NET Core MVC scenarios, including WithObjectConverter(MessagePackSerializer).
MessagePackInputFormatter(ITypeShapeProvider, MessagePackSerializer)
Initializes a new instance of the MessagePackInputFormatter class with the specified MessagePack serializer.
public MessagePackInputFormatter(ITypeShapeProvider typeShapeProvider, MessagePackSerializer serializer)
Parameters
typeShapeProviderITypeShapeProviderThe type shape provider used to resolve type shapes for deserialization. This may be Default but is recommended to be a source generated type shape provider for better startup performance.
serializerMessagePackSerializerThe serializer to use.
Exceptions
- ArgumentNullException
Thrown when
serializeris null.
Methods
ReadRequestBodyAsync(InputFormatterContext)
Reads and deserializes the request body from MessagePack format into the target model type.
public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
Parameters
contextInputFormatterContextThe input formatter context containing the HTTP request and model type information.
Returns
- Task<InputFormatterResult>
A task that represents the asynchronous read operation. The task result contains an InputFormatterResult indicating success and the deserialized model object.
Remarks
This method creates a PipeReader from the request body stream, resolves the type shape for the target model type, and uses the configured MessagePack serializer to deserialize the content asynchronously.
Exceptions
- ArgumentNullException
Thrown when
contextis null.