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 with a default MessagePackSerializer.
public MessagePackInputFormatter(ITypeShapeProvider typeShapeProvider)
Parameters
typeShapeProvider
ITypeShapeProvider- 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.
MessagePackInputFormatter(ITypeShapeProvider, MessagePackSerializer)
Initializes a new instance of the MessagePackInputFormatter class with the specified MessagePack serializer.
public MessagePackInputFormatter(ITypeShapeProvider typeShapeProvider, MessagePackSerializer serializer)
Parameters
typeShapeProvider
ITypeShapeProviderThe 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.
serializer
MessagePackSerializerThe serializer to use.
Exceptions
- ArgumentNullException
Thrown when
serializer
is 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
context
InputFormatterContextThe 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
context
is null.