Hi Hong, Cap'n Proto doesn't support defining enums with non-contiguous numeric values. If you must represent your enum this way, then you will need to encode it as an integer in Cap'n Proto -- you won't be able to declare an equivalent enum type.
That said, it does seem like a bug in Python's Cap'n Proto implementation that it can't handle enum values outside the declared range. Such values are expected to show up on the wire if the peer is using a newer version of the protocol where additional values are defined. -Kenton On Thu, Feb 21, 2019 at 10:12 AM <[email protected]> wrote: > Hi, > > I encountered a problem when try to deserialize an Enum type using python. > My Enum type and capnp proto as follow: > > definition in C++: > enum Case { > A = 0, > B = 1, > C = 2, > D = 255 > }; > > proto: > enum Case { > A @0; > B @1; > C @2; > D @3; > } > > python code to parse data: > encoded_msg = self.sock.recv() > dbg_msg = self.msg_capnp.Msg.from_bytes(encoded_msg) > msg_dict = dbg_msg.to_dict() > > python crashes with following error messages: > File "capnp/lib/capnp.pyx", line 1108, in > capnp.lib.capnp._DynamicStructReader.to_dict (capnp/lib/capnp.cpp:24297) > > File "capnp/lib/capnp.pyx", line 893, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:19834) > > File "capnp/lib/capnp.pyx", line 899, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:20017) > > File "capnp/lib/capnp.pyx", line 863, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:19215) > > File "capnp/lib/capnp.pyx", line 899, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:20017) > > File "capnp/lib/capnp.pyx", line 899, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:20017) > > File "capnp/lib/capnp.pyx", line 907, in capnp.lib.capnp._to_dict > (capnp/lib/capnp.cpp:20140) > > File "capnp/lib/capnp.pyx", line 929, in > capnp.lib.capnp._DynamicEnum._as_str (capnp/lib/capnp.cpp:20509) > > RuntimeError: Member was null. > > It seems that python try to find a matching string for the given value, > but if my Enum type is Case::D, it can't find any. > As my Enum has to be defined in this way, and capn proto member have to > use continuous value, then how to let my python code works? > > Cheers, > > Hong > > > -- > You received this message because you are subscribed to the Google Groups > "Cap'n Proto" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > Visit this group at https://groups.google.com/group/capnproto. > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. Visit this group at https://groups.google.com/group/capnproto.
