Hi
I’m using the Paho C++ library.
I’m having trouble with the type information for V5 properties that are stored in mqtt::properties which is a wrapper around the native ‘C’ support for properties.
I would like to be able to serialize an MQTT message which means storing the topic, payload, qos, retain flag and also a list of V5 properties such as correlation data etc.
There are different flavours of constructor for mqtt::property, so it’s easy to create one, but nothing is stored about the type, so I don’t see how it is possible to know you could deserialize it.
For example:
mqtt::properties props {
{ mqtt::property::RESPONSE_TOPIC, "a/b/reply" },
{ mqtt::property::CORRELATION_DATA, 100 },
{ mqtt::property::USER_PROPERTY, "timestamp", “2024-01-12” }
};
That sets up a set of three properties that could be used when building a message for say a publish. If I were to then use the props variable to get say the entry with a type of CORRELATION_DATA, how could I know that is contains an integer
and not say a string?
The underlying ‘C’ struct has a union for storing the value so the size will always be the largest member, but again it doesn’t store anything to say which member is the one containing the actual data.
Gary Metalle
Senior Embedded Software Engineer