protobuff协议在C/S传输数据注意的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_30071459/article/details/75007471

在C/S中,使用protobuff协议传输数据,首先需要在.proto文件中写message。例如:

message up_msg{
	optional unit32 _id = 1;
	optional string _name = 2;
	optional set_line_up = 3;
}
message set_line_up{
	repeated line_up _line_up = 1;
}

message line_up{
	required unit32 _id = 1;
	repeated unit32 _hero_id = 2;
}

其中up_msg是客户端给服务器发送的message结构,在erlang中我们需要用record匹配这个结构:

-record(up_msg,{
	id,
	name,
	set_line_up
	}).

需要注意的是,record字段的顺序必须和message对应,否则erlang匹配时会出错。

猜你喜欢

转载自blog.csdn.net/sinat_30071459/article/details/75007471
今日推荐