结构体嵌套结构体(Struct in struct)
Excel 结构体中嵌套结构体的规范说明。
结构体嵌套结构体(Struct in struct)
HelloWorld.xlsx 中的工作表 ItemConf:
| RewardID | RewardItemID | RewardItemNum |
|---|---|---|
| {Reward}int32 | {Item}int32 | int32 |
| Reward’s ID | Item’s ID | Item’s num |
| 1 | 1 | 10 |
生成结果:
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"};
Reward reward = 1 [(tableau.field) = {name:"Reward"}];
message Reward {
int32 id = 1 [(tableau.field) = {name:"ID"}];
Item item = 2 [(tableau.field) = {name:"Item"}];
message Item {
int32 id = 1 [(tableau.field) = {name:"ID"}];
int32 num = 2 [(tableau.field) = {name:"Num"}];
}
}
}
ItemConf.json
{
"reward": {
"id": 1,
"item": {"id": 1, "num": 10}
}
}
结构体嵌套预定义结构体(Predefined-struct in struct)
common.proto 中预定义的 Item:
message Item {
int32 id = 1 [(tableau.field) = {name:"ID"}];
int32 num = 2 [(tableau.field) = {name:"Num"}];
}
HelloWorld.xlsx 中的工作表 ItemConf:
| RewardID | RewardItemID | RewardItemNum |
|---|---|---|
| {Reward}int32 | {.Item}int32 | int32 |
| Reward’s ID | Item’s ID | Item’s num |
| 1 | 1 | 10 |
生成结果:
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"};
Reward reward = 1 [(tableau.field) = {name:"Reward"}];
message Reward {
int32 id = 1 [(tableau.field) = {name:"ID"}];
protoconf.Item item = 2 [(tableau.field) = {name:"Item"}];
}
}
ItemConf.json
{
"reward": {
"id": 1,
"item": {"id": 1, "num": 10}
}
}
结构体嵌套单元格内结构体(Incell-struct in struct)
HelloWorld.xlsx 中的工作表 ItemConf:
| RewardID | RewardItem |
|---|---|
| {Reward}int32 | {int32 ID, int32 Num}Item |
| Reward’s ID | Reward’s item |
| 1 | 1,100 |
| 2,200 |
生成结果:
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"};
Reward reward = 1 [(tableau.field) = {name:"Reward"}];
message Reward {
int32 id = 1 [(tableau.field) = {name:"ID"}];
Item item = 2 [(tableau.field) = {name:"Item" span:SPAN_INNER_CELL}];
message Item {
int32 id = 1 [(tableau.field) = {name:"ID"}];
int32 num = 2 [(tableau.field) = {name:"Num"}];
}
}
}
ItemConf.json
{
"reward": {
"id": 1,
"item": {"id": 2, "num": 200}
}
}