choosing the bits of the string to work on
I figured that as well, except I can't figure out how it is working in this example. I'm using Wildfire as an example and I don't understand how the substr is getting the needed info from the string. Usually there is a position and then length in a substring function. This is using only one component.
I suppose it might me logical if looked at a certain way and the order the data was placed into the msg and know the length of each data type that was placed there. But this would be a really messy way to do this.
the example is...
Send
broadcast.send(ignition_msg(pos));
return Binary.encodeInt(seq) ~ Binary.encodeByte(1) ~ Binary.encodeCoord(pos);
The parsing
Parse(source, msg)
var type = Binary.decodeByte(substr(msg, 5));
var pos = Binary.decodeCoord(substr(msg, 6));
Another example using different data...
Send
broadcast.send(retardant_drop_msg(pos, radius, volume));
Parse
var pos = Binary.decodeCoord(substr(msg, 6));
var radius = Binary.decodeDouble(substr(msg, 36));
Does it know what data by the "type" and the substring is the length of that type data or is it the position?
In the first example "byte" is at pos 5 and 1 byte or position long? So pos is at 6?
pos in both examples must be at position 6 and is by default the size of a coord?
OK, I think I see it now. For Coord...
coord.set_latlon(Binary.decodeDouble(substr(str, 0)),
Binary.decodeDouble(substr(str, 10)),
Binary.decodeDouble(substr(str, 20)));
That is 30, so pos, which is a coord starts at 6 and is 30 long, so radius "double" stars at 36.
I think the message has a 4 Byte id at the start, so the first encoded data will always be at 5.
Still need to know how to encode and decode a "type" sting.
I may have to use Emesary, but it looks as complicated and I am so close to having this working.