Git Product home page Git Product logo

Comments (6)

dcodeIO avatar dcodeIO commented on July 23, 2024

The problem is that there is no true long support in JavaScript, as it falls back to double at values greater than 2^53. See: http://ecma262-5.com/ELS5_HTML.htm#Section_8.5

Therefore I decided to skip int64 for the moment and I am thinking about implementing the math long class from the closure library into ByteBuffer.js. It's just that I am not yet sure if it's worth the trouble because when working with JavaScript, it's simply better to use a double instead for large values. If you are working on something entirely new, it might already be an option for you to use a double.

from protobuf.js.

tiantian20007 avatar tiantian20007 commented on July 23, 2024

How about use int64 in c-types:
https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/Int64
I'm not sure it works on other js platform such as chrome or nodeJS.
Actually I'm developing a game using cocos2dx with its js-binding base on SpiderMonkey:https://developer.mozilla.org/en/docs/SpiderMonkey
And our publisher need the user_id to be int64.

from protobuf.js.

dcodeIO avatar dcodeIO commented on July 23, 2024

I took a look but it doesn't seem that it's possible to do the required calculations on it, i.e. for varint encoding, and its available for spidermonkey only. However, you could use c-types on your own and transfer the values as custom types, let's say in a "bytes" field. Bytes fields take ArrayBuffers or ByteBuffers of arbitrary data. You could simply write the .hi() and .lo() portions into a ByteBuffer for example.

from protobuf.js.

dcodeIO avatar dcodeIO commented on July 23, 2024

I just finished int64 support in ByteBuffer.js through Long.js. For now, it's possible to work with sfixed64 fields.

However, this solves only a part of the overall 64bit support. I've added a comment with the details here: https://github.com/dcodeIO/ProtoBuf.js/blob/master/src/ProtoBuf/Lang.js

from protobuf.js.

dcodeIO avatar dcodeIO commented on July 23, 2024

0.9.13: fixed64 (uint64) through ByteBuffer.js>=1.2.1, Long.js>=1.1.0

from protobuf.js.

dcodeIO avatar dcodeIO commented on July 23, 2024

see

from protobuf.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.