Skynet(3)-Sproto协议的使用
文章整理和来源:https://github.com/cloudwu/skynet/wiki/Sproto
1.首先看下Sproto的协议的格式:
.Person {
name 0 : string
id 1 : integer
email 2 : string
.PhoneNumber {
number 0 : string
type 1 : integer
}
phone 3 : *PhoneNumber
}
.AddressBook {
person 0 : *Person
}
我们可以看到,凡以“.”开头定义的皆为一种自定义的类型,例如这里的.Person,.AddressBook都是一种类型,而且类型之中可以包含其他的类型。而 “ * ” 加变量名代表一个数组。Sproto中支持以下5种基本类型。
- string : string
- binary : binary string (it's a sub type of string)
- integer : integer, the max length of an integer is signed 64bit. It can be a fixed-point number with specified precision.
- double : double, floating-point number.
- boolean : true or false
我们再看一个符合这个协议的sproto数据:
local ab = {
person = {
{
name = "Alice",
id = 10000,
phone = {
{ number = "123456789" , type = 1 },
{ numb


2425

被折叠的 条评论
为什么被折叠?



