Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define an alias for type (enum or message) in google protobuf?

I have two enums in my proto file which define almost the same values.

Is it possible to cut out one of them and to leave an alias to keep all the code working?

Example:

enum A {
   a = 0;
   b = 1;
}
enum B {
   a = 0;
   b = 1;
}

I want to have something like typedef in c++:

enum A {
   a = 0;
   b = 1;
}

typedef A B;

I haven't found this in documentation. Are there any workarounds ?

like image 872
vrogach Avatar asked Jul 08 '13 18:07

vrogach


2 Answers

As of protobuf version 3, this is not possible.

like image 97
Giovanni Funchal Avatar answered Sep 18 '22 23:09

Giovanni Funchal


This is an old question, but if some people are still interested, It is possible to create alias on enum with protobuf now

enum EnumAllowingAlias {
  option allow_alias = true;
  UNKNOWN = 0;
  STARTED = 1;
  RUNNING = 1;
}
enum EnumNotAllowingAlias {
  UNKNOWN = 0;
  STARTED = 1;
  // RUNNING = 1;  // Uncommenting this line will cause a compile error inside Google and a warning message outside.
}

As explained in the official documentation here. You just need to enable the alias option by adding option allow_alias = true;

like image 23
FreeYourSoul Avatar answered Sep 18 '22 23:09

FreeYourSoul