Skip to content

Commit

Permalink
refactor(npdu): fail early on protocol version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
kueblc committed May 15, 2024
1 parent 5e22199 commit c120144
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/npdu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ module.exports.decodeFunction = (buffer, offset) => {
module.exports.decode = (buffer, offset) => {
let adrLen;
const orgOffset = offset;
offset++;
const protocolVersion = buffer[offset++];
if (protocolVersion !== BACNET_PROTOCOL_VERSION) {
return undefined;
}
const funct = buffer[offset++];
let destination;
if (funct & baEnum.NpduControlBit.DESTINATION_SPECIFIED) {
Expand Down Expand Up @@ -80,9 +83,6 @@ module.exports.decode = (buffer, offset) => {
offset += 2;
}
}
if (buffer[orgOffset + 0] !== BACNET_PROTOCOL_VERSION) {
return undefined;
}
return {
len: offset - orgOffset,
funct,
Expand Down

0 comments on commit c120144

Please sign in to comment.