Proto 'planilla' expander
The code in this module is used to preprocess a process definition (A.K.A. Protocol) and expand it to a flattened format.
Motivation
SWAR version 1.x doesn't support arrays
so every value needs to be a scalar.
The current workaround is to expand an array
as a set of scalar values using a postfix number.
So instead of having an array x
you will have n scalars:
x_1 x_2 ... x_n
To be able to do that you need to know n beforehand. This limit the workaround to cases where n is fixed.
This module was created to solve that problem
Payload Management
Given the data to initialize a process in a standard json format, for example:
const initialPayload = {
"a": 10,
"b": "xxx",
"tires": [
{"pressure": 36},
{"pressure": 36},
{"pressure": 40},
{"pressure": 40}
],
"doors": [
{"width": 10},
{"width": 10},
]
}
The data can be transformed in a flatten version of the payload for example:
flattenPayload(initialPayload)
Will return
const result = {
"a": 10,
"b": "xxx",
"pressure_1": 36,
"pressure_2": 36,
"pressure_3": 40,
"pressure_4": 40,
"width_1": 10,
"width_2": 10
};
Also check payload.ts
for additional functions to operate Payloads
Process (a.k.a. Protocol) parsing and expansion
As of today a Protocol is just a set of activities each one containing a set of instructions
Appropriate Classes Activity
and Instructions
are created to represent this concepts. A protocol definition is just an Array<Activity>
A simple end to end example of expansion will be like this:
const dimensions: Dimensions = extractDimensions(payload)
const activities: Array<Activity> = parseProtoString("A proto file loaded in a string")
const expandedActivities: Array<Activity> = expandAllActivities(activities, dimensions)
const bigString = exportToString(expandedActivities)