giggetto71 Active Member Licensed User Longtime User Jul 6, 2016 #1 Hi, I am using a B4XSerializator object to convert a payload I get from a MQTT message. In the mqttclient_messageArrived event handler I get an error I can't fix. Basically the below line crashes Code: Copy Dim obj As Object = serializator.ConvertBytesToObject(Payload) ' this one crashes Dim s As String = obj select s case "start" timer1.Enabled = True case "stop" timer1.enabled = False ......... serializator is defined in the Process_Global as Code: Copy Dim serializator As B4XSerializator while Payload is a parameter of the handler Code: Copy Sub mqttclient_MessageArrived (Topic As String, Payload() As Byte) The crash message is: java.util.zip.ZipException: incorrect header check at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:122) at java.io.DataInputStream.readByte(DataInputStream.java:265) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:131)..... ......... It really seems a trivial mistake but I can't understand what's wrong. Can anyone help? thanks!! pierluigi
Hi, I am using a B4XSerializator object to convert a payload I get from a MQTT message. In the mqttclient_messageArrived event handler I get an error I can't fix. Basically the below line crashes Code: Copy Dim obj As Object = serializator.ConvertBytesToObject(Payload) ' this one crashes Dim s As String = obj select s case "start" timer1.Enabled = True case "stop" timer1.enabled = False ......... serializator is defined in the Process_Global as Code: Copy Dim serializator As B4XSerializator while Payload is a parameter of the handler Code: Copy Sub mqttclient_MessageArrived (Topic As String, Payload() As Byte) The crash message is: java.util.zip.ZipException: incorrect header check at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:122) at java.io.DataInputStream.readByte(DataInputStream.java:265) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:131)..... ......... It really seems a trivial mistake but I can't understand what's wrong. Can anyone help? thanks!! pierluigi
Daestrum Expert Licensed User Longtime User Jul 7, 2016 #2 I may be totally wrong (as I have not used B4XSerializator or mqtt), but unless the object has been serialized by the sender, you cannot just convert an array of bytes back to an object, as the information about what type of object is encoded will be missing. Upvote 0
I may be totally wrong (as I have not used B4XSerializator or mqtt), but unless the object has been serialized by the sender, you cannot just convert an array of bytes back to an object, as the information about what type of object is encoded will be missing.
Erel B4X founder Staff member Licensed User Longtime User Jul 7, 2016 #3 How are you sending the messages? As @Daestrum wrote it will only work with messages that were serialized before being sent. If you are just sending strings then you can use BytesToString to convert the bytes to a string. Upvote 0
How are you sending the messages? As @Daestrum wrote it will only work with messages that were serialized before being sent. If you are just sending strings then you can use BytesToString to convert the bytes to a string.
giggetto71 Active Member Licensed User Longtime User Jul 7, 2016 #4 it worked. Thanks (as usual). Upvote 0