Reputation: 19975
I am using the package:
http://bigeasy.github.io/packet
On the documentation it says parsing is done by:
parser.packet("pkt_id", "x16, l16 => id");
...
parser.parse(buffer);
...
parser.extract("pkt_id", function (packet) {...
But how do I serialize data and send it as buffer?
I tried
var stuff = serializer("pkt_id", {var1, var2});
socket.write(stuff);
But it is just wrong, I can't find it anywhere in the documentation on how to pack data and build it into a buffer and send it to the client.
Upvotes: 1
Views: 3586
Reputation: 10481
You can create a Buffer
in node thusly:
var stuff = serializer("pkt_id", "this should be a string");
socket.write(new Buffer(stuff, 'binary');
For more on the Buffer
global object, check the docs:
http://nodejs.org/api/buffer.html
Upvotes: 1