6.5Adding MessagePack Support
Updated on Aug 20, 2026~4 min read
MessagePack is a compact, efficient binary serialization format designed for data exchange across multiple languages. Compared with JSON, MessagePack offers higher performance and a smaller data footprint. Although it is a binary format, MessagePack was designed with cross-language convenience in mind, and it is now widely used in many programming languages such as Python, Ruby, JavaScript, C++, and C#.
To enable MessagePack support in your project, follow these steps:
- Install the
MessagePackpackage:
dotnet add package MessagePack- Add the
MessagePackContentProcessorcontent processor:
public class MessagePackContentProcessor : HttpContentProcessorBase{ /// <inheritdoc /> public override bool CanProcess(HttpContentProcessorContext context) => context.ContentType == "application/msgpack"; /// <inheritdoc /> public override HttpContent? Process(HttpContentProcessorContext context) { // Attempt to resolve the HttpContent type if (TryProcess(context, out var httpContent)) { return httpContent; } // Convert the raw request content to a byte array var content = context.RawContent as byte[] ?? MessagePackSerializer.Serialize(context.RawContent); // Initialize a ByteArrayContent instance var byteArrayContent = new ByteArrayContent(content); byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue(context.ContentType) { CharSet = context.Encoding?.WebName }; return byteArrayContent; }}- Apply the
MessagePackContentProcessorcontent processor:
- Per-request configuration:
HttpRequestBuilder.Post("https://furion.net/") .AddHttpContentProcessors(() => [ new MessagePackContentProcessor() ]) .SetContent(new MessagePackModel { Id = 1, Name = "Furion" }, "application/msgpack");- Global configuration:
In the Startup.cs or Program.cs file, configure and register the HttpRemote service to enable the MessagePackContentProcessor content processor:
services.AddHttpRemote(builder =>{ builder.AddHttpContentProcessors(() => [ new MessagePackContentProcessor() ]);});This way you can send data in the application/msgpack format via HTTP remote requests in your project.