Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Getting type information for MQTT V5 properties

Hi

 

Sorry I didn’t spot it earlier but there is a function in the ‘C’ library called MQTTProperty_getType() that will return a code from the following enum when given a V5 property type:

 

/** The one byte MQTT V5 property type */

enum MQTTPropertyTypes {

  MQTTPROPERTY_TYPE_BYTE,

  MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER,

  MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER,

  MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER,

  MQTTPROPERTY_TYPE_BINARY_DATA,

  MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING,

  MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR

};

 

So for example CORRELATION_DATA is binary data and USER_PROPERTY is always a string pair.

 

Something that is binary data can be easily stored and read-back, but I guess unless you were the one that generated it, it’s probably not safe to assume the format other than it is an array of raw bytes.

 

Gary

 

From: paho-dev <paho-dev-bounces@xxxxxxxxxxx> On Behalf Of Gary Metalle via paho-dev
Sent: 12 January 2024 14:05
To: paho-dev@xxxxxxxxxxx
Cc: Gary Metalle <Gary.Metalle@xxxxxxxxx>
Subject: [paho-dev] Getting type information for MQTT V5 properties

 

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

 

 


Back to the top