admin管理员组

文章数量:1122832

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?

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?

Share Improve this question asked Nov 22, 2024 at 8:06 OznOgOznOg 4,6502 gold badges28 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

本文标签: capnprotoHow to give the same value at two enum identifier with cap39n protoStack Overflow