emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.57k stars 411 forks source link

Why is only the value part of the dictionary-type UserProperty used? #527

Open JyHu opened 1 year ago

JyHu commented 1 year ago

In the definition of the entire framework, UserProperty is defined as a dictionary type. However, in the usage of FrameSubscribe.swift and FrameUnsubscribe.swift, only the values of the dictionary are extracted. Why is that?

        if let userProperty = self.userProperty {
            let dictValues = [String](userProperty.values)
            for (value) in dictValues {
                properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.userProperty.rawValue, value: value.bytesWithLength)
            }
        }
JyHu commented 1 year ago

Same as https://github.com/emqx/CocoaMQTT/issues/488

leeway1208 commented 1 year ago

Sorry for the late reply. If you wanna use some properties, you can submit issues here or make PR to us. Thanks

JyHu commented 1 year ago

I wonder if there is an official standard practice for this. In the actual implementation, the userProperty is set as a Dictionary type, but when interacting with the backend, only the values of the Dictionary are used. In my testing, I found that we need to send all the data to the backend. Here is an example of the code:

 if let userProperty = self.userProperties {
     for (key, value) in userProperty {
           properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.userProperty.rawValue, value: key.bytesWithLength + value.bytesWithLength)
     }
}

Furthermore, I noticed that there are many places within the framework where userProperty is passed around, but only the values are used.

@leeway1208