Skip to content

Instantly share code, notes, and snippets.

@nik-kor
Last active December 19, 2015 13:59
Show Gist options
  • Save nik-kor/5965677 to your computer and use it in GitHub Desktop.
Save nik-kor/5965677 to your computer and use it in GitHub Desktop.

Revisions

  1. nik-kor revised this gist Jul 10, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@

    ->thrift -version
    Thrift version 0.8.0
    -> thrift --gen js:node test.thrift #how to generate test_types.js
    ->node client.js

    /home/nick/dev/ged_projects/admin-panel-gate/gen-nodejs/test_types.js:11
  2. nik-kor revised this gist Jul 10, 2013. No changes.
  3. nik-kor created this gist Jul 10, 2013.
    2 changes: 2 additions & 0 deletions client.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    var thrift = require('thrift')
    , Foo = require('./gen-nodejs/test_types.js');
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    ->node client.js

    /home/nick/dev/ged_projects/admin-panel-gate/gen-nodejs/test_types.js:11
    var foo.Bar = module.exports.foo.Bar = function(args) {
    ^
    SyntaxError: Unexpected token .
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/nick/dev/ged_projects/admin-panel-gate/client.js:19:11)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    16 changes: 16 additions & 0 deletions test.thrift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    namespace js foo


    struct Bar {
    1: optional string name;
    }


    service Test {

    Bar read_bar(
    1: string name,
    2: i32 some_parameter
    );

    }
    62 changes: 62 additions & 0 deletions test_types.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    //
    // Autogenerated by Thrift Compiler (0.8.0)
    //
    // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
    //
    var Thrift = require('thrift').Thrift;
    var ttypes = module.exports = {};
    if (typeof foo === 'undefined') {
    foo = {};
    }
    var foo.Bar = module.exports.foo.Bar = function(args) {
    this.name = null;
    if (args) {
    if (args.name !== undefined) {
    this.name = args.name;
    }
    }
    };
    foo.Bar.prototype = {};
    foo.Bar.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
    var ret = input.readFieldBegin();
    var fname = ret.fname;
    var ftype = ret.ftype;
    var fid = ret.fid;
    if (ftype == Thrift.Type.STOP) {
    break;
    }
    switch (fid)
    {
    case 1:
    if (ftype == Thrift.Type.STRING) {
    this.name = input.readString();
    } else {
    input.skip(ftype);
    }
    break;
    case 0:
    input.skip(ftype);
    break;
    default:
    input.skip(ftype);
    }
    input.readFieldEnd();
    }
    input.readStructEnd();
    return;
    };

    foo.Bar.prototype.write = function(output) {
    output.writeStructBegin('Bar');
    if (this.name) {
    output.writeFieldBegin('name', Thrift.Type.STRING, 1);
    output.writeString(this.name);
    output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
    };