Skip to content

Conversation

ysfscream
Copy link
Member

PR Checklist

If you have any questions, you can refer to the Contributing Guide

What is the current behavior?

MQTTX CLI currently lacks the capability to display and generate payload sizes. Users cannot easily view message sizes or generate payloads of specific sizes for testing purposes.

Issue Number

Example: #123

What is the new behavior?

New Features:

  1. Payload Size Display: The sub command now shows message payload sizes in human-readable format (e.g., "1.5KB", "2.3MB")
  2. Payload Size Generation: Added support for generating random payloads of specified sizes

CLI Usage:

  • Subscribe with size display: mqttx sub -t topic (automatically shows payload sizes)
❯ mqttx sub -t test --format base64
✔ Connected
✔ Subscribed to test
topic: test, qos: 0, size: 10B
C/3OGIJyOcbebQ==
  • Generate payload: Use size format like 1KB, 2.5MB, 512B, or plain numbers (defaults to bytes)
❯ mqttx pub -t test --payload-size 10B
✔ Generated random payload of 10B.
✔ Connected
✔ Message published

❯ mqttx bench pub -c 5 -t "test" --payload-size 1KB
✔ Generated random payload of 1KB.
❯  Starting publish benchmark, connections: 5, req interval: 10ms, message interval: 1000ms
✔  [5/5] - Connected
✔  Created 5 connections in 0.695s
Published total: 15, message rate: 5/s

Technical Additions:

  • formatBytes(): Converts bytes to human-readable format with proper decimal handling
  • parsePayloadSize(): Parses size strings (supports B/KB/MB/GB, case-insensitive)
  • generateRandomPayload(): Creates random payloads with MQTT size limit validation

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

The new payload size utilities are fully backward compatible. The sub command output now includes size information without affecting existing functionality.

Other information

All new functions include comprehensive test coverage with 37+ test cases covering edge cases, error handling, and various size formats.

@ysfscream ysfscream added this to the v1.12.0 milestone Jun 6, 2025
@ysfscream ysfscream requested review from Red-Asuka and Copilot June 6, 2025 07:29
@ysfscream ysfscream self-assigned this Jun 6, 2025
@ysfscream ysfscream added feature This pr is a feature CLI MQTTX CLI labels Jun 6, 2025
@ysfscream ysfscream added this to MQTTX Jun 6, 2025
@ysfscream ysfscream moved this to In Progress in MQTTX Jun 6, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new payload size feature for the MQTTX CLI, enabling users to view message payload sizes in human-readable format and generate random payloads of specified sizes.

  • Adds utility functions to parse and format payload sizes.
  • Integrates payload size display in the subscribe command and payload generation in the publish/benchmark commands.
  • Updates tests to cover edge cases for payload size parsing and random payload generation.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cli/src/utils/payloadGenerator.ts Implements functions for parsing payload size strings and generating random payloads.
cli/src/utils/formatter.ts Provides a utility for formatting bytes into human-readable strings.
cli/src/lib/sub.ts Enhances subscription output to display payload size information.
cli/src/lib/pub.ts Adds logic to generate and use random payload based on provided size options.
cli/src/index.ts Registers new CLI options for payload size handling.
cli/src/tests/utils/*.test.ts Adds comprehensive tests for the new payload size functionalities.

@Red-Asuka Red-Asuka merged commit d420512 into main Jun 7, 2025
8 checks passed
@Red-Asuka Red-Asuka deleted the ysf/cli branch June 7, 2025 00:18
@github-project-automation github-project-automation bot moved this from In Progress to Done in MQTTX Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI MQTTX CLI feature This pr is a feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants