Script input/output

Encode

Input to the encoder is an object (for example, impactRequest). The following table lists the methods that are required in the script.

info Method Remark
requestType utils.getRequestType(impactRequest); var utils = Java.type('com.nokia.transformation.script.model.TransformUtil');
resourceUri impactRequest.getResource();
resourceValue impactRequest.getValue();

The output of encode function is expected to be a byte array. There is a method in utils to form the return message.

Method Remark
utils.createBinaryResponse(int8ArrBuf);

var utils = Java.type('com.nokia.transformation.script.model.TransformUtil');

input is an int8 array

utils.createBinaryResponse(int8ArrBuf, _map, true); If the request is unacknowledged, that is, the device does not send any ack/response uplink message then pass the 3rd arg as true

Decode

The input to the decoder is an object (for example, decodeCtx). Following methods are used in the script.

info Method Remark
bytes decodeCtx.getUplinkMessage(); this returns an int8 array and contains the payload from device
corrId decodeCtx.getRequest().getCorrelatorId(); Correlation ID for the associated read request. This is not required in case of notification message from device.
endpointClientName client.getEndpoint(); The resource "device/0/endPointClientName" need to be set with the return value of this method.
For Read Response:
{
    "responseCode": 0,
    "requestStatus": 0,
    "response": [
        {
            "device/0/endPointClientName": "output of client.getEndpoint()",
            "resource1": "value1",
            "resource2": "value2"
        }
    ],
    "correlatorId": "output of decodeCtx.getRequest().getCorrelatorId()"
};

For Notify Message:

{
    "details": {
        "device/0/endPointClientName": "output of client.getEndpoint()",
        "resource1": "value1",
        "resource2": "value2"
    }
}

To return the JSON you can use the utils function utils.createJsonResponse(JSON.stringify(resp));

Method Remark
utils.createJsonResponse(JSON.stringify(resp));

var utils = Java.type('com.nokia.transformation.script.model.TransformUtil');

Input is a stringified JSON