Guide - Taneb/ecore2thrift GitHub Wiki

The examples in this document are written in Emfatic, a language designed to be compiled into EMF's ECore.

The structure of the file is generally something like

Header  
Definition of Services  
Definition of Entities  

Although the definitions of services and entities may be intermingled.

Header

The header defines the name of the Thrift package, and lets you specify the Java namespace the generated code will use.

Example

@thrift(javans="namespace")  
package package_name;

Generates a Thrift file with the Java namespace set to namespace.
Something of this form should be at the start of every .emf file that will be used with Ecore2Thrift.

Structures

Structures are the custom data types of Thrift. They take the form of a collection of strongly typed fields, each with a unique name, which may be marked as optional.

Examples

class StructName {  
  attr String field1;  
  @doc(optional="true")  
  attr int field2;  
}

Generates a struct or an exception with name StructName and the fields field1 of type string, and field2 of type i32.

class AnotherStruct {  
  attr StructName aStruct;  
  val int[*] someNumbers;  
}

Generates a struct or an exception with name AnotherStruct and the fields aStruct of type StructName and someNumbers of type list<int>.

Note that Ecore2Thrift decides whether to generate a struct or an exception depending on how it is used elsewhere in the specification. That is, if any operation throws it, it is an exception, otherwise it is a struct.

Services

Services are a collection of operations which may be performed over a network using Thrift. These all take as their parameters some number of arguments all of Thrift types, including primitives and user-defined structures, and may return a value of a similar type. They may also throw exceptions, which are defined in the same way as structs.

Example

class MyService {  
  op void anOperation(  
    int parameter1,  
    AnotherStruct parameter2  
  ) throws AnException, AnotherException;  
  op int anotherOperation(  
    @doc(optional="true") String stringParameter  
  );  
  op StructName[*] getStructs();  
}

Generates a service named MyService, with three operations:

  • anOperatorion, which has no return value and two parameters, parameter1 of typeint and parameter2 of type AnotherStruct, and may throw the AnException or AnotherException exceptions.* anotherOperation, which returns an int and has one optional paramter, stringParamter of type string.
  • getStructs, which has no parameters and has the return type list<StructName>

Types

It is possible to generate most of Thrift's types from Emfatic using ECore2Thrift. There are several basic types which convert trivially:

Thrift basic type Emfatic type
bool boolean
byte byte
i16 short
i32 int
i64 double
double double
string String

For other Emfatic types, a sensible conversion is made. Note that floats are transformed into doubles, as Thrift does not support single-width floats.

Structs can be defined and used as documented in the Structures section of this document.

Lists can be created using Emfatic's multiplicity expression [*]. Ecore2Thrift supports lists of both basic types and structs.

⚠️ **GitHub.com Fallback** ⚠️