Skip to content

Add async MessagePack converter for method parameters#587

Draft
Copilot wants to merge 20 commits into
mainfrom
copilot/msgpack
Draft

Add async MessagePack converter for method parameters#587
Copilot wants to merge 20 commits into
mainfrom
copilot/msgpack

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 31, 2026

Review feedback called for MethodParameters to use a custom Nerdbank.MessagePack converter that delegates each parameter to its declared type converter, carries operation metadata via SerializationContext, and supports async serialization.

  • Method parameter conversion

    • Added custom MethodParameters converters on client and server.
    • Serialize/deserialize parameter maps by parameter name.
    • Delegate each value to the converter for the declared parameter type.
  • Async and security handling

    • Implemented async converter paths.
    • Added DepthStep() and cancellation-aware async buffering/flush behavior.
  • Wire schema and cleanup

    • Updated MessagePack docs to describe typed values instead of raw payload bytes.
    • Addressed open CodeQL cleanup comments in MessagePack type-shape support.

Copilot AI linked an issue May 31, 2026 that may be closed by this pull request
1 task
Co-authored-by: Daniel-Svensson <3167509+Daniel-Svensson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add MessagePack serialization as optional wire format Add optional MessagePack wire format for AspNetCore hosting and HTTP domain clients May 31, 2026
Copilot AI requested a review from Daniel-Svensson May 31, 2026 13:18
@Daniel-Svensson
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@Daniel-Svensson Daniel-Svensson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address review comments

}

using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var envelope = (MessagePackResponseEnvelope)_serializer.DeserializeObject(stream, _typeShapeProvider.GetTypeShapeOrThrow(typeof(MessagePackResponseEnvelope)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create Request and Response types for Query, Invoke and Submit Operations.

For queries you can create a derived generic QueryCompletedResult

  • Try to use PolyType attributes to annotate the Request and Response types
  • If PolyType attributes is not enough (such as for request where parameters of type IDictionary<string,object>) is passed then consider custom Converters https://aarnott.github.io/Nerdbank.MessagePack/docs/custom-converters.html might be needed for serializing requests and deserializing responsees (in client project)
  • Any converter must support async operation and follow security recommendations

In Hosting.AspNetCore the converters must deserialize requests and serialize responses.
In the server consider creating a FaultResponse class.


internal sealed class MessagePackRequestEnvelope
{
public Dictionary<string, byte[]?>? Parameters { get; set; } = new(StringComparer.Ordinal);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change type to a new class "MethodParameters", and write a custom Converter for the type.

You should pass in DomainOperationEntry _operation to the MessagePackSerializers SerializationContext

Then the type should be serialized/deserialized as a map with keys set to parameter names ,
the actual data should be serialized by delegating to converter registered for the ParameterType of the corresponding "Parameters" on the DomainOperationEntry.

Co-authored-by: Daniel-Svensson <3167509+Daniel-Svensson@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 31, 2026

@copilot please address review comments

Implemented the requested review updates in commit c87adeb (async MessagePack stream usage, operation-specific request/response envelope types, server FilteredTypeShapeProvider wrapping/caching, and updated serialization tests).

Copilot AI and others added 2 commits May 31, 2026 19:50
Co-authored-by: Daniel-Svensson <3167509+Daniel-Svensson@users.noreply.github.com>
Co-authored-by: Daniel-Svensson <3167509+Daniel-Svensson@users.noreply.github.com>
Copilot AI changed the title Add optional MessagePack wire format for AspNetCore hosting and HTTP domain clients Add async MessagePack converter for method parameters May 31, 2026
var provider = ReflectionTypeShapeProvider.Default;
var responseType = typeof(MessagePackInvokeResponseEnvelope<>).MakeGenericType(resultType);
dynamic response = serializer.DeserializeObject(payload, provider.GetTypeShapeOrThrow(responseType));
return (string)response.Result;
// If the name is new then should a separate property be added
//

string _name = (inner.AttributeProvider.GetCustomAttribute<IncludeAttribute>() is IncludeAttribute includeAttribute
Comment on lines +45 to +49
catch (System.Exception)
{
// Ignore throwing domain services
continue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea: MessagePack serialization

3 participants