TAF (Total Application Framework) communication protocol based language Tars

Interface file

Tars language is a language c ++ class identifier, service specific interface file for generating

Tars Tars framework document is a communication interface client and server, remote objects by mapping call Tars

Tars file extension must .tars extension

For definition of structure, can be extended to support field, i.e. the field can be increased without affecting the original structure of the parsing, can be used alone local memory / protocol

Case Sensitive

Lexical rules

Using c ++ comment specifications.

Keywords:

void,struct
bool,byte,short,int,double,float,long,
string,vector,map,
key,routekey,
module,interface,
out,
require,optional,
false,true,
enum,const,

Not all identifiers with 'tars_' symbol, and must begin with a letter, but can not and keyword conflicts.

The basic types supported include the following:

  • void: only represents the return value of the function
  • bool: Boolean type, mapped to tars :: Bool
  • byte: Signed characters mapped to tars :: Char
  • short: signed short, mapped to tars :: Short
  • int: signed integer, mapped to tars :: Int32
  • long: a signed long integer, mapped to tars :: Int64
  • float: mapped to tars :: Float
  • double: mapped to tars :: Double
  • string: maps to std :: string, java: String
  • unsigned byte: unsigned char, c ++ unsigend char mapped to other versions tars :: Short
  • unsigned short: unsigned short integer c ++ mapped to other unsigned short version tars :: Int32
  • Unsigned int: unsigned integer unsigned int c ++ mapped to other versions tars :: Int64

Enumerated type is defined as follows:

enum TE
{
    E1,
    E2,
    E3
};
  • Enum types are supported enumeration value specified, for example, support: E1 = 1 defined in this manner;

  • The first definition of enumerated type is 0, where E1 is 0;

  • After tars file enumeration type definition generation by tars2cpp later, in addition to generating a corresponding enum defined outside, and generates etos stoe functions enumerated value into a string, and converting the string to an enumeration value, which is quite handy when debugging code.

  • Recommendations of tars in c ++ files, all interfaces to int return, and return value to enumeration to define tars file.

Tars file can define constants, such as:

const int a = 0;
const string s = “abc”;
  • Since the map, there is no constant value vector described and therefore does not support the map, the definition of the vector;

Structure is defined as follows:

struct Test
{
    0  require  string s;
    1  optional int  i = 23;
};
​
key[Test, s, i];
  • The first number represents the field identification (Tag), regardless of changes in the structure of field, which have the same values, and in response to a corresponding field must;

  • Tag values ​​must be> = 0 and <= 255;

  • It indicates that the field require mandatory;

  • This optional field indicates optional;

  • For optional field, can have a default value, the default value default is not packaged in coding;

Description key: the comparison is less than the symbol represents, is no less than the operating Struct default configuration, if the definition of the key, generates less than comparison operators:

  • key[Stuct, member…]:
  • Struct: name indicates the structure
  • Member: The member variables of the structure, there may be a plurality;
  • Produced less than the comparison operator performs the priority order key member variables defined in <comparison;
  • After generating less than comparison operators, the structure can be used as the key map;

other:

  • In the Tars of c ++ language, for a structure that provides two member functions directly used to print the contents of the structure, it can be used for debugging and logging:

  • ostream & display (ostream & _os, int _level = 0): direct printing the details of the structure, primarily for debugging;

  • ostream & displaySimple (ostream & _os, int _level = 0): All the member variables in order to automatically | separated print, for logging;

Sequence defined by the vector, as follows:

vector<int> vi;

A dictionary to define map, as follows:

map<int, string> m;
  • For struct, not usually used as the map key, so there is no size struct comparison symbols;

  • Struct if necessary can be used as the map key, you need to define the sequence comparison struct members with less;

  • Array type structures can be defined, with the array [] is defined as follows:

byte m[5];
  • Array types in C ++ code generated simultaneously generates length of the array mLen

  • After array assignment must be assigned to the array length

  • In the non-c ++ version will be translated into an array of type vector <type>

  • byte m [5] is equivalent to define the vector: 5

Byte can be defined in structure pointer type, a pointer * defined as follows:

byte *m;

Pre-allocated block of memory in advance the type of pointer used to point when the pre-allocated memory block by memory pointers need to shift, reducing the memory allocation in the decoding process.

  • For the type of pointer, in c ++ code generated mLen simultaneously, is used to specify the length of the pointer.

  • Pointer assignment must be assigned for the length mLen

  • C ++ release in the non-pointer type to be translated into vector <type>

  • BufferReader containing data reading pointer type must MapBufferReader, while necessary to set in advance the pointer to the buffer memory

Any struct, map, vector can be nested;

The interface is defined as follows, for example:

interface Demo
{
    int get(out vector<map<int, string>> v);int set(vector<map<int, string>> v);
};

It represents the output parameters

After the interface definition, by an automatic code generation tools (eg: tars2cpp) synchronous and asynchronous interfaces interface code generation

All struct, interface must be in the name space, for example:

module MemCache
{
    struct Key
    {
        0 require string s;
    };struct Value
    {
        0 require string s;
    };
​
    interface MemCacheI
    {
        int get(Key k, out Value v);int set(Key k, Value v);
    };
};
  • Namespace can not be nested;
  • You can reference other namespaces, such as: Demo1 :: Key

Read the official document relatively comfortable

Published 202 original articles · won praise 14 · views 40000 +

Guess you like

Origin blog.csdn.net/LU_ZHAO/article/details/105021826