Is there a simple built-in way to convert output data in to formatted data in Node.js?

51 views
Skip to first unread message

Jaydipsinh Raol

unread,
May 29, 2014, 6:19:56 AM5/29/14
to nod...@googlegroups.com

i've zmq implementation in node. i subscribe for one topic among all channels and got message in slow buffer object.

if i directly print that message on console, i got something like this.

<SlowBuffer 49 12 00 00 5a 00 00 00 00 00 00 00 00 00 00 01>

so this is slowbuffer object containing raw data. and i'm trying to convert it in readable format.

here is my code

console.log("Type of Message "+err.readInt8(0));
        console.log("action "+err.readInt8(1));
        var temp = "";
        var s = ""
        for (var i=0;i<8;i++) {
            temp += err.readInt8(i + 8)

        }
        console.log("dpid "+temp);

output

Type of Message 73
action 18
dpid 00000003

now i have to format dpid in 00:00:00:00:00:00:00:02 this format. it may contain character and digit, hexadecimal. so i have to convert dpid to hexa decimal and check whether it is two character then oky otherwise i have to add extra "0" at front. something like that. i'm very new to this concepts. i don't know how to do this ?

please help me.

Darren DeRidder

unread,
Jun 1, 2014, 10:32:13 AM6/1/14
to nod...@googlegroups.com
Did you use '.toString()' when logging the message to the console?
See https://github.com/JustinTulloss/zeromq.node/issues/52
Reply all
Reply to author
Forward
0 new messages