Skip to content

Commit cbbf60c

Browse files
committed
Revert "use msgpackr instead of @msgpack/msgpack (#350)"
This reverts commit b2d7454.
1 parent b2d7454 commit cbbf60c

File tree

3 files changed

+47
-223
lines changed

3 files changed

+47
-223
lines changed

codec/binary.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
1-
import { Options, Packr } from 'msgpackr';
1+
import { DecodeError, ExtensionCodec, decode, encode } from '@msgpack/msgpack';
22
import { Codec } from './types';
33

4-
const packr = new Packr({
5-
useRecords: false,
6-
moreTypes: true,
7-
bundleStrings: true,
8-
useTimestamp32: false,
9-
useBigIntExtension: true,
10-
skipValues: [undefined],
11-
} as Options);
4+
const BIGINT_EXT_TYPE = 0;
5+
const extensionCodec = new ExtensionCodec();
6+
extensionCodec.register({
7+
type: BIGINT_EXT_TYPE,
8+
encode(input: unknown): Uint8Array | null {
9+
if (typeof input === 'bigint') {
10+
if (
11+
input <= Number.MAX_SAFE_INTEGER &&
12+
input >= Number.MIN_SAFE_INTEGER
13+
) {
14+
return encode(Number(input));
15+
} else {
16+
return encode(String(input));
17+
}
18+
} else {
19+
return null;
20+
}
21+
},
22+
decode(data: Uint8Array): bigint {
23+
const val = decode(data);
24+
if (!(typeof val === 'string' || typeof val === 'number')) {
25+
throw new DecodeError(`unexpected BigInt source: ${typeof val}`);
26+
}
27+
28+
return BigInt(val);
29+
},
30+
});
1231

1332
/**
14-
* Binary codec, uses [msgpackr](https://www.npmjs.com/package/msgpackr) under the hood
33+
* Binary codec, uses [msgpack](https://www.npmjs.com/package/@msgpack/msgpack) under the hood
1534
* @type {Codec}
1635
*/
1736
export const BinaryCodec: Codec = {
1837
toBuffer(obj) {
19-
return packr.pack(obj);
38+
return encode(obj, { ignoreUndefined: true, extensionCodec });
2039
},
2140
fromBuffer: (buff: Uint8Array) => {
22-
const res: unknown = packr.unpack(buff);
41+
const res = decode(buff, { extensionCodec });
2342
if (typeof res !== 'object' || res === null) {
2443
throw new Error('unpacked msg is not an object');
2544
}

package-lock.json

Lines changed: 14 additions & 209 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@replit/river",
33
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4-
"version": "0.211.0",
4+
"version": "0.210.1",
55
"type": "module",
66
"exports": {
77
".": {
@@ -40,7 +40,7 @@
4040
"dist"
4141
],
4242
"dependencies": {
43-
"msgpackr": "^1.11.2",
43+
"@msgpack/msgpack": "^3.0.0-beta2",
4444
"nanoid": "^5.0.9",
4545
"ws": "^8.17.0"
4646
},

0 commit comments

Comments
 (0)