tableau icon indicating copy to clipboard operation
tableau copied to clipboard

union(protogen): reuse same field type for different fields

Open wenchy opened this issue 2 years ago • 0 comments

The concept is like Custom named struct.

Syntax: just after struct type name, use parentheses () to specify struct variable name: VariableType(VariableName).

Example

Name Alias Field1 Field2 Field3
Battle(PvpBattle) PVP BattleId
int32
Kills
uint32
Damage
int64
Battle(PveBattle) PVE BattleId
int32
Kills
uint32
Damage
int64
message ActivityTarget {
  option (tableau.union) = true;

  Type type = 9999 [(tableau.field) = { name: "Type" }];
  oneof value {
    option (tableau.oneof) = {field: "Field"};

    Battle pvp_battle = 1; // Bound to enum value: TYPE_PVP_BATTLE.
    Battle pve_battle = 2; // Bound to enum value: TYPE_PVE_BATTLE.
  }
  enum Type {
    TYPE_INVALID = 0;
    TYPE_PVP_BATTLE = 1 [(tableau.evalue).name = "PVP"];
    TYPE_PVE_BATTLE = 2 [(tableau.evalue).name = "PVE"];
  }
  message Battle {
    // ...
  }
}

wenchy avatar Oct 25 '23 02:10 wenchy