Closed jayvdb closed 3 years ago
I notice that there is code which sounds like it might be doing this, under a confusing & private name _which
And there is as_enum
everywhere, but I keep getting "Tried to use non-enum schema as an enum" or "Tried to get() a union member which is not currently initialized" or similar.
Ok, that is a bad example, because the union is a named member of the struct, and there is a capnp.lib.capnp._StructModuleWhich
at addressbook.Person.Employment
.
As a result, it is already possible to do
alice.employment.which == addressbook.Person.Employment.school
The case I am interested in is
struct ConnectRequest {
...
}
struct Status {
...
}
struct Message {
union {
connectRequest @0 :ConnectRequest;
status @2 :Status;
...
}
}
For that case, there is no named spot to mount a _StructModuleWhich
. Suggestions on how to proceed?
Currently https://capnproto.github.io/pycapnp/quickstart.html#reading-unions recommends the user compared
.which()
to strings that match union member names defined in the .capnp file.It would be nice if those strings could be provided in an enum, so that the example could be
union_enum
would be dynamically built to be like