Skip to content

Commit

Permalink
Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Baba committed Jul 23, 2018
1 parent 61ff424 commit fbfcb60
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/lwm2m-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,18 +874,15 @@ class Observe extends RequestHandler {
class Discover extends Read {
buildResponse() {
let buf = [];
let len = 0;
Object.keys(this.resources).forEach((key) => {
let r = this.resources[key];
if (r instanceof Resource) {
buf.push(r.id & 0xff); // ResourceId LSB
buf.push((r.id >> 8) & 0xff); // ResourceId MSB
++len;
}
this.resources.map((r) => {
return parseInt(r.uri.split('/')[3]);
}).sort((a, b) => a - b).forEach((id) => {
buf.push(id & 0xff); // ResourceId LSB
buf.push((id >> 8) & 0xff); // ResourceId MSB
});
if (this.getStatus() < COAP_ERROR.COAP_400_BAD_REQUEST) {
this.response = Buffer.concat([this.response, Buffer.from(buf)]);
this.setResourceLen(len);
this.setResourceLen(this.resources.length);
}
}
}
Expand Down

0 comments on commit fbfcb60

Please sign in to comment.