Skip to content

Add SuperSocket.MQTT.Client with shared pipeline filter and E2E tests#21

Merged
kerryjiang merged 5 commits intomasterfrom
copilot/create-mqtt-client-project
Jan 31, 2026
Merged

Add SuperSocket.MQTT.Client with shared pipeline filter and E2E tests#21
kerryjiang merged 5 commits intomasterfrom
copilot/create-mqtt-client-project

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

  • Create SuperSocket.MQTT.Client project
  • Implement MQTTPacketEncoder implementing IPackageEncoder interface
  • Update MQTTPipelineFilter to use singleton MQTTPacketDecoder
  • Use UsePipelineFilter() instead of UsePipelineFilterFactory
  • Use Assembly.GetExecutingAssembly() for command assembly
  • Make MQTTPacketEncoder a singleton with static Default instance
  • Use _client.SendAsync(encoder, packet) directly instead of manual encoding
  • Add end-to-end integration tests
  • All 55 tests pass

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 31, 2026 06:31
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add SuperSocket.MQTT.Client project implementation Add SuperSocket.MQTT.Client with shared pipeline filter and E2E tests Jan 31, 2026
Copilot AI requested a review from kerryjiang January 31, 2026 06:37
/// <summary>
/// Encodes MQTT packets to bytes for transmission.
/// </summary>
public static class MQTTPacketEncoder
Copy link
Member

Choose a reason for hiding this comment

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

should implement the interface IPackageEncoder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented IPackageEncoder<MQTTPacket> interface in commit 89ffcf9.

{
return builder
.UsePipelineFilter<MQTTPipelineFilter>()
.UsePipelineFilterFactory<MQTTPipelineFilterFactory>()
Copy link
Member

Choose a reason for hiding this comment

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

UsePipelineFilter() should be enough, why do you want to use UsePipelineFilterFactory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to UsePipelineFilter<MQTTPipelineFilter>() and removed MQTTPipelineFilterFactory in commit 89ffcf9. The Decoder property now falls back to a static singleton if not set externally.

// Add all command classes from the current assembly
options.AddCommandAssembly(typeof(MQTTPacket).Assembly);
// Add all command classes from the Server assembly
options.AddCommandAssembly(typeof(SuperSocketHostBuilderExtensions).Assembly);
Copy link
Member

Choose a reason for hiding this comment

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

current executing assembly can be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to Assembly.GetExecutingAssembly() in commit 89ffcf9.

/// </summary>
public MQTTPipelineFilter()
{
Decoder = new MQTTPacketDecoder();
Copy link
Member

Choose a reason for hiding this comment

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

singleton MQTTPacketDecoder instance should be use here because MQTTPacketDecoder is stateless for different MQTTPipelineFilter instances

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use a singleton _sharedDecoder static field. The Decoder getter now returns _decoder ?? _sharedDecoder to ensure the singleton is always used as fallback. Commit 89ffcf9.

…decoder, use executing assembly

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
}

private async ValueTask SendPacketAsync(MQTTPacket packet)
{
Copy link
Member

Choose a reason for hiding this comment

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

the encoder should be assigned to pipeline filter, and send package directly using _client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the SendPacketAsync helper method and now using _client.SendAsync(MQTTPacketEncoder.Default, packet) directly in commit a8abb9d.

public class MQTTClient : IAsyncDisposable
{
private readonly IEasyClient<MQTTPacket> _client;
private readonly MQTTPacketEncoder _encoder = new MQTTPacketEncoder();
Copy link
Member

Choose a reason for hiding this comment

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

The encoder should be singleton

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made MQTTPacketEncoder a singleton with public static readonly MQTTPacketEncoder Default = new MQTTPacketEncoder() in commit a8abb9d.

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
@kerryjiang kerryjiang marked this pull request as ready for review January 31, 2026 08:20
@kerryjiang kerryjiang merged commit a5411db into master Jan 31, 2026
3 checks passed
@kerryjiang kerryjiang deleted the copilot/create-mqtt-client-project branch January 31, 2026 08:20
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.

2 participants