starpc 0.13.2 → 0.14.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.
@@ -0,0 +1,182 @@
1
+ /* eslint-disable */
2
+ import Long from 'long'
3
+ import _m0 from 'protobufjs/minimal.js'
4
+
5
+ export const protobufPackage = 'e2e.mock'
6
+
7
+ /** MockMsg is the mock message body. */
8
+ export interface MockMsg {
9
+ body: string
10
+ }
11
+
12
+ function createBaseMockMsg(): MockMsg {
13
+ return { body: '' }
14
+ }
15
+
16
+ export const MockMsg = {
17
+ encode(
18
+ message: MockMsg,
19
+ writer: _m0.Writer = _m0.Writer.create()
20
+ ): _m0.Writer {
21
+ if (message.body !== '') {
22
+ writer.uint32(10).string(message.body)
23
+ }
24
+ return writer
25
+ },
26
+
27
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockMsg {
28
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
29
+ let end = length === undefined ? reader.len : reader.pos + length
30
+ const message = createBaseMockMsg()
31
+ while (reader.pos < end) {
32
+ const tag = reader.uint32()
33
+ switch (tag >>> 3) {
34
+ case 1:
35
+ message.body = reader.string()
36
+ break
37
+ default:
38
+ reader.skipType(tag & 7)
39
+ break
40
+ }
41
+ }
42
+ return message
43
+ },
44
+
45
+ // encodeTransform encodes a source of message objects.
46
+ // Transform<MockMsg, Uint8Array>
47
+ async *encodeTransform(
48
+ source: AsyncIterable<MockMsg | MockMsg[]> | Iterable<MockMsg | MockMsg[]>
49
+ ): AsyncIterable<Uint8Array> {
50
+ for await (const pkt of source) {
51
+ if (Array.isArray(pkt)) {
52
+ for (const p of pkt) {
53
+ yield* [MockMsg.encode(p).finish()]
54
+ }
55
+ } else {
56
+ yield* [MockMsg.encode(pkt).finish()]
57
+ }
58
+ }
59
+ },
60
+
61
+ // decodeTransform decodes a source of encoded messages.
62
+ // Transform<Uint8Array, MockMsg>
63
+ async *decodeTransform(
64
+ source:
65
+ | AsyncIterable<Uint8Array | Uint8Array[]>
66
+ | Iterable<Uint8Array | Uint8Array[]>
67
+ ): AsyncIterable<MockMsg> {
68
+ for await (const pkt of source) {
69
+ if (Array.isArray(pkt)) {
70
+ for (const p of pkt) {
71
+ yield* [MockMsg.decode(p)]
72
+ }
73
+ } else {
74
+ yield* [MockMsg.decode(pkt)]
75
+ }
76
+ }
77
+ },
78
+
79
+ fromJSON(object: any): MockMsg {
80
+ return { body: isSet(object.body) ? String(object.body) : '' }
81
+ },
82
+
83
+ toJSON(message: MockMsg): unknown {
84
+ const obj: any = {}
85
+ message.body !== undefined && (obj.body = message.body)
86
+ return obj
87
+ },
88
+
89
+ fromPartial<I extends Exact<DeepPartial<MockMsg>, I>>(object: I): MockMsg {
90
+ const message = createBaseMockMsg()
91
+ message.body = object.body ?? ''
92
+ return message
93
+ },
94
+ }
95
+
96
+ /** Mock service mocks some RPCs for the e2e tests. */
97
+ export interface Mock {
98
+ /** MockRequest runs a mock unary request. */
99
+ MockRequest(request: MockMsg): Promise<MockMsg>
100
+ }
101
+
102
+ export class MockClientImpl implements Mock {
103
+ private readonly rpc: Rpc
104
+ private readonly service: string
105
+ constructor(rpc: Rpc, opts?: { service?: string }) {
106
+ this.service = opts?.service || 'e2e.mock.Mock'
107
+ this.rpc = rpc
108
+ this.MockRequest = this.MockRequest.bind(this)
109
+ }
110
+ MockRequest(request: MockMsg): Promise<MockMsg> {
111
+ const data = MockMsg.encode(request).finish()
112
+ const promise = this.rpc.request(this.service, 'MockRequest', data)
113
+ return promise.then((data) => MockMsg.decode(new _m0.Reader(data)))
114
+ }
115
+ }
116
+
117
+ /** Mock service mocks some RPCs for the e2e tests. */
118
+ export type MockDefinition = typeof MockDefinition
119
+ export const MockDefinition = {
120
+ name: 'Mock',
121
+ fullName: 'e2e.mock.Mock',
122
+ methods: {
123
+ /** MockRequest runs a mock unary request. */
124
+ mockRequest: {
125
+ name: 'MockRequest',
126
+ requestType: MockMsg,
127
+ requestStream: false,
128
+ responseType: MockMsg,
129
+ responseStream: false,
130
+ options: {},
131
+ },
132
+ },
133
+ } as const
134
+
135
+ interface Rpc {
136
+ request(
137
+ service: string,
138
+ method: string,
139
+ data: Uint8Array
140
+ ): Promise<Uint8Array>
141
+ }
142
+
143
+ type Builtin =
144
+ | Date
145
+ | Function
146
+ | Uint8Array
147
+ | string
148
+ | number
149
+ | boolean
150
+ | undefined
151
+
152
+ export type DeepPartial<T> = T extends Builtin
153
+ ? T
154
+ : T extends Long
155
+ ? string | number | Long
156
+ : T extends Array<infer U>
157
+ ? Array<DeepPartial<U>>
158
+ : T extends ReadonlyArray<infer U>
159
+ ? ReadonlyArray<DeepPartial<U>>
160
+ : T extends { $case: string }
161
+ ? { [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]> } & {
162
+ $case: T['$case']
163
+ }
164
+ : T extends {}
165
+ ? { [K in keyof T]?: DeepPartial<T[K]> }
166
+ : Partial<T>
167
+
168
+ type KeysOfUnion<T> = T extends T ? keyof T : never
169
+ export type Exact<P, I extends P> = P extends Builtin
170
+ ? P
171
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & {
172
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never
173
+ }
174
+
175
+ if (_m0.util.Long !== Long) {
176
+ _m0.util.Long = Long as any
177
+ _m0.configure()
178
+ }
179
+
180
+ function isSet(value: any): boolean {
181
+ return value !== null && value !== undefined
182
+ }
@@ -0,0 +1,13 @@
1
+ syntax = "proto3";
2
+ package e2e.mock;
3
+
4
+ // Mock service mocks some RPCs for the e2e tests.
5
+ service Mock {
6
+ // MockRequest runs a mock unary request.
7
+ rpc MockRequest(MockMsg) returns (MockMsg);
8
+ }
9
+
10
+ // MockMsg is the mock message body.
11
+ message MockMsg {
12
+ string body = 1;
13
+ }
@@ -0,0 +1,128 @@
1
+ // Code generated by protoc-gen-srpc. DO NOT EDIT.
2
+ // protoc-gen-srpc version: v0.13.2
3
+ // source: github.com/aperturerobotics/starpc/e2e/mock/mock.proto
4
+
5
+ package e2e_mock
6
+
7
+ import (
8
+ context "context"
9
+
10
+ srpc "github.com/aperturerobotics/starpc/srpc"
11
+ )
12
+
13
+ type SRPCMockClient interface {
14
+ SRPCClient() srpc.Client
15
+
16
+ MockRequest(ctx context.Context, in *MockMsg) (*MockMsg, error)
17
+ }
18
+
19
+ type srpcMockClient struct {
20
+ cc srpc.Client
21
+ serviceID string
22
+ }
23
+
24
+ func NewSRPCMockClient(cc srpc.Client) SRPCMockClient {
25
+ return &srpcMockClient{cc: cc, serviceID: SRPCMockServiceID}
26
+ }
27
+
28
+ func NewSRPCMockClientWithServiceID(cc srpc.Client, serviceID string) SRPCMockClient {
29
+ if serviceID == "" {
30
+ serviceID = SRPCMockServiceID
31
+ }
32
+ return &srpcMockClient{cc: cc, serviceID: serviceID}
33
+ }
34
+
35
+ func (c *srpcMockClient) SRPCClient() srpc.Client { return c.cc }
36
+
37
+ func (c *srpcMockClient) MockRequest(ctx context.Context, in *MockMsg) (*MockMsg, error) {
38
+ out := new(MockMsg)
39
+ err := c.cc.ExecCall(ctx, c.serviceID, "MockRequest", in, out)
40
+ if err != nil {
41
+ return nil, err
42
+ }
43
+ return out, nil
44
+ }
45
+
46
+ type SRPCMockServer interface {
47
+ MockRequest(context.Context, *MockMsg) (*MockMsg, error)
48
+ }
49
+
50
+ type SRPCMockUnimplementedServer struct{}
51
+
52
+ func (s *SRPCMockUnimplementedServer) MockRequest(context.Context, *MockMsg) (*MockMsg, error) {
53
+ return nil, srpc.ErrUnimplemented
54
+ }
55
+
56
+ const SRPCMockServiceID = "e2e.mock.Mock"
57
+
58
+ type SRPCMockHandler struct {
59
+ serviceID string
60
+ impl SRPCMockServer
61
+ }
62
+
63
+ // NewSRPCMockHandler constructs a new RPC handler.
64
+ // serviceID: if empty, uses default: e2e.mock.Mock
65
+ func NewSRPCMockHandler(impl SRPCMockServer, serviceID string) srpc.Handler {
66
+ if serviceID == "" {
67
+ serviceID = SRPCMockServiceID
68
+ }
69
+ return &SRPCMockHandler{impl: impl, serviceID: serviceID}
70
+ }
71
+
72
+ // SRPCRegisterMock registers the implementation with the mux.
73
+ // Uses the default serviceID: e2e.mock.Mock
74
+ func SRPCRegisterMock(mux srpc.Mux, impl SRPCMockServer) error {
75
+ return mux.Register(NewSRPCMockHandler(impl, ""))
76
+ }
77
+
78
+ func (d *SRPCMockHandler) GetServiceID() string { return d.serviceID }
79
+
80
+ func (SRPCMockHandler) GetMethodIDs() []string {
81
+ return []string{
82
+ "MockRequest",
83
+ }
84
+ }
85
+
86
+ func (d *SRPCMockHandler) InvokeMethod(
87
+ serviceID, methodID string,
88
+ strm srpc.Stream,
89
+ ) (bool, error) {
90
+ if serviceID != "" && serviceID != d.GetServiceID() {
91
+ return false, nil
92
+ }
93
+
94
+ switch methodID {
95
+ case "MockRequest":
96
+ return true, d.InvokeMethod_MockRequest(d.impl, strm)
97
+ default:
98
+ return false, nil
99
+ }
100
+ }
101
+
102
+ func (SRPCMockHandler) InvokeMethod_MockRequest(impl SRPCMockServer, strm srpc.Stream) error {
103
+ req := new(MockMsg)
104
+ if err := strm.MsgRecv(req); err != nil {
105
+ return err
106
+ }
107
+ out, err := impl.MockRequest(strm.Context(), req)
108
+ if err != nil {
109
+ return err
110
+ }
111
+ return strm.MsgSend(out)
112
+ }
113
+
114
+ type SRPCMock_MockRequestStream interface {
115
+ srpc.Stream
116
+ SendAndClose(*MockMsg) error
117
+ }
118
+
119
+ type srpcMock_MockRequestStream struct {
120
+ srpc.Stream
121
+ }
122
+
123
+ func (x *srpcMock_MockRequestStream) SendAndClose(m *MockMsg) error {
124
+ if err := x.MsgSend(m); err != nil {
125
+ return err
126
+ }
127
+ return x.CloseSend()
128
+ }
@@ -0,0 +1,290 @@
1
+ // Code generated by protoc-gen-go-vtproto. DO NOT EDIT.
2
+ // protoc-gen-go-vtproto version: v0.3.1-0.20220817155510-0ae748fd2007
3
+ // source: github.com/aperturerobotics/starpc/e2e/mock/mock.proto
4
+
5
+ package e2e_mock
6
+
7
+ import (
8
+ fmt "fmt"
9
+ io "io"
10
+ bits "math/bits"
11
+
12
+ proto "google.golang.org/protobuf/proto"
13
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
14
+ )
15
+
16
+ const (
17
+ // Verify that this generated code is sufficiently up-to-date.
18
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
19
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
20
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
21
+ )
22
+
23
+ func (m *MockMsg) CloneVT() *MockMsg {
24
+ if m == nil {
25
+ return (*MockMsg)(nil)
26
+ }
27
+ r := &MockMsg{
28
+ Body: m.Body,
29
+ }
30
+ if len(m.unknownFields) > 0 {
31
+ r.unknownFields = make([]byte, len(m.unknownFields))
32
+ copy(r.unknownFields, m.unknownFields)
33
+ }
34
+ return r
35
+ }
36
+
37
+ func (m *MockMsg) CloneGenericVT() proto.Message {
38
+ return m.CloneVT()
39
+ }
40
+
41
+ func (this *MockMsg) EqualVT(that *MockMsg) bool {
42
+ if this == nil {
43
+ return that == nil
44
+ } else if that == nil {
45
+ return false
46
+ }
47
+ if this.Body != that.Body {
48
+ return false
49
+ }
50
+ return string(this.unknownFields) == string(that.unknownFields)
51
+ }
52
+
53
+ func (m *MockMsg) MarshalVT() (dAtA []byte, err error) {
54
+ if m == nil {
55
+ return nil, nil
56
+ }
57
+ size := m.SizeVT()
58
+ dAtA = make([]byte, size)
59
+ n, err := m.MarshalToSizedBufferVT(dAtA[:size])
60
+ if err != nil {
61
+ return nil, err
62
+ }
63
+ return dAtA[:n], nil
64
+ }
65
+
66
+ func (m *MockMsg) MarshalToVT(dAtA []byte) (int, error) {
67
+ size := m.SizeVT()
68
+ return m.MarshalToSizedBufferVT(dAtA[:size])
69
+ }
70
+
71
+ func (m *MockMsg) MarshalToSizedBufferVT(dAtA []byte) (int, error) {
72
+ if m == nil {
73
+ return 0, nil
74
+ }
75
+ i := len(dAtA)
76
+ _ = i
77
+ var l int
78
+ _ = l
79
+ if m.unknownFields != nil {
80
+ i -= len(m.unknownFields)
81
+ copy(dAtA[i:], m.unknownFields)
82
+ }
83
+ if len(m.Body) > 0 {
84
+ i -= len(m.Body)
85
+ copy(dAtA[i:], m.Body)
86
+ i = encodeVarint(dAtA, i, uint64(len(m.Body)))
87
+ i--
88
+ dAtA[i] = 0xa
89
+ }
90
+ return len(dAtA) - i, nil
91
+ }
92
+
93
+ func encodeVarint(dAtA []byte, offset int, v uint64) int {
94
+ offset -= sov(v)
95
+ base := offset
96
+ for v >= 1<<7 {
97
+ dAtA[offset] = uint8(v&0x7f | 0x80)
98
+ v >>= 7
99
+ offset++
100
+ }
101
+ dAtA[offset] = uint8(v)
102
+ return base
103
+ }
104
+ func (m *MockMsg) SizeVT() (n int) {
105
+ if m == nil {
106
+ return 0
107
+ }
108
+ var l int
109
+ _ = l
110
+ l = len(m.Body)
111
+ if l > 0 {
112
+ n += 1 + l + sov(uint64(l))
113
+ }
114
+ n += len(m.unknownFields)
115
+ return n
116
+ }
117
+
118
+ func sov(x uint64) (n int) {
119
+ return (bits.Len64(x|1) + 6) / 7
120
+ }
121
+ func soz(x uint64) (n int) {
122
+ return sov(uint64((x << 1) ^ uint64((int64(x) >> 63))))
123
+ }
124
+ func (m *MockMsg) UnmarshalVT(dAtA []byte) error {
125
+ l := len(dAtA)
126
+ iNdEx := 0
127
+ for iNdEx < l {
128
+ preIndex := iNdEx
129
+ var wire uint64
130
+ for shift := uint(0); ; shift += 7 {
131
+ if shift >= 64 {
132
+ return ErrIntOverflow
133
+ }
134
+ if iNdEx >= l {
135
+ return io.ErrUnexpectedEOF
136
+ }
137
+ b := dAtA[iNdEx]
138
+ iNdEx++
139
+ wire |= uint64(b&0x7F) << shift
140
+ if b < 0x80 {
141
+ break
142
+ }
143
+ }
144
+ fieldNum := int32(wire >> 3)
145
+ wireType := int(wire & 0x7)
146
+ if wireType == 4 {
147
+ return fmt.Errorf("proto: MockMsg: wiretype end group for non-group")
148
+ }
149
+ if fieldNum <= 0 {
150
+ return fmt.Errorf("proto: MockMsg: illegal tag %d (wire type %d)", fieldNum, wire)
151
+ }
152
+ switch fieldNum {
153
+ case 1:
154
+ if wireType != 2 {
155
+ return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType)
156
+ }
157
+ var stringLen uint64
158
+ for shift := uint(0); ; shift += 7 {
159
+ if shift >= 64 {
160
+ return ErrIntOverflow
161
+ }
162
+ if iNdEx >= l {
163
+ return io.ErrUnexpectedEOF
164
+ }
165
+ b := dAtA[iNdEx]
166
+ iNdEx++
167
+ stringLen |= uint64(b&0x7F) << shift
168
+ if b < 0x80 {
169
+ break
170
+ }
171
+ }
172
+ intStringLen := int(stringLen)
173
+ if intStringLen < 0 {
174
+ return ErrInvalidLength
175
+ }
176
+ postIndex := iNdEx + intStringLen
177
+ if postIndex < 0 {
178
+ return ErrInvalidLength
179
+ }
180
+ if postIndex > l {
181
+ return io.ErrUnexpectedEOF
182
+ }
183
+ m.Body = string(dAtA[iNdEx:postIndex])
184
+ iNdEx = postIndex
185
+ default:
186
+ iNdEx = preIndex
187
+ skippy, err := skip(dAtA[iNdEx:])
188
+ if err != nil {
189
+ return err
190
+ }
191
+ if (skippy < 0) || (iNdEx+skippy) < 0 {
192
+ return ErrInvalidLength
193
+ }
194
+ if (iNdEx + skippy) > l {
195
+ return io.ErrUnexpectedEOF
196
+ }
197
+ m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...)
198
+ iNdEx += skippy
199
+ }
200
+ }
201
+
202
+ if iNdEx > l {
203
+ return io.ErrUnexpectedEOF
204
+ }
205
+ return nil
206
+ }
207
+ func skip(dAtA []byte) (n int, err error) {
208
+ l := len(dAtA)
209
+ iNdEx := 0
210
+ depth := 0
211
+ for iNdEx < l {
212
+ var wire uint64
213
+ for shift := uint(0); ; shift += 7 {
214
+ if shift >= 64 {
215
+ return 0, ErrIntOverflow
216
+ }
217
+ if iNdEx >= l {
218
+ return 0, io.ErrUnexpectedEOF
219
+ }
220
+ b := dAtA[iNdEx]
221
+ iNdEx++
222
+ wire |= (uint64(b) & 0x7F) << shift
223
+ if b < 0x80 {
224
+ break
225
+ }
226
+ }
227
+ wireType := int(wire & 0x7)
228
+ switch wireType {
229
+ case 0:
230
+ for shift := uint(0); ; shift += 7 {
231
+ if shift >= 64 {
232
+ return 0, ErrIntOverflow
233
+ }
234
+ if iNdEx >= l {
235
+ return 0, io.ErrUnexpectedEOF
236
+ }
237
+ iNdEx++
238
+ if dAtA[iNdEx-1] < 0x80 {
239
+ break
240
+ }
241
+ }
242
+ case 1:
243
+ iNdEx += 8
244
+ case 2:
245
+ var length int
246
+ for shift := uint(0); ; shift += 7 {
247
+ if shift >= 64 {
248
+ return 0, ErrIntOverflow
249
+ }
250
+ if iNdEx >= l {
251
+ return 0, io.ErrUnexpectedEOF
252
+ }
253
+ b := dAtA[iNdEx]
254
+ iNdEx++
255
+ length |= (int(b) & 0x7F) << shift
256
+ if b < 0x80 {
257
+ break
258
+ }
259
+ }
260
+ if length < 0 {
261
+ return 0, ErrInvalidLength
262
+ }
263
+ iNdEx += length
264
+ case 3:
265
+ depth++
266
+ case 4:
267
+ if depth == 0 {
268
+ return 0, ErrUnexpectedEndOfGroup
269
+ }
270
+ depth--
271
+ case 5:
272
+ iNdEx += 4
273
+ default:
274
+ return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
275
+ }
276
+ if iNdEx < 0 {
277
+ return 0, ErrInvalidLength
278
+ }
279
+ if depth == 0 {
280
+ return iNdEx, nil
281
+ }
282
+ }
283
+ return 0, io.ErrUnexpectedEOF
284
+ }
285
+
286
+ var (
287
+ ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling")
288
+ ErrIntOverflow = fmt.Errorf("proto: integer overflow")
289
+ ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group")
290
+ )