fix(cli): correct data conversion for publishing messages with format #1695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
When publishing a message using the
mqttx pub
command with theformat
option specified, the received data differs from the original data. This issue occurs because the data read from a file is already aBuffer
. However, the conversion process unnecessarily converts it to a string and back to aBuffer
, causing data corruption.Issue Number
Example: #1692 #1694
What is the new behavior?
The new behavior ensures that unnecessary conversions are avoided when a message is read from a file and the
format
option is specified. TheconvertPayload
function now correctly handles thebinary
format without additional transformations. This fix ensures the integrity of the data during the publishing process.Does this PR introduce a breaking change?
Specific Instructions
None.
Other information
The updated function now:
format
is specified and applies format conversion only if necessary.Buffer
are not converted to strings and back to buffers, preserving data integrity.Reviewed and tested to ensure the input and output messages are entirely identical.