-
Notifications
You must be signed in to change notification settings - Fork 6
Baiji IDL Definition
Baiji IDL is used for the definition of data structs and service interface, user can use BaijiGenerator to edit IDL, then generate source code targeting Java/C#/iOS/Android/WinPhone platfroms. This article introduces the definition of Baiji IDL.
For a sample Baiji IDL, refer to here.
One Baiji IDL file consists of three parts, header definition, types definition and service definition.
Header definition consists of two parts, file including and namespace definition.
File including can be used to include data structs defined in other IDL file(s). The including syntax is include 'file path', the path can be either relative or absolute path. After including, you can use [file name without suffix].[type name] to reference types in other file. For example:
include 'common.bjsc'
If you want to reference CommonResponseType defined in common.bjsc, you can use common.CommonResponseType.
The namespace defined here will be used by code generation, the syntax is : namespace language 'your namespace'. We current support generation of Java/C#/Objective-C code, corresponding language is java/csharp/objc. For example:
namespace csharp 'CTripOSS.Sample'
Baiji IDL supports two kinds of data types: class & enum
Class can contain as many data members as you wish, it can also contain no data member, however it does not support constant. The syntax for class definition is:
class className {
memberType1 memberName1;
memberType2 memberName2;
...
}
memberType can be built-in data types, types defined in current file(not necessarily defined before this type), or types defined in included file(s).
memberName can contain English alphabet, digits and underline, but it can only start with English alphabet or underline.
For example:
class TestRecord {
int num;
list names;
}
Attention, if a class type will be used as a return type of an interface method, then it must contain a member called responseStatus, and the memberType must be ResponseStatusType defined in Baiji common types. This policy is enforced by the code generation, if violated, code generation will fail.
built-in types | mapping to C# types | mapping to Java types | mapping to objective-c types | note |
---|---|---|---|---|
bool | bool | java.lang.Boolean | ||
int | int | java.lang.Integer | ||
long | long | java.lang.Long | ||
double | double | java.lang.Double | ||
string | string | java.lang.String | ||
binary | byte[] | byte[] | ||
datetime | System.DateTime | java.util.Calendar | ||
list<elmentType> | System.Collections.Generic.List<elementType> | java.util.List<elementType> | elementType can be any types allowed by Baiji IDL, except list or map | |
map<string, valueType> | System.Collections.Generic.Dictionary<string, valueType> | java.util.Map<string, valueType> | map only supports string as key type, valueType can be any types allowed by Baiji IDL, except list or map |
Enum type can contain any number of enum symbols as you like, but it can't contain enum value. The syntax to define enum is:
enum enumName {
symbolName1;
symbolName2;
...
}
symbolName can contain English alphabet, digits and underline, but it can only start with English alphabet or underline.
For example
enum Number {
One;
Two;
Three;
Four
}
The service in IDL looks like an interface, it defines a list of method signatures. Attention Baiji IDL allows one and only one method parameter, and the type of the parameter must be a class type. The syntax to define service is as following:
@serviceName='your serviceName here'
@serviceNamespace='your serviceNamespace here'
service nameOfService {
returnType1 methodName1(parameterType1 parameterName1);
returnType2 methodName2(parameterType2 parameterName2);
...
}
the serviceName and serviceNamespace here are only used for governance purpose, serviceName can contain English alphabet and digits, serviceNamespace should be in URI format.
Attention, per Baiji service policy, every service must contain a checkHealth method, parameter type and return type must be CheckHealthRequestType and CheckHealthResponseType defined in Baiji common types. Code generation will fail if this policy is violated.
In Baiji IDL, all types and type members(including class/enum definition, member definition, service definition) can be annotated with /* */ style block comment, during code generation, corresponding comment will be generated as code comments in targeting source.
Single line style comment starting with // can be used in IDL, but will be ignored during code generation.