Quantcast
Channel: User aggsol - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by aggsol for How to enable LZ4 compression for messagepack content type in Asp.net Core Web API

$
0
0

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);        }    }

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>