Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputForma
request.Body.Seek(0L, SeekOrigin.Begin);
}

var result = MessagePackSerializer.NonGeneric.Deserialize(context.ModelType, request.Body, _options.FormatterResolver);
var formatterResult = await InputFormatterResult.SuccessAsync(result);

return formatterResult;
using (MemoryStream stream = new MemoryStream())
{
await request.Body.CopyToAsync(stream);
stream.Position = 0;
var result = MessagePackSerializer.NonGeneric.Deserialize(context.ModelType, stream, _options.FormatterResolver);
return await InputFormatterResult.SuccessAsync(result);
}
}

protected override bool CanReadType(Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ public MessagePackOutputFormatter(MessagePackFormatterOptions messagePackFormatt
}
}

public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

MessagePackSerializer.NonGeneric.Serialize(context.ObjectType, context.HttpContext.Response.Body, context.Object, _options.FormatterResolver);
return Task.FromResult(0);
using (MemoryStream stream = new MemoryStream())
{
MessagePackSerializer.NonGeneric.Serialize(context.ObjectType, stream, context.Object, _options.FormatterResolver);
await context.HttpContext.Response.Body.WriteAsync(stream.ToArray(), 0, (int)stream.Length);
}
}
}
}