<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 4.4 protobuf語法 protobuf 通常會把用戶定義的結構體類型叫做一個消息,這里我們遵循慣例,統一稱為消息。protobuf 消息的定義(或者稱為描述)通常都寫在一個以 .proto 結尾的文件中。 ##### A\) 一個簡單的例子 ```protobuf syntax = "proto3"; //指定版本信息,不指定會報錯 package pb; //后期生成go文件的包名 //message為關鍵字,作用為定義一種消息類型 message Person { string name = 1; //姓名 int32 age = 2; //年齡 repeated string emails = 3; //電子郵件(repeated表示字段允許重復) repeated PhoneNumber phones = 4; //手機號 } //enum為關鍵字,作用為定義一種枚舉類型 enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } //message為關鍵字,作用為定義一種消息類型可以被另外的消息類型嵌套使用 message PhoneNumber { string number = 1; PhoneType type = 2; } ``` ##### B\) 消息格式說明 消息由字段組成,每個消息的字段格式為: (字段修飾符 +)數據類型 + 字段名稱 + 唯一的編號標簽值; * 字段名稱:蛇形或者駝峰 * 唯一的編號標簽:代表每個字段的一個唯一的編號標簽,在同一個消息里不可以重復。這些編號標簽用與在消息二進制格式中標識你的字段,并且消息一旦定義就不能更改。需要說明的是標簽在1到15范圍的采用一個字節進行編碼,所以通常將標簽1到15用于頻繁發生的消息字段。編號標簽大小的范圍是1到229 * 注釋格式:向.proto文件添加注釋,可以使用C/C++/java/Go風格的雙斜杠(//) 語法格式 ##### C\) 數據類型 | **.proto Type** | **Go Type** | **Notes** | | :--- | :--- | :--- | | double | float64 | 64位浮點數 | | float | float32 | 32位浮點數 | | int32 | int32 | 使用變長編碼,對于負值的效率很低,如果你的域有可能有負值,請使用sint64替代 | | uint32 | uint32 | 使用變長編碼 | | uint64 | uint64 | 使用變長編碼 | | sint32 | int32 | 使用變長編碼,這些編碼在負值時比int32高效的多 | | sint64 | int64 | 使用變長編碼,有符號的整型值。編碼時比通常的int64高效。 | | fixed32 | uint32 | 總是4個字節,如果數值總是比總是比228大的話,這個類型會比uint32高效。 | | fixed64 | uint64 | 總是8個字節,如果數值總是比總是比256大的話,這個類型會比uint64高效。 | | sfixed32 | int32 | 總是4個字節 | | sfixed32 | int32 | 總是4個字節 | | sfixed64 | int64 | 總是8個字節 | | bool | bool | | | string | string | 一個字符串必須是UTF-8編碼或者7-bit ASCII編碼的文本。 | | bytes | \[\]byte | 可能包含任意順序的字節數據。 | 更多詳情請看:[https://developers.google.com/protocol-buffers/docs/encoding](https://developers.google.com/protocol-buffers/docs/encoding) ##### D\) 默認缺省值 當一個消息被解析的時候,如果被編碼的信息不包含一個特定的元素,被解析的對象鎖對應的域被設置位一個默認值,對于不同類型指定如下: * 對于strings,默認是一個空string * 對于bytes,默認是一個空的bytes * 對于bools,默認是false * 對于數值類型,默認是0
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看