Allow user properties as pre-encoded UTF-8 binary buffer
Issue: When extensively using MQTT v5 user properties, handling the key and value as string has two major downsides (allocation time and garbage collection). Keys can use string interning or defined as const but the values (when they are changing) can cause high allocation rate and latency spikes when the garbage collector has to collect them.
Proposal:
Allow value of MQTT v5 user properties to be added as bytes (pre-encoded UTF-8 binary buffer), using performance optimized dotnet types like ReadOnlyMemory
Outlook:
The current implementation optimizes the MQTT message send path, it would be also possible to optimize the receive path and handling values of user properties only as ReadOnlyMemory
Pull Request contains the implementation of the proposal, including tests for binary user properties, a sample demonstrating publishing a message with binary user properties (Samples/Client/Client_Publish_Samples.cs) and minor fixes for consistency and correctness.
@dotnet-policy-service agree
There is a breaking change in dotnet 10, that doesn't allow VSTest runner when using dotnet test. It is recommended to switch to Microsoft.Test.Platform (MTP). I made the required changes in this PR, that the test github workflow can run successfully.
Details under: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test
Avoid failing build workflow, by only signing the package when executing the pipeline from the main repo, not from a fork
Had to update a few more places, that also the samples and tests use only the nonobsolete methods