@opensumi/ide-connection 2.27.3-rc-1708399099.0 → 2.27.3-rc-1710386185.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 +1 -1
- package/lib/browser/ws-channel-handler.d.ts +1 -1
- package/lib/browser/ws-channel-handler.d.ts.map +1 -1
- package/lib/browser/ws-channel-handler.js +23 -33
- package/lib/browser/ws-channel-handler.js.map +1 -1
- package/lib/common/buffers/buffers.d.ts +1 -0
- package/lib/common/buffers/buffers.d.ts.map +1 -1
- package/lib/common/buffers/buffers.js +3 -3
- package/lib/common/buffers/buffers.js.map +1 -1
- package/lib/common/{utils.d.ts → capturer.d.ts} +1 -19
- package/lib/common/capturer.d.ts.map +1 -0
- package/lib/common/capturer.js +26 -0
- package/lib/common/capturer.js.map +1 -0
- package/lib/common/connection/drivers/frame-decoder.d.ts +40 -1
- package/lib/common/connection/drivers/frame-decoder.d.ts.map +1 -1
- package/lib/common/connection/drivers/frame-decoder.js +9 -10
- package/lib/common/connection/drivers/frame-decoder.js.map +1 -1
- package/lib/common/connection/drivers/index.d.ts +0 -1
- package/lib/common/connection/drivers/index.d.ts.map +1 -1
- package/lib/common/connection/drivers/index.js +0 -1
- package/lib/common/connection/drivers/index.js.map +1 -1
- package/lib/common/connection/drivers/message-port.d.ts.map +1 -1
- package/lib/common/connection/drivers/message-port.js +1 -4
- package/lib/common/connection/drivers/message-port.js.map +1 -1
- package/lib/common/connection/drivers/node-message-port.d.ts +1 -1
- package/lib/common/connection/drivers/node-message-port.d.ts.map +1 -1
- package/lib/common/connection/drivers/node-message-port.js.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.d.ts.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.js +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.js.map +1 -1
- package/lib/common/connection/drivers/socket.d.ts +3 -10
- package/lib/common/connection/drivers/socket.d.ts.map +1 -1
- package/lib/common/connection/drivers/socket.js +3 -36
- package/lib/common/connection/drivers/socket.js.map +1 -1
- package/lib/common/connection/drivers/stream.d.ts +17 -0
- package/lib/common/connection/drivers/stream.d.ts.map +1 -0
- package/lib/common/connection/drivers/stream.js +70 -0
- package/lib/common/connection/drivers/stream.js.map +1 -0
- package/lib/common/connection/drivers/ws-websocket.d.ts +1 -1
- package/lib/common/connection/drivers/ws-websocket.d.ts.map +1 -1
- package/lib/common/connection/drivers/ws-websocket.js.map +1 -1
- package/lib/common/fury-extends/any.d.ts +10 -7
- package/lib/common/fury-extends/any.d.ts.map +1 -1
- package/lib/common/fury-extends/any.js +126 -105
- package/lib/common/fury-extends/any.js.map +1 -1
- package/lib/common/fury-extends/one-of.d.ts +10 -5
- package/lib/common/fury-extends/one-of.d.ts.map +1 -1
- package/lib/common/fury-extends/one-of.js +65 -30
- package/lib/common/fury-extends/one-of.js.map +1 -1
- package/lib/common/fury-extends/shared.d.ts +2 -0
- package/lib/common/fury-extends/shared.d.ts.map +1 -1
- package/lib/common/fury-extends/shared.js.map +1 -1
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -2
- package/lib/common/index.js.map +1 -1
- package/lib/common/message.d.ts +1 -1
- package/lib/common/message.d.ts.map +1 -1
- package/lib/common/rpc/connection.d.ts +31 -15
- package/lib/common/rpc/connection.d.ts.map +1 -1
- package/lib/common/rpc/connection.js +206 -138
- package/lib/common/rpc/connection.js.map +1 -1
- package/lib/common/rpc/index.d.ts +1 -1
- package/lib/common/rpc/index.d.ts.map +1 -1
- package/lib/common/rpc/index.js +1 -1
- package/lib/common/rpc/index.js.map +1 -1
- package/lib/common/rpc/message-io.d.ts +61 -0
- package/lib/common/rpc/message-io.d.ts.map +1 -0
- package/lib/common/rpc/message-io.js +159 -0
- package/lib/common/rpc/message-io.js.map +1 -0
- package/lib/common/rpc/multiplexer.d.ts +3 -0
- package/lib/common/rpc/multiplexer.d.ts.map +1 -1
- package/lib/common/rpc/multiplexer.js +3 -0
- package/lib/common/rpc/multiplexer.js.map +1 -1
- package/lib/common/rpc/types.d.ts +26 -5
- package/lib/common/rpc/types.d.ts.map +1 -1
- package/lib/common/rpc-service/center.d.ts +6 -3
- package/lib/common/rpc-service/center.d.ts.map +1 -1
- package/lib/common/rpc-service/center.js +39 -31
- package/lib/common/rpc-service/center.js.map +1 -1
- package/lib/common/rpc-service/proxy/base.d.ts +5 -3
- package/lib/common/rpc-service/proxy/base.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/base.js +56 -17
- package/lib/common/rpc-service/proxy/base.js.map +1 -1
- package/lib/common/rpc-service/proxy/index.d.ts +1 -3
- package/lib/common/rpc-service/proxy/index.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/index.js +1 -3
- package/lib/common/rpc-service/proxy/index.js.map +1 -1
- package/lib/common/rpc-service/proxy/{legacy.d.ts → json.d.ts} +5 -5
- package/lib/common/rpc-service/proxy/json.d.ts.map +1 -0
- package/lib/common/rpc-service/proxy/{legacy.js → json.js} +46 -56
- package/lib/common/rpc-service/proxy/json.js.map +1 -0
- package/lib/common/rpc-service/proxy/sumi.d.ts +1 -1
- package/lib/common/rpc-service/proxy/sumi.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/sumi.js +25 -37
- package/lib/common/rpc-service/proxy/sumi.js.map +1 -1
- package/lib/common/rpc-service/{proxy/registry.d.ts → registry.d.ts} +12 -1
- package/lib/common/rpc-service/registry.d.ts.map +1 -0
- package/lib/common/rpc-service/registry.js +99 -0
- package/lib/common/rpc-service/registry.js.map +1 -0
- package/lib/common/rpc-service/stub.js +4 -6
- package/lib/common/rpc-service/stub.js.map +1 -1
- package/lib/common/{ext-rpc-protocol.d.ts → rpcProtocol.d.ts} +2 -2
- package/lib/common/rpcProtocol.d.ts.map +1 -0
- package/lib/common/{ext-rpc-protocol.js → rpcProtocol.js} +5 -6
- package/lib/common/rpcProtocol.js.map +1 -0
- package/lib/common/server-handler.d.ts +35 -0
- package/lib/common/server-handler.d.ts.map +1 -0
- package/lib/common/server-handler.js +165 -0
- package/lib/common/server-handler.js.map +1 -0
- package/lib/common/types.d.ts +14 -0
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/ws-channel.d.ts +6 -10
- package/lib/common/ws-channel.d.ts.map +1 -1
- package/lib/common/ws-channel.js +16 -15
- package/lib/common/ws-channel.js.map +1 -1
- package/lib/electron/channel-handler.d.ts +14 -0
- package/lib/electron/channel-handler.d.ts.map +1 -0
- package/lib/electron/channel-handler.js +26 -0
- package/lib/electron/channel-handler.js.map +1 -0
- package/lib/electron/index.d.ts +2 -0
- package/lib/electron/index.d.ts.map +1 -0
- package/lib/electron/index.js +5 -0
- package/lib/electron/index.js.map +1 -0
- package/lib/node/common-channel-handler.d.ts +6 -25
- package/lib/node/common-channel-handler.d.ts.map +1 -1
- package/lib/node/common-channel-handler.js +9 -151
- package/lib/node/common-channel-handler.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/ws-channel-handler.ts +26 -40
- package/src/common/buffers/buffers.ts +1 -1
- package/src/common/capturer.ts +36 -0
- package/src/common/connection/drivers/frame-decoder.ts +11 -11
- package/src/common/connection/drivers/index.ts +0 -1
- package/src/common/connection/drivers/message-port.ts +1 -4
- package/src/common/connection/drivers/node-message-port.ts +2 -2
- package/src/common/connection/drivers/reconnecting-websocket.ts +3 -2
- package/src/common/connection/drivers/socket.ts +4 -42
- package/src/common/connection/drivers/stream.ts +76 -0
- package/src/common/connection/drivers/ws-websocket.ts +2 -2
- package/src/common/fury-extends/any.ts +122 -102
- package/src/common/fury-extends/one-of.ts +79 -31
- package/src/common/fury-extends/shared.ts +3 -0
- package/src/common/index.ts +2 -2
- package/src/common/message.ts +1 -1
- package/src/common/rpc/connection.ts +228 -166
- package/src/common/rpc/index.ts +1 -1
- package/src/common/rpc/message-io.ts +223 -0
- package/src/common/rpc/multiplexer.ts +3 -0
- package/src/common/rpc/types.ts +30 -5
- package/src/common/rpc-service/center.ts +37 -31
- package/src/common/rpc-service/proxy/base.ts +59 -12
- package/src/common/rpc-service/proxy/index.ts +1 -3
- package/src/common/rpc-service/proxy/{legacy.ts → json.ts} +47 -57
- package/src/common/rpc-service/proxy/sumi.ts +23 -35
- package/src/common/rpc-service/registry.ts +125 -0
- package/src/common/rpc-service/stub.ts +6 -6
- package/src/common/{ext-rpc-protocol.ts → rpcProtocol.ts} +2 -2
- package/src/common/server-handler.ts +183 -0
- package/src/common/types.ts +13 -0
- package/src/common/ws-channel.ts +21 -23
- package/src/electron/channel-handler.ts +26 -0
- package/src/electron/index.ts +1 -0
- package/src/node/common-channel-handler.ts +10 -165
- package/lib/common/connection/drivers/utils.d.ts +0 -12
- package/lib/common/connection/drivers/utils.d.ts.map +0 -1
- package/lib/common/connection/drivers/utils.js +0 -49
- package/lib/common/connection/drivers/utils.js.map +0 -1
- package/lib/common/ext-rpc-protocol.d.ts.map +0 -1
- package/lib/common/ext-rpc-protocol.js.map +0 -1
- package/lib/common/rpc/packet.d.ts +0 -65
- package/lib/common/rpc/packet.d.ts.map +0 -1
- package/lib/common/rpc/packet.js +0 -82
- package/lib/common/rpc/packet.js.map +0 -1
- package/lib/common/rpc/protocol-repository.d.ts +0 -32
- package/lib/common/rpc/protocol-repository.d.ts.map +0 -1
- package/lib/common/rpc/protocol-repository.js +0 -118
- package/lib/common/rpc/protocol-repository.js.map +0 -1
- package/lib/common/rpc/utils.d.ts +0 -2
- package/lib/common/rpc/utils.d.ts.map +0 -1
- package/lib/common/rpc/utils.js +0 -10
- package/lib/common/rpc/utils.js.map +0 -1
- package/lib/common/rpc-service/proxy/invoker.d.ts +0 -14
- package/lib/common/rpc-service/proxy/invoker.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/invoker.js +0 -34
- package/lib/common/rpc-service/proxy/invoker.js.map +0 -1
- package/lib/common/rpc-service/proxy/legacy.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/legacy.js.map +0 -1
- package/lib/common/rpc-service/proxy/registry.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/registry.js +0 -46
- package/lib/common/rpc-service/proxy/registry.js.map +0 -1
- package/lib/common/utils.d.ts.map +0 -1
- package/lib/common/utils.js +0 -57
- package/lib/common/utils.js.map +0 -1
- package/src/common/connection/drivers/utils.ts +0 -52
- package/src/common/rpc/packet.ts +0 -104
- package/src/common/rpc/protocol-repository.ts +0 -180
- package/src/common/rpc/utils.ts +0 -5
- package/src/common/rpc-service/proxy/invoker.ts +0 -45
- package/src/common/rpc-service/proxy/registry.ts +0 -56
- package/src/common/utils.ts +0 -80
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BinaryReader, BinaryWriter } from '@furyjs/fury/dist/lib/type';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const { reader, writer } = furyFactory();
|
|
3
|
+
import { Uri, isUint8Array } from '@opensumi/ide-core-common';
|
|
6
4
|
|
|
7
5
|
export enum ProtocolType {
|
|
8
6
|
String,
|
|
@@ -15,119 +13,140 @@ export enum ProtocolType {
|
|
|
15
13
|
Union,
|
|
16
14
|
Object,
|
|
17
15
|
Undefined,
|
|
16
|
+
Null,
|
|
18
17
|
Boolean,
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
writer
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
export class AnySerializer {
|
|
21
|
+
constructor(protected writer: BinaryWriter, protected reader: BinaryReader) {}
|
|
22
|
+
|
|
23
|
+
write(data: any) {
|
|
24
|
+
const { writer } = this;
|
|
25
|
+
const type = typeof data;
|
|
26
|
+
writer.reserve(1);
|
|
27
|
+
|
|
28
|
+
switch (type) {
|
|
29
|
+
case 'undefined':
|
|
30
|
+
writer.uint8(ProtocolType.Undefined);
|
|
31
|
+
break;
|
|
32
|
+
case 'string':
|
|
33
|
+
writer.uint8(ProtocolType.String);
|
|
34
|
+
writer.stringOfVarUInt32(data);
|
|
35
|
+
break;
|
|
36
|
+
case 'boolean':
|
|
37
|
+
writer.reserve(1);
|
|
38
|
+
writer.uint8(ProtocolType.Boolean);
|
|
39
|
+
writer.uint8(data ? 1 : 0);
|
|
40
|
+
break;
|
|
41
|
+
case 'number':
|
|
42
|
+
writer.reserve(8);
|
|
43
|
+
if ((data | 0) === data) {
|
|
44
|
+
writer.uint8(ProtocolType.Int32);
|
|
45
|
+
writer.int32(data);
|
|
46
|
+
} else {
|
|
47
|
+
writer.uint8(ProtocolType.Number);
|
|
48
|
+
writer.double(data);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'bigint':
|
|
52
|
+
writer.reserve(8);
|
|
53
|
+
writer.uint8(ProtocolType.BigInt);
|
|
54
|
+
writer.int64(data);
|
|
55
|
+
break;
|
|
56
|
+
case 'object':
|
|
57
|
+
if (data === null) {
|
|
58
|
+
writer.uint8(ProtocolType.Null);
|
|
59
|
+
} else if (Array.isArray(data)) {
|
|
60
|
+
writer.reserve(4);
|
|
61
|
+
writer.uint8(ProtocolType.Array);
|
|
62
|
+
writer.varUInt32(data.length);
|
|
63
|
+
for (const element of data) {
|
|
64
|
+
this.write(element);
|
|
65
|
+
}
|
|
66
|
+
} else if (isUint8Array(data)) {
|
|
67
|
+
writer.reserve(4);
|
|
68
|
+
writer.uint8(ProtocolType.Buffer);
|
|
69
|
+
writer.varUInt32(data.byteLength);
|
|
70
|
+
writer.buffer(data);
|
|
71
|
+
} else {
|
|
72
|
+
writer.uint8(ProtocolType.JSONObject);
|
|
73
|
+
writer.stringOfVarUInt32(JSON.stringify(data, ObjectTransfer.replacer));
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unknown type ${type}`);
|
|
40
78
|
}
|
|
41
|
-
} else if (typeof data === 'string') {
|
|
42
|
-
writer.uint8(ProtocolType.String);
|
|
43
|
-
writer.stringOfVarUInt32(data);
|
|
44
|
-
} else if (data instanceof Uint8Array) {
|
|
45
|
-
writer.uint8(ProtocolType.Buffer);
|
|
46
|
-
writer.varUInt32(data.byteLength);
|
|
47
|
-
writer.buffer(data);
|
|
48
|
-
} else if (typeof data === 'bigint') {
|
|
49
|
-
writer.uint8(ProtocolType.BigInt);
|
|
50
|
-
writer.int64(data);
|
|
51
|
-
} else if (typeof data === 'object') {
|
|
52
|
-
writer.uint8(ProtocolType.JSONObject);
|
|
53
|
-
writer.stringOfVarUInt32(JSON.stringify(data, ObjectTransfer.replacer));
|
|
54
|
-
} else {
|
|
55
|
-
throw new Error(`Unknown type ${typeof data}`);
|
|
56
79
|
}
|
|
57
|
-
}
|
|
58
80
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const length = reader.varUInt32();
|
|
82
|
-
const data = [] as unknown[];
|
|
83
|
-
for (let i = 0; i < length; i++) {
|
|
84
|
-
data.push(deserializeWorker());
|
|
81
|
+
read() {
|
|
82
|
+
const { reader } = this;
|
|
83
|
+
|
|
84
|
+
const type = reader.uint8();
|
|
85
|
+
switch (type) {
|
|
86
|
+
case ProtocolType.Undefined:
|
|
87
|
+
return undefined;
|
|
88
|
+
case ProtocolType.Null:
|
|
89
|
+
return null;
|
|
90
|
+
case ProtocolType.String:
|
|
91
|
+
return reader.stringOfVarUInt32();
|
|
92
|
+
case ProtocolType.Buffer: {
|
|
93
|
+
const length = reader.varUInt32();
|
|
94
|
+
return reader.buffer(length);
|
|
95
|
+
}
|
|
96
|
+
case ProtocolType.Int32:
|
|
97
|
+
return reader.int32();
|
|
98
|
+
case ProtocolType.Number:
|
|
99
|
+
return reader.double();
|
|
100
|
+
case ProtocolType.JSONObject: {
|
|
101
|
+
const json = reader.stringOfVarUInt32();
|
|
102
|
+
return JSON.parse(json, ObjectTransfer.reviver);
|
|
85
103
|
}
|
|
86
|
-
|
|
104
|
+
case ProtocolType.BigInt:
|
|
105
|
+
return reader.int64();
|
|
106
|
+
case ProtocolType.Array: {
|
|
107
|
+
const length = reader.varUInt32();
|
|
108
|
+
const data = [] as unknown[];
|
|
109
|
+
for (let i = 0; i < length; i++) {
|
|
110
|
+
data.push(this.read());
|
|
111
|
+
}
|
|
112
|
+
return data;
|
|
113
|
+
}
|
|
114
|
+
case ProtocolType.Boolean:
|
|
115
|
+
return reader.uint8() === 1;
|
|
116
|
+
default:
|
|
117
|
+
throw new Error(`Unknown type ${type}`);
|
|
87
118
|
}
|
|
88
|
-
case ProtocolType.Boolean:
|
|
89
|
-
return reader.uint8() === 1;
|
|
90
|
-
default:
|
|
91
|
-
throw new Error(`Unknown type ${type}`);
|
|
92
119
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const deserialize = (bytes: Uint8Array) => {
|
|
96
|
-
reader.reset(bytes);
|
|
97
|
-
|
|
98
|
-
return deserializeWorker();
|
|
99
|
-
};
|
|
100
120
|
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
deserialize = (bytes: Uint8Array) => {
|
|
122
|
+
this.reader.reset(bytes);
|
|
123
|
+
return this.read();
|
|
124
|
+
};
|
|
103
125
|
|
|
104
|
-
|
|
126
|
+
serialize = (v: any) => {
|
|
127
|
+
this.writer.reset();
|
|
128
|
+
this.write(v);
|
|
105
129
|
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const serialize = (v: any) => {
|
|
110
|
-
writer.reset();
|
|
111
|
-
serializeWorker(v);
|
|
112
|
-
|
|
113
|
-
return writer.dump();
|
|
114
|
-
};
|
|
130
|
+
return this.writer.dump();
|
|
131
|
+
};
|
|
132
|
+
}
|
|
115
133
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
serializeVolatile,
|
|
120
|
-
};
|
|
134
|
+
enum EObjectTransferType {
|
|
135
|
+
CODE_URI = 'CODE_URI',
|
|
136
|
+
}
|
|
121
137
|
|
|
122
138
|
class ObjectTransfer {
|
|
123
139
|
static replacer(key: string | undefined, value: any) {
|
|
124
140
|
if (value) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
switch (value.$mid) {
|
|
142
|
+
case 1: {
|
|
143
|
+
// `$mid === 1` is defined in `vscode-uri` package
|
|
144
|
+
const uri = Uri.revive(value);
|
|
145
|
+
return {
|
|
146
|
+
$type: EObjectTransferType.CODE_URI,
|
|
147
|
+
data: uri.toString(),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
131
150
|
}
|
|
132
151
|
}
|
|
133
152
|
|
|
@@ -135,8 +154,9 @@ class ObjectTransfer {
|
|
|
135
154
|
}
|
|
136
155
|
static reviver(key: string | undefined, value: any) {
|
|
137
156
|
if (value && value.$type !== undefined && value.data !== undefined) {
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
switch (value.$type) {
|
|
158
|
+
case EObjectTransferType.CODE_URI:
|
|
159
|
+
return Uri.parse(value.data);
|
|
140
160
|
}
|
|
141
161
|
}
|
|
142
162
|
return value;
|
|
@@ -1,61 +1,109 @@
|
|
|
1
1
|
import { ObjectTypeDescription, Serializer, TypeDescription } from '@furyjs/fury';
|
|
2
2
|
import { generateSerializer } from '@furyjs/fury/dist/lib/gen';
|
|
3
3
|
|
|
4
|
-
import { furyFactory } from './shared';
|
|
5
|
-
const { fury, reader, writer } = furyFactory();
|
|
4
|
+
import { FuryFactoryReturn, furyFactory } from './shared';
|
|
6
5
|
|
|
7
6
|
type Writable = Record<string, any> & { kind: string };
|
|
8
7
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
8
|
+
export const oneOf7 = (
|
|
9
|
+
schemas: [
|
|
10
|
+
TypeDescription,
|
|
11
|
+
TypeDescription,
|
|
12
|
+
TypeDescription,
|
|
13
|
+
TypeDescription,
|
|
14
|
+
TypeDescription,
|
|
15
|
+
TypeDescription,
|
|
16
|
+
TypeDescription,
|
|
17
|
+
],
|
|
18
|
+
context?: FuryFactoryReturn,
|
|
19
|
+
) => {
|
|
20
|
+
if (!context) {
|
|
21
|
+
context = furyFactory();
|
|
22
|
+
}
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
const { fury, reader, writer } = context;
|
|
25
|
+
|
|
26
|
+
const serializers = new Array(7) as Serializer[];
|
|
27
|
+
const kinds = new Array(7) as string[];
|
|
28
|
+
|
|
29
|
+
const kindToIndex = {} as Record<string, number>;
|
|
30
|
+
|
|
31
|
+
schemas.forEach((schema, i) => {
|
|
32
|
+
const kind = (schema as ObjectTypeDescription).options.tag;
|
|
33
|
+
serializers[i] = generateSerializer(fury, schema);
|
|
34
|
+
kinds[i] = kind;
|
|
35
|
+
kindToIndex[kind] = i;
|
|
14
36
|
});
|
|
15
37
|
|
|
16
38
|
const deserialize = (bytes: Uint8Array) => {
|
|
17
39
|
reader.reset(bytes);
|
|
18
|
-
const
|
|
19
|
-
const serializer = registry.get(kind);
|
|
20
|
-
if (!serializer) {
|
|
21
|
-
throw new Error(`Unknown kind: ${kind}`);
|
|
22
|
-
}
|
|
40
|
+
const idx = reader.uint8();
|
|
23
41
|
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
let v: any;
|
|
43
|
+
switch (idx) {
|
|
44
|
+
case 0:
|
|
45
|
+
v = serializers[0].read();
|
|
46
|
+
break;
|
|
47
|
+
case 1:
|
|
48
|
+
v = serializers[1].read();
|
|
49
|
+
break;
|
|
50
|
+
case 2:
|
|
51
|
+
v = serializers[2].read();
|
|
52
|
+
break;
|
|
53
|
+
case 3:
|
|
54
|
+
v = serializers[3].read();
|
|
55
|
+
break;
|
|
56
|
+
case 4:
|
|
57
|
+
v = serializers[4].read();
|
|
58
|
+
break;
|
|
59
|
+
case 5:
|
|
60
|
+
v = serializers[5].read();
|
|
61
|
+
break;
|
|
62
|
+
case 6:
|
|
63
|
+
v = serializers[6].read();
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
26
66
|
|
|
67
|
+
v.kind = kinds[idx];
|
|
27
68
|
return v;
|
|
28
69
|
};
|
|
29
70
|
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
if (!serializer) {
|
|
33
|
-
throw new Error(`Unknown kind: ${v.kind}`);
|
|
34
|
-
}
|
|
71
|
+
const serialize = (v: Writable) => {
|
|
72
|
+
const index = kindToIndex[v.kind];
|
|
35
73
|
|
|
36
74
|
writer.reset();
|
|
37
|
-
writer.stringOfVarUInt32(v.kind);
|
|
38
|
-
serializer.write(v);
|
|
39
75
|
|
|
40
|
-
|
|
41
|
-
};
|
|
76
|
+
writer.uint8(index);
|
|
42
77
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
switch (index) {
|
|
79
|
+
case 0:
|
|
80
|
+
serializers[0].write(v);
|
|
81
|
+
break;
|
|
82
|
+
case 1:
|
|
83
|
+
serializers[1].write(v);
|
|
84
|
+
break;
|
|
85
|
+
case 2:
|
|
86
|
+
serializers[2].write(v);
|
|
87
|
+
break;
|
|
88
|
+
case 3:
|
|
89
|
+
serializers[3].write(v);
|
|
90
|
+
break;
|
|
91
|
+
case 4:
|
|
92
|
+
serializers[4].write(v);
|
|
93
|
+
break;
|
|
94
|
+
case 5:
|
|
95
|
+
serializers[5].write(v);
|
|
96
|
+
break;
|
|
97
|
+
case 6:
|
|
98
|
+
serializers[6].write(v);
|
|
99
|
+
break;
|
|
47
100
|
}
|
|
48
101
|
|
|
49
|
-
writer.reset();
|
|
50
|
-
writer.stringOfVarUInt32(v.kind);
|
|
51
|
-
serializer.write(v);
|
|
52
|
-
|
|
53
102
|
return writer.dump();
|
|
54
103
|
};
|
|
55
104
|
|
|
56
105
|
return {
|
|
57
106
|
deserialize,
|
|
58
107
|
serialize,
|
|
59
|
-
serializeVolatile,
|
|
60
108
|
};
|
|
61
109
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Fury from '@furyjs/fury/dist/lib/fury';
|
|
2
|
+
|
|
2
3
|
import type { Config } from '@furyjs/fury/dist/lib/type';
|
|
3
4
|
|
|
4
5
|
export const furyFactory = (config?: Config) => {
|
|
@@ -14,3 +15,5 @@ export const furyFactory = (config?: Config) => {
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
export type FuryFactoryReturn = ReturnType<typeof furyFactory>;
|
|
18
|
+
export type Writer = FuryFactoryReturn['writer'];
|
|
19
|
+
export type Reader = FuryFactoryReturn['reader'];
|
package/src/common/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './message';
|
|
2
2
|
export * from './rpc-service/proxy';
|
|
3
3
|
export * from './rpc/multiplexer';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './rpcProtocol';
|
|
5
|
+
export * from './capturer';
|
|
6
6
|
export * from './ws-channel';
|
|
7
7
|
export * from './connect';
|
|
8
8
|
export * from './types';
|
package/src/common/message.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createMessageConnection,
|
|
5
5
|
} from '@opensumi/vscode-jsonrpc/lib/common/api';
|
|
6
6
|
import { Disposable } from '@opensumi/vscode-jsonrpc/lib/common/disposable';
|
|
7
|
-
import {
|
|
7
|
+
import { DataCallback, MessageReader } from '@opensumi/vscode-jsonrpc/lib/common/messageReader';
|
|
8
8
|
import { MessageWriter } from '@opensumi/vscode-jsonrpc/lib/common/messageWriter';
|
|
9
9
|
/**
|
|
10
10
|
* FIXME: 由于 `createMessageConnection` 方法隐式依赖了 `@opensumi/vscode-jsonrpc/lib/browser/main` 或 `@opensumi/vscode-jsonrpc/lib/node/main`
|