List 嵌套 Map

Excel list 中嵌套 map 的规范说明。

纵向 list 中的嵌套

纵向 list 中的横向 map

HelloWorld.xlsx 中的 worksheet ItemConf

IDNameProp1IDProp1ValueProp2IDProp2Value
[Item]uint32stringmap<int32, Prop>int64int32int64
Item’s IDItem’s nameProp1’s IDProp1’s valueProp2’s IDProp2’s value
1Apple110220
2Orange330
3Banana

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Item item_list = 1 [(tableau.field) = {layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
    map<int32, Prop> prop_map = 3 [(tableau.field) = {name:"Prop" key:"ID" layout:LAYOUT_HORIZONTAL}];
    message Prop {
      int32 id = 1 [(tableau.field) = {name:"ID"}];
      int64 value = 2 [(tableau.field) = {name:"Value"}];
    }
  }
}
ItemConf.json
{
    "itemList": [
        {"id": 1, "name": "Apple", "propMap": {"1": {"id": 1, "value": "10"}, "2": {"id": 2, "value": "20"}}},
        {"id": 2, "name": "Orange", "propMap": {"3": {"id": 3, "value": "30"}}},
        {"id": 3, "name": "Banana", "propMap": {}}
    ]
}

纵向 keyed-list 中的纵向 map

HelloWorld.xlsx 中的 worksheet ItemConf

IDNamePropIDPropValue
[Item]<uint32>stringmap<int32, Prop>int64
Item’s IDItem’s nameProp’s IDProp’s value
1Apple110
2Orange120
2Banana230

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Item item_list = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
    map<int32, Prop> prop_map = 3 [(tableau.field) = {key:"PropID" layout:LAYOUT_VERTICAL}];
    message Prop {
      int32 prop_id = 1 [(tableau.field) = {name:"PropID"}];
      int64 prop_value = 2 [(tableau.field) = {name:"PropValue"}];
    }
  }
}
ItemConf.json
{
    "itemList": [
        {"id": 1, "name": "Apple", "propMap": {"1": {"propId": 1, "propValue": "10"}}},
        {"id": 2, "name": "Orange", "propMap": {"1": {"propId": 1, "propValue": "20"}, "2": {"propId": 2, "propValue": "30"}}}
    ]
}

纵向 list 中的 incell map

HelloWorld.xlsx 中的 worksheet ItemConf

IDProps
[Item]uint32map<int32, string>
Item’s IDItem’s props
11:sour,2:sweet,3:delicious
21:sour,2:sweet
31:sour

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Item item_list = 1 [(tableau.field) = {layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    map<int32, string> props_map = 2 [(tableau.field) = {name:"Props" layout:LAYOUT_INCELL}];
  }
}
ItemConf.json
{
    "itemList": [
        {"id": 1, "propsMap": {"1": "sour", "2": "sweet", "3": "delicious"}},
        {"id": 2, "propsMap": {"1": "sour", "2": "sweet"}},
        {"id": 3, "propsMap": {"1": "sour"}}
    ]
}

横向 list 的第一个字段

横向 list 中的横向 map

HelloWorld.xlsx 中的 worksheet ItemConf

Reward1Item1IDReward1Item1NumReward1Item2IDReward1Item2NumReward1NameReward2Item1IDReward2Item1NumReward2Name
[Reward]map<int32, Item>int32int32int32stringint32int32string
Item1’s IDItem1’s numItem2’s IDItem2’s numReward’s nameItem1’s IDItem1’s numReward’s name
110220Lotto10100Super Lotto

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Reward reward_list = 1 [(tableau.field) = {name:"Reward" layout:LAYOUT_HORIZONTAL}];
  message Reward {
    map<int32, Item> item_map = 1 [(tableau.field) = {name:"Item" key:"ID" layout:LAYOUT_HORIZONTAL}];
    message Item {
      int32 id = 1 [(tableau.field) = {name:"ID"}];
      int32 num = 2 [(tableau.field) = {name:"Num"}];
    }
    string name = 2 [(tableau.field) = {name:"Name"}];
  }
}
ItemConf.json
{
    "rewardList": [
        {"itemMap": {"1": {"id": 1, "num": 10}, "2": {"id": 2, "num": 20}}, "name": "Lotto"},
        {"itemMap": {"10": {"id": 10, "num": 100}}, "name": "Super Lotto"}
    ]
}

横向 list 中的 predefined struct map

common.proto 中预定义的 Item

message Item {
    int32 id = 1 [(tableau.field) = {name:"ID"}];
    int32 num = 2 [(tableau.field) = {name:"Num"}];
}

HelloWorld.xlsx 中的 worksheet ItemConf

Reward1Item1IDReward1Item1NumReward1Item2IDReward1Item2NumReward1NameReward2Item1IDReward2Item1NumReward2Name
[Reward]map<int32, .Item>int32int32int32stringint32int32string
Item1’s IDItem1’s numItem2’s IDItem2’s numReward’s nameItem1’s IDItem1’s numReward’s name
110220Lotto10100Super Lotto

生成结果:

hello_world.proto
// --snip--
import "common.proto";
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Reward reward_list = 1 [(tableau.field) = {name:"Reward" layout:LAYOUT_HORIZONTAL}];
  message Reward {
    map<int32, protoconf.Item> item_map = 1 [(tableau.field) = {name:"Item" key:"ID" layout:LAYOUT_HORIZONTAL}];
    string name = 2 [(tableau.field) = {name:"Name"}];
  }
}
ItemConf.json
{
    "rewardList": [
        {"itemMap": {"1": {"id": 1, "num": 10}, "2": {"id": 2, "num": 20}}, "name": "Lotto"},
        {"itemMap": {"10": {"id": 10, "num": 100}}, "name": "Super Lotto"}
    ]
}