Unsigned integers and Int64 in node.js

1,657 views
Skip to first unread message

Tony Huang

unread,
Apr 18, 2012, 12:31:23 PM4/18/12
to nod...@googlegroups.com
Hi all,

I've implemented a binary based protocol in node.js, and I need a Int64 to present the id of the messages.

What library should I use to represent unsigned integers as well as UInt64s?

I've taken a look at the node-int64 module, but it doesn't support any calculation which is necessary in my case to decode a compressed int64.

Thank you.

Best regards.

--
------------------------------------------------------
Tony Huang    cnw...@gmail.com
                     wz...@hotmail.com
                     wz...@vip.sina.com

Paddy Byers

unread,
Apr 18, 2012, 12:48:42 PM4/18/12
to nod...@googlegroups.com
Hi,

I've implemented a binary based protocol in node.js, and I need a Int64 to present the id of the messages.

What library should I use to represent unsigned integers as well as UInt64s?

I've taken a look at the node-int64 module, but it doesn't support any calculation which is necessary in my case to decode a compressed int64.

Have you looked at Protocol Buffers? Javascript isn't one of their officially supported languages but there is an independent implementation for javascript which includes an implementation of their I64 type:


They have a variable-length wire encoding (base 128) for these as well.

I'm doing someone a bit similar for thrift's int64 type so I'm happy to contribute to a joint effort.

What kinds of calculation do you want to do?

Paddy

Chad Retz

unread,
Apr 18, 2012, 3:26:40 PM4/18/12
to nod...@googlegroups.com
I had the same problem with a binary protocol. I just gave the data back as a big numeric string and suggested he use node-bigint[1] or bigdecimal.js[2] to do more with it. Both of those support arithmetic operations.

[1] - https://github.com/substack/node-bigint
[2] - https://github.com/iriscouch/bigdecimal.js

christkv

unread,
Apr 18, 2012, 4:51:54 PM4/18/12
to nodejs
The Long class from

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

might be helpful as well it's from the google closure lib


On Apr 18, 9:26 pm, Chad Retz <chad.r...@gmail.com> wrote:
> I had the same problem with a binary protocol. I just gave the data back as
> a big numeric string and suggested he use node-bigint[1] or
> bigdecimal.js[2] to do more with it. Both of those support arithmetic
> operations.
>
> [1] -https://github.com/substack/node-bigint
> [2] -https://github.com/iriscouch/bigdecimal.js
>
>
>
>
>
>
>
> On Wednesday, April 18, 2012 11:31:23 AM UTC-5, Tony Huang wrote:
>
> > Hi all,
>
> > I've implemented a binary based protocol in node.js, and I need a Int64 to
> > present the id of the messages.
>
> > What library should I use to represent unsigned integers as well as
> > UInt64s?
>
> > I've taken a look at the node-int64 module, but it doesn't support any
> > calculation which is necessary in my case to decode a compressed int64.
>
> > Thank you.
>
> > Best regards.
>
> > --
> > ------------------------------------------------------
> > Tony Huang    cnwz...@gmail.com
> >                      wz...@hotmail.com
> >                      wz...@vip.sina.com

Tony Huang

unread,
Apr 18, 2012, 11:50:17 PM4/18/12
to nod...@googlegroups.com
The Long class just fit my requirement, thank you christ, thank you all.


--
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 nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Reply all
Reply to author
Forward
0 new messages