Enum
YAML enum guide.
On this page
Enum
Enum type FruitType
in common.proto is predefined as:
enum FruitType {
FRUIT_TYPE_UNKNOWN = 0 [(tableau.evalue).name = "Unknown"];
FRUIT_TYPE_APPLE = 1 [(tableau.evalue).name = "Apple"];
FRUIT_TYPE_ORANGE = 3 [(tableau.evalue).name = "Orange"];
FRUIT_TYPE_BANANA = 4 [(tableau.evalue).name = "Banana"];
}
A worksheet ItemConf
in HelloWorld.yaml:
# define metasheet: generate all sheets
"@sheet": "@TABLEAU"
---
# define schema
"@sheet": "@ItemConf"
ID: uint32
Type: "enum<.FruitType>"
Desc: string
---
"@sheet": ItemConf
ID: 1
Type: FRUIT_TYPE_APPLE
Desc: A kind of delicious fruit.
Generated:
hello_world.proto
// --snip--
import "common.proto";
option (tableau.workbook) = {name:"HelloWorld.yaml"};
message ItemConf {
option (tableau.worksheet) = {name:"ItemConf"};
uint32 id = 1 [(tableau.field) = {name:"ID"}];
protoconf.FruitType type = 2 [(tableau.field) = {name:"Type"}];
string desc = 3 [(tableau.field) = {name:"Desc"}];
}
ItemConf.json
{
"id": 1,
"type": "FRUIT_TYPE_APPLE",
"desc": "A kind of delicious fruit."
}