Skip to content

Commit

Permalink
fixes for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan lavon committed May 4, 2015
1 parent 47c3c10 commit 4d3c647
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ module.exports = function buildDecode(decodingTypes) {

var first = buf.readUInt8(offset)
, length
, result
, result = 0
, type
, bytePos

if (!hasMinBufferSize(first, bufLength)) {
return null
Expand All @@ -142,10 +143,9 @@ module.exports = function buildDecode(decodingTypes) {
return buildDecodeResult(result, 5)
case 0xcf:
// 8-bytes BE unsigned int
// Read long byte by byte, big-endian
var result = 0;
for (var k = 7; k >= 0; k--) {
result += (buf.readUInt8(offset + k + 1) * Math.pow(2 , (8 *(7-k))));
// Read long byte by byte, big-endian
for (bytePos = 7; bytePos >= 0; bytePos--) {
result += (buf.readUInt8(offset + bytePos + 1) * Math.pow(2 , (8 *(7-bytePos))));
}
return buildDecodeResult(result, 9)
case 0xd0:
Expand Down
8 changes: 4 additions & 4 deletions lib/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ module.exports = function buildEncode(encodingTypes) {

function write64BitUint(buf, obj) {
// Write long byte by byte, in big-endian order
for (var k = 7; k >= 0; k--) {
buf[k + 1] = (obj & 0xff);
obj = obj / 256;
}
for (var currByte = 7; currByte >= 0; currByte--) {
buf[currByte + 1] = (obj & 0xff);
obj = obj / 256;
}
}

function isFloat(n) {
Expand Down
1 change: 1 addition & 0 deletions test/64-bits-unsigned-integers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test('encoding/decoding 64-bits big-endian unsigned integers', function(t) {
for (var k = 7; k >= 0; k--) {
result += (buf.readUInt8(k + 1) * Math.pow(2 , (8 *(7-k))));
}
t.equal(result, num, 'must decode correctly');
t.end()
})

Expand Down

0 comments on commit 4d3c647

Please sign in to comment.