Skip to content

Commit

Permalink
chore(rpc): add test to make sure buffer is not copied
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed May 1, 2024
1 parent e5dafb4 commit 8c77a8e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/rpc/tests/chunks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import { DirectClient } from '../src/client/client-direct.js';
import { rpc } from '../src/decorators.js';
import { RpcKernel } from '../src/server/kernel.js';
import { ClientProgress } from '../src/writer.js';
import { RpcBufferReader } from '../src/protocol.js';

test('buffer read does not do copy', async () => {
const data = Buffer.from('hello world');
data.writeUint32LE(data.length, 0);
let received: Uint8Array | undefined = undefined;

new RpcBufferReader((p) => {
received = p;
}).feed(data);

expect(received!.buffer === data.buffer).toBe(true);
});

test('chunks', async () => {
@rpc.controller('test')
Expand Down

0 comments on commit 8c77a8e

Please sign in to comment.