2018-05-06 14:18:41 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
import Utils from "../Utils.mjs";
|
|
|
|
import {DELIM_OPTIONS} from "../lib/Delim.mjs";
|
2018-05-06 14:18:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To Decimal operation
|
|
|
|
*/
|
|
|
|
class ToDecimal extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ToDecimal constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "To Decimal";
|
|
|
|
this.module = "Default";
|
|
|
|
this.description = "Converts the input data to an ordinal integer array.<br><br>e.g. <code>Hello</code> becomes <code>72 101 108 108 111</code>";
|
2019-07-29 18:09:46 +02:00
|
|
|
this.inputType = "ArrayBuffer";
|
2018-05-06 14:18:41 +02:00
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
"name": "Delimiter",
|
|
|
|
"type": "option",
|
|
|
|
"value": DELIM_OPTIONS
|
2018-11-07 15:39:33 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Support signed values",
|
|
|
|
"type": "boolean",
|
|
|
|
"value": false
|
2018-05-06 14:18:41 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-29 18:09:46 +02:00
|
|
|
* @param {ArrayBuffer} input
|
2018-05-06 14:18:41 +02:00
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
2019-07-29 18:09:46 +02:00
|
|
|
input = new Uint8Array(input);
|
2018-11-07 15:39:33 +01:00
|
|
|
const delim = Utils.charRep(args[0]),
|
|
|
|
signed = args[1];
|
|
|
|
if (signed) {
|
|
|
|
input = input.map(v => v > 0x7F ? v - 0xFF - 1 : v);
|
|
|
|
}
|
2018-05-06 14:18:41 +02:00
|
|
|
return input.join(delim);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ToDecimal;
|