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

Compiled javascript code does not write falsy values

    XMLWordPrintableJSON

Details

    Description

      I compiled cassandra.thrift using "thrift --gen js:node cassandra.thrift".

      When I use this code this results in the following error from cassandra / thrift:

      { name: 'TApplicationException',  type: 7,
        message: 'Required field \'reversed\' was not found in serialized data! Struct : SliceRange(start:null, finish:null, reversed:false, count:100)' }
      

      If I look in the generated code, I find

      SliceRange.prototype.write = function(output) {
        output.writeStructBegin('SliceRange');
        if (this.start) {
          output.writeFieldBegin('start', Thrift.Type.STRING, 1);
          output.writeString(this.start);
          output.writeFieldEnd();
        }
        if (this.finish) {
          output.writeFieldBegin('finish', Thrift.Type.STRING, 2);
          output.writeString(this.finish);
          output.writeFieldEnd();
        }
        if (this.reversed) {
          output.writeFieldBegin('reversed', Thrift.Type.BOOL, 3);
          output.writeBool(this.reversed);
          output.writeFieldEnd();
        }
        if (this.count) {
          output.writeFieldBegin('count', Thrift.Type.I32, 4);
          output.writeI32(this.count);
          output.writeFieldEnd();
        }
        output.writeFieldStop();
        output.writeStructEnd();
        return;
      };
      

      this.reversed is false and subsequently does not get sent
      If I look at the compiled version that was generated by 0.6.1 I see:

      SliceRange.prototype.write = function(output){ 
        output.writeStructBegin('SliceRange')
        if (null != this.start) {
          output.writeFieldBegin('start', Thrift.Type.STRING, 1)
          output.writeString(this.start)
          output.writeFieldEnd()
        }
        if (null != this.finish) {
          output.writeFieldBegin('finish', Thrift.Type.STRING, 2)
          output.writeString(this.finish)
          output.writeFieldEnd()
        }
        if (null != this.reversed) {
          output.writeFieldBegin('reversed', Thrift.Type.BOOL, 3)
          output.writeBool(this.reversed)
          output.writeFieldEnd()
        }
        if (null != this.count) {
          output.writeFieldBegin('count', Thrift.Type.I32, 4)
          output.writeI32(this.count)
          output.writeFieldEnd()
        }
        output.writeFieldStop()
        output.writeStructEnd()
        return
      }
      

      null is also not be completely correct, the solution would be:

      ...
      if (undefined !== this.reversed)
      ...
      

      Unless this change was intentional and breaks things because cassandra is perhaps using an old thrift version?

      Attachments

        Issue Links

          Activity

            People

              henrique Henrique Mendonca
              jorisw Joris van der Wel
              Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: