@hegeldev/hegel 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/cbor.d.ts +15 -0
- package/dist/cbor.d.ts.map +1 -0
- package/dist/cbor.js +32 -0
- package/dist/cbor.js.map +1 -0
- package/dist/checksums.d.ts +16 -0
- package/dist/checksums.d.ts.map +1 -0
- package/dist/checksums.js +26 -0
- package/dist/checksums.js.map +1 -0
- package/dist/generators/numeric.d.ts.map +1 -1
- package/dist/generators/numeric.js +16 -7
- package/dist/generators/numeric.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/libhegel.d.ts +169 -0
- package/dist/libhegel.d.ts.map +1 -0
- package/dist/libhegel.js +338 -0
- package/dist/libhegel.js.map +1 -0
- package/dist/locate.d.ts +42 -0
- package/dist/locate.d.ts.map +1 -0
- package/dist/locate.js +94 -0
- package/dist/locate.js.map +1 -0
- package/dist/runner.d.ts +30 -22
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +150 -201
- package/dist/runner.js.map +1 -1
- package/dist/session.d.ts +16 -13
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +32 -145
- package/dist/session.js.map +1 -1
- package/dist/testCase.d.ts +7 -7
- package/dist/testCase.d.ts.map +1 -1
- package/dist/testCase.js +1 -5
- package/dist/testCase.js.map +1 -1
- package/dist/wtf8.d.ts +2 -0
- package/dist/wtf8.d.ts.map +1 -1
- package/dist/wtf8.js +2 -0
- package/dist/wtf8.js.map +1 -1
- package/native/libhegel-darwin-arm64.dylib +0 -0
- package/native/libhegel-linux-amd64.so +0 -0
- package/native/libhegel-linux-arm64.so +0 -0
- package/native/libhegel-windows-amd64.dll +0 -0
- package/native/libhegel-windows-arm64.dll +0 -0
- package/package.json +9 -11
- package/dist/connection.d.ts +0 -82
- package/dist/connection.d.ts.map +0 -1
- package/dist/connection.js +0 -231
- package/dist/connection.js.map +0 -1
- package/dist/crc32.d.ts +0 -13
- package/dist/crc32.d.ts.map +0 -1
- package/dist/crc32.js +0 -30
- package/dist/crc32.js.map +0 -1
- package/dist/protocol.d.ts +0 -25
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js +0 -77
- package/dist/protocol.js.map +0 -1
- package/dist/uv-install.sh +0 -2226
- package/dist/uv.d.ts +0 -20
- package/dist/uv.d.ts.map +0 -1
- package/dist/uv.js +0 -103
- package/dist/uv.js.map +0 -1
package/dist/connection.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous connection and stream multiplexing over stdio pipes.
|
|
3
|
-
*
|
|
4
|
-
* The Connection reads/writes raw bytes via file descriptors using
|
|
5
|
-
* `fs.readSync`/`fs.writeSync`. The Stream class provides request/reply
|
|
6
|
-
* semantics with CBOR encoding on top.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import * as fs from "node:fs";
|
|
11
|
-
import { encodePacket, readPacketFrom, CLOSE_STREAM_MESSAGE_ID, CLOSE_STREAM_PAYLOAD, } from "./protocol.js";
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// Sleep helper (for EAGAIN retry on non-blocking fds)
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
const sleepArray = new Int32Array(new SharedArrayBuffer(4));
|
|
16
|
-
function sleepMs(ms) {
|
|
17
|
-
Atomics.wait(sleepArray, 0, 0, ms);
|
|
18
|
-
}
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Connection
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
export class Connection {
|
|
23
|
-
readFd;
|
|
24
|
-
writeFd;
|
|
25
|
-
nextStreamCounter = 0;
|
|
26
|
-
streamInboxes = new Map();
|
|
27
|
-
serverExited = false;
|
|
28
|
-
constructor(readFd, writeFd) {
|
|
29
|
-
this.readFd = readFd;
|
|
30
|
-
this.writeFd = writeFd;
|
|
31
|
-
}
|
|
32
|
-
markServerExited() {
|
|
33
|
-
this.serverExited = true;
|
|
34
|
-
}
|
|
35
|
-
hasServerExited() {
|
|
36
|
-
return this.serverExited;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Read exactly `n` bytes from the pipe, blocking until available.
|
|
40
|
-
* Handles EAGAIN from non-blocking file descriptors.
|
|
41
|
-
*/
|
|
42
|
-
readExact(n) {
|
|
43
|
-
const buf = Buffer.alloc(n);
|
|
44
|
-
let offset = 0;
|
|
45
|
-
while (offset < n) {
|
|
46
|
-
try {
|
|
47
|
-
const bytesRead = fs.readSync(this.readFd, buf, offset, n - offset, null);
|
|
48
|
-
if (bytesRead === 0) {
|
|
49
|
-
this.serverExited = true;
|
|
50
|
-
throw new Error("Connection closed: server process exited");
|
|
51
|
-
}
|
|
52
|
-
offset += bytesRead;
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
if (e instanceof Error &&
|
|
56
|
-
"code" in e &&
|
|
57
|
-
(e.code === "EAGAIN" ||
|
|
58
|
-
e.code === "EWOULDBLOCK")) {
|
|
59
|
-
sleepMs(1);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
throw e;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return buf;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Write a packet to the server synchronously.
|
|
69
|
-
*/
|
|
70
|
-
sendPacket(packet) {
|
|
71
|
-
const data = encodePacket(packet);
|
|
72
|
-
fs.writeSync(this.writeFd, data);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Read packets until one for the given stream arrives.
|
|
76
|
-
* Packets for other streams are buffered in their inboxes.
|
|
77
|
-
*/
|
|
78
|
-
readPacketForStream(streamId) {
|
|
79
|
-
// Check inbox first
|
|
80
|
-
const inbox = this.streamInboxes.get(streamId);
|
|
81
|
-
if (inbox && inbox.length > 0) {
|
|
82
|
-
return inbox.shift();
|
|
83
|
-
}
|
|
84
|
-
// Read from pipe until we get a packet for this stream
|
|
85
|
-
while (true) {
|
|
86
|
-
const packet = readPacketFrom((n) => this.readExact(n));
|
|
87
|
-
if (packet.streamId === streamId) {
|
|
88
|
-
return packet;
|
|
89
|
-
}
|
|
90
|
-
// Buffer for other streams
|
|
91
|
-
let otherInbox = this.streamInboxes.get(packet.streamId);
|
|
92
|
-
if (!otherInbox) {
|
|
93
|
-
otherInbox = [];
|
|
94
|
-
this.streamInboxes.set(packet.streamId, otherInbox);
|
|
95
|
-
}
|
|
96
|
-
otherInbox.push(packet);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Create a new client-initiated stream (odd ID).
|
|
101
|
-
*/
|
|
102
|
-
newStream() {
|
|
103
|
-
const id = ((this.nextStreamCounter++ << 1) | 1) >>> 0;
|
|
104
|
-
return new Stream(id, this);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Connect to an existing server-allocated stream.
|
|
108
|
-
*/
|
|
109
|
-
connectStream(streamId) {
|
|
110
|
-
return new Stream(streamId, this);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the control stream (stream ID 0).
|
|
114
|
-
*/
|
|
115
|
-
controlStream() {
|
|
116
|
-
return new Stream(0, this);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Remove buffered packets for a stream.
|
|
120
|
-
*/
|
|
121
|
-
unregisterStream(streamId) {
|
|
122
|
-
this.streamInboxes.delete(streamId);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Stream
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
export class Stream {
|
|
129
|
-
streamId;
|
|
130
|
-
connection;
|
|
131
|
-
nextMessageId = 1;
|
|
132
|
-
responses = new Map();
|
|
133
|
-
requests = [];
|
|
134
|
-
closed = false;
|
|
135
|
-
constructor(streamId, connection) {
|
|
136
|
-
this.streamId = streamId;
|
|
137
|
-
this.connection = connection;
|
|
138
|
-
}
|
|
139
|
-
markClosed() {
|
|
140
|
-
this.closed = true;
|
|
141
|
-
}
|
|
142
|
-
checkClosed() {
|
|
143
|
-
if (this.closed) {
|
|
144
|
-
throw new Error("Stream is closed");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Send a request packet and return the message ID.
|
|
149
|
-
*/
|
|
150
|
-
sendRequest(payload) {
|
|
151
|
-
this.checkClosed();
|
|
152
|
-
const messageId = this.nextMessageId++;
|
|
153
|
-
this.connection.sendPacket({
|
|
154
|
-
streamId: this.streamId,
|
|
155
|
-
messageId,
|
|
156
|
-
isReply: false,
|
|
157
|
-
payload,
|
|
158
|
-
});
|
|
159
|
-
return messageId;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Send a reply to an incoming request.
|
|
163
|
-
*/
|
|
164
|
-
writeReply(messageId, payload) {
|
|
165
|
-
this.connection.sendPacket({
|
|
166
|
-
streamId: this.streamId,
|
|
167
|
-
messageId,
|
|
168
|
-
isReply: true,
|
|
169
|
-
payload,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Wait for a reply to a previously sent request.
|
|
174
|
-
*/
|
|
175
|
-
receiveReply(messageId) {
|
|
176
|
-
// Check buffered responses first
|
|
177
|
-
const buffered = this.responses.get(messageId);
|
|
178
|
-
if (buffered !== undefined) {
|
|
179
|
-
this.responses.delete(messageId);
|
|
180
|
-
return buffered;
|
|
181
|
-
}
|
|
182
|
-
while (true) {
|
|
183
|
-
this.checkClosed();
|
|
184
|
-
const packet = this.connection.readPacketForStream(this.streamId);
|
|
185
|
-
if (packet.isReply && packet.messageId === messageId) {
|
|
186
|
-
return packet.payload;
|
|
187
|
-
}
|
|
188
|
-
// Buffer for later
|
|
189
|
-
if (packet.isReply) {
|
|
190
|
-
this.responses.set(packet.messageId, packet.payload);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
this.requests.push(packet);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Wait for an incoming request from the server.
|
|
199
|
-
*/
|
|
200
|
-
receiveRequest() {
|
|
201
|
-
if (this.requests.length > 0) {
|
|
202
|
-
const packet = this.requests.shift();
|
|
203
|
-
return [packet.messageId, packet.payload];
|
|
204
|
-
}
|
|
205
|
-
while (true) {
|
|
206
|
-
this.checkClosed();
|
|
207
|
-
const packet = this.connection.readPacketForStream(this.streamId);
|
|
208
|
-
if (!packet.isReply) {
|
|
209
|
-
return [packet.messageId, packet.payload];
|
|
210
|
-
}
|
|
211
|
-
// Buffer reply for later
|
|
212
|
-
this.responses.set(packet.messageId, packet.payload);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Close this stream gracefully.
|
|
217
|
-
*/
|
|
218
|
-
close() {
|
|
219
|
-
if (this.closed)
|
|
220
|
-
return;
|
|
221
|
-
this.closed = true;
|
|
222
|
-
this.connection.unregisterStream(this.streamId);
|
|
223
|
-
this.connection.sendPacket({
|
|
224
|
-
streamId: this.streamId,
|
|
225
|
-
messageId: CLOSE_STREAM_MESSAGE_ID,
|
|
226
|
-
isReply: false,
|
|
227
|
-
payload: CLOSE_STREAM_PAYLOAD,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
//# sourceMappingURL=connection.js.map
|
package/dist/connection.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAEL,YAAY,EACZ,cAAc,EACd,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,8EAA8E;AAC9E,sDAAsD;AAC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LC, polynomial 0xEDB88320).
|
|
3
|
-
*
|
|
4
|
-
* Vendored so the library works on Node versions older than 22.2.0.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Compute the CRC32 checksum of a byte buffer.
|
|
8
|
-
*
|
|
9
|
-
* @param data - The bytes to checksum.
|
|
10
|
-
* @returns The CRC32 as an unsigned 32-bit integer.
|
|
11
|
-
*/
|
|
12
|
-
export declare function crc32(data: Uint8Array): number;
|
|
13
|
-
//# sourceMappingURL=crc32.d.ts.map
|
package/dist/crc32.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crc32.d.ts","sourceRoot":"","sources":["../src/crc32.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAM9C"}
|
package/dist/crc32.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CRC32 (IEEE 802.3 / ISO-HDLC, polynomial 0xEDB88320).
|
|
3
|
-
*
|
|
4
|
-
* Vendored so the library works on Node versions older than 22.2.0.
|
|
5
|
-
*/
|
|
6
|
-
const CRC_TABLE = (() => {
|
|
7
|
-
const table = new Uint32Array(256);
|
|
8
|
-
for (let i = 0; i < 256; i++) {
|
|
9
|
-
let c = i;
|
|
10
|
-
for (let k = 0; k < 8; k++) {
|
|
11
|
-
c = (c & 1) !== 0 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
12
|
-
}
|
|
13
|
-
table[i] = c;
|
|
14
|
-
}
|
|
15
|
-
return table;
|
|
16
|
-
})();
|
|
17
|
-
/**
|
|
18
|
-
* Compute the CRC32 checksum of a byte buffer.
|
|
19
|
-
*
|
|
20
|
-
* @param data - The bytes to checksum.
|
|
21
|
-
* @returns The CRC32 as an unsigned 32-bit integer.
|
|
22
|
-
*/
|
|
23
|
-
export function crc32(data) {
|
|
24
|
-
let crc = 0xffffffff;
|
|
25
|
-
for (let i = 0; i < data.length; i++) {
|
|
26
|
-
crc = CRC_TABLE[(crc ^ data[i]) & 0xff] ^ (crc >>> 8);
|
|
27
|
-
}
|
|
28
|
-
return (crc ^ 0xffffffff) >>> 0;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=crc32.js.map
|
package/dist/crc32.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crc32.js","sourceRoot":"","sources":["../src/crc32.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,SAAS,GAAgB,CAAC,GAAG,EAAE;IACnC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC;QACD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,EAAE,CAAC;AAEL;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,IAAgB;IACpC,IAAI,GAAG,GAAG,UAAU,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,GAAG,GAAG,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/protocol.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const MAGIC = 1212499788;
|
|
2
|
-
export declare const HEADER_SIZE = 20;
|
|
3
|
-
export declare const TERMINATOR = 10;
|
|
4
|
-
export declare const REPLY_BIT = 2147483648;
|
|
5
|
-
export declare const CLOSE_STREAM_MESSAGE_ID = 2147483647;
|
|
6
|
-
export declare const CLOSE_STREAM_PAYLOAD: Buffer<ArrayBuffer>;
|
|
7
|
-
export declare const HANDSHAKE_STRING = "hegel_handshake_start";
|
|
8
|
-
export interface Packet {
|
|
9
|
-
streamId: number;
|
|
10
|
-
messageId: number;
|
|
11
|
-
isReply: boolean;
|
|
12
|
-
payload: Buffer;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Encode a packet into a single Buffer ready for writing.
|
|
16
|
-
*/
|
|
17
|
-
export declare function encodePacket(packet: Packet): Buffer;
|
|
18
|
-
/**
|
|
19
|
-
* Decode a packet from raw bytes.
|
|
20
|
-
*
|
|
21
|
-
* @param readExact - Function that synchronously reads exactly `n` bytes.
|
|
22
|
-
* @returns The decoded packet.
|
|
23
|
-
*/
|
|
24
|
-
export declare function readPacketFrom(readExact: (n: number) => Buffer): Packet;
|
|
25
|
-
//# sourceMappingURL=protocol.d.ts.map
|
package/dist/protocol.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,aAAa,CAAC;AAChC,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,UAAU,KAAO,CAAC;AAC/B,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAClD,eAAO,MAAM,oBAAoB,qBAAsB,CAAC;AACxD,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AAkBxD,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAenD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAoCvE"}
|
package/dist/protocol.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { addExtension } from "cbor-x";
|
|
2
|
-
import { crc32 } from "./crc32.js";
|
|
3
|
-
import { wtf8ToString } from "./wtf8.js";
|
|
4
|
-
export const MAGIC = 0x4845474c;
|
|
5
|
-
export const HEADER_SIZE = 20;
|
|
6
|
-
export const TERMINATOR = 0x0a;
|
|
7
|
-
export const REPLY_BIT = 0x80000000;
|
|
8
|
-
export const CLOSE_STREAM_MESSAGE_ID = 0x7fffffff;
|
|
9
|
-
export const CLOSE_STREAM_PAYLOAD = Buffer.from([0xfe]);
|
|
10
|
-
export const HANDSHAKE_STRING = "hegel_handshake_start";
|
|
11
|
-
// cbor-x requires a Class for addExtension, but we only use the decode
|
|
12
|
-
// path (tag 91 is sent by the server, never by the client).
|
|
13
|
-
addExtension({
|
|
14
|
-
/* v8 ignore start */
|
|
15
|
-
Class: class HegelString {
|
|
16
|
-
},
|
|
17
|
-
tag: 91,
|
|
18
|
-
encode: () => Buffer.alloc(0),
|
|
19
|
-
/* v8 ignore stop */
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
decode(data) {
|
|
22
|
-
if (Buffer.isBuffer(data))
|
|
23
|
-
return wtf8ToString(data);
|
|
24
|
-
if (data instanceof Uint8Array)
|
|
25
|
-
return wtf8ToString(Buffer.from(data));
|
|
26
|
-
return String(data);
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Encode a packet into a single Buffer ready for writing.
|
|
31
|
-
*/
|
|
32
|
-
export function encodePacket(packet) {
|
|
33
|
-
const messageIdRaw = packet.isReply ? (packet.messageId | REPLY_BIT) >>> 0 : packet.messageId;
|
|
34
|
-
const header = Buffer.alloc(HEADER_SIZE);
|
|
35
|
-
header.writeUInt32BE(MAGIC, 0);
|
|
36
|
-
// checksum placeholder at offset 4 (already 0)
|
|
37
|
-
header.writeUInt32BE(packet.streamId, 8);
|
|
38
|
-
header.writeUInt32BE(messageIdRaw, 12);
|
|
39
|
-
header.writeUInt32BE(packet.payload.length, 16);
|
|
40
|
-
// CRC32 over header (checksum zeroed) + payload
|
|
41
|
-
const checksum = crc32(Buffer.concat([header, packet.payload]));
|
|
42
|
-
header.writeUInt32BE(checksum, 4);
|
|
43
|
-
return Buffer.concat([header, packet.payload, Buffer.from([TERMINATOR])]);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Decode a packet from raw bytes.
|
|
47
|
-
*
|
|
48
|
-
* @param readExact - Function that synchronously reads exactly `n` bytes.
|
|
49
|
-
* @returns The decoded packet.
|
|
50
|
-
*/
|
|
51
|
-
export function readPacketFrom(readExact) {
|
|
52
|
-
const header = readExact(HEADER_SIZE);
|
|
53
|
-
const magic = header.readUInt32BE(0);
|
|
54
|
-
if (magic !== MAGIC) {
|
|
55
|
-
throw new Error(`Invalid magic: expected 0x${MAGIC.toString(16)}, got 0x${magic.toString(16)}`);
|
|
56
|
-
}
|
|
57
|
-
const checksum = header.readUInt32BE(4);
|
|
58
|
-
const streamId = header.readUInt32BE(8);
|
|
59
|
-
const messageIdRaw = header.readUInt32BE(12);
|
|
60
|
-
const payloadLength = header.readUInt32BE(16);
|
|
61
|
-
const isReply = (messageIdRaw & REPLY_BIT) !== 0;
|
|
62
|
-
const messageId = messageIdRaw & ~REPLY_BIT;
|
|
63
|
-
const payload = readExact(payloadLength);
|
|
64
|
-
const terminator = readExact(1);
|
|
65
|
-
if (terminator[0] !== TERMINATOR) {
|
|
66
|
-
throw new Error(`Invalid terminator: expected 0x${TERMINATOR.toString(16)}, got 0x${terminator[0].toString(16)}`);
|
|
67
|
-
}
|
|
68
|
-
// Verify CRC32
|
|
69
|
-
const headerForCheck = Buffer.from(header);
|
|
70
|
-
headerForCheck.writeUInt32BE(0, 4); // zero out checksum field
|
|
71
|
-
const computed = crc32(Buffer.concat([headerForCheck, payload]));
|
|
72
|
-
if (computed !== checksum) {
|
|
73
|
-
throw new Error(`CRC32 mismatch: expected 0x${checksum.toString(16)}, got 0x${computed.toString(16)}`);
|
|
74
|
-
}
|
|
75
|
-
return { streamId, messageId, isReply, payload };
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=protocol.js.map
|
package/dist/protocol.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAAC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AACpC,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,u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