Hi all,
is there somewhere any documentation about the headers used by the B4XSerializator?
I'd like to peek at first few bytes in order to find out:
1. whether a bytes array was originally serialized by B4XSerializator
2. the type of the original message
What will it be useful for?
Today I opened up an old project of mine that made use of Cloudmqtt service as the MQTT broker.
Everything works as expected as long I use my app and its B4J counterpart (both use a common user defined type). But when I try Cloudmqtt's websocket console it obviously can't work since that doesn't even know about a B4XSerializator object.
So my idea was to add a flag byte initialized to value zero to my user defined type and inspect Payload first byte to test whether it was zero (message generated by my app) or not (message from Cloudmqtt console).
That didn't work because of the B4XSerializator header. So my question: can I inspect the first few bytes of a Payload to determine if it comes from a B4XSerializator object or not?
Thank you.
I can confirm that testing for 0x78-0x9C as the first two bytes in Payload leads to a correct identification of a message.
If it can be helpful to others, this is the code I'm using when "decoding" a received message:
B4X:
Dim m1 As TMessage
If ((Payload(0) = 120) And (Payload(1) = -100)) Then 'B4xSerializator object
m1 = ser.ConvertBytesToObject(Payload)
Else 'Cloudmqtt console
m1.Initialize
m1.Body = BytesToString(Payload, 0, Payload.Length, "utf8")
m1.From = "<anonymous>"
End If