cargo / src /mqtt /topicParser.js
vish85521's picture
Upload 53 files
964569f verified
Raw
History Blame Contribute Delete
441 Bytes
const TELEMETRY_TOPIC_REGEX =
/^tenant\/([^/]+)\/truck\/([^/]+)\/container\/([^/]+)\/telemetry$/;
function parseTelemetryTopic(topic) {
if (typeof topic !== "string") {
return null;
}
const match = topic.match(TELEMETRY_TOPIC_REGEX);
if (!match) {
return null;
}
return {
tenantCode: match[1],
truckCode: match[2],
containerCode: match[3],
topic,
};
}
module.exports = {
parseTelemetryTopic,
};