Hello everyone,
I am trying to wrap a C++ library for use from Python that makes use of protobuf messages. Based on data gathered in Python, I would like to construct these messages in Cython and pass these message objects to the C++ library for use. The general message structure combines a struct with a union like below:
# messages.pb.h:typedef struct _Messages_GeneralMessage {
uint64_t timestamp;
pb_size_t which_contents;
union {
Messages_SensorData sensor_data;
Messages_DeviceEvent device_event;
} contents;
} Messages_GeneralMessage;
I've attempted to define this message struct in my .pxd file like below. This was based on a suggestion found on StackOverflow
here combined with the documentation on
interfacing with Extercal C Code.
# c_messages.pxd: cdef extern from "messages.pb.h":
ctypedef struct Messages_SensorData:
...
ctypedef struct Messages_DeviceEvent:
...
ctypedef union Messages:
Messages_SensorData sensor_data
Messages_DeviceEvent device_event
ctypedef struct Messages_GeneralMessage:
uint64_t timestamp
pb_type_t which_contents
Messages contents
This however runs into trouble with the 'Messages' union I've defined when compiling the extension.
use_c_messages.cpp(2385): error C2065: 'Messages': undeclared identifierIt seems to be looking for the 'Messages' identifier in the .pb.h file, which is logically not defined there. Any thoughts on how to properly handle the Messages_GeneralMessage structure from the .pb.h file?
Cheers,
Jeroen