0

背景

我正在尝试将 protobuff 用于我们的一个应用程序,但我无法理解协议,我需要帮助创建.proto文件。

数据

我需要编码的数据是一个地图列表,具有以下结构:

[
  {
    "AwayTeam": "Osasuna",
    "Date": "2017-05-07",
    "Div": "SP1",
    "FTAG": 1,
    "FTHG": 4,
    "FTR": "H",
    "HTAG": 0,
    "HTHG": 2,
    "HTR": "H",
    "HomeTeam": "Valencia",
    "Season": 201617
  },
  {
    "AwayTeam": "Osasuna",
    "Date": "2016-02-27",
    "Div": "SP2",
    "FTAG": 1,
    "FTHG": 0,
    "FTR": "A",
    "HTAG": 0,
    "HTHG": 0,
    "HTR": "D",
    "HomeTeam": "Cordoba",
    "Season": 201516
  }
]

每个地图具有以下结构:

{
  "AwayTeam": string,  required: true
  "Date":     string,  required: true
  "Div":      string,  required: true
  "FTAG":     integer, required: true
  "FTHG":     integer, required: true
  "FTR":      string,  required: true
  "HTAG":     integer, required: true
  "HTHG":     integer, required: true
  "HTR":      string,  required: true
  "HomeTeam": string,  required: true
  "Season":   integer, required: true
}

研究

我的目标是使用 .proto 创建 .proto 文件proto3。所以我决定阅读 .proto3 文件的文档:

https://developers.google.com/protocol-buffers/docs/proto3#maps

但我更加困惑。根据文档,我不能拥有包含不同类型值的地图:

为此,我需要 JSONobject类型的等效项并检查文档,.struct.proto但该页面没有提及任何有关它的内容。

问题

所以我在这里很迷茫。如何在 a 中表示提到的数据结构.proto

4

1 回答 1

0

回答

事实证明,我实际上并不需要地图,对象列表(消息)就足够了:

    syntax = "proto3";

    message Result {
      string AwayTeam = 1;
      string Date = 2;
      string Div = 3;
      int32 FTAG = 4;
      int32 FTHG = 5;
      string FTR = 6;
      int32 HTAG = 7;
      int32 HTHG = 8;
      string HTR = 9;
      string HomeTeam = 10;
      int32 Season = 11;
  }

  message Response {
    repeated Result results = 1;
  }
于 2019-07-10T10:58:07.147 回答