Messages that send data for a number of components can use indexing to reduce data size. For example TLC S0001 sends the signal group status of all signal groups.
Each signal group has a unique component id. Let's assume format A is used and these components exist:
KK+AG0503=001SG001
KK+AG0503=001SG002
KK+AG0503=001SG002
A simple way to send the status of each group would be:
{
"KK+AG0503=001SG001": "0",
"KK+AG0503=001SG002": "A",
"KK+AG0503=001SG002": "1"
}While this works, it takes up a bit of space, since you need to send the all the full component ids. Indexing can be used to reduce the space used:
{
"1": "b",
"2": "A",
"3": "1"
}This requires a clear link between index and compomnent id. With format A ids, the last part is an integer, which is unique for each type of component. E.g. "KK+AG0503=001SG001" has index 1 due to the trailing "001".
Data can be further reduces by packing the statuses into a single string, with each character representing the status of a component:
"0A1"
However, this use of indexes is stil the same.
With format B, slashes can be used to organize components into groups:
/sg/a/1
/sg/a/2
/sg/b/1
/sg/b/2
/dl/video/1
/dl/video/2
/dl/radar/1
/dl/radar/2
With format B, ids does not have to include integers, e.g.:
/sg/a1_bus
/sg/a1_bike
/sg/a1_car
You can reference groups of components, e.g.:
`/`: all components
`/dl`: all detecors
`/dl/video`: all video detectors
`/dl/radar`: all detectors
`/dl/radar/2`: a particular radar detector
Referencing a group of components can be used when you subscribe to certain status updates. In cases where the result is send in a concise format that relies on indexes, you will receive an explicing mapping.
Because the mapping only changes in the rare case that the configuration of components changes, you will typically only receive it once, which saves bandwidth.
The mapping consists of an ordered array with array positions represents indexes, starting from 1. For example, if you subscribe to status updates for /sg, you will receive this mapping:
[
"/sg/a/1",
"/sg/a/2",
"/sg/b/1",
"/sg/b/2"
]The actual data can then be send as a concise string, with each character providing the status for the corresponding component in the mapping. For example if you get the status string "bA01" it would mean:
/sg/a/1 = b
/sg/a/2 = A
/sg/b/1 = 0
/sg/b/2 = 1
If if you subscribe to /sg/b, you will receive this mapping:
[
"/sg/b/1",
"/sg/b/2"
]If you get the status string "A2" it would mean:
/sg/b/1 = A
/sg/b/2 = 2
If you subscribe to a single component, e.g. /dl/radar/2 there is no need for a mapping. The status string will consists of a single character, e.g. "B" which referes to the component you subscribed to.
All this indexing can be left out of the core spec if we send explicit mappings in each relevant statuses.
But we could choose to add support for indexing in the core, for example by sending an ordered list of components when you connect:
/sg/a/1
/sg/a/2
/sg/b/1
/sg/b/2
/dl/video/1
/dl/video/2
/dl/radar/1
/dl/radar/2
Based on this list, it's easy to get indexes relative to a group. Simply enumerate all ids under the given path (group). Eg. if you subscribe to /dl/video, the following ids fall under that path:
/dl/video/1
/dl/video/2
First item is index 1, second is 2, and so on.