根据此post,我已定义了Protocol Buffer
格式的几条消息,如下所示
message MsgHead
{
extensions 80 to max;
enum Type
{
REQ = 1;
RESP = 2;
}
required string version = 1;
required Type type = 2;
}
message Req
{
extend MsgHead
{
required Req msg = 81; // unique message extend number
}
optional string id = 1;
optional string ip_address = 2;
}
message Resp
{
extend MsgHead
{
required Resp msg = 82;
}
optional string id = 1;
optional string time = 2;
}
ProtoBuf.js
用于构造和解析这些自定义消息。
var req = new Req({
"id": "60"
"ip_address": "172.17.67.60"
});
var msg_head = new Header();
msg_head.set("version", '1.0');
msg_head.set('type', 1);
msg_head.set('.Req.msg', req);
// how to construct req message within msg_head?
如何直接从Req
构建MsgHead
消息,就像req = msg_head.Extensions[Req.msg]
一样?