Can an enum value be composed of another enum value?

50 views
Skip to first unread message

Phani Deepak Parasuramuni

unread,
Aug 31, 2020, 2:42:33 AM8/31/20
to Protocol Buffers
i have a use case where a first level of proto file declares a set of enum values and the secondary proto file that imports the primary level proto file, declares another set of enum values composed using the enum values from first level proto file.

first.proto:
syntax = "proto3";
enum Type {
     INVALID = 0;
     NUMERIC = 0xA0000;
     STATE   = 0xB0000;
     EVENT   = 0xC0000;
     BLOB    = 0xD0000;
};

second.proto:
syntax = "proto3";
import "first.proto";
enum ID {
     ID_INVALID = 0;
     ABC = NUMERIC | 0x1;
     DEF = STATE   | 0x2;
};

when second.proto is compiled, it fails with error: 
second.proto:5:12: Expected integer.
second.proto:6:12: Expected integer.

Any suggestions on how to workaround this problem?

Thanks,
Phani

Adam Cozzette

unread,
Aug 31, 2020, 11:57:35 AM8/31/20
to Phani Deepak Parasuramuni, Protocol Buffers
I'm afraid this is not possible, because enum values can't reference other enum values.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/89989477-8bc4-48ac-9238-3d2eda0b5351n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages