UNPKG

2.15 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Duplex } from 'stream';
3import { Disposable, Emitter, Event } from '../../common';
4/**
5 * A `BinaryMessagePipe` is capable of sending and retrieving binary messages i.e. {@link Uint8Array}s over
6 * and underlying streamed process pipe/fd. The message length of individual messages is encoding at the beginning of
7 * a new message. This makes it possible to extract messages from the streamed data.
8 */
9export declare class BinaryMessagePipe implements Disposable {
10 protected readonly underlyingPipe: Duplex;
11 static readonly MESSAGE_START_IDENTIFIER = "<MessageStart>";
12 protected dataHandler: (chunk: Uint8Array) => void;
13 protected onMessageEmitter: Emitter<Uint8Array>;
14 protected cachedMessageData: StreamedMessageData;
15 get onMessage(): Event<Uint8Array>;
16 constructor(underlyingPipe: Duplex);
17 send(message: Uint8Array): void;
18 protected handleChunk(chunk: Uint8Array): void;
19 protected handleNewMessage(chunk: Uint8Array): void;
20 protected handleMessageContentChunk(chunk: Uint8Array): void;
21 protected emitCachedMessage(): void;
22 /**
23 * Encodes the start of a new message into a {@link Uint8Array}.
24 * The message start consists of a identifier string and the length of the following message.
25 * @returns the buffer contains the encoded message start
26 */
27 protected encodeMessageStart(message: Uint8Array): Uint8Array;
28 protected get messageStartByteLength(): number;
29 /**
30 * Reads the start of a new message from a stream chunk (or cached message) received from the underlying pipe.
31 * The message start is expected to consist of an identifier string and the length of the message.
32 * @param chunk The stream chunk.
33 * @returns The length of the message content to read.
34 * @throws An error if the message start can not be read successfully.
35 */
36 protected readMessageStart(chunk: Uint8Array): number;
37 dispose(): void;
38}
39interface StreamedMessageData {
40 chunks: Uint8Array[];
41 missingBytes: number;
42 partialMessageStart?: Uint8Array;
43}
44export {};
45//# sourceMappingURL=binary-message-pipe.d.ts.map
\No newline at end of file