Skip to content

Commit cddd4a8

Browse files
authored
Merge pull request #773 from amqp-node/support-for-unsigned-int-edits
Support for unsigned int edits
2 parents 0a87ee4 + 648c155 commit cddd4a8

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

lib/codec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,31 @@ function encodeFieldValue(buffer, value, offset) {
188188
tag('b');
189189
buffer.writeInt8(val, offset); offset++;
190190
break;
191+
case 'unsignedbyte':
192+
case 'uint8':
193+
tag('B');
194+
buffer.writeUInt8(val, offset); offset++;
195+
break;
191196
case 'short':
192197
case 'int16':
193198
tag('s');
194199
buffer.writeInt16BE(val, offset); offset += 2;
195200
break;
201+
case 'unsignedshort':
202+
case 'uint16':
203+
tag('u');
204+
buffer.writeUInt16BE(val, offset); offset += 2;
205+
break;
196206
case 'int':
197207
case 'int32':
198208
tag('I');
199209
buffer.writeInt32BE(val, offset); offset += 4;
200210
break;
211+
case 'unsignedint':
212+
case 'uint32':
213+
tag('i');
214+
buffer.writeUInt32BE(val, offset); offset += 4;
215+
break;
201216
case 'long':
202217
case 'int64':
203218
tag('l');
@@ -243,6 +258,9 @@ function decodeFields(slice) {
243258
case 'b':
244259
val = slice.readInt8(offset); offset++;
245260
break;
261+
case 'B':
262+
val = slice.readUInt8(offset); offset++;
263+
break;
246264
case 'S':
247265
len = slice.readUInt32BE(offset); offset += 4;
248266
val = slice.toString('utf8', offset, offset + len);
@@ -251,6 +269,9 @@ function decodeFields(slice) {
251269
case 'I':
252270
val = slice.readInt32BE(offset); offset += 4;
253271
break;
272+
case 'i':
273+
val = slice.readUInt32BE(offset); offset += 4;
274+
break;
254275
case 'D': // only positive decimals, apparently.
255276
var places = slice[offset]; offset++;
256277
var digits = slice.readUInt32BE(offset); offset += 4;
@@ -282,6 +303,9 @@ function decodeFields(slice) {
282303
case 's':
283304
val = slice.readInt16BE(offset); offset += 2;
284305
break;
306+
case 'u':
307+
val = slice.readUInt16BE(offset); offset += 2;
308+
break;
285309
case 't':
286310
val = slice[offset] != 0; offset++;
287311
break;

test/codec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,16 @@ var testCases = [
4444
['null', {'void': null}, [4,118,111,105,100,86]],
4545

4646
// array, object
47-
['array', {array: [6, true, "foo"]},
48-
[5,97,114,114,97,121,65,0,0,0,12,98,6,116,1,83,0,0,0,3,102,111,111]],
49-
['object', {object: {foo: "bar", baz: 12}},
50-
[6,111,98,106,101,99,116,70,0,0,0,18,3,102,111,111,83,0,
51-
0,0,3,98,97,114,3,98,97,122,98,12]],
47+
['array', {array: [6, true, "foo"]},[5,97,114,114,97,121,65,0,0,0,12,98,6,116,1,83,0,0,0,3,102,111,111]],
48+
['object', {object: {foo: "bar", baz: 12}},[6,111,98,106,101,99,116,70,0,0,0,18,3,102,111,111,83,0,0,0,3,98,97,114,3,98,97,122,98,12]],
5249

5350
// exotic types
54-
['timestamp', {timestamp: {'!': 'timestamp', value: 1357212277527}},
55-
[9,116,105,109,101,115,116,97,109,112,84,0,0,1,60,0,39,219,23]],
56-
['decimal', {decimal: {'!': 'decimal', value: {digits: 2345, places: 2}}},
57-
[7,100,101,99,105,109,97,108,68,2,0,0,9,41]],
58-
['float', {float: {'!': 'float', value: 0.1}},
59-
[5,102,108,111,97,116,102,61,204,204,205]],
51+
['timestamp', {timestamp: {'!': 'timestamp', value: 1357212277527}},[9,116,105,109,101,115,116,97,109,112,84,0,0,1,60,0,39,219,23]],
52+
['decimal', {decimal: {'!': 'decimal', value: {digits: 2345, places: 2}}},[7,100,101,99,105,109,97,108,68,2,0,0,9,41]],
53+
['float', {float: {'!': 'float', value: 0.1}},[5,102,108,111,97,116,102,61,204,204,205]],
54+
['unsignedbyte', {unsignedbyte:{'!': 'unsignedbyte', value: 255}}, [12,117,110,115,105,103,110,101,100,98,121,116,101,66,255]],
55+
['unsignedshort', {unsignedshort:{'!': 'unsignedshort', value: 65535}}, [13,117,110,115,105,103,110,101,100,115,104,111,114,116,117,255,255]],
56+
['unsignedint', {unsignedint:{'!': 'unsignedint', value: 4294967295}}, [11,117,110,115,105,103,110,101,100,105,110,116,105,255,255,255,255]],
6057
];
6158

6259
function bufferToArray(b) {
@@ -109,6 +106,9 @@ suite("Roundtrip values", function() {
109106
amqp.Bit,
110107
amqp.Decimal,
111108
amqp.Timestamp,
109+
amqp.UnsignedByte,
110+
amqp.UnsignedShort,
111+
amqp.UnsignedInt,
112112
amqp.Double,
113113
amqp.Float,
114114
amqp.FieldArray,

test/data.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ var Decimal = label('decimal', transform(
8989
function(args) {
9090
return {'!': 'decimal', value: {places: args[1], digits: args[0]}};
9191
}, sequence(arb.UInt, Octet)));
92+
var UnsignedByte = label('unsignedbyte', transform(
93+
function(n) {
94+
return {'!': 'unsignedbyte', value: n};
95+
}, Octet));
96+
var UnsignedShort = label('unsignedshort', transform(
97+
function(n) {
98+
return {'!': 'unsignedshort', value: n};
99+
}, UShort));
100+
var UnsignedInt = label('unsignedint', transform(
101+
function(n) {
102+
return {'!': 'unsignedint', value: n};
103+
}, ULong));
92104

93105
// Signed 8 bit int
94106
var Byte = rangeInt('byte', -128, 127);
@@ -244,6 +256,9 @@ module.exports = {
244256
Float: Float,
245257
Timestamp: Timestamp,
246258
Decimal: Decimal,
259+
UnsignedByte: UnsignedByte,
260+
UnsignedShort: UnsignedShort,
261+
UnsignedInt: UnsignedInt,
247262
FieldArray: FieldArray,
248263
FieldTable: FieldTable,
249264

0 commit comments

Comments
 (0)