1 | import { Packr as MsgPack } from 'msgpackr';
|
2 | import { ReadBuffer, WriteBuffer } from './message-buffer';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export declare type RpcMessage = RequestMessage | ReplyMessage | ReplyErrMessage | CancelMessage | NotificationMessage;
|
11 | export declare const enum RpcMessageType {
|
12 | Request = 1,
|
13 | Notification = 2,
|
14 | Reply = 3,
|
15 | ReplyErr = 4,
|
16 | Cancel = 5
|
17 | }
|
18 | export interface CancelMessage {
|
19 | type: RpcMessageType.Cancel;
|
20 | id: number;
|
21 | }
|
22 | export interface RequestMessage {
|
23 | type: RpcMessageType.Request;
|
24 | id: number;
|
25 | method: string;
|
26 | args: any[];
|
27 | }
|
28 | export interface NotificationMessage {
|
29 | type: RpcMessageType.Notification;
|
30 | id: number;
|
31 | method: string;
|
32 | args: any[];
|
33 | }
|
34 | export interface ReplyMessage {
|
35 | type: RpcMessageType.Reply;
|
36 | id: number;
|
37 | res: any;
|
38 | }
|
39 | export interface ReplyErrMessage {
|
40 | type: RpcMessageType.ReplyErr;
|
41 | id: number;
|
42 | err: any;
|
43 | }
|
44 | export interface SerializedError {
|
45 | readonly $isError: true;
|
46 | readonly name: string;
|
47 | readonly message: string;
|
48 | readonly stack: string;
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | export declare class ResponseError extends Error {
|
56 | readonly code: number;
|
57 | readonly data: any;
|
58 | constructor(code: number, message: string, data: any);
|
59 | }
|
60 | /**
|
61 | * Custom error thrown by the {@link RpcMessageEncoder} if an error occurred during the encoding and the
|
62 | * object could not be written to the given {@link WriteBuffer}
|
63 | */
|
64 | export declare class EncodingError extends Error {
|
65 | cause?: Error | undefined;
|
66 | constructor(msg: string, cause?: Error | undefined);
|
67 | }
|
68 | /**
|
69 | * A `RpcMessageDecoder` parses a a binary message received via {@link ReadBuffer} into a {@link RpcMessage}
|
70 | */
|
71 | export interface RpcMessageDecoder {
|
72 | parse(buffer: ReadBuffer): RpcMessage;
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | export interface RpcMessageEncoder {
|
80 | cancel(buf: WriteBuffer, requestId: number): void;
|
81 | notification(buf: WriteBuffer, requestId: number, method: string, args: any[]): void;
|
82 | request(buf: WriteBuffer, requestId: number, method: string, args: any[]): void;
|
83 | replyOK(buf: WriteBuffer, requestId: number, res: any): void;
|
84 | replyErr(buf: WriteBuffer, requestId: number, err: any): void;
|
85 | }
|
86 | export declare const defaultMsgPack: MsgPack;
|
87 | export declare class MsgPackMessageEncoder implements RpcMessageEncoder {
|
88 | protected readonly msgPack: MsgPack;
|
89 | constructor(msgPack?: MsgPack);
|
90 | cancel(buf: WriteBuffer, requestId: number): void;
|
91 | notification(buf: WriteBuffer, requestId: number, method: string, args: any[]): void;
|
92 | request(buf: WriteBuffer, requestId: number, method: string, args: any[]): void;
|
93 | replyOK(buf: WriteBuffer, requestId: number, res: any): void;
|
94 | replyErr(buf: WriteBuffer, requestId: number, err: any): void;
|
95 | encode<T = unknown>(buf: WriteBuffer, value: T): void;
|
96 | }
|
97 | export declare class MsgPackMessageDecoder implements RpcMessageDecoder {
|
98 | protected readonly msgPack: MsgPack;
|
99 | constructor(msgPack?: MsgPack);
|
100 | decode<T = any>(buf: ReadBuffer): T;
|
101 | parse(buffer: ReadBuffer): RpcMessage;
|
102 | }
|
103 | export declare function registerMsgPackExtensions(): void;
|
104 | //# sourceMappingURL=rpc-message-encoder.d.ts.map |
\ | No newline at end of file |