When publishing a message using the mqttx pub command with the format option specified, the received data differs from the original data. This issue occurs because the data read from a file is already a Buffer. However, the conversion process unnecessarily converts it to a string and back to a Buffer, 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. The convertPayload function now correctly handles the binary format without additional transformations. This fix ensures the integrity of the data during the publishing process.
Does this PR introduce a breaking change?
[ ] Yes
[x] No
Specific Instructions
None.
Other information
The updated function now:
Checks if format is specified and applies format conversion only if necessary.
Ensures messages already Buffer are not converted to strings and back to buffers, preserving data integrity.
Separates the logic into clearly defined functions for better readability and maintenance.
Reviewed and tested to ensure the input and output messages are entirely identical.
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.