starpc 0.18.2 → 0.19.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/dist/e2e/mock/mock.pb.js +10 -6
- package/dist/echo/echo.pb.js +11 -7
- package/dist/rpcstream/pushable-sink.d.ts +0 -0
- package/dist/rpcstream/pushable-sink.js +1 -0
- package/dist/rpcstream/rpcstream.js +1 -1
- package/dist/rpcstream/rpcstream.pb.js +45 -25
- package/dist/srpc/client.js +3 -4
- package/dist/srpc/common-rpc.js +1 -1
- package/dist/srpc/conn.d.ts +1 -1
- package/dist/srpc/conn.js +16 -6
- package/dist/srpc/errors.d.ts +1 -0
- package/dist/srpc/errors.js +23 -0
- package/dist/srpc/index.d.ts +4 -2
- package/dist/srpc/index.js +4 -2
- package/dist/srpc/pushable.d.ts +2 -0
- package/dist/srpc/pushable.js +23 -0
- package/dist/srpc/rpcproto.pb.js +69 -31
- package/dist/srpc/server.d.ts +3 -4
- package/dist/srpc/server.js +11 -12
- package/e2e/mock/mock.pb.go +1 -1
- package/e2e/mock/mock.pb.ts +12 -6
- package/e2e/mock/mock_srpc.pb.go +1 -1
- package/e2e/mock/mock_vtproto.pb.go +13 -5
- package/echo/echo.pb.go +1 -1
- package/echo/echo.pb.ts +13 -7
- package/echo/echo_srpc.pb.go +1 -1
- package/echo/echo_vtproto.pb.go +13 -5
- package/go.mod +3 -3
- package/go.sum +6 -6
- package/package.json +18 -18
- package/srpc/client-prefix.go +7 -0
- package/srpc/client-set.go +18 -3
- package/srpc/client.go +19 -3
- package/srpc/client.ts +3 -9
- package/srpc/common-rpc.ts +1 -1
- package/srpc/conn.ts +22 -8
- package/srpc/errors.go +2 -0
- package/srpc/errors.ts +24 -0
- package/srpc/index.ts +9 -2
- package/srpc/message.go +12 -0
- package/srpc/muxed-conn.go +1 -1
- package/srpc/packet-rw.go +18 -15
- package/srpc/packet.go +19 -0
- package/srpc/pushable.ts +23 -0
- package/srpc/raw-stream-rwc.go +153 -0
- package/srpc/rpcproto.pb.go +1 -1
- package/srpc/rpcproto.pb.ts +89 -34
- package/srpc/rpcproto_vtproto.pb.go +35 -13
- package/srpc/server-pipe.go +1 -1
- package/srpc/server-rpc.go +9 -0
- package/srpc/server.go +2 -1
- package/srpc/server.ts +11 -13
- package/srpc/stream-rwc.go +85 -0
- package/srpc/stream.ts +1 -0
- package/srpc/writer.go +2 -0
package/dist/e2e/mock/mock.pb.js
CHANGED
|
@@ -13,19 +13,23 @@ export const MockMsg = {
|
|
|
13
13
|
return writer;
|
|
14
14
|
},
|
|
15
15
|
decode(input, length) {
|
|
16
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
16
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
17
17
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
18
18
|
const message = createBaseMockMsg();
|
|
19
19
|
while (reader.pos < end) {
|
|
20
20
|
const tag = reader.uint32();
|
|
21
21
|
switch (tag >>> 3) {
|
|
22
22
|
case 1:
|
|
23
|
+
if (tag != 10) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
23
26
|
message.body = reader.string();
|
|
24
|
-
|
|
25
|
-
default:
|
|
26
|
-
reader.skipType(tag & 7);
|
|
27
|
-
break;
|
|
27
|
+
continue;
|
|
28
28
|
}
|
|
29
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
reader.skipType(tag & 7);
|
|
29
33
|
}
|
|
30
34
|
return message;
|
|
31
35
|
},
|
|
@@ -83,7 +87,7 @@ export class MockClientImpl {
|
|
|
83
87
|
MockRequest(request, abortSignal) {
|
|
84
88
|
const data = MockMsg.encode(request).finish();
|
|
85
89
|
const promise = this.rpc.request(this.service, 'MockRequest', data, abortSignal || undefined);
|
|
86
|
-
return promise.then((data) => MockMsg.decode(
|
|
90
|
+
return promise.then((data) => MockMsg.decode(_m0.Reader.create(data)));
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
export const MockDefinition = {
|
package/dist/echo/echo.pb.js
CHANGED
|
@@ -14,19 +14,23 @@ export const EchoMsg = {
|
|
|
14
14
|
return writer;
|
|
15
15
|
},
|
|
16
16
|
decode(input, length) {
|
|
17
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
17
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
18
18
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
19
19
|
const message = createBaseEchoMsg();
|
|
20
20
|
while (reader.pos < end) {
|
|
21
21
|
const tag = reader.uint32();
|
|
22
22
|
switch (tag >>> 3) {
|
|
23
23
|
case 1:
|
|
24
|
+
if (tag != 10) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
24
27
|
message.body = reader.string();
|
|
25
|
-
|
|
26
|
-
default:
|
|
27
|
-
reader.skipType(tag & 7);
|
|
28
|
-
break;
|
|
28
|
+
continue;
|
|
29
29
|
}
|
|
30
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
reader.skipType(tag & 7);
|
|
30
34
|
}
|
|
31
35
|
return message;
|
|
32
36
|
},
|
|
@@ -88,7 +92,7 @@ export class EchoerClientImpl {
|
|
|
88
92
|
Echo(request, abortSignal) {
|
|
89
93
|
const data = EchoMsg.encode(request).finish();
|
|
90
94
|
const promise = this.rpc.request(this.service, 'Echo', data, abortSignal || undefined);
|
|
91
|
-
return promise.then((data) => EchoMsg.decode(
|
|
95
|
+
return promise.then((data) => EchoMsg.decode(_m0.Reader.create(data)));
|
|
92
96
|
}
|
|
93
97
|
EchoServerStream(request, abortSignal) {
|
|
94
98
|
const data = EchoMsg.encode(request).finish();
|
|
@@ -98,7 +102,7 @@ export class EchoerClientImpl {
|
|
|
98
102
|
EchoClientStream(request, abortSignal) {
|
|
99
103
|
const data = EchoMsg.encodeTransform(request);
|
|
100
104
|
const promise = this.rpc.clientStreamingRequest(this.service, 'EchoClientStream', data, abortSignal || undefined);
|
|
101
|
-
return promise.then((data) => EchoMsg.decode(
|
|
105
|
+
return promise.then((data) => EchoMsg.decode(_m0.Reader.create(data)));
|
|
102
106
|
}
|
|
103
107
|
EchoBidiStream(request, abortSignal) {
|
|
104
108
|
const data = EchoMsg.encodeTransform(request);
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -31,7 +31,7 @@ export async function openRpcStream(componentId, caller, waitAck) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
// build & return the data stream
|
|
34
|
-
return new RpcStream(packetSink, packetIt);
|
|
34
|
+
return new RpcStream(packetSink, packetIt);
|
|
35
35
|
}
|
|
36
36
|
// buildRpcStreamOpenStream builds a OpenStream func with a RpcStream.
|
|
37
37
|
export function buildRpcStreamOpenStream(componentId, caller) {
|
|
@@ -7,43 +7,55 @@ function createBaseRpcStreamPacket() {
|
|
|
7
7
|
}
|
|
8
8
|
export const RpcStreamPacket = {
|
|
9
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
switch (message.body?.$case) {
|
|
11
|
+
case 'init':
|
|
12
|
+
RpcStreamInit.encode(message.body.init, writer.uint32(10).fork()).ldelim();
|
|
13
|
+
break;
|
|
14
|
+
case 'ack':
|
|
15
|
+
RpcAck.encode(message.body.ack, writer.uint32(18).fork()).ldelim();
|
|
16
|
+
break;
|
|
17
|
+
case 'data':
|
|
18
|
+
writer.uint32(26).bytes(message.body.data);
|
|
19
|
+
break;
|
|
18
20
|
}
|
|
19
21
|
return writer;
|
|
20
22
|
},
|
|
21
23
|
decode(input, length) {
|
|
22
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
24
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
23
25
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
24
26
|
const message = createBaseRpcStreamPacket();
|
|
25
27
|
while (reader.pos < end) {
|
|
26
28
|
const tag = reader.uint32();
|
|
27
29
|
switch (tag >>> 3) {
|
|
28
30
|
case 1:
|
|
31
|
+
if (tag != 10) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
29
34
|
message.body = {
|
|
30
35
|
$case: 'init',
|
|
31
36
|
init: RpcStreamInit.decode(reader, reader.uint32()),
|
|
32
37
|
};
|
|
33
|
-
|
|
38
|
+
continue;
|
|
34
39
|
case 2:
|
|
40
|
+
if (tag != 18) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
35
43
|
message.body = {
|
|
36
44
|
$case: 'ack',
|
|
37
45
|
ack: RpcAck.decode(reader, reader.uint32()),
|
|
38
46
|
};
|
|
39
|
-
|
|
47
|
+
continue;
|
|
40
48
|
case 3:
|
|
49
|
+
if (tag != 26) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
41
52
|
message.body = { $case: 'data', data: reader.bytes() };
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
56
|
+
break;
|
|
46
57
|
}
|
|
58
|
+
reader.skipType(tag & 7);
|
|
47
59
|
}
|
|
48
60
|
return message;
|
|
49
61
|
},
|
|
@@ -140,19 +152,23 @@ export const RpcStreamInit = {
|
|
|
140
152
|
return writer;
|
|
141
153
|
},
|
|
142
154
|
decode(input, length) {
|
|
143
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
155
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
144
156
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
145
157
|
const message = createBaseRpcStreamInit();
|
|
146
158
|
while (reader.pos < end) {
|
|
147
159
|
const tag = reader.uint32();
|
|
148
160
|
switch (tag >>> 3) {
|
|
149
161
|
case 1:
|
|
162
|
+
if (tag != 10) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
150
165
|
message.componentId = reader.string();
|
|
151
|
-
|
|
152
|
-
default:
|
|
153
|
-
reader.skipType(tag & 7);
|
|
154
|
-
break;
|
|
166
|
+
continue;
|
|
155
167
|
}
|
|
168
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
reader.skipType(tag & 7);
|
|
156
172
|
}
|
|
157
173
|
return message;
|
|
158
174
|
},
|
|
@@ -214,19 +230,23 @@ export const RpcAck = {
|
|
|
214
230
|
return writer;
|
|
215
231
|
},
|
|
216
232
|
decode(input, length) {
|
|
217
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
233
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
218
234
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
219
235
|
const message = createBaseRpcAck();
|
|
220
236
|
while (reader.pos < end) {
|
|
221
237
|
const tag = reader.uint32();
|
|
222
238
|
switch (tag >>> 3) {
|
|
223
239
|
case 1:
|
|
240
|
+
if (tag != 10) {
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
224
243
|
message.error = reader.string();
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
247
|
+
break;
|
|
229
248
|
}
|
|
249
|
+
reader.skipType(tag & 7);
|
|
230
250
|
}
|
|
231
251
|
return message;
|
|
232
252
|
},
|
package/dist/srpc/client.js
CHANGED
|
@@ -3,8 +3,7 @@ import { pushable } from 'it-pushable';
|
|
|
3
3
|
import { ERR_RPC_ABORT } from './errors.js';
|
|
4
4
|
import { ClientRPC } from './client-rpc.js';
|
|
5
5
|
import { writeToPushable } from './pushable.js';
|
|
6
|
-
import { decodePacketSource, encodePacketSource,
|
|
7
|
-
import { combineUint8ArrayListTransform } from './array-list.js';
|
|
6
|
+
import { decodePacketSource, encodePacketSource, } from './packet.js';
|
|
8
7
|
import { OpenStreamCtr } from './open-stream-ctr.js';
|
|
9
8
|
// Client implements the ts-proto Rpc interface with the drpcproto protocol.
|
|
10
9
|
export class Client {
|
|
@@ -75,12 +74,12 @@ export class Client {
|
|
|
75
74
|
throw new Error(ERR_RPC_ABORT);
|
|
76
75
|
}
|
|
77
76
|
const openStreamFn = await this.openStreamCtr.wait();
|
|
78
|
-
const
|
|
77
|
+
const stream = await openStreamFn();
|
|
79
78
|
const call = new ClientRPC(rpcService, rpcMethod);
|
|
80
79
|
abortSignal?.addEventListener('abort', () => {
|
|
81
80
|
call.close(new Error(ERR_RPC_ABORT));
|
|
82
81
|
});
|
|
83
|
-
pipe(
|
|
82
|
+
pipe(stream, decodePacketSource, call, encodePacketSource, stream);
|
|
84
83
|
await call.writeCallStart(data || undefined);
|
|
85
84
|
return call;
|
|
86
85
|
}
|
package/dist/srpc/common-rpc.js
CHANGED
package/dist/srpc/conn.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface ConnParams {
|
|
|
9
9
|
direction?: Direction;
|
|
10
10
|
}
|
|
11
11
|
export interface StreamHandler {
|
|
12
|
-
|
|
12
|
+
handlePacketStream(strm: SRPCStream): void;
|
|
13
13
|
}
|
|
14
14
|
export declare function streamToSRPCStream(stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): SRPCStream;
|
|
15
15
|
export declare class Conn implements Duplex<Uint8Array> {
|
package/dist/srpc/conn.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { pipe } from 'it-pipe';
|
|
2
2
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
3
3
|
import isPromise from 'is-promise';
|
|
4
|
+
import { pushable } from 'it-pushable';
|
|
4
5
|
import { Client } from './client.js';
|
|
5
6
|
import { combineUint8ArrayListTransform } from './array-list.js';
|
|
7
|
+
import { parseLengthPrefixTransform, prependLengthPrefixTransform } from './packet.js';
|
|
8
|
+
import { buildPushableSink } from './pushable.js';
|
|
6
9
|
// streamToSRPCStream converts a Stream to a SRPCStream.
|
|
10
|
+
// uses length-prefix for packet framing
|
|
7
11
|
export function streamToSRPCStream(stream) {
|
|
12
|
+
const pushSink = pushable({ objectMode: true });
|
|
13
|
+
pipe(pushSink, prependLengthPrefixTransform(), stream.sink);
|
|
8
14
|
return {
|
|
9
|
-
source: pipe(stream, combineUint8ArrayListTransform()),
|
|
10
|
-
sink:
|
|
15
|
+
source: pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform()),
|
|
16
|
+
sink: buildPushableSink(pushSink),
|
|
11
17
|
};
|
|
12
18
|
}
|
|
13
19
|
// Conn implements a generic connection with a two-way stream.
|
|
@@ -46,9 +52,13 @@ export class Conn {
|
|
|
46
52
|
}
|
|
47
53
|
// openStream implements the client open stream function.
|
|
48
54
|
async openStream() {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const streamPromise = this.muxer.newStream();
|
|
56
|
+
let stream;
|
|
57
|
+
if (isPromise(streamPromise)) {
|
|
58
|
+
stream = await streamPromise;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
stream = streamPromise;
|
|
52
62
|
}
|
|
53
63
|
return streamToSRPCStream(stream);
|
|
54
64
|
}
|
|
@@ -62,6 +72,6 @@ export class Conn {
|
|
|
62
72
|
if (!server) {
|
|
63
73
|
return strm.abort(new Error('server not implemented'));
|
|
64
74
|
}
|
|
65
|
-
server.
|
|
75
|
+
server.handlePacketStream(streamToSRPCStream(strm));
|
|
66
76
|
}
|
|
67
77
|
}
|
package/dist/srpc/errors.d.ts
CHANGED
package/dist/srpc/errors.js
CHANGED
|
@@ -8,3 +8,26 @@ export function isAbortError(err) {
|
|
|
8
8
|
const message = err.message;
|
|
9
9
|
return message === ERR_RPC_ABORT;
|
|
10
10
|
}
|
|
11
|
+
// castToError casts an object to an Error.
|
|
12
|
+
// if err is a string, uses it as the message.
|
|
13
|
+
// if err is undefined, returns new Error(defaultMsg)
|
|
14
|
+
export function castToError(err, defaultMsg) {
|
|
15
|
+
defaultMsg = defaultMsg || 'error';
|
|
16
|
+
if (!err) {
|
|
17
|
+
return new Error(defaultMsg);
|
|
18
|
+
}
|
|
19
|
+
if (typeof err === 'string') {
|
|
20
|
+
return new Error(err);
|
|
21
|
+
}
|
|
22
|
+
const asError = err;
|
|
23
|
+
if (asError.message) {
|
|
24
|
+
return asError;
|
|
25
|
+
}
|
|
26
|
+
if (err.toString) {
|
|
27
|
+
const errString = err.toString();
|
|
28
|
+
if (errString) {
|
|
29
|
+
return new Error(errString);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return new Error(defaultMsg);
|
|
33
|
+
}
|
package/dist/srpc/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { PacketHandler, Stream, OpenStreamFunc } from './stream.js';
|
|
2
|
-
export { ERR_RPC_ABORT, isAbortError } from './errors.js';
|
|
2
|
+
export { ERR_RPC_ABORT, isAbortError, castToError } from './errors.js';
|
|
3
3
|
export { Client } from './client.js';
|
|
4
4
|
export { Server } from './server.js';
|
|
5
5
|
export { Conn, ConnParams } from './conn.js';
|
|
@@ -9,6 +9,8 @@ export { Mux, StaticMux, createMux } from './mux.js';
|
|
|
9
9
|
export { BroadcastChannelDuplex, newBroadcastChannelDuplex, BroadcastChannelConn, } from './broadcast-channel.js';
|
|
10
10
|
export { MessagePortIterable, newMessagePortIterable, MessagePortConn, } from './message-port.js';
|
|
11
11
|
export { MessageDefinition, DecodeMessageTransform, buildDecodeMessageTransform, EncodeMessageTransform, buildEncodeMessageTransform, memoProto, memoProtoDecode, } from './message.js';
|
|
12
|
+
export { parseLengthPrefixTransform, prependLengthPrefixTransform, decodePacketSource, encodePacketSource, } from './packet.js';
|
|
13
|
+
export { combineUint8ArrayListTransform } from './array-list.js';
|
|
12
14
|
export { ValueCtr } from './value-ctr.js';
|
|
13
15
|
export { OpenStreamCtr } from './open-stream-ctr.js';
|
|
14
|
-
export { writeToPushable } from './pushable';
|
|
16
|
+
export { writeToPushable, buildPushableSink } from './pushable.js';
|
package/dist/srpc/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ERR_RPC_ABORT, isAbortError } from './errors.js';
|
|
1
|
+
export { ERR_RPC_ABORT, isAbortError, castToError } from './errors.js';
|
|
2
2
|
export { Client } from './client.js';
|
|
3
3
|
export { Server } from './server.js';
|
|
4
4
|
export { Conn } from './conn.js';
|
|
@@ -8,6 +8,8 @@ export { StaticMux, createMux } from './mux.js';
|
|
|
8
8
|
export { BroadcastChannelDuplex, newBroadcastChannelDuplex, BroadcastChannelConn, } from './broadcast-channel.js';
|
|
9
9
|
export { MessagePortIterable, newMessagePortIterable, MessagePortConn, } from './message-port.js';
|
|
10
10
|
export { buildDecodeMessageTransform, buildEncodeMessageTransform, memoProto, memoProtoDecode, } from './message.js';
|
|
11
|
+
export { parseLengthPrefixTransform, prependLengthPrefixTransform, decodePacketSource, encodePacketSource, } from './packet.js';
|
|
12
|
+
export { combineUint8ArrayListTransform } from './array-list.js';
|
|
11
13
|
export { ValueCtr } from './value-ctr.js';
|
|
12
14
|
export { OpenStreamCtr } from './open-stream-ctr.js';
|
|
13
|
-
export { writeToPushable } from './pushable';
|
|
15
|
+
export { writeToPushable, buildPushableSink } from './pushable.js';
|
package/dist/srpc/pushable.d.ts
CHANGED
package/dist/srpc/pushable.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { castToError } from './errors.js';
|
|
1
2
|
// writeToPushable writes the incoming server data to the pushable.
|
|
2
3
|
export async function writeToPushable(dataSource, out) {
|
|
3
4
|
try {
|
|
@@ -11,3 +12,25 @@ export async function writeToPushable(dataSource, out) {
|
|
|
11
12
|
throw err;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
15
|
+
// buildPushableSink builds a Sink from a Pushable.
|
|
16
|
+
export function buildPushableSink(target) {
|
|
17
|
+
return async function pushableSink(source) {
|
|
18
|
+
try {
|
|
19
|
+
for await (const pkt of source) {
|
|
20
|
+
if (Array.isArray(pkt)) {
|
|
21
|
+
for (const p of pkt) {
|
|
22
|
+
target.push(p);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
target.push(pkt);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
target.end();
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
const error = castToError(err);
|
|
33
|
+
target.end(error);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -7,43 +7,55 @@ function createBasePacket() {
|
|
|
7
7
|
}
|
|
8
8
|
export const Packet = {
|
|
9
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
switch (message.body?.$case) {
|
|
11
|
+
case 'callStart':
|
|
12
|
+
CallStart.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
|
|
13
|
+
break;
|
|
14
|
+
case 'callData':
|
|
15
|
+
CallData.encode(message.body.callData, writer.uint32(18).fork()).ldelim();
|
|
16
|
+
break;
|
|
17
|
+
case 'callCancel':
|
|
18
|
+
writer.uint32(24).bool(message.body.callCancel);
|
|
19
|
+
break;
|
|
18
20
|
}
|
|
19
21
|
return writer;
|
|
20
22
|
},
|
|
21
23
|
decode(input, length) {
|
|
22
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
24
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
23
25
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
24
26
|
const message = createBasePacket();
|
|
25
27
|
while (reader.pos < end) {
|
|
26
28
|
const tag = reader.uint32();
|
|
27
29
|
switch (tag >>> 3) {
|
|
28
30
|
case 1:
|
|
31
|
+
if (tag != 10) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
29
34
|
message.body = {
|
|
30
35
|
$case: 'callStart',
|
|
31
36
|
callStart: CallStart.decode(reader, reader.uint32()),
|
|
32
37
|
};
|
|
33
|
-
|
|
38
|
+
continue;
|
|
34
39
|
case 2:
|
|
40
|
+
if (tag != 18) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
35
43
|
message.body = {
|
|
36
44
|
$case: 'callData',
|
|
37
45
|
callData: CallData.decode(reader, reader.uint32()),
|
|
38
46
|
};
|
|
39
|
-
|
|
47
|
+
continue;
|
|
40
48
|
case 3:
|
|
49
|
+
if (tag != 24) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
41
52
|
message.body = { $case: 'callCancel', callCancel: reader.bool() };
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
56
|
+
break;
|
|
46
57
|
}
|
|
58
|
+
reader.skipType(tag & 7);
|
|
47
59
|
}
|
|
48
60
|
return message;
|
|
49
61
|
},
|
|
@@ -157,28 +169,41 @@ export const CallStart = {
|
|
|
157
169
|
return writer;
|
|
158
170
|
},
|
|
159
171
|
decode(input, length) {
|
|
160
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
172
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
161
173
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
162
174
|
const message = createBaseCallStart();
|
|
163
175
|
while (reader.pos < end) {
|
|
164
176
|
const tag = reader.uint32();
|
|
165
177
|
switch (tag >>> 3) {
|
|
166
178
|
case 1:
|
|
179
|
+
if (tag != 10) {
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
167
182
|
message.rpcService = reader.string();
|
|
168
|
-
|
|
183
|
+
continue;
|
|
169
184
|
case 2:
|
|
185
|
+
if (tag != 18) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
170
188
|
message.rpcMethod = reader.string();
|
|
171
|
-
|
|
189
|
+
continue;
|
|
172
190
|
case 3:
|
|
191
|
+
if (tag != 26) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
173
194
|
message.data = reader.bytes();
|
|
174
|
-
|
|
195
|
+
continue;
|
|
175
196
|
case 4:
|
|
197
|
+
if (tag != 32) {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
176
200
|
message.dataIsZero = reader.bool();
|
|
177
|
-
|
|
178
|
-
default:
|
|
179
|
-
reader.skipType(tag & 7);
|
|
180
|
-
break;
|
|
201
|
+
continue;
|
|
181
202
|
}
|
|
203
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
reader.skipType(tag & 7);
|
|
182
207
|
}
|
|
183
208
|
return message;
|
|
184
209
|
},
|
|
@@ -266,28 +291,41 @@ export const CallData = {
|
|
|
266
291
|
return writer;
|
|
267
292
|
},
|
|
268
293
|
decode(input, length) {
|
|
269
|
-
const reader = input instanceof _m0.Reader ? input :
|
|
294
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
270
295
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
271
296
|
const message = createBaseCallData();
|
|
272
297
|
while (reader.pos < end) {
|
|
273
298
|
const tag = reader.uint32();
|
|
274
299
|
switch (tag >>> 3) {
|
|
275
300
|
case 1:
|
|
301
|
+
if (tag != 10) {
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
276
304
|
message.data = reader.bytes();
|
|
277
|
-
|
|
305
|
+
continue;
|
|
278
306
|
case 2:
|
|
307
|
+
if (tag != 16) {
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
279
310
|
message.dataIsZero = reader.bool();
|
|
280
|
-
|
|
311
|
+
continue;
|
|
281
312
|
case 3:
|
|
313
|
+
if (tag != 24) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
282
316
|
message.complete = reader.bool();
|
|
283
|
-
|
|
317
|
+
continue;
|
|
284
318
|
case 4:
|
|
319
|
+
if (tag != 34) {
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
285
322
|
message.error = reader.string();
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
326
|
+
break;
|
|
290
327
|
}
|
|
328
|
+
reader.skipType(tag & 7);
|
|
291
329
|
}
|
|
292
330
|
return message;
|
|
293
331
|
},
|
package/dist/srpc/server.d.ts
CHANGED
|
@@ -10,8 +10,7 @@ export declare class Server implements StreamHandler {
|
|
|
10
10
|
constructor(lookupMethod: LookupMethod);
|
|
11
11
|
get rpcStreamHandler(): RpcStreamHandler;
|
|
12
12
|
startRpc(): ServerRPC;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
handlePacketDuplex(stream: Duplex<
|
|
16
|
-
handlePacketStream(stream: Duplex<Packet>): ServerRPC;
|
|
13
|
+
handleFragmentStream(stream: Stream): ServerRPC;
|
|
14
|
+
handlePacketStream(stream: Stream): ServerRPC;
|
|
15
|
+
handlePacketDuplex(stream: Duplex<Packet>): ServerRPC;
|
|
17
16
|
}
|
package/dist/srpc/server.js
CHANGED
|
@@ -8,33 +8,32 @@ export class Server {
|
|
|
8
8
|
this.lookupMethod = lookupMethod;
|
|
9
9
|
}
|
|
10
10
|
// rpcStreamHandler implements the RpcStreamHandler interface.
|
|
11
|
+
// uses handlePacketDuplex (expects 1 buf = 1 Packet)
|
|
11
12
|
get rpcStreamHandler() {
|
|
12
|
-
return this.
|
|
13
|
+
return this.handlePacketStream.bind(this);
|
|
13
14
|
}
|
|
14
15
|
// startRpc starts a new server-side RPC.
|
|
15
16
|
// the returned RPC handles incoming Packets.
|
|
16
17
|
startRpc() {
|
|
17
18
|
return new ServerRPC(this.lookupMethod);
|
|
18
19
|
}
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// handleDuplex handles an incoming message duplex.
|
|
24
|
-
handleDuplex(stream) {
|
|
20
|
+
// handleFragmentStream handles an incoming stream.
|
|
21
|
+
// assumes that stream does not maintain packet framing.
|
|
22
|
+
// uses length-prefixed packets for packet framing.
|
|
23
|
+
handleFragmentStream(stream) {
|
|
25
24
|
const rpc = this.startRpc();
|
|
26
25
|
pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), combineUint8ArrayListTransform(), stream);
|
|
27
26
|
return rpc;
|
|
28
27
|
}
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
28
|
+
// handlePacketStream handles an incoming Uint8Array duplex.
|
|
29
|
+
// the stream has one Uint8Array per packet w/o length prefix.
|
|
30
|
+
handlePacketStream(stream) {
|
|
32
31
|
const rpc = this.startRpc();
|
|
33
32
|
pipe(stream, decodePacketSource, rpc, encodePacketSource, stream);
|
|
34
33
|
return rpc;
|
|
35
34
|
}
|
|
36
|
-
//
|
|
37
|
-
|
|
35
|
+
// handlePacketDuplex handles an incoming Packet duplex.
|
|
36
|
+
handlePacketDuplex(stream) {
|
|
38
37
|
const rpc = this.startRpc();
|
|
39
38
|
pipe(stream, rpc, stream);
|
|
40
39
|
return rpc;
|