-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.d.ts
79 lines (67 loc) · 2.18 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// <reference types="node" />
declare module '@luckydrq/tcp-net' {
import { Socket } from 'net';
import SdkBase from 'sdk-base';
interface ITransCoder {
encode: (data: Buffer | Record<string, any> | string | number | boolean | null) => Buffer;
decode: (data: Buffer) => string;
}
interface IProtocolOptions {
encoding?: string;
transCoder?: ITransCoder;
}
interface ILengthBasedProtocolOptions extends IProtocolOptions {
packetSize?: number;
}
interface ILineBasedProtocolOptions extends IProtocolOptions {
packetDelimiter: string;
}
interface IPacket {
reqType: number;
packetId?: number;
packetType: number;
body?: string;
}
abstract class Protocol extends SdkBase {
constructor(options: IProtocolOptions);
pack: (data: Buffer, pkt: IPacket) => { id: number; packet: Buffer };
parse: (data: Buffer) => Buffer | null;
encode: (data: Buffer | Record<string, any> | string | number | boolean | null) => Buffer;
decode: (data: Buffer) => string;
}
class LengthBasedProtocol extends Protocol {
constructor(options?: ILengthBasedProtocolOptions);
read: (data: Buffer) => void;
write: (data: Buffer, pkt?: IPacket) => void;
}
class LineBasedProtocol extends Protocol {
constructor(options: ILineBasedProtocolOptions);
read: (data: Buffer) => void;
write: (data: Buffer, pkt?: IPacket, encoded?: boolean) => void;
}
interface IConnectionOptions {
socket?: Socket;
host?: string;
port?: number;
protocol?: Protocol;
idleTimeout?: number;
finWaitTimeout?: number;
heartbeatInterval?: number;
heartbeatTimeout?: number;
heartbeatTimeoutLimit?: number;
}
class Connection extends SdkBase {
constructor(options: IConnectionOptions);
get connected(): boolean;
get localAddress(): string | undefined;
get remoteAddress(): string | undefined;
get remotePort(): number | undefined;
read: (data: Buffer) => void;
write: <T = Buffer | Record<string, any> | string | number | boolean | null>(
data: T,
pkt?: IPacket
) => void;
end: () => void;
}
export { Connection, LengthBasedProtocol, LineBasedProtocol, IPacket };
}