Skip to content

Commit

Permalink
fix(long-ulong-decoding): if we can represent it in js then do so
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Dec 9, 2015
1 parent 9870b9b commit 04bfd67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
14 changes: 12 additions & 2 deletions lib/types.js
Expand Up @@ -415,7 +415,12 @@ Types.prototype._initTypesArray = function() {
}
}
},
decoder: function(buf) { return new Int64(buf); }
decoder: function(buf) {
var int64 = new Int64(buf);
var number = int64.toNumber(false);
if (isFinite(number)) return number;
return int64;
}
},
{
code: 0x53,
Expand Down Expand Up @@ -495,7 +500,12 @@ Types.prototype._initTypesArray = function() {
throw new errors.EncodingError('Invalid encoding type for 64-bit value: ' + val);
}
},
decoder: function(buf) { return new Int64(buf); }
decoder: function(buf) {
var int64 = new Int64(buf);
var number = int64.toNumber(false);
if (isFinite(number)) return number;
return int64;
}
},
{
code: 0x55,
Expand Down
19 changes: 19 additions & 0 deletions test/integration/qpid/types.test.js
Expand Up @@ -59,5 +59,24 @@ describe('Types', function() {
});
});

it('should be able to send a big number', function(done) {
var message = 2148532224;
test.client.connect(config.address)
.then(function() {
return Promise.all([
test.client.createReceiver(config.defaultLink),
test.client.createSender(config.defaultLink)
]);
})
.spread(function(receiver, sender) {
receiver.on('message', function(msg) {
expect(msg.body).to.eql(message);
done();
});

return sender.send(message);
});
});

});
});
23 changes: 14 additions & 9 deletions test/unit/test_types.js
Expand Up @@ -461,11 +461,6 @@ describe('Types', function() {
});

describe('primitives', function() {
describe('errors', function() {

});


describe('scalar', function() {
[
{ name: 'null', value: buf([0x40]), expectedOutput: null },
Expand All @@ -483,10 +478,15 @@ describe('Types', function() {
{ name: 'smalluint', value: buf([0x52, 0x01]), expectedOutput: 1 },
{ name: 'uint0', value: buf([0x43]), expectedOutput: 0 },

{
name: 'ulong-not-int64',
value: buf([0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00]),
expectedOutput: 2148532224
},
{
name: 'ulong',
value: buf([0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]),
expectedOutput: new Int64(0xFFFFFFFF, 0xFFFFFFFF)
value: buf([0x80, 0x01, 0x01, 0x01, 0x01, 0x23, 0x45, 0x67, 0x89]),
expectedOutput: new Int64(0x01010101, 0x23456789)
},
{
name: 'smallulong', value: buf([0x53, 0x01]),
Expand All @@ -501,10 +501,15 @@ describe('Types', function() {
{ name: 'short', value: buf([0x61, 0x00, 0x01]), expectedOutput: 1 },
{ name: 'int', value: buf([0x71, 0x00, 0x00, 0x00, 0x01]), expectedOutput: 1 },
{ name: 'smallint', value: buf([0x54, 0x01]), expectedOutput: 1 },
{
name: 'long-not-int64',
value: buf([0x81, 0x00, 0x00, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00]),
expectedOutput: 2148532224
},
{
name: 'long',
value: buf([0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]),
expectedOutput: new Int64(0xFFFFFFFF, 0xFFFFFFFF)
value: buf([0x81, 0x01, 0x01, 0x01, 0x01, 0x23, 0x45, 0x67, 0x89]),
expectedOutput: new Int64(0x01010101, 0x23456789)
},
{ name: 'smalllong', value: buf([0x55, 0x23]), expectedOutput: 0x23 },
{
Expand Down

0 comments on commit 04bfd67

Please sign in to comment.