zoukankan      html  css  js  c++  java
  • protobuf 嵌套示例

    1.嵌套 Message

    message Person

    {

    required string name = 1;

    required int32 id = 2;        // Unique ID number for this person.

    optional string email = 3;

    enum PhoneType

    {

    MOBILE = 0;

    HOME = 1;

    WORK = 2;

    }

    message PhoneNumber

    {

    required string number = 1;

    optional PhoneType type = 2 [default = HOME];

    }

    repeated PhoneNumber phone = 4;

    }

    2. Import Message

    在一个 .proto 文件中,还可以用 Import 关键字引入在其他 .proto 文件中定义的消息,这可以称做 Import Message,或者 Dependency Message

    import common.header;

    message youMsg

    {

    required common.info_header header = 1;

    required string youPrivateData = 2;

    }

    Import Message 的用处主要在于提供了方便的代码管理机制,类似 C 语言中的头文件。您可以将一些公用的 Message 定义在一个 package 中,然后在别的 .proto 文件中引入该 package,进而使用其中的消息定义。Google Protocol Buffer 可以很好地支持嵌套 Message 和引入 Message

    3.更多关于动态编译的内容,参数[1]

    原文

    [1]http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/

    [2]https://developers.google.com/protocol-buffers/docs/overview?hl=zh-CN

    [3]https://developers.google.com/protocol-buffers/docs/cpptutorial?hl=zh-CN

  • 相关阅读:
    poj 1753 Flip Game
    SDIBT 2345 (3.2.1 Factorials 阶乘)
    HDU 1176 免费馅饼
    HDU 1058 Humble Numbers
    HDU 1003 MAXSUM(最大子序列和)
    HDU1864 最大报销额
    HDU 1114 Piggy-Bank(完全背包)
    POJ 3624 Charm Bracelet
    处理textarea里Enter(回车换行符)
    uniApp打卡日历
  • 原文地址:https://www.cnblogs.com/mydomain/p/3176373.html
Copyright © 2011-2022 走看看