Skip to content

Commit

Permalink
Update coap-in.js
Browse files Browse the repository at this point in the history
Remove payload.toString() for text/plain and unknown formats.
  • Loading branch information
JohnnyPicnic committed Aug 15, 2023
1 parent e57e611 commit a142ba4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions coap/coap-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function (RED) {
if (rawBuffer) {
return payload;
} else if (_checkContentFormat(contentFormat, "text/plain")) {
return payload.toString();
return payload;
} else if (_checkContentFormat(contentFormat, "json")) {
return JSON.parse(payload.toString());
} else if (_checkContentFormat(contentFormat, "cbor")) {
Expand All @@ -79,7 +79,7 @@ module.exports = function (RED) {
} else if (_checkContentFormat(contentFormat, "application/link-format")) {
return linkFormat.parse(payload.toString());
} else {
return payload.toString();
return payload;
}
}

Expand Down Expand Up @@ -149,13 +149,13 @@ module.exports = function (RED) {
}

if (_checkContentFormat(contentFormat, "text/plain")) {
return msg.payload.toString();
return msg.payload;
} else if (_checkContentFormat(contentFormat, "json")) {
return JSON.stringify(msg.payload);
} else if (_checkContentFormat(contentFormat, "cbor")) {
return cbor.encode(msg.payload);
} else {
return msg.payload.toString();
return msg.payload;
}
}

Expand Down

0 comments on commit a142ba4

Please sign in to comment.