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

NodeJS thrift enums not mappable back to their string values

    XMLWordPrintableJSON

Details

    Description

      While attempting to build a javascript-based web tool to read encoded thrift objects, I hit a wall. While I was able to decode from a base64 thrift string to an object, all enum fields are only in their numeral representations with no way to reverse them.

       

      Here is one example, where there is a Common.thrift file containing enums, and an Event.thrift using one of the enums from Common.thrift.

       

      Here is the generated Event_types.js:

      var Common_ttypes = require('./Common_types');
      
      var ttypes = module.exports = {};
      var Event = module.exports.Event = function(args) {
      this.id = null;
      this.type = null;
      ...
      }
      

      Here is the generated Common_types.js

      var ttypes = module.exports = {};
      ttypes.EventType = {
      'OUTBOUND' : 0,
      'INBOUND' : 1,
      }

      While Common_types is being required in Event_types, there is no use of it anywhere. The field type is solely being treated as a number:

      if (this.type !== null && this.type !== undefined) {
      output.writeFieldBegin('type', Thrift.Type.I32, 3);
      output.writeI32(this.type);
      output.writeFieldEnd();
      }
      

       

      It seems to be a bug, since I assume from the import that we would expect to use enums instead of numbers. Perhaps this is intended, but if that's the case, could this be made into a feature? The ability to know and display the enum string values instead of a number is a game changer.

      Attachments

        Activity

          People

            Unassigned Unassigned
            anthonyalayo Anthony Alayo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: