Hi
Following on from something like this - How to create msg keys? - #11 by waquete
I'd like to create adhoc object key names depending on the contents of the incoming payload.
For example, I never know what the payload will contain, but I can strip it into the component parts.
IE
508 transport info:
status: play
speed: 100
A simple .split("\n")
gives me an array containing each line.
I can split each link to give me the pairs of data (IE, Label and Value)
replies: array[3]
0: "508 transport info:
"
1: "status: play
"
2: "speed: 100
"
What I really want to do is create a new MSG.object
using the Label and put the Value in place.
var part = [];
var label = [];
var value = [];
msg.decode =[];
while (n < replies.length){
part =replies[n].split(":");
node.status({fill:"red",shape:"ring",text:"n = "+n});
if (part[0].length > 1 && part[1].length > 1){
label =part[0].replace(" ","").replace("\n","").replace("\r","");
value =part[1].replace(" ","").replace("\n","").replace("\r","");
msg.decode[n] = {[label]:value};
}
n = n + 1;
part = [];
label = [];
value = [];
}
which gives me something like
decode: array[3]
0: undefined
1: object
status: "play"
2: object
speed: "100"
This gets me close, but all it's done is make an array of objects again, which doesn't work for me further down the flow when I'm trying trigger events based on the existent of a MSG object (or not)
What I really would like to see is
msg.status = "play"
msg.speed = "100"
msg.timecode = "867"
msg.clipid = "1"
and so on
(I can deal with converting Strings to Numbers later if needed, but most of the time they are simply being pushed back out as String commands and the next device doesn't care)
in my noob mind I thought that I can create the msg object a little like this
msg.'label' = value
I'm sure I'm not the first to ask this question, but I've searched for hours trying to find a similar question / answer.
For those that are interested in the "why", I'm working with BlackMagicDesign HyperDecks and trying to sync multiple decks to clips and timecode positions, to avoid the slightest drift
A basic test worked really well, until an unexpected payload arrives with "extra" data, then it all goes wrong.
So I need a solution that can tolerate these extra bits of data