SwiftMQTT
SwiftMQTT copied to clipboard
paranthesis missing
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.
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" } }
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.
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.