SwiftMQTT icon indicating copy to clipboard operation
SwiftMQTT copied to clipboard

paranthesis missing

Open venkatajagannathtata opened this issue 8 years ago • 3 comments

Hi,

whenever I publish or subscribe we are missing "{" in the JSON. so finally it says invalid JSON payload to server. So app is unable to consume that JSON.

venkatajagannathtata avatar Nov 22 '16 09:11 venkatajagannathtata

for a sample json like this { d = { text = "siva this is venkata" } }

after receiving in atleast once case its missing "{" and receiving like below. I solved this as well. I am ready to share the changes . you are taking payload from 2nd character after dividing from header and payload combination.

d = { text = "siva this is venkata" } }

venkatajagannathtata avatar Nov 22 '16 14:11 venkatajagannathtata

Sorry, but I didn't face this issue till now. It would be great if you could replicate this issue with a failing test case.

bhargavg avatar Nov 23 '16 09:11 bhargavg

I have corrected in my code and the change is in MQTTPublishPacket.swift

` if qos != .atLeastOnce { messageID = 256 * UInt16(payload[0]) + UInt16(payload[1]) payload = payload.subdata(in: 0..<payload.endIndex)

        let datastring = NSString(data: payload, encoding: String.Encoding.utf8.rawValue)
        print(datastring)
        
    } else {
        messageID = 0
    }

`

Now if you notice your old code the payload.subdata line you are not starting from 0. You are starting from 2...which was the cause of that problem.

venkatajagannathtata avatar Nov 25 '16 13:11 venkatajagannathtata