starpc 0.15.0 → 0.15.2

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/Makefile CHANGED
@@ -119,7 +119,8 @@ gents: $(PROTOWRAP) node_modules
119
119
  git \
120
120
  ls-files "*.proto" |\
121
121
  xargs printf -- \
122
- "$$(pwd)/vendor/$${PROJECT}/%s "); \
122
+ "$$(pwd)/vendor/$${PROJECT}/%s ");
123
+ npm run format
123
124
  go mod vendor
124
125
 
125
126
  .PHONY: genproto
@@ -32,7 +32,7 @@ export declare class MockClientImpl implements Mock {
32
32
  MockRequest(request: MockMsg): Promise<MockMsg>;
33
33
  }
34
34
  /** Mock service mocks some RPCs for the e2e tests. */
35
- export declare type MockDefinition = typeof MockDefinition;
35
+ export type MockDefinition = typeof MockDefinition;
36
36
  export declare const MockDefinition: {
37
37
  readonly name: "Mock";
38
38
  readonly fullName: "e2e.mock.Mock";
@@ -75,8 +75,8 @@ export declare const MockDefinition: {
75
75
  interface Rpc {
76
76
  request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
77
77
  }
78
- declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
79
- export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
78
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
79
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
80
80
  $case: string;
81
81
  } ? {
82
82
  [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
@@ -85,8 +85,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
85
85
  } : T extends {} ? {
86
86
  [K in keyof T]?: DeepPartial<T[K]>;
87
87
  } : Partial<T>;
88
- declare type KeysOfUnion<T> = T extends T ? keyof T : never;
89
- export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
88
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
89
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
90
90
  [K in keyof P]: Exact<P[K], I[K]>;
91
91
  } & {
92
92
  [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
@@ -45,7 +45,7 @@ export declare class EchoerClientImpl implements Echoer {
45
45
  RpcStream(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket>;
46
46
  }
47
47
  /** Echoer service returns the given message. */
48
- export declare type EchoerDefinition = typeof EchoerDefinition;
48
+ export type EchoerDefinition = typeof EchoerDefinition;
49
49
  export declare const EchoerDefinition: {
50
50
  readonly name: "Echoer";
51
51
  readonly fullName: "echo.Echoer";
@@ -321,8 +321,8 @@ interface Rpc {
321
321
  serverStreamingRequest(service: string, method: string, data: Uint8Array): AsyncIterable<Uint8Array>;
322
322
  bidirectionalStreamingRequest(service: string, method: string, data: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
323
323
  }
324
- declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
325
- export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
324
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
325
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
326
326
  $case: string;
327
327
  } ? {
328
328
  [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
@@ -331,8 +331,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
331
331
  } : T extends {} ? {
332
332
  [K in keyof T]?: DeepPartial<T[K]>;
333
333
  } : Partial<T>;
334
- declare type KeysOfUnion<T> = T extends T ? keyof T : never;
335
- export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
334
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
335
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
336
336
  [K in keyof P]: Exact<P[K], I[K]>;
337
337
  } & {
338
338
  [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
@@ -3,11 +3,11 @@ import { OpenStreamFunc, Stream } from '../srpc/stream.js';
3
3
  import { Pushable } from 'it-pushable';
4
4
  import { Source, Sink } from 'it-stream-types';
5
5
  import { Uint8ArrayList } from 'uint8arraylist';
6
- export declare type RpcStreamCaller = (request: AsyncIterable<RpcStreamPacket>) => AsyncIterable<RpcStreamPacket>;
6
+ export type RpcStreamCaller = (request: AsyncIterable<RpcStreamPacket>) => AsyncIterable<RpcStreamPacket>;
7
7
  export declare function openRpcStream(componentId: string, caller: RpcStreamCaller): Promise<Stream>;
8
8
  export declare function buildRpcStreamOpenStream(componentId: string, caller: RpcStreamCaller): OpenStreamFunc;
9
- export declare type RpcStreamHandler = (stream: Stream) => void;
10
- export declare type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
9
+ export type RpcStreamHandler = (stream: Stream) => void;
10
+ export type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
11
11
  export declare function handleRpcStream(packetStream: AsyncIterator<RpcStreamPacket>, getter: RpcStreamGetter): AsyncIterable<RpcStreamPacket>;
12
12
  export declare class RpcStream implements Stream {
13
13
  readonly source: Source<Uint8Array>;
@@ -112,8 +112,8 @@ export declare const RpcAck: {
112
112
  error?: string | undefined;
113
113
  } & { [K in Exclude<keyof I, "error">]: never; }>(object: I): RpcAck;
114
114
  };
115
- declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
116
- export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
115
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
116
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
117
117
  $case: string;
118
118
  } ? {
119
119
  [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
@@ -122,8 +122,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
122
122
  } : T extends {} ? {
123
123
  [K in keyof T]?: DeepPartial<T[K]>;
124
124
  } : Partial<T>;
125
- declare type KeysOfUnion<T> = T extends T ? keyof T : never;
126
- export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
125
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
126
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
127
127
  [K in keyof P]: Exact<P[K], I[K]>;
128
128
  } & {
129
129
  [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
@@ -1,12 +1,12 @@
1
1
  import type { Sink, Source } from 'it-stream-types';
2
2
  import { Definition, MethodDefinition } from './definition.js';
3
- export declare type InvokeFn = (dataSource: Source<Uint8Array>, dataSink: Sink<Uint8Array>) => Promise<void>;
3
+ export type InvokeFn = (dataSource: Source<Uint8Array>, dataSink: Sink<Uint8Array>) => Promise<void>;
4
4
  export interface Handler {
5
5
  getServiceID(): string;
6
6
  getMethodIDs(): string[];
7
7
  lookupMethod(serviceID: string, methodID: string): Promise<InvokeFn | null>;
8
8
  }
9
- export declare type MethodMap = {
9
+ export type MethodMap = {
10
10
  [name: string]: InvokeFn;
11
11
  };
12
12
  export declare class StaticHandler implements Handler {
@@ -17,7 +17,7 @@ export declare class StaticHandler implements Handler {
17
17
  getMethodIDs(): string[];
18
18
  lookupMethod(serviceID: string, methodID: string): Promise<InvokeFn | null>;
19
19
  }
20
- declare type MethodProto<R, O> = ((request: R) => Promise<O>) | ((request: R) => AsyncIterable<O>) | ((request: AsyncIterable<R>) => Promise<O>) | ((request: AsyncIterable<R>) => AsyncIterable<O>);
20
+ type MethodProto<R, O> = ((request: R) => Promise<O>) | ((request: R) => AsyncIterable<O>) | ((request: AsyncIterable<R>) => Promise<O>) | ((request: AsyncIterable<R>) => AsyncIterable<O>);
21
21
  export declare function createInvokeFn<R, O>(methodInfo: MethodDefinition<R, O>, methodProto: MethodProto<R, O>): InvokeFn;
22
22
  export declare function createHandler(definition: Definition, impl: any, serviceID?: string): Handler;
23
23
  export {};
@@ -4,8 +4,8 @@ export interface MessageDefinition<T> {
4
4
  encode(message: T, writer?: pbjs.Writer): pbjs.Writer;
5
5
  decode(input: pbjs.Reader | Uint8Array, length?: number): T;
6
6
  }
7
- declare type DecodeMessageTransform<T> = (source: Source<Uint8Array | Uint8Array[]>) => AsyncIterable<T>;
7
+ type DecodeMessageTransform<T> = (source: Source<Uint8Array | Uint8Array[]>) => AsyncIterable<T>;
8
8
  export declare function buildDecodeMessageTransform<T>(def: MessageDefinition<T>): DecodeMessageTransform<T>;
9
- declare type EncodeMessageTransform<T> = (source: Source<T | T[]>) => AsyncIterable<Uint8Array>;
9
+ type EncodeMessageTransform<T> = (source: Source<T | T[]>) => AsyncIterable<Uint8Array>;
10
10
  export declare function buildEncodeMessageTransform<T>(def: MessageDefinition<T>): EncodeMessageTransform<T>;
11
11
  export {};
@@ -1,5 +1,5 @@
1
1
  import { InvokeFn, Handler } from './handler';
2
- export declare type LookupMethod = (serviceID: string, methodID: string) => Promise<InvokeFn | null>;
2
+ export type LookupMethod = (serviceID: string, methodID: string) => Promise<InvokeFn | null>;
3
3
  export interface Mux {
4
4
  lookupMethod(serviceID: string, methodID: string): Promise<InvokeFn | null>;
5
5
  }
@@ -172,8 +172,8 @@ export declare const CallData: {
172
172
  error?: string | undefined;
173
173
  } & { [K in Exclude<keyof I, keyof CallData>]: never; }>(object: I): CallData;
174
174
  };
175
- declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
176
- export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
175
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
176
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
177
177
  $case: string;
178
178
  } ? {
179
179
  [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
@@ -182,8 +182,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
182
182
  } : T extends {} ? {
183
183
  [K in keyof T]?: DeepPartial<T[K]>;
184
184
  } : Partial<T>;
185
- declare type KeysOfUnion<T> = T extends T ? keyof T : never;
186
- export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
185
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
186
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
187
187
  [K in keyof P]: Exact<P[K], I[K]>;
188
188
  } & {
189
189
  [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
@@ -1,5 +1,5 @@
1
1
  import type { Packet } from './rpcproto.pb.js';
2
2
  import type { Duplex } from 'it-stream-types';
3
- export declare type PacketHandler = (packet: Packet) => Promise<void>;
4
- export declare type Stream = Duplex<Uint8Array>;
5
- export declare type OpenStreamFunc = () => Promise<Stream>;
3
+ export type PacketHandler = (packet: Packet) => Promise<void>;
4
+ export type Stream = Duplex<Uint8Array>;
5
+ export type OpenStreamFunc = () => Promise<Stream>;
@@ -1,7 +1,7 @@
1
1
  // Code generated by protoc-gen-go. DO NOT EDIT.
2
2
  // versions:
3
3
  // protoc-gen-go v1.28.1-devel
4
- // protoc v3.19.3
4
+ // protoc v3.21.9
5
5
  // source: github.com/aperturerobotics/starpc/e2e/mock/mock.proto
6
6
 
7
7
  package e2e_mock
@@ -1,5 +1,5 @@
1
1
  // Code generated by protoc-gen-srpc. DO NOT EDIT.
2
- // protoc-gen-srpc version: v0.13.2
2
+ // protoc-gen-srpc version: v0.15.1
3
3
  // source: github.com/aperturerobotics/starpc/e2e/mock/mock.proto
4
4
 
5
5
  package e2e_mock
package/echo/echo.pb.go CHANGED
@@ -1,7 +1,7 @@
1
1
  // Code generated by protoc-gen-go. DO NOT EDIT.
2
2
  // versions:
3
3
  // protoc-gen-go v1.28.1-devel
4
- // protoc v3.19.3
4
+ // protoc v3.21.9
5
5
  // source: github.com/aperturerobotics/starpc/echo/echo.proto
6
6
 
7
7
  package echo
@@ -1,5 +1,5 @@
1
1
  // Code generated by protoc-gen-srpc. DO NOT EDIT.
2
- // protoc-gen-srpc version: v0.13.2
2
+ // protoc-gen-srpc version: v0.15.1
3
3
  // source: github.com/aperturerobotics/starpc/echo/echo.proto
4
4
 
5
5
  package echo
package/go.mod CHANGED
@@ -9,8 +9,8 @@ require (
9
9
  )
10
10
 
11
11
  require (
12
- github.com/aperturerobotics/util v0.0.0-20221125031036-d86bb72019f6
13
- github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4
12
+ github.com/aperturerobotics/util v0.0.0-20221202094321-2fde40039383
13
+ github.com/libp2p/go-libp2p v0.24.0-dev.0.20221202071826-2cc4de512664
14
14
  github.com/libp2p/go-yamux/v4 v4.0.1-0.20220919134236-1c09f2ab3ec1
15
15
  github.com/sirupsen/logrus v1.9.0
16
16
  )
@@ -28,7 +28,7 @@ require (
28
28
  github.com/mr-tron/base58 v1.2.0 // indirect
29
29
  github.com/multiformats/go-base32 v0.1.0 // indirect
30
30
  github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c // indirect
31
- github.com/multiformats/go-multiaddr v0.7.0 // indirect
31
+ github.com/multiformats/go-multiaddr v0.8.0 // indirect
32
32
  github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1 // indirect
33
33
  github.com/multiformats/go-multicodec v0.7.1-0.20221017174837-a2baec7ca709 // indirect
34
34
  github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6 // indirect
package/go.sum CHANGED
@@ -1,5 +1,5 @@
1
- github.com/aperturerobotics/util v0.0.0-20221125031036-d86bb72019f6 h1:qABa0SjNgWhwcqM5RhB+PYaHxeYoiBfHcAkbkGnh1Nw=
2
- github.com/aperturerobotics/util v0.0.0-20221125031036-d86bb72019f6/go.mod h1:XEAYwKz5dN1eqc7LFyoprXBD7AR/X3UC6o6NqSxnAG0=
1
+ github.com/aperturerobotics/util v0.0.0-20221202094321-2fde40039383 h1:r0TEmQAFN1Ji+1iMqBW1ymiofevQaUb3uOQTje2wp3Q=
2
+ github.com/aperturerobotics/util v0.0.0-20221202094321-2fde40039383/go.mod h1:up2AYcp62UgmFVTm7QhM4USXAKGv73gpb5dHraKmzxQ=
3
3
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4
4
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5
5
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -52,8 +52,8 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
52
52
  github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
53
53
  github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
54
54
  github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
55
- github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4 h1:Qo2C6xKnszNiB8nJ8M9E/wBakSktWccnm+ro+EGluX4=
56
- github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4/go.mod h1:9lqLgktzI5Gn2bplyrZvFSuDirYRBMU+Tu/FYBIjvek=
55
+ github.com/libp2p/go-libp2p v0.24.0-dev.0.20221202071826-2cc4de512664 h1:pv+MuIVoXKlPfxZ/dGjK+aDK3fFmfuo7ombAjrBN7z0=
56
+ github.com/libp2p/go-libp2p v0.24.0-dev.0.20221202071826-2cc4de512664/go.mod h1:WVV1V9SPcZ0uV/sBB5X3zsKZW/EikukrgTp1ABOcqWk=
57
57
  github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
58
58
  github.com/libp2p/go-openssl v0.1.0 h1:LBkKEcUv6vtZIQLVTegAil8jbNpJErQ9AnT+bWV+Ooo=
59
59
  github.com/libp2p/go-openssl v0.1.0/go.mod h1:OiOxwPpL3n4xlenjx2h7AwSGaFSC/KZvf6gNdOBQMtc=
@@ -75,8 +75,8 @@ github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aG
75
75
  github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI=
76
76
  github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c h1:3eLctj5+2JpWf0E8PICebevkyD0KcZUhye8ggScrnEQ=
77
77
  github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
78
- github.com/multiformats/go-multiaddr v0.7.0 h1:gskHcdaCyPtp9XskVwtvEeQOG465sCohbQIirSyqxrc=
79
- github.com/multiformats/go-multiaddr v0.7.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
78
+ github.com/multiformats/go-multiaddr v0.8.0 h1:aqjksEcqK+iD/Foe1RRFsGZh8+XFiGo7FgUCZlpv3LU=
79
+ github.com/multiformats/go-multiaddr v0.8.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
80
80
  github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1 h1:fts9VGSGzcENj3XnQ3iz9LGMAJAqT46fUGyaUDGFuxQ=
81
81
  github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1/go.mod h1:ReOVfKN5TNx1Z6d9Ba4GdcbPfPgAT8gC7lSG0ZJjEl4=
82
82
  github.com/multiformats/go-multicodec v0.7.1-0.20221017174837-a2baec7ca709 h1:XwgbSBFN6TU/aBJk0BLucpFL6I9zL9GMJp+WflbHkos=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -59,17 +59,17 @@
59
59
  "singleQuote": true
60
60
  },
61
61
  "devDependencies": {
62
- "@typescript-eslint/eslint-plugin": "^5.42.1",
63
- "@typescript-eslint/parser": "^5.42.1",
62
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
63
+ "@typescript-eslint/parser": "^5.45.0",
64
64
  "bufferutil": "^4.0.7",
65
65
  "depcheck": "^1.4.3",
66
- "esbuild": "^0.15.13",
67
- "eslint": "^8.27.0",
66
+ "esbuild": "^0.15.16",
67
+ "eslint": "^8.28.0",
68
68
  "eslint-config-prettier": "^8.5.0",
69
- "prettier": "^2.7.1",
69
+ "prettier": "^2.8.0",
70
70
  "rimraf": "^3.0.2",
71
- "ts-proto": "^1.130.0",
72
- "typescript": "^4.8.4",
71
+ "ts-proto": "^1.135.0",
72
+ "typescript": "^4.9.3",
73
73
  "utf-8-validate": "^5.0.10"
74
74
  },
75
75
  "dependencies": {
@@ -88,7 +88,7 @@
88
88
  "long": "^5.2.1",
89
89
  "patch-package": "^6.5.0",
90
90
  "protobufjs": "^7.1.2",
91
- "uint8arraylist": "^2.3.3",
91
+ "uint8arraylist": "^2.4.2",
92
92
  "ws": "^8.11.0"
93
93
  }
94
94
  }
@@ -102,9 +102,8 @@ func (r *ClientRPC) Close() {
102
102
  r.mtx.Lock()
103
103
  if r.writer != nil {
104
104
  _ = r.writeCancelLocked()
105
- _ = r.writer.Close()
106
105
  }
106
+ r.closeLocked()
107
107
  r.bcast.Broadcast()
108
108
  r.mtx.Unlock()
109
- r.ctxCancel()
110
109
  }
@@ -50,7 +50,9 @@ func (c *commonRPC) Wait(ctx context.Context) error {
50
50
  for {
51
51
  c.mtx.Lock()
52
52
  if c.dataClosed {
53
- break
53
+ err := c.remoteErr
54
+ c.mtx.Unlock()
55
+ return err
54
56
  }
55
57
  waiter := c.bcast.GetWaitCh()
56
58
  c.mtx.Unlock()
@@ -60,9 +62,6 @@ func (c *commonRPC) Wait(ctx context.Context) error {
60
62
  case <-waiter:
61
63
  }
62
64
  }
63
- err := c.remoteErr
64
- c.mtx.Unlock()
65
- return err
66
65
  }
67
66
 
68
67
  // ReadOne reads a single message and returns.
@@ -80,14 +79,14 @@ func (c *commonRPC) ReadOne() ([]byte, error) {
80
79
  c.closeLocked()
81
80
  err = context.Canceled
82
81
  c.mtx.Unlock()
83
- break
82
+ return nil, err
84
83
  }
85
84
  if len(c.dataQueue) != 0 {
86
85
  msg = c.dataQueue[0]
87
86
  c.dataQueue[0] = nil
88
87
  c.dataQueue = c.dataQueue[1:]
89
88
  c.mtx.Unlock()
90
- break
89
+ return msg, nil
91
90
  }
92
91
  if c.dataClosed || c.remoteErr != nil {
93
92
  err = c.remoteErr
@@ -95,7 +94,7 @@ func (c *commonRPC) ReadOne() ([]byte, error) {
95
94
  err = io.EOF
96
95
  }
97
96
  c.mtx.Unlock()
98
- break
97
+ return nil, err
99
98
  }
100
99
  c.mtx.Unlock()
101
100
  select {
@@ -104,7 +103,6 @@ func (c *commonRPC) ReadOne() ([]byte, error) {
104
103
  case <-waiter:
105
104
  }
106
105
  }
107
- return msg, err
108
106
  }
109
107
 
110
108
  // WriteCallData writes a call data packet.
@@ -190,8 +188,8 @@ func (c *commonRPC) closeLocked() {
190
188
  c.remoteErr = context.Canceled
191
189
  }
192
190
  if c.writer != nil {
193
- _ = c.writeCancelLocked()
194
191
  _ = c.writer.Close()
195
192
  }
193
+ c.bcast.Broadcast()
196
194
  c.ctxCancel()
197
195
  }
package/srpc/invoker.go CHANGED
@@ -7,3 +7,26 @@ type Invoker interface {
7
7
  // If service string is empty, ignore it.
8
8
  InvokeMethod(serviceID, methodID string, strm Stream) (bool, error)
9
9
  }
10
+
11
+ // InvokerSlice is a list of invokers.
12
+ type InvokerSlice []Invoker
13
+
14
+ // InvokeMethod invokes the method matching the service & method ID.
15
+ // Returns false, nil if not found.
16
+ // If service string is empty, ignore it.
17
+ func (s InvokerSlice) InvokeMethod(serviceID, methodID string, strm Stream) (bool, error) {
18
+ for _, invoker := range s {
19
+ if invoker == nil {
20
+ continue
21
+ }
22
+
23
+ found, err := invoker.InvokeMethod(serviceID, methodID, strm)
24
+ if found || err != nil {
25
+ return found && err == nil, err
26
+ }
27
+ }
28
+ return false, nil
29
+ }
30
+
31
+ // _ is a type assertion
32
+ var _ Invoker = (InvokerSlice)(nil)
package/srpc/message.go CHANGED
@@ -5,3 +5,56 @@ type Message interface {
5
5
  MarshalVT() ([]byte, error)
6
6
  UnmarshalVT([]byte) error
7
7
  }
8
+
9
+ // RawMessage is a raw protobuf message container.
10
+ type RawMessage struct {
11
+ data []byte
12
+ copy bool
13
+ }
14
+
15
+ // NewRawMessage constructs a new raw message.
16
+ // If copy=true, copies data in MarshalVT.
17
+ // Note: the data buffer will be retained and used.
18
+ // The data buffer will be written to and/or replaced in UnmarshalVT.
19
+ func NewRawMessage(data []byte, copy bool) *RawMessage {
20
+ return &RawMessage{data: data, copy: copy}
21
+ }
22
+
23
+ // GetData returns the data buffer without copying.
24
+ func (m *RawMessage) GetData() []byte {
25
+ return m.data
26
+ }
27
+
28
+ // SetData sets the data buffer.
29
+ // if copy=true, copies the data to the internal slice.
30
+ // otherwise retains the buffer.
31
+ func (m *RawMessage) SetData(data []byte) {
32
+ if m.copy {
33
+ if cap(m.data) >= len(data) {
34
+ m.data = m.data[:len(data)]
35
+ } else {
36
+ m.data = make([]byte, len(data))
37
+ }
38
+ copy(m.data, data)
39
+ } else {
40
+ m.data = data
41
+ }
42
+ }
43
+
44
+ func (m *RawMessage) MarshalVT() ([]byte, error) {
45
+ if !m.copy {
46
+ return m.data, nil
47
+ }
48
+
49
+ data := make([]byte, len(m.data))
50
+ copy(data, m.data)
51
+ return data, nil
52
+ }
53
+
54
+ func (m *RawMessage) UnmarshalVT(data []byte) error {
55
+ m.SetData(data)
56
+ return nil
57
+ }
58
+
59
+ // _ is a type assertion
60
+ var _ Message = ((*RawMessage)(nil))
@@ -0,0 +1,29 @@
1
+ package srpc
2
+
3
+ import (
4
+ "bytes"
5
+ "testing"
6
+ )
7
+
8
+ // TestRawMessage tests the raw message container.
9
+ func TestRawMessage(t *testing.T) {
10
+ pkt := NewCallStartPacket("test-service", "test-method", nil, false)
11
+ data, err := pkt.MarshalVT()
12
+ if err != nil {
13
+ t.Fatal(err.Error())
14
+ }
15
+
16
+ rawMsg := &RawMessage{}
17
+ if err := rawMsg.UnmarshalVT(data); err != nil {
18
+ t.Fatal(err.Error())
19
+ }
20
+
21
+ outMsg, err := rawMsg.MarshalVT()
22
+ if err != nil {
23
+ t.Fatal(err.Error())
24
+ }
25
+
26
+ if !bytes.Equal(outMsg, data) {
27
+ t.Fatal("not equal")
28
+ }
29
+ }
@@ -1,7 +1,7 @@
1
1
  // Code generated by protoc-gen-go. DO NOT EDIT.
2
2
  // versions:
3
3
  // protoc-gen-go v1.28.1-devel
4
- // protoc v3.19.3
4
+ // protoc v3.21.9
5
5
  // source: github.com/aperturerobotics/starpc/srpc/rpcproto.proto
6
6
 
7
7
  package srpc
@@ -73,13 +73,11 @@ func (r *ServerRPC) HandleCallStart(pkt *CallStart) error {
73
73
 
74
74
  // invokeRPC invokes the RPC after CallStart is received.
75
75
  func (r *ServerRPC) invokeRPC(serviceID, methodID string) {
76
- // ctx := r.ctx
77
76
  strm := NewMsgStream(r.ctx, r, r.ctxCancel)
78
77
  ok, err := r.invoker.InvokeMethod(serviceID, methodID, strm)
79
78
  if err == nil && !ok {
80
79
  err = ErrUnimplemented
81
80
  }
82
- // TODO: close dataCh here?
83
81
  outPkt := NewCallDataPacket(nil, false, true, err)
84
82
  _ = r.writer.WritePacket(outPkt)
85
83
  _ = r.writer.Close()