capnproto

How to give the same value at two enum identifier with cap'n proto


I have an enum in capnp declared like this:

enum Color {
    red @0;
    blue @1;
    orange @2;
}

And I would like to add a new identifier to replace an old one without breaking the binary api (say I want the new code to manipulate yellow instead of orange, but not modify legacy code).

I tried this:

enum Color {
    red @0;
    blue @1;
    orange @2;
    yellow @2;
}

and this

enum Color {
    red @0;
    blue @1;
    orange @2;
    yellow = orange;
}

more or less the way I would write it in C++, but none works: the former gives error: Duplicate ordinal number, and the later error: Parse error..

I did not find much on this in documentation.

So is there a way to do this with capn proto, and how?


Solution

  • Sorry, you cannot give the same value to two enumerants.

    You could, however, define a constant that aliases a value:

    const yellow :Color = orange;
    

    But this constant won't be scoped inside the enum; it'll have to be a sibling to the type declaration.