Protobuf supports integral enums using the enum keyword. We should be able to map Cadl enum to Proto3 enum:
@service interface WidgetService {
paint(@field(1) id: int32, @field(2) color: WidgetColor): void;
}
enum WidgetColor {
RED: 0,
BLUE: 1
}
This should yield the following service:
enum WidgetColor {
RED = 0;
BLUE = 1;
}
message PaintRequest {
int32 id = 1;
WidgetColor color = 2;
}
service WidgetService {
rpc paint(PaintRequest) returns Empty;
}
There are some considerations:
- The values must be int32 values, and there must be a zero value (which is implied to be the default value), so we would likely require Cadl enums to explicitly specify integral values to use them in gRPC emit.
- We could also provide a template or decorator to "gRPC-ify" an enum.
- The zero value is required to be the first value in the enum for proto2 compatibility reasons.
- Protobuf enums support an option called
allow_alias (off by default) that will permit multiple keys of the enum to refer to the same integral value.
Protobuf supports integral enums using the
enumkeyword. We should be able to map Cadlenumto Proto3enum:This should yield the following service:
There are some considerations:
allow_alias(off by default) that will permit multiple keys of the enum to refer to the same integral value.