Skip to content

Commit c78a2a2

Browse files
committed
fix(rpc): ensure message size is reset to 0 after reaching a buffer that is too small
also fix core
1 parent 66e8f0d commit c78a2a2

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

packages/core/tests/reflection.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test('simple', () => {
3838
}
3939

4040
const code = extractMethodBody(User.toString(), 'constructor');
41-
expect(code.trim()).toBe(''); //doesn't work anymore in es2022
41+
expect(code.trim()).toBe('this.id=uuid();this.bla=;');
4242
});
4343

4444

packages/rpc/src/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ export class RpcBinaryBufferReader {
688688
if (currentBuffer.byteLength < 4) {
689689
//not enough data to read the header. Wait for next onData
690690
this.currentMessage = currentBuffer;
691+
this.currentMessageSize = 0;
691692
return;
692693
}
693694

packages/rpc/tests/chunks.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ test('buffer read does not do copy', async () => {
2020
});
2121

2222
test('RpcBinaryBufferReader', () => {
23-
const a = Buffer.from('00000000010203040506070809', 'hex');
23+
const a = Buffer.from('0000000001020304050607', 'hex');
2424
a.writeUint32LE(a.byteLength, 0);
25-
const b = Buffer.from('0000000002030405060708090a', 'hex');
25+
const b = Buffer.from('000000000203040506070809', 'hex');
2626
b.writeUint32LE(b.byteLength, 0);
27-
const c = Buffer.from('0000000002030405060708090b', 'hex');
28-
c.writeUint32LE(b.byteLength, 0);
27+
const c = Buffer.from('00000000020304050607', 'hex');
28+
c.writeUint32LE(c.byteLength, 0);
2929
const data = Buffer.concat([a, b, c]);
3030

3131
function test(cb: (reader: RpcBinaryBufferReader) => void) {
@@ -35,9 +35,9 @@ test('RpcBinaryBufferReader', () => {
3535
});
3636
cb(reader);
3737
expect(received).toEqual([
38-
'0d000000010203040506070809',
39-
'0d00000002030405060708090a',
40-
'0d00000002030405060708090b',
38+
'0b00000001020304050607',
39+
'0c0000000203040506070809',
40+
'0a000000020304050607',
4141
]);
4242
}
4343

0 commit comments

Comments
 (0)