Skip to content

Commit

Permalink
chore: slice -> subarray (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting authored Nov 28, 2023
1 parent f2db0c2 commit 03f458d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions bin/generate-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function decoderFn(method) {
break;
case 'longstr':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = buffer.slice(offset, offset + len);');
println('val = buffer.subarray(offset, offset + len);');
println('offset += len;');
break;
case 'shortstr':
Expand All @@ -505,7 +505,7 @@ function decoderFn(method) {
break;
case 'table':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = decodeFields(buffer.slice(offset, offset + len));');
println('val = decodeFields(buffer.subarray(offset, offset + len));');
println('offset += len;');
break;
default:
Expand Down Expand Up @@ -657,7 +657,7 @@ function encodePropsFn(props) {
// size does not include the frame header or frame end byte
println('buffer.writeUInt32BE(offset - 7, 3);');
println('buffer.writeUInt16BE(flags, 19);');
println('return buffer.slice(0, offset + 1);');
println('return buffer.subarray(0, offset + 1);');
println('}');
}

Expand Down Expand Up @@ -697,7 +697,7 @@ function decodePropsFn(props) {
break;
case 'longstr':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = buffer.slice(offset, offset + len);');
println('val = buffer.subarray(offset, offset + len);');
println('offset += len;');
break;
case 'shortstr':
Expand All @@ -707,7 +707,7 @@ function decodePropsFn(props) {
break;
case 'table':
println('len = buffer.readUInt32BE(offset); offset += 4;');
println('val = decodeFields(buffer.slice(offset, offset + len));');
println('val = decodeFields(buffer.subarray(offset, offset + len));');
println('offset += len;');
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions lib/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function decodeFields(slice) {
break;
case 'F':
len = slice.readUInt32BE(offset); offset += 4;
val = decodeFields(slice.slice(offset, offset + len));
val = decodeFields(slice.subarray(offset, offset + len));
offset += len;
break;
case 'A':
Expand Down Expand Up @@ -290,7 +290,7 @@ function decodeFields(slice) {
break;
case 'x':
len = slice.readUInt32BE(offset); offset += 4;
val = slice.slice(offset, offset + len);
val = slice.subarray(offset, offset + len);
offset += len;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class Connection extends EventEmitter {

for (var offset = 0; offset < body.length; offset += maxBody) {
var end = offset + maxBody;
var slice = (end > body.length) ? body.slice(offset) : body.slice(offset, end);
var slice = (end > body.length) ? body.subarray(offset) : body.subarray(offset, end);
var bodyFrame = makeBodyFrame(channel, slice);
writeResult = buffer.write(bodyFrame);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports.amqplain = function(user, passwd) {
response: function() {
const buffer = Buffer.alloc(16384);
const size = codec.encodeTable(buffer, { LOGIN: user, PASSWORD: passwd}, 0);
return buffer.slice(4, size);
return buffer.subarray(4, size);
},
username: user,
password: passwd
Expand Down
8 changes: 4 additions & 4 deletions test/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ suite("Implicit encodings", function() {
test(name, function() {
var buffer = Buffer.alloc(1000);
var size = codec.encodeTable(buffer, val, 0);
var result = buffer.slice(4, size);
var result = buffer.subarray(4, size);
assert.deepEqual(expect, bufferToArray(result));
});
});
Expand All @@ -83,7 +83,7 @@ var amqp = require('./data');
function roundtrip_table(t) {
var buf = Buffer.alloc(4096);
var size = codec.encodeTable(buf, t, 0);
var decoded = codec.decodeFields(buf.slice(4, size)); // ignore the length-prefix
var decoded = codec.decodeFields(buf.subarray(4, size)); // ignore the length-prefix
try {
assert.deepEqual(removeExplicitTypes(t), decoded);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ function roundtripMethod(Method) {
return forAll(Method).satisfy(function(method) {
var buf = defs.encodeMethod(method.id, 0, method.fields);
// FIXME depends on framing, ugh
var fs1 = defs.decode(method.id, buf.slice(11, buf.length));
var fs1 = defs.decode(method.id, buf.subarray(11, buf.length));
assertEqualModuloDefaults(method, fs1);
return true;
});
Expand All @@ -215,7 +215,7 @@ function roundtripProperties(Properties) {
var buf = defs.encodeProperties(properties.id, 0, properties.size,
properties.fields);
// FIXME depends on framing, ugh
var fs1 = defs.decode(properties.id, buf.slice(19, buf.length));
var fs1 = defs.decode(properties.id, buf.subarray(19, buf.length));
assert.equal(properties.size, ints.readUInt64BE(buf, 11));
assertEqualModuloDefaults(properties, fs1);
return true;
Expand Down
10 changes: 5 additions & 5 deletions test/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ suite("Explicit parsing", function() {
test('Parse partitioned', function() {
var input = inputs();
var frames = new Frames(input);
input.write(HB.slice(0, 3));
input.write(HB.subarray(0, 3));
assert(!frames.recvFrame());
input.write(HB.slice(3));
input.write(HB.subarray(3));
assert(frames.recvFrame() === HEARTBEAT);
assert(!frames.recvFrame());
});
Expand Down Expand Up @@ -143,9 +143,9 @@ suite("Parsing", function() {
var onethird = Math.floor(full.length / 3);
var twothirds = 2 * onethird;
return [
full.slice(0, onethird),
full.slice(onethird, twothirds),
full.slice(twothirds)
full.subarray(0, onethird),
full.subarray(onethird, twothirds),
full.subarray(twothirds)
];
}));
});
Expand Down

0 comments on commit 03f458d

Please sign in to comment.