β

How to construct extension message in protobuf.js

User zangw - Stack Overflow 221 阅读

According to this post, I have defined several messages in Protocol Buffer format as following

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;
}

And ProtoBuf.js is used to construct and parse those custom messages.

    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?

How to construct Req message from MsgHead directly, just like req = msg_head.Extensions[Req.msg]?

作者:User zangw - Stack Overflow
most recent 30 from stackoverflow.com
原文地址:How to construct extension message in protobuf.js, 感谢原作者分享。

发表评论