You have to write a custom media type formatter because the compression is used in a different module. Instead of MessagePackSerializer
you have to use LZ4MessagePackSerializer
. The usage is the same. Also the recommended MIME type is application/msgpack
.
See this basic example:
public class MsgPackMediaTypeFormatter: BufferedMediaTypeFormatter { public MsgPackMediaTypeFormatter() { SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/msgpack")); } public override bool CanReadType(Type type) { return !type.IsAbstract && !type.IsInterface && type.IsPublic; } public override bool CanWriteType(Type type) { return !type.IsAbstract && !type.IsInterface && type.IsPublic; } public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { return LZ4MessagePackSerializer.NonGeneric.Deserialize(type, readStream); } public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content) { LZ4MessagePackSerializer.NonGeneric.Serialize(type, writeStream, value, MessagePack.Resolvers.ContractlessStandardResolver.Instance); } }