chrisdew / protobuf

Protocol Buffers for Node.JS
http://code.google.com/p/protobuf-for-node/
Apache License 2.0
234 stars 71 forks source link

Use Number present uint64 and int64, when they are safe numbers (-2^53 < n < 2^53) #35

Closed fengmk2 closed 1 year ago

fengmk2 commented 10 years ago

In 90% cases, the (u)int64 numbers are small integer. I think we should use Number to present them when they are safe in Javascript.

alsotang commented 10 years ago

+1

chrisdew commented 10 years ago

Good idea, I'll test and merge next week.

fengmk2 commented 10 years ago

Cool, finally

imkira commented 10 years ago

This would actually be a problem for me since I am assuming they will (as they are already in the current version of the package) converted to String no matter what. Would it be possible to make this backwards compatible by enabling conversion to Number only by enabling some kind of option?

require('protobuf').uint64ToNumber = true

kinda thing?

alsotang commented 10 years ago

agree @imkira . I think uint64ToNumber flas is necessary, and by default protobuf should return String. Otherwise its behavior is inconsistency

chrisdew commented 10 years ago

I'll not merge this, as it will break code for others.

We need a well-thought-out system for letting the module user decide how they want uint64s, enums and other types represented.

I do not have time to do this at the moment.

fengmk2 commented 10 years ago

How about add the options like @imkira says 'uint64ToNumber = true' ?

chrisdew commented 10 years ago

@fengmk2 We need at least:

uint64ToNumber = true sint64ToNumber = true enumToNumber = true

Should these be at the module level, per-schema or per-parse?

fengmk2 commented 10 years ago

module level will be good 2014-5-7 下午5:25于 "Chris Dew" notifications@github.com写道:

@fengmk2 https://github.com/fengmk2 We need at least:

uint64ToNumber = true sint64ToNumber = true enumToNumber = true

Should these be at the module level, per-schema or per-parse?

— Reply to this email directly or view it on GitHubhttps://github.com/chrisdew/protobuf/pull/35#issuecomment-42406251 .