diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index cab68a96..7a6eb22b 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -306,6 +306,49 @@ typedef guint pyg_flags_type; Py_XINCREF($input); } +/* Cast PacketPayload pointers to correct subclass type. */ +%ignore sigrok::Packet::payload; + +%extend sigrok::Packet +{ + std::shared_ptr _payload_header() + { + return dynamic_pointer_cast($self->payload()); + } + std::shared_ptr _payload_meta() + { + return dynamic_pointer_cast($self->payload()); + } + std::shared_ptr _payload_analog() + { + return dynamic_pointer_cast($self->payload()); + } + std::shared_ptr _payload_logic() + { + return dynamic_pointer_cast($self->payload()); + } +} + +%extend sigrok::Packet +{ +%pythoncode +{ + def _payload(self): + if self.type == PacketType.HEADER: + return self._payload_header() + elif self.type == PacketType.META: + return self._payload_meta() + elif self.type == PacketType.LOGIC: + return self._payload_logic() + elif self.type == PacketType.ANALOG: + return self._payload_analog() + else: + return None + + payload = property(_payload) +} +} + %{ #include "libsigrok/libsigrok.hpp" diff --git a/bindings/swig/classes.i b/bindings/swig/classes.i index 07ec9139..4fb37315 100644 --- a/bindings/swig/classes.i +++ b/bindings/swig/classes.i @@ -260,8 +260,6 @@ typedef std::map %attribute(sigrok::Packet, const sigrok::PacketType *, type, type); -%attributestring(sigrok::Packet, - std::shared_ptr, payload, payload); %attributemap(Meta, map_ConfigKey_Variant, config, config);