Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SmlProtocol.prototype.handleMessage = function handleMessage(message) {
message = message.toString('hex');
var regMessage = message.match(regCompleteMsg);
if (!regMessage || !regMessage[1]) {
this.callUserCallback(new Error('Message ' + message + 'invalid'), null);
return null;
}
var smlFile = new OpenSml.SmlFile();
var idx = message.indexOf(regMessage[1]);
if (this.options.debug === 2) this.options.logger('MSG IDX ' + idx);
try {
smlFile.parse(Buffer.from(regMessage[1], 'hex'));
}
catch (err) {
smlFile = null;
this.callUserCallback(new Error('Error while parsing SML message: ' + err + ': Message: ' + regMessage[1]), null);
if (idx !== -1) {
return Buffer.from(message.substr(idx+regMessage[1].length), 'hex');
}
return null;
}
if (this.options.debug === 2) this.options.logger('SML MESSAGE: ' + smlFile.toString());