Differences between revisions 4 and 5
Revision 4 as of 2009-08-31 19:33:40
Size: 1267
Editor: RobSlifka
Comment: Honed variable/datatype non-example. Also added overloading non-example.
Revision 5 as of 2009-09-20 23:47:11
Size: 1268
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 * [:ThriftInstallation:Download and install] the thrift code generator  * [[ThriftInstallation|Download and install]] the thrift code generator

Quick steps to generate a thrift interface for your language:

  • Download and install the thrift code generator

  • Navigate to the directory containing your .thrift files.
  • Run thrift with the options for your language of choice. e.g. thrift -php myproject.thrift

  • Your files will be generated in a sub directory called e.g. gen-php

Caveat: Service Method Parameter Naming

Make sure you don't name variables the same as their datatype - you WILL run in to trouble.

Consider this example BAD CODE:

typedef i32 somevariable

service Example {
    // Function that takes somevariable called somevariable  
    i32 regenerate(1:somevarable somevariable),
}

Though the Thrift compiler compiles this example successfully the generated code will NOT compile.

Also note that using terms like "new" as a function name will cause errors in the generated code.

Caveat: Service Method Name Overloading

Make sure you don't overload service methods.

service Example {
    // Two 'regenerate' functions with different arguments
    i32 regenerate(1:String foo),
    i32 regenerate(1:i16 bar),
}

Thrift will compile this, however the generated code will NOT compile.

ThriftGeneration (last edited 2009-09-20 23:47:11 by localhost)