Skip to content

Commit

Permalink
fix(bacnet-asn1): correct octet-string encoding and decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
fh1ch committed May 30, 2017
1 parent f10984b commit aee51a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/bacnet-asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var encode_octetString = function(buffer, octetString, octetOffset, octetCount)
};

var encode_application_octetString = function(buffer, octetString, octetOffset, octetCount) {
encodeTag(buffer, baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_octetString, false, octetCount);
encodeTag(buffer, baEnum.BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING, false, octetCount);
encode_octetString(buffer, octetString, octetOffset, octetCount);
};

Expand Down Expand Up @@ -865,9 +865,13 @@ var decode_double_safe = function(buffer, offset, lenValue) {
};

var decode_octetString = function(buffer, offset, maxLength, octetStringOffset, octetStringLength) {
var octetString = [];
for (var i = octetStringOffset; i < (octetStringOffset + octetStringLength); i++) {
octetString.push(buffer[offset + i]);
}
return {
len: octetStringLength,
value: Buffer.from(buffer.slice(offset, octetStringLength))
value: octetString
};
};

Expand Down
11 changes: 5 additions & 6 deletions test/unit/bacnet-services.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@ describe('bacstack - Services layer', function() {
});
});

xit('should successfully encode and decode an octet-string value', function() {
it('should successfully encode and decode an octet-string value', function() {
var buffer = utils.getBuffer();
baServices.EncodeReadPropertyAcknowledge(buffer, {type: 8, instance: 40000}, 81, 0xFFFFFFFF, [
// FIXME: correct octet-string implementation
// {Tag: 6, Value: []}
// {Tag: 6, Value: [1, 2, 100, 200]}
{Tag: 6, Value: []},
{Tag: 6, Value: [1, 2, 100, 200]}
]);
var result = baServices.DecodeReadPropertyAcknowledge(buffer.buffer, 0, buffer.offset);
delete result.len;
Expand All @@ -210,8 +209,8 @@ describe('bacstack - Services layer', function() {
propertyIdentifier: 81
},
valueList: [
{type: 6, value: [], len: 0},
{type: 6, value: [1, 2, 100, 200], len: 4}
{type: 6, value: [], len: 1},
{type: 6, value: [1, 2, 100, 200], len: 5}
]
});
});
Expand Down

0 comments on commit aee51a5

Please sign in to comment.