FAQ
Hi,

I'm trying out nodejs as a TCP server. The client server protocol is binary
and the first value is a unsigned 64bit integer. The actual value in this 8
byte's is a unix epoch such as 1340304234643. The bytes are in network byte
order/big endian.

Is there anyway that I'm going to be able to read this value in nodejs?

Thanks

Ben

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Ben Short at Jun 21, 2012 at 7:48 pm
    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js
    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Tim Caswell at Jun 21, 2012 at 8:04 pm
    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)
    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Nathan Rajlich at Jun 21, 2012 at 8:53 pm
    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Short at Jun 21, 2012 at 9:06 pm
    Thanks Nathan that looks like just what I'm after.
    On 21 June 2012 21:52, Nathan Rajlich wrote:

    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Short at Jun 21, 2012 at 9:14 pm
    Nathan,

    I'm trying this code:

    var eventTimeStamp = buffer.readUInt64BE(0);

    but get the following error:

    var eventTimeStamp = buffer.readUInt64BE(0);
    ^
    TypeError: Object

    What am I missing?

    Ben

    On 21 June 2012 22:06, Ben Short wrote:

    Thanks Nathan that looks like just what I'm after.

    On 21 June 2012 21:52, Nathan Rajlich wrote:

    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Nathan Rajlich at Jun 21, 2012 at 9:24 pm
    Ben, can you tell me what "ref.endianness" is reporting on your machine? If
    it's "LE" then I'll need to make an update to "ref" to support the
    non-native-endian read/write functions. It's been on my todo list, just
    haven't had a need yet. Gimme a minute...
    On Thu, Jun 21, 2012 at 2:14 PM, Ben Short wrote:

    Nathan,

    I'm trying this code:

    var eventTimeStamp = buffer.readUInt64BE(0);

    but get the following error:

    var eventTimeStamp = buffer.readUInt64BE(0);
    ^
    TypeError: Object

    What am I missing?

    Ben

    On 21 June 2012 22:06, Ben Short wrote:

    Thanks Nathan that looks like just what I'm after.

    On 21 June 2012 21:52, Nathan Rajlich wrote:

    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in
    nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Nathan Rajlich at Jun 21, 2012 at 10:13 pm
    Ok Ben, try out v0.0.18 of ref. It adds the "non-native-endianness" version
    of those read/write functions as well. Cheers!
    On Thu, Jun 21, 2012 at 2:23 PM, Nathan Rajlich wrote:

    Ben, can you tell me what "ref.endianness" is reporting on your machine?
    If it's "LE" then I'll need to make an update to "ref" to support the
    non-native-endian read/write functions. It's been on my todo list, just
    haven't had a need yet. Gimme a minute...

    On Thu, Jun 21, 2012 at 2:14 PM, Ben Short wrote:

    Nathan,

    I'm trying this code:

    var eventTimeStamp = buffer.readUInt64BE(0);

    but get the following error:

    var eventTimeStamp = buffer.readUInt64BE(0);
    ^
    TypeError: Object

    What am I missing?

    Ben

    On 21 June 2012 22:06, Ben Short wrote:

    Thanks Nathan that looks like just what I'm after.

    On 21 June 2012 21:52, Nathan Rajlich wrote:

    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a native
    javascript number. JS numbers are defined to be double floats. (though I
    head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol is
    binary and the first value is a unsigned 64bit integer. The actual value in
    this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in
    nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Short at Jun 22, 2012 at 7:20 am
    Nathan,

    ref.endianness reports LE.

    I upgraded to v 0.0.18 and the code works as expected.

    Many thanks

    Ben


    On 21 June 2012 23:12, Nathan Rajlich wrote:

    Ok Ben, try out v0.0.18 of ref. It adds the "non-native-endianness"
    version of those read/write functions as well. Cheers!

    On Thu, Jun 21, 2012 at 2:23 PM, Nathan Rajlich wrote:

    Ben, can you tell me what "ref.endianness" is reporting on your machine?
    If it's "LE" then I'll need to make an update to "ref" to support the
    non-native-endian read/write functions. It's been on my todo list, just
    haven't had a need yet. Gimme a minute...

    On Thu, Jun 21, 2012 at 2:14 PM, Ben Short wrote:

    Nathan,

    I'm trying this code:

    var eventTimeStamp = buffer.readUInt64BE(0);

    but get the following error:

    var eventTimeStamp = buffer.readUInt64BE(0);
    ^
    TypeError: Object

    What am I missing?

    Ben

    On 21 June 2012 22:06, Ben Short wrote:

    Thanks Nathan that looks like just what I'm after.

    On 21 June 2012 21:52, Nathan Rajlich wrote:

    My "ref"[1] module can do this. It extends Buffer.prototype with the
    missing {read,write}{U}Int64{LE,BE] functions by calling into native
    functions. It can accept Strings with big integers inside of it and it will
    strtoll or strtoull the value in C-land. It also returns Strings when the
    value being returned is outside the range of a valid JS Number.

    Cheers!

    1: https://github.com/TooTallNate/ref
    On Thu, Jun 21, 2012 at 1:04 PM, Tim Caswell wrote:

    Keep in mind that you'll lose precision when converting it to a
    native javascript number. JS numbers are defined to be double floats.
    (though I head long type is coming in future JS)

    On Thu, Jun 21, 2012 at 2:48 PM, Ben Short wrote:

    After searching this group I got it to work using the long class [1]

    code snipit:

    var Long = require('./long.js').Long;

    var high = buffer.readUInt32BE(0);
    var low = buffer.readUInt32BE(4);

    var l = Long.fromBits(low, high);

    var timestamp = l.toNumber();


    [1] https://github.com/mongodb/js-bson/blob/master/lib/bson/long.js

    On Thursday, June 21, 2012 8:15:05 PM UTC+1, Ben Short wrote:

    Hi,

    I'm trying out nodejs as a TCP server. The client server protocol
    is binary and the first value is a unsigned 64bit integer. The actual value
    in this 8 byte's is a unix epoch such as 1340304234643. The bytes are in
    network byte order/big endian.

    Is there anyway that I'm going to be able to read this value in
    nodejs?

    Thanks

    Ben
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedJun 21, '12 at 7:36p
activeJun 22, '12 at 7:20a
posts9
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase