同步操作将从 Plato/rpc-frontend 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
将IDL文件转换为通用JSON中间格式,方便使用任何支持JSON访问的语言用来生成RPC框架代码
#import "test.idl"
// I'm a single line comment
/*
* I'm a multi-line comment
*/
struct Data {
i32 field1
string field2
seq<string> field3
set<string> field4
dict<i64,string> field5
bool field6
float field7
double field8
}
service Service {
void method1(Data,string)
string method2(i8,set<string>,ui64)
}
如上所示IDL文件支持struct和service, struct是纯数据结构,不支持定义方法,service为接口定义,接口内可以包含若干方法,struct内可以嵌套定义struct,例如:
strutct A {
struct B {
...
}
}
所有定义的struct都为全局作用域,不论是否定义在任何一个struct内部,service内部也可以定义struct,struct内部不能定义service,struct支持多种数据类型,包含基础数据类型和容器,所有数据类型如下:
数据类型 | 描述 |
---|---|
i8 | 8位有符号整数 |
i16 | 16位有符号整数 |
i32 | 32位有符号整数 |
i64 | 64位有符号整数 |
ui8 | 8位无符号整数 |
ui16 | 16位无符号整数 |
ui32 | 32位无符号整数 |
ui64 | 64位无符号整数 |
string | 字符串 |
bool | 布尔 |
float | 单精度浮点数 |
double | 双精度浮点数 |
dict | 字典 |
set | 集合 |
seq | 序列(数组) |
当有多个IDL文件时,可以将struct和service组织在不同的文件内,将要使用的文件通过#import来导入到入口文件,被导入的文件都会被工具在运行时合并到一起并输出。当工具检测到错误时会给出错误现场.
// 做多可以生成16个实例
service Service multiple=16 {
}
// 单件,只能有一个实例
service Service single {
}
// 单件,只能有一个实例,但可以被并发调用
service Service reentrant {
}
// 单件,只能有一个实例,但可以被并发调用,同时是动态加载
service dynamic Service reentrant {
}
service Service multiple=16 {
// 单工
oneway void method1(Data,string)
}
service Service multiple=16 {
// 单工
void method1(Data,string) timeout=2000 retry=3
}
以上的配置为超时2秒,最多重试3次
frontend是一个命令行工具,运行help可以得到使用方法
运行命令后可以得到对应类型的JSON文件,后续开发这可以使用这个JSON文件来生成自己的RPC框架代码,生成的构成已经进行对IDL做了语法检查和错误校验。
可以通过 -i 或者--include 添加 你自己的import文件搜索路径 例子如下
./frontend -f test1.idl -t cpp -i ../example
上面的例子所生成的JSON文件如下:
./frontend -f test1.idl -t cpp
{
"serviceNames" :
[
"Service"
],
"services" :
[
{
"methods" :
[
{
"arguments" :
[
{
"isStruct" : true,
"type" : "Data"
},
{
"type" : "std::string"
}
],
"name" : "method1",
"retType" :
{
"type" : "void"
}
},
{
"arguments" :
[
{
"type" : "std::int8_t"
},
{
"key" :
{
"type" : "std::string"
},
"type" : "std::unordered_set"
},
{
"type" : "std::uint64_t"
}
],
"name" : "method2",
"retType" :
{
"type" : "std::string"
}
}
],
"name" : "Service"
}
],
"structNames" :
[
"Data"
],
"structs" :
[
{
"fields" :
[
{
"name" : "field1",
"type" : "std::int32_t"
},
{
"name" : "field2",
"type" : "std::string"
},
{
"key" :
{
"type" : "std::string"
},
"name" : "field3",
"type" : "std::vector"
},
{
"key" :
{
"type" : "std::string"
},
"name" : "field4",
"type" : "std::unordered_set"
},
{
"key" :
{
"type" : "std::int64_t"
},
"name" : "field5",
"type" : "std::unordered_map",
"value" :
{
"type" : "std::string"
}
},
{
"name" : "field6",
"type" : "bool"
},
{
"name" : "field7",
"type" : "float"
},
{
"name" : "field8",
"type" : "double"
}
],
"name" : "Data"
}
]
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。