Skip to content

Commit

Permalink
Rename writeBuffers into copyBuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Sep 8, 2020
1 parent 732106d commit 63ce9c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/network/ClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {BuildInfo} from '../BuildInfo';
import {HazelcastClient} from '../HazelcastClient';
import {AddressImpl, IOError, UUID} from '../core';
import {ClientMessageHandler} from '../protocol/ClientMessage';
import {DeferredPromise, writeBuffers} from '../util/Util';
import {DeferredPromise, copyBuffers} from '../util/Util';
import {ILogger} from '../logging/ILogger';
import {
ClientMessage,
Expand Down Expand Up @@ -130,7 +130,7 @@ export class PipelinedWriter extends Writer {
buf = buffers[0];
} else {
// coalesce buffers
writeBuffers(this.coalesceBuf, buffers, totalLength);
copyBuffers(this.coalesceBuf, buffers, totalLength);
buf = this.coalesceBuf.slice(0, totalLength);
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ export function DeferredPromise<T>(): Promise.Resolver<T> {
}

/**
* Writes given array of buffers into the target.
* Copy contents of the given array of buffers into the target buffer.
*
* @param target target buffer
* @param sources source buffers
* @param totalLength total length of all source buffers
* @internal
*/
export function writeBuffers(target: Buffer, sources: Buffer[], totalLength: number): void {
export function copyBuffers(target: Buffer, sources: Buffer[], totalLength: number): void {
if (target.length < totalLength) {
throw new RangeError('Target length ' + target.length + ' is less than requested ' + totalLength);
}
Expand Down
14 changes: 7 additions & 7 deletions test/unit/UtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@
'use strict';

const { expect } = require('chai');
const { writeBuffers } = require('../../lib/util/Util');
const { copyBuffers } = require('../../lib/util/Util');

describe('UtilTest', function () {

it('writeBuffers: throws on invalid total length', function () {
expect(() => writeBuffers(Buffer.from([0x1]), [ Buffer.from([0x2]) ], 3))
it('copyBuffers: throws on invalid total length', function () {
expect(() => copyBuffers(Buffer.from([0x1]), [ Buffer.from([0x2]) ], 3))
.to.throw(RangeError);
});

it('writeBuffers: writes single buffer of less length', function () {
it('copyBuffers: writes single buffer of less length', function () {
const target = Buffer.from('abc');
const sources = [ Buffer.from('d') ];
writeBuffers(target, sources, 1);
copyBuffers(target, sources, 1);

expect(Buffer.compare(target, Buffer.from('dbc'))).to.be.equal(0);
});

it('writeBuffers: writes multiple buffers of same total length', function () {
it('copyBuffers: writes multiple buffers of same total length', function () {
const target = Buffer.from('abc');
const sources = [
Buffer.from('d'),
Buffer.from('e'),
Buffer.from('f')
];
writeBuffers(target, sources, 3);
copyBuffers(target, sources, 3);

expect(Buffer.compare(target, Buffer.from('def'))).to.be.equal(0);
});
Expand Down

0 comments on commit 63ce9c6

Please sign in to comment.