-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBJ_parser.js
42 lines (30 loc) · 1.09 KB
/
BJ_parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const parserModule = __importDefault(require('./src/BJ_parser'));
const parserSchemaModule = require('./src/parseSchema');
module.exports = function (RED) {
function ParserNode(config) {
RED.nodes.createNode(this, config);
const parserConfig = {
suppressHeader: config.suppressedLogs.toUpperCase().split(',').map(value => value.trim()),
maxStrLength: config.maxBinLen,
binAsHex: true,
directToConsole: false,
};
this.on('input', message => {
const stringHex = message.payload;
// DELETE: This is just for development, all schemas should be validated beforehand
const schema = parserSchemaModule.parseRuleMap(message.parsingSchema);
const parser = new parserModule.default(schema, parserConfig);
message.payload = parser.runHexAndWrap(stringHex);
if(schema.clearGlobalVars == true){
global = {};
}
message.payload.schemaInfo = {
"name" : schema.name,
"version" : schema.version,
"schemaVersion" : schema.schemaVersion
};
this.send(message);
});
}
RED.nodes.registerType('BJ-parser', ParserNode);
};