mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Move msg pack node to more supported lib msgpack-lite
This commit is contained in:
parent
dbff575e24
commit
7950b7d39a
@ -35,6 +35,6 @@
|
||||
"poplib": "^0.1.7",
|
||||
"mailparser": "^0.6.1",
|
||||
"imap": "^0.8.19",
|
||||
"msgpack-js": "^0.3.0"
|
||||
"msgpack-lite": "^0.1.26"
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,12 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="msgpack">
|
||||
<p>A function that converts the <code>msg.payload</code> to and from <a href = "https://github.com/msgpack/msgpack-node"><i>msgpack</i></a> format.</p>
|
||||
<p>A function that converts the <code>msg.payload</code> to and from
|
||||
<a href = "http://msgpack.org/"><i>msgpack</i></a> format.</p>
|
||||
<p>If the input is NOT a buffer it tries to convert it to a msgpack buffer.</p>
|
||||
<p>If the input is a msgpack buffer it tries to decode it back.</p>
|
||||
<p><b>Note</b>: this node does not currently encode raw <code>buffer</code> types.
|
||||
It will automatically try to <i>decode</i> any buffer received, and may not cause an error.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var msgpack = require('msgpack-js');
|
||||
var msgpack = require('msgpack-lite');
|
||||
|
||||
function MsgPackNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -16,15 +16,15 @@ module.exports = function(RED) {
|
||||
node.status({text:l +" b->o "+ JSON.stringify(msg.payload).length});
|
||||
}
|
||||
catch (e) {
|
||||
node.warn("Bad decode: "+e);
|
||||
node.error("Bad decode",msg);
|
||||
node.status({text:"not a msgpack buffer"});
|
||||
}
|
||||
}
|
||||
else {
|
||||
var le = JSON.stringify(msg.payload).length;
|
||||
msg.payload = msgpack.encode(msg.payload);
|
||||
node.send(msg);
|
||||
node.status({text:le +" o->b "+ msg.payload.length});
|
||||
node.send(msg);
|
||||
}
|
||||
}
|
||||
else { node.warn("No payload found to process"); }
|
||||
|
@ -10,11 +10,19 @@ Run the following command in your Node-RED user directory - typically `~/.node-r
|
||||
|
||||
npm install node-red-node-msgpack
|
||||
|
||||
Changes
|
||||
-------
|
||||
|
||||
Version 1.0.0 - move to msgpack-lite library (more supported and faster) - This uses the more
|
||||
recent msgpack specification so please ensure all your endpoints are also using the latest spec.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Uses the <a href="https://www.npmjs.org/package/msgpack">msgpack npm</a> to pack and unpack msg.payload objects to <a href="http://msgpack.org/">msgpack</a> format buffers.
|
||||
Uses the <a href="https://www.npmjs.org/package/msgpack-lite">msgpack-lite npm</a> to pack and unpack msg.payload objects to <a href="http://msgpack.org/">msgpack</a> format buffers.
|
||||
|
||||
**Note**: this node does not currently encode raw <code>buffer</code> types.
|
||||
It will automatically try to *decode* any buffer received, and may not cause an error.
|
||||
|
||||
If the input is NOT a buffer it converts it into a msgpack buffer.
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name" : "node-red-node-msgpack",
|
||||
"version" : "0.0.6",
|
||||
"version" : "1.0.0",
|
||||
"description" : "A Node-RED node to pack and unpack objects to msgpack format",
|
||||
"dependencies" : {
|
||||
"msgpack-js" : "0.3.0"
|
||||
"msgpack-lite" : "^0.1.26"
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
|
@ -66,6 +66,7 @@ describe('msgpack node', function() {
|
||||
});
|
||||
|
||||
it('should error if the buffer fails to decode', function(done) {
|
||||
buf[0] = 0x87;
|
||||
var flow = [{"id":"n1", "type":"msgpack", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
@ -77,7 +78,7 @@ describe('msgpack node', function() {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 25);
|
||||
n1.emit("input", {payload:Buffer("12345")});
|
||||
n1.emit("input", {payload:buf});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user