Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3048

NodeJS decoding of I64 is inconsistent across protocols

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.2
    • Fix Version/s: 0.9.3
    • Component/s: Node.js - Library
    • Labels:
      None

      Description

      The NodeJS libraries decode i64 differently between protocols. The TCompactProtocol returns a number whereas TBinaryProtocol and TJSONProtocol return an object

      Compact: https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/compact_protocol.js#L815

      Binary: https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/binary_protocol.js#L273

      JSON:
      https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/json_protocol.js#L664

      This leads to a lack interoperability when switching between protocols:

      service BTest {
        bool testMethod (
          1: string protocol
          2: i64 int64
        );
      }
      
      var handlers = {
        testMethod: function(desc, int64, callback) {
          console.log(util.format('%s: %d, %s', desc, int64, typeof int64));
          callback(null, true);
        }
      };
      
      var startServer = function(callback){
        var serverOptions = {
          services: {
            '/thrift': {
              handler: handlers,
              processor: BTest,
              protocol: thrift.TCompactProtocol,
              transport: thrift.TBufferedTransport
            },
            '/thrift.binary': {
              handler: handlers,
              processor: BTest,
              protocol: thrift.TBinaryProtocol,
              transport: thrift.TBufferedTransport
            }
          }
        };
      
        this.server = thrift.createWebServer(serverOptions);
        this.server.listen(9887, function serverCreated(){
          callback();
        }.bind(this));
      };
      

      Client side:

        compactClient.testMethod('compact small', 123);
        binaryClient.testMethod('binary small', 456);
      
        compactClient.testMethod('compact', 4294967297);
        binaryClient.testMethod('binary', 4294967297);
      
        compactClient.testMethod('compact large', 3.602879702e16);
        binaryClient.testMethod('binary large', 3.602879702e16);
      

      Results (0.9.2 and 1.0-dev):

      compact small: 123, number
      binary small: 456, object
      compact: 4294967297, number
      binary: 4294967297, object
      binary large: Infinity, object
      

        Attachments

          Activity

            People

            • Assignee:
              codesf Randy Abernethy
              Reporter:
              Willyham Will Demaine
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: