grpc-dc 0.32.13 → 0.32.14
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/package.json +1 -1
- package/plugin/gen/generators.js +309 -73
package/package.json
CHANGED
package/plugin/gen/generators.js
CHANGED
|
@@ -5255,6 +5255,10 @@ function cppClientStreamClass(m, svc) {
|
|
|
5255
5255
|
+ ' ' + m.output + ' Recv() {\n'
|
|
5256
5256
|
+ ' ' + m.output + ' resp;\n'
|
|
5257
5257
|
+ ' stream_.Recv(resp);\n return resp;\n }\n\n'
|
|
5258
|
+
+ ' /// Initial metadata (response headers).\n'
|
|
5259
|
+
+ ' const grpcdc::Metadata& Headers() const { return stream_.headers().metadata; }\n\n'
|
|
5260
|
+
+ ' /// Trailing metadata of the terminal status.\n'
|
|
5261
|
+
+ ' const grpcdc::Metadata& Trailers() const { return stream_.trailers(); }\n\n'
|
|
5258
5262
|
+ ' private:\n'
|
|
5259
5263
|
+ ' grpcdc::Channel::ClientStream stream_;\n };\n\n';
|
|
5260
5264
|
}
|
|
@@ -5973,21 +5977,68 @@ function xppMessageClass(model, msg, support, indent) {
|
|
|
5973
5977
|
+ msg.fields.map((f) => pad + ' ' + xppType(model, f) + ' ' + f.name + ' = ' + xppDefault(model, f) + ';\n').join('')
|
|
5974
5978
|
+ pad + ' grpcdc::Bytes unknown_fields;\n'
|
|
5975
5979
|
+ pad + ' ' + name + '() = default;\n'
|
|
5976
|
-
+ pad + ' grpcdc::Bytes MarshalDc() const override
|
|
5977
|
-
+ pad + '
|
|
5980
|
+
+ pad + ' grpcdc::Bytes MarshalDc() const override;\n'
|
|
5981
|
+
+ pad + ' void UnmarshalDc(const grpcdc::Bytes& data) override;\n'
|
|
5982
|
+
+ pad + '};\n';
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5985
|
+
function xppMessageImpls(model, msg, support, qual) {
|
|
5986
|
+
const q = qual ? qual + '::' + msg.name : msg.name;
|
|
5987
|
+
return 'inline grpcdc::Bytes ' + q + '::MarshalDc() const {\n'
|
|
5988
|
+
+ ' ' + support + '::Writer w;\n'
|
|
5978
5989
|
+ msg.fields.map((f) => xppEncodeGuard(model, f, xppEncodeField(model, f, support))).join('')
|
|
5979
|
-
+
|
|
5980
|
-
+
|
|
5981
|
-
+
|
|
5982
|
-
+
|
|
5983
|
-
+ msg.fields.map((f) =>
|
|
5984
|
-
+
|
|
5985
|
-
+
|
|
5986
|
-
+
|
|
5990
|
+
+ ' w.Raw(unknown_fields);\n'
|
|
5991
|
+
+ ' return w.ToBytes();\n}\n\n'
|
|
5992
|
+
+ 'inline void ' + q + '::UnmarshalDc(const grpcdc::Bytes& data) {\n'
|
|
5993
|
+
+ ' unknown_fields.clear();\n'
|
|
5994
|
+
+ msg.fields.map((f) => ' ' + f.name + ' = ' + xppDefault(model, f) + ';\n').join('')
|
|
5995
|
+
+ ' ' + support + '::Reader r(data);\n'
|
|
5996
|
+
+ ' ' + support + '::Field field;\n'
|
|
5997
|
+
+ ' while (r.Next(field)) {\n switch (field.number) {\n'
|
|
5987
5998
|
+ msg.fields.map((f) => xppDecodeCase(model, f, support)).join('')
|
|
5988
|
-
+
|
|
5989
|
-
+
|
|
5990
|
-
+
|
|
5999
|
+
+ ' default: unknown_fields.insert(unknown_fields.end(), field.raw.begin(), field.raw.end()); break;\n'
|
|
6000
|
+
+ ' }\n }\n}\n\n'
|
|
6001
|
+
+ msg.nested.filter((n) => !n.mapEntry).map((n) => xppMessageImpls(model, n, support, q)).join('');
|
|
6002
|
+
}
|
|
6003
|
+
|
|
6004
|
+
function xppOrderedMessages(model) {
|
|
6005
|
+
const tops = model.messages.filter((m) => !m.mapEntry);
|
|
6006
|
+
const topOf = (e) => {
|
|
6007
|
+
if (!e || e.file !== model.name) return null;
|
|
6008
|
+
return xppRel(model.package, e.full).split('::')[0];
|
|
6009
|
+
};
|
|
6010
|
+
const depsOf = (m) => {
|
|
6011
|
+
const out = [];
|
|
6012
|
+
const note = (f) => {
|
|
6013
|
+
if (f.type !== 11) return;
|
|
6014
|
+
const e = xppResolve(model, f.typeName);
|
|
6015
|
+
if (!e) return;
|
|
6016
|
+
if (e.kind === 'map') {
|
|
6017
|
+
const valF = e.msg.fields.find((x) => x.name === 'value');
|
|
6018
|
+
if (valF && valF.type === 11) {
|
|
6019
|
+
const ve = xppResolve(model, valF.typeName);
|
|
6020
|
+
if (ve && ve.kind === 'message') { const t = topOf(ve); if (t && !out.includes(t)) out.push(t); }
|
|
6021
|
+
}
|
|
6022
|
+
} else if (e.kind === 'message' && f.label !== 3) {
|
|
6023
|
+
const t = topOf(e); if (t && !out.includes(t)) out.push(t);
|
|
6024
|
+
}
|
|
6025
|
+
};
|
|
6026
|
+
const walk = (msg) => { msg.fields.forEach(note); msg.nested.forEach(walk); };
|
|
6027
|
+
walk(m);
|
|
6028
|
+
return out;
|
|
6029
|
+
};
|
|
6030
|
+
const depMap = new Map(tops.map((m) => [m.name, depsOf(m)]));
|
|
6031
|
+
const remaining = new Set(tops.map((m) => m.name));
|
|
6032
|
+
const out = [];
|
|
6033
|
+
let rest = tops.slice();
|
|
6034
|
+
while (rest.length) {
|
|
6035
|
+
const next = rest.find((m) => depMap.get(m.name).every((d) => d === m.name || !remaining.has(d)));
|
|
6036
|
+
if (!next) throw new Error('emitCppPbFile: message dependency cycle');
|
|
6037
|
+
out.push(next);
|
|
6038
|
+
remaining.delete(next.name);
|
|
6039
|
+
rest = rest.filter((m) => m !== next);
|
|
6040
|
+
}
|
|
6041
|
+
return out;
|
|
5991
6042
|
}
|
|
5992
6043
|
|
|
5993
6044
|
function emitCppPbFile(model) {
|
|
@@ -6010,6 +6061,7 @@ function emitCppPbFile(model) {
|
|
|
6010
6061
|
for (const n of msg.nested) collect(n);
|
|
6011
6062
|
};
|
|
6012
6063
|
for (const m of model.messages) collect(m);
|
|
6064
|
+
const ordered = xppOrderedMessages(model);
|
|
6013
6065
|
const deps = model.dependencies || [];
|
|
6014
6066
|
const content = '// @generated by protoc-gen-grpc-dc-cpp. DO NOT EDIT.\n'
|
|
6015
6067
|
+ '#pragma once\n\n'
|
|
@@ -6025,9 +6077,12 @@ function emitCppPbFile(model) {
|
|
|
6025
6077
|
+ '\n};\n\n').join('')
|
|
6026
6078
|
+ 'namespace pb_' + base + ' {\n\n'
|
|
6027
6079
|
+ XPP_SUPPORT_BODY
|
|
6028
|
-
+ helpers.map((h) => h.decls).join('')
|
|
6029
6080
|
+ '} // namespace pb_' + base + '\n\n'
|
|
6030
|
-
+
|
|
6081
|
+
+ ordered.map((m) => xppMessageClass(model, m, support, '')).join('')
|
|
6082
|
+
+ (helpers.length
|
|
6083
|
+
? 'namespace pb_' + base + ' {\n\n' + helpers.map((h) => h.decls).join('') + '} // namespace pb_' + base + '\n\n'
|
|
6084
|
+
: '')
|
|
6085
|
+
+ ordered.map((m) => xppMessageImpls(model, m, support, '')).join('')
|
|
6031
6086
|
+ (helpers.length
|
|
6032
6087
|
? 'namespace pb_' + base + ' {\n\n' + helpers.map((h) => h.defs).join('') + '} // namespace pb_' + base + '\n\n'
|
|
6033
6088
|
: '')
|
|
@@ -6035,10 +6090,22 @@ function emitCppPbFile(model) {
|
|
|
6035
6090
|
return { name: base + '_messages.hpp', content };
|
|
6036
6091
|
}
|
|
6037
6092
|
|
|
6093
|
+
function cppStubIncludes(model) {
|
|
6094
|
+
if (!model.types) return '#include "examples/' + baseName(model.name) + '_messages.hpp"\n';
|
|
6095
|
+
const files = new Set();
|
|
6096
|
+
for (const svc of model.services) {
|
|
6097
|
+
for (const m of svc.methods) {
|
|
6098
|
+
files.add(xppResolve(model, m.inputFull).file);
|
|
6099
|
+
files.add(xppResolve(model, m.outputFull).file);
|
|
6100
|
+
}
|
|
6101
|
+
}
|
|
6102
|
+
return [...files].map((f) => '#include "examples/' + baseName(f) + '_messages.hpp"\n').join('');
|
|
6103
|
+
}
|
|
6104
|
+
|
|
6038
6105
|
function emitCppFile(model, params) {
|
|
6039
6106
|
const base = baseName(model.name);
|
|
6040
6107
|
const structName = pascalName(base) + 'GrpcDc';
|
|
6041
|
-
const ns = model.package
|
|
6108
|
+
const ns = xppNs(model.package);
|
|
6042
6109
|
const stub = {
|
|
6043
6110
|
name: base + '_grpc_dc.hpp',
|
|
6044
6111
|
content: '// @generated by protoc-gen-grpc-dc-cpp. DO NOT EDIT.\n'
|
|
@@ -6046,7 +6113,7 @@ function emitCppFile(model, params) {
|
|
|
6046
6113
|
+ '#pragma once\n\n'
|
|
6047
6114
|
+ '#include <future>\n#include <optional>\n\n#if __cplusplus >= 202002L\n#include "grpcdc/async.hpp"\n#endif\n'
|
|
6048
6115
|
+ '#include <memory>\n#include <vector>\n\n'
|
|
6049
|
-
+
|
|
6116
|
+
+ cppStubIncludes(model)
|
|
6050
6117
|
+ '#include "grpcdc/channel.hpp"\n#include "grpcdc/server.hpp"\n\n'
|
|
6051
6118
|
+ 'namespace ' + ns + ' {\n\n'
|
|
6052
6119
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
@@ -6095,7 +6162,12 @@ function swiftClientStreamClass(m, svc) {
|
|
|
6095
6162
|
+ ' init(_ stream: Channel.ClientStream) { self.stream = stream }\n'
|
|
6096
6163
|
+ ' func Recv() throws -> ' + m.output + ' {\n'
|
|
6097
6164
|
+ ' let resp = ' + m.output + '()\n'
|
|
6098
|
-
+ ' try stream.Recv(resp)\n return resp\n }\n
|
|
6165
|
+
+ ' try stream.Recv(resp)\n return resp\n }\n'
|
|
6166
|
+
+ ' /// Initial metadata (response headers); nil until they arrive.\n'
|
|
6167
|
+
+ ' var Headers: [String: String]? { stream.headers?.metadata }\n'
|
|
6168
|
+
+ ' /// Trailing metadata of the terminal status; nil until it arrives.\n'
|
|
6169
|
+
+ ' var Trailers: [String: String]? { stream.trailers }\n'
|
|
6170
|
+
+ ' func Cancel() { stream.Cancel() }\n func Close() { stream.Close() }\n }\n\n';
|
|
6099
6171
|
}
|
|
6100
6172
|
|
|
6101
6173
|
function swiftClientAsyncMethod(m, svc) {
|
|
@@ -6315,16 +6387,16 @@ function swiftService(svc) {
|
|
|
6315
6387
|
+ ' static func Register' + sname + 'ServerAsync(_ server: Server, _ impl: ' + sname + 'ServerAsync) {\n'
|
|
6316
6388
|
+ ' // Adapters are retained for the process lifetime: registration is\n'
|
|
6317
6389
|
+ ' // once-per-process and bounded by service count.\n'
|
|
6318
|
-
+ '
|
|
6319
|
-
+ ' Register' + sname + 'Server(server,
|
|
6320
|
-
+ ' private static var
|
|
6390
|
+
+ ' ' + sname + 'Adapters.append(' + sname + 'ServerAsyncAdapter(impl))\n'
|
|
6391
|
+
+ ' Register' + sname + 'Server(server, ' + sname + 'Adapters.last!)\n }\n\n'
|
|
6392
|
+
+ ' private static var ' + sname + 'Adapters: [' + sname + 'ServerAsyncAdapter] = []\n'
|
|
6321
6393
|
+ ' #endif\n';
|
|
6322
6394
|
}
|
|
6323
6395
|
|
|
6324
6396
|
const SWIFT_RUN_BLOCKING =
|
|
6325
6397
|
'#if canImport(Foundation)\n'
|
|
6326
6398
|
+ '/// Run an async operation to completion on a blocking thread.\n'
|
|
6327
|
-
+ 'func RunBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {\n'
|
|
6399
|
+
+ 'fileprivate func RunBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {\n'
|
|
6328
6400
|
+ ' let semaphore = DispatchSemaphore(value: 0)\n'
|
|
6329
6401
|
+ ' var result: Result<T, Error>!\n'
|
|
6330
6402
|
+ ' Task.detached {\n'
|
|
@@ -6601,7 +6673,7 @@ function swpDecodeCase(model, f, support) {
|
|
|
6601
6673
|
}
|
|
6602
6674
|
if (SWP_VARINT.has(f.type)) {
|
|
6603
6675
|
const conv = (src) => f.type === 14
|
|
6604
|
-
? swpEntryRef(model, swpResolve(model, f.typeName)) + '(rawValue: ' + swpVarintDecode({ ...f, type: 5 }, src) + ') ?? ' + swpDefault(model, f)
|
|
6676
|
+
? swpEntryRef(model, swpResolve(model, f.typeName)) + '(rawValue: ' + swpVarintDecode({ ...f, type: 5 }, src) + ') ?? ' + swpDefault(model, { ...f, label: 1 })
|
|
6605
6677
|
: swpVarintDecode(f, src);
|
|
6606
6678
|
return head
|
|
6607
6679
|
+ ' if field.wire == 2 {\n'
|
|
@@ -6800,8 +6872,7 @@ function emitSwiftFile(model, params) {
|
|
|
6800
6872
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
6801
6873
|
+ 'enum ' + enumName + ' {\n'
|
|
6802
6874
|
+ model.services.map(swiftService).join('')
|
|
6803
|
-
+ '}\n
|
|
6804
|
-
+ SWIFT_RUN_BLOCKING,
|
|
6875
|
+
+ '}\n',
|
|
6805
6876
|
};
|
|
6806
6877
|
const pbFile = emitSwiftPbFile(model);
|
|
6807
6878
|
return pbFile ? [stub, pbFile] : stub;
|
|
@@ -7654,6 +7725,14 @@ function dartClientStreamClass(m, svc) {
|
|
|
7654
7725
|
+ ' Future<' + m.output + '> recv() async {\n'
|
|
7655
7726
|
+ ' final resp = ' + m.output + '();\n'
|
|
7656
7727
|
+ ' await _stream.recv(resp);\n return resp;\n }\n\n'
|
|
7728
|
+
+ ' /// Initial metadata (response headers); null until they arrive.\n'
|
|
7729
|
+
+ ' Map<String, String>? get headers => _stream.headers?.metadata;\n\n'
|
|
7730
|
+
+ ' /// Trailing metadata of the terminal status; null until it arrives.\n'
|
|
7731
|
+
+ ' Map<String, String>? get trailers => _stream.trailers;\n\n'
|
|
7732
|
+
+ ' /// Abort this stream (sends RST, wakes a pending recv).\n'
|
|
7733
|
+
+ ' void cancel() => _stream.cancel();\n\n'
|
|
7734
|
+
+ ' /// Abandon the call if still live (RST); no-op once terminated.\n'
|
|
7735
|
+
+ ' void close() => _stream.close();\n\n'
|
|
7657
7736
|
+ ' /// Responses as a Dart Stream (native async surface).\n'
|
|
7658
7737
|
+ ' /// Cancelling the subscription abandons the call:\n'
|
|
7659
7738
|
+ ' /// RST CANCELLED is sent so the server stops.\n'
|
|
@@ -8284,6 +8363,18 @@ function emitDartPbFile(model) {
|
|
|
8284
8363
|
return { name: base + '_messages.dart', content };
|
|
8285
8364
|
}
|
|
8286
8365
|
|
|
8366
|
+
function dartStubImports(model) {
|
|
8367
|
+
if (!model.types) return "import '" + baseName(model.name) + "_messages.dart';\n\n";
|
|
8368
|
+
const files = new Set();
|
|
8369
|
+
for (const svc of model.services) {
|
|
8370
|
+
for (const m of svc.methods) {
|
|
8371
|
+
files.add(dtpResolve(model, m.inputFull).file);
|
|
8372
|
+
files.add(dtpResolve(model, m.outputFull).file);
|
|
8373
|
+
}
|
|
8374
|
+
}
|
|
8375
|
+
return [...files].map((f) => "import '" + baseName(f) + "_messages.dart';\n").join('') + '\n';
|
|
8376
|
+
}
|
|
8377
|
+
|
|
8287
8378
|
function emitDartFile(model, params) {
|
|
8288
8379
|
const base = baseName(model.name);
|
|
8289
8380
|
const className = pascalName(base) + 'GrpcDc';
|
|
@@ -8293,7 +8384,7 @@ function emitDartFile(model, params) {
|
|
|
8293
8384
|
+ '// source: ' + model.name + '\n\n'
|
|
8294
8385
|
+ "import 'dart:async';\n\n"
|
|
8295
8386
|
+ "import '../grpcdc/channel.dart';\nimport '../grpcdc/endpoint.dart';\nimport '../grpcdc/server.dart';\nimport '../grpcdc/status.dart';\nimport '../grpcdc/wire.dart';\n"
|
|
8296
|
-
+
|
|
8387
|
+
+ dartStubImports(model)
|
|
8297
8388
|
+ model.services.map(dartService).join('')
|
|
8298
8389
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
8299
8390
|
+ 'class ' + className + ' {\n'
|
|
@@ -8361,6 +8452,12 @@ function zigClientStreamClass(m, svc) {
|
|
|
8361
8452
|
+ ' .message => return .{ .message = resp },\n'
|
|
8362
8453
|
+ ' .end => return .end,\n'
|
|
8363
8454
|
+ ' .status => |st| return .{ .status = st },\n }\n }\n\n'
|
|
8455
|
+
+ ' /// Initial metadata (response headers); null until they arrive.\n'
|
|
8456
|
+
+ ' pub fn headers(self: *' + svc + m.name + 'Client) ?grpcdc.codec.Headers {\n'
|
|
8457
|
+
+ ' return self.stream.headers;\n }\n\n'
|
|
8458
|
+
+ ' /// Trailing metadata of the terminal status.\n'
|
|
8459
|
+
+ ' pub fn trailers(self: *' + svc + m.name + 'Client) []const status_mod.TrailerPair {\n'
|
|
8460
|
+
+ ' return self.stream.trailers;\n }\n\n'
|
|
8364
8461
|
+ ' pub fn deinit(self: *' + svc + m.name + 'Client) void {\n'
|
|
8365
8462
|
+ ' self.stream.deinit();\n }\n};\n\n';
|
|
8366
8463
|
}
|
|
@@ -8422,7 +8519,7 @@ function zigServerVtableField(m, svc) {
|
|
|
8422
8519
|
function zigAdapter(m, svc) {
|
|
8423
8520
|
const name = lowerFirst(m.name);
|
|
8424
8521
|
const impl = zigSnake(m.implName);
|
|
8425
|
-
const head = 'fn ' + name + 'Adapter(ctx: *anyopaque, call_ctx: *CallContext, reqs: *server_mod.RequestStream, sink: server_mod.Sink) Status {\n'
|
|
8522
|
+
const head = 'fn ' + lowerFirst(svc) + m.name + 'Adapter(ctx: *anyopaque, call_ctx: *CallContext, reqs: *server_mod.RequestStream, sink: server_mod.Sink) Status {\n'
|
|
8426
8523
|
+ ' const impl: *' + svc + 'Server = @ptrCast(@alignCast(ctx));\n';
|
|
8427
8524
|
switch (m.kind) {
|
|
8428
8525
|
case 'unary':
|
|
@@ -8475,8 +8572,8 @@ const ZIG_KIND_CONSTS = {
|
|
|
8475
8572
|
bidi: 'bidi',
|
|
8476
8573
|
};
|
|
8477
8574
|
|
|
8478
|
-
function zigRegisterMethod(m) {
|
|
8479
|
-
return ' .{ .name = ' + q(m.name) + ', .path = ' + q(m.path) + ', .kind = .' + ZIG_KIND_CONSTS[m.kind] + ', .ctx = impl, .handler = ' + lowerFirst(m.name
|
|
8575
|
+
function zigRegisterMethod(m, svc) {
|
|
8576
|
+
return ' .{ .name = ' + q(m.name) + ', .path = ' + q(m.path) + ', .kind = .' + ZIG_KIND_CONSTS[m.kind] + ', .ctx = impl, .handler = ' + lowerFirst(svc) + m.name + 'Adapter },\n';
|
|
8480
8577
|
}
|
|
8481
8578
|
|
|
8482
8579
|
function zigService(svc) {
|
|
@@ -8499,6 +8596,26 @@ function zigService(svc) {
|
|
|
8499
8596
|
+ svc.methods.concat(aliasServerMethods(svc)).map((m) => zigAdapter(m, sname)).join('');
|
|
8500
8597
|
}
|
|
8501
8598
|
|
|
8599
|
+
function zigTypeOrigins(model) {
|
|
8600
|
+
const seen = [];
|
|
8601
|
+
for (const svc of model.services) {
|
|
8602
|
+
for (const m of svc.methods) {
|
|
8603
|
+
for (const [simple, full] of [[m.input, m.inputFull], [m.output, m.outputFull]]) {
|
|
8604
|
+
if (!seen.some(([n]) => n === simple)) {
|
|
8605
|
+
seen.push([simple, baseName(zgpResolve(model, full).file)]);
|
|
8606
|
+
}
|
|
8607
|
+
}
|
|
8608
|
+
}
|
|
8609
|
+
}
|
|
8610
|
+
return seen;
|
|
8611
|
+
}
|
|
8612
|
+
|
|
8613
|
+
function zigStubImports(model) {
|
|
8614
|
+
if (!model.types) return 'const messages = @import("' + baseName(model.name) + '_messages.zig");\n\n';
|
|
8615
|
+
const bases = [...new Set(zigTypeOrigins(model).map(([, b]) => b))];
|
|
8616
|
+
return bases.map((b) => 'const ' + b + '_messages = @import("' + b + '_messages.zig");\n').join('') + '\n';
|
|
8617
|
+
}
|
|
8618
|
+
|
|
8502
8619
|
function zigMessageNames(model) {
|
|
8503
8620
|
const seen = [];
|
|
8504
8621
|
for (const svc of model.services) {
|
|
@@ -8516,7 +8633,7 @@ function zigRegisterService(svc) {
|
|
|
8516
8633
|
+ ' server.registerService(.{\n'
|
|
8517
8634
|
+ ' .name = ' + q(svc.fullName) + ',\n'
|
|
8518
8635
|
+ ' .methods = &.{\n'
|
|
8519
|
-
+ svc.methods.concat(aliasServerMethods(svc)).map(zigRegisterMethod).join('')
|
|
8636
|
+
+ svc.methods.concat(aliasServerMethods(svc)).map((m) => zigRegisterMethod(m, sname)).join('')
|
|
8520
8637
|
+ ' },\n });\n }\n';
|
|
8521
8638
|
}
|
|
8522
8639
|
|
|
@@ -8840,6 +8957,7 @@ function zgpMapHelpers(model, entry) {
|
|
|
8840
8957
|
: zgpEncodeSingular(model, { ...valF, label: 1 }, 'value', ' '))
|
|
8841
8958
|
+ ' return w.toBytes();\n}\n\n'
|
|
8842
8959
|
+ 'pub fn decode' + sname + '(alloc: std.mem.Allocator, data: []const u8) ' + sname + ' {\n'
|
|
8960
|
+
+ ([9, 12, 11].includes(keyF.type) || [9, 12, 11].includes(valF.type) ? '' : ' _ = alloc;\n')
|
|
8843
8961
|
+ ' var result: ' + sname + ' = .{ .key = ' + zgpDefault(model, { ...keyF, label: 1 }) + ', .value = ' + (valF.type === FT.MESSAGE ? '.{}' : zgpDefault(model, { ...valF, label: 1 })) + ' };\n'
|
|
8844
8962
|
+ ' var r = PbReader.init(data);\n while (r.next()) |field| {\n switch (field.number) {\n'
|
|
8845
8963
|
+ ' ' + keyF.number + ' => { ' + zgpDecodeSingular(model, { ...keyF, label: 1 }, 'result.key', zgpSrc(keyF), '').replace(/\s+$/, '') + ' },\n'
|
|
@@ -8941,7 +9059,7 @@ function zgpMessageStruct(model, msg, indent) {
|
|
|
8941
9059
|
+ indent + ' self.unknown_fields = unknown_fields_list.toOwnedSlice(alloc) catch &.{};\n'
|
|
8942
9060
|
+ msg.fields.filter((f) => zgpIsListField(model, f)).map((f) => indent + ' self.' + f.name + ' = ' + f.name + '_list.toOwnedSlice(alloc) catch &.{};\n').join('')
|
|
8943
9061
|
+ indent + ' }\n'
|
|
8944
|
-
+ msg.nested.map((n) => zgpMessageStruct(model, n, indent + ' ')).join('')
|
|
9062
|
+
+ msg.nested.filter((n) => !n.mapEntry).map((n) => zgpMessageStruct(model, n, indent + ' ')).join('')
|
|
8945
9063
|
+ msg.enums.map((e) => zgpNestedEnum(e, indent + ' ')).join('')
|
|
8946
9064
|
+ indent + '};\n';
|
|
8947
9065
|
}
|
|
@@ -8997,14 +9115,16 @@ function emitZigFile(model, params) {
|
|
|
8997
9115
|
+ 'const std = @import("std");\n'
|
|
8998
9116
|
+ 'const grpcdc = @import("grpcdc");\n'
|
|
8999
9117
|
+ 'const channel_mod = grpcdc.channel;\nconst endpoint_mod = grpcdc.endpoint;\nconst server_mod = grpcdc.server;\nconst status_mod = grpcdc.status;\nconst wire = grpcdc.wire;\n'
|
|
9000
|
-
+
|
|
9118
|
+
+ zigStubImports(model)
|
|
9001
9119
|
+ 'pub const Channel = channel_mod.Channel;\n'
|
|
9002
9120
|
+ 'pub const ClientStream = channel_mod.ClientStream;\n'
|
|
9003
9121
|
+ 'pub const CallContext = endpoint_mod.CallContext;\n'
|
|
9004
9122
|
+ 'pub const Server = server_mod.Server;\n'
|
|
9005
9123
|
+ 'pub const Status = status_mod.Status;\n'
|
|
9006
9124
|
+ 'pub const Metadata = channel_mod.Metadata;\n'
|
|
9007
|
-
+
|
|
9125
|
+
+ (model.types
|
|
9126
|
+
? zigTypeOrigins(model).map(([n, b]) => 'pub const ' + n + ' = ' + b + '_messages.' + n + ';\n').join('')
|
|
9127
|
+
: zigMessageNames(model).map((msg) => 'pub const ' + msg + ' = messages.' + msg + ';\n').join(''))
|
|
9008
9128
|
+ '\n'
|
|
9009
9129
|
+ model.services.map(zigService).join('')
|
|
9010
9130
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
@@ -9118,6 +9238,10 @@ function luaClientStreamClass(m, svc) {
|
|
|
9118
9238
|
+ 'function ' + t + ':recv()\n'
|
|
9119
9239
|
+ ' local resp = ' + m.output + '.new()\n'
|
|
9120
9240
|
+ ' self.stream:recv(resp)\n return resp\nend\n\n'
|
|
9241
|
+
+ '--- Response initial metadata (after the first recv).\n'
|
|
9242
|
+
+ 'function ' + t + ':headers()\n return self.stream.headers and self.stream.headers.metadata\nend\n\n'
|
|
9243
|
+
+ '--- Response trailing metadata (after the call ends).\n'
|
|
9244
|
+
+ 'function ' + t + ':trailers()\n return self.stream.trailers\nend\n\n'
|
|
9121
9245
|
+ '--- Abandon the call early: RST so the server stops producing.\n'
|
|
9122
9246
|
+ 'function ' + t + ':close()\n self.stream:close()\nend\n\n'
|
|
9123
9247
|
+ 'function ' + t + ':cancel()\n self.stream:cancel()\nend\n\n'
|
|
@@ -9584,6 +9708,33 @@ function emitLuaPbFile(model) {
|
|
|
9584
9708
|
return { name: base + '_messages.lua', content };
|
|
9585
9709
|
}
|
|
9586
9710
|
|
|
9711
|
+
function luaStubRequires(model) {
|
|
9712
|
+
if (!model.types) {
|
|
9713
|
+
return 'local messages = require("examples.' + baseName(model.name) + '_messages")\n\n'
|
|
9714
|
+
+ zigMessageNames(model).map((msg) => 'local ' + msg + ' = messages.' + msg + '\n').join('')
|
|
9715
|
+
+ '\n';
|
|
9716
|
+
}
|
|
9717
|
+
const origins = [];
|
|
9718
|
+
const seenNames = new Set();
|
|
9719
|
+
for (const svc of model.services) {
|
|
9720
|
+
for (const m of svc.methods) {
|
|
9721
|
+
for (const pair of [[m.input, m.inputFull], [m.output, m.outputFull]]) {
|
|
9722
|
+
if (seenNames.has(pair[0])) continue;
|
|
9723
|
+
seenNames.add(pair[0]);
|
|
9724
|
+
origins.push({ name: pair[0], file: lpResolve(model, pair[1]).file });
|
|
9725
|
+
}
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
const files = [...new Set(origins.map((o) => o.file))];
|
|
9729
|
+
return files.map((fn) => {
|
|
9730
|
+
const b = baseName(fn);
|
|
9731
|
+
return 'local ' + lpFlat('', b) + 'Messages = require("examples.' + b + '_messages")\n';
|
|
9732
|
+
}).join('')
|
|
9733
|
+
+ '\n'
|
|
9734
|
+
+ origins.map((o) => 'local ' + o.name + ' = ' + lpFlat('', baseName(o.file)) + 'Messages.' + o.name + '\n').join('')
|
|
9735
|
+
+ '\n';
|
|
9736
|
+
}
|
|
9737
|
+
|
|
9587
9738
|
function emitLuaFile(model, params) {
|
|
9588
9739
|
const base = baseName(model.name);
|
|
9589
9740
|
const stub = {
|
|
@@ -9594,13 +9745,11 @@ function emitLuaFile(model, params) {
|
|
|
9594
9745
|
+ 'local serverModule = require("grpcdc.server")\n'
|
|
9595
9746
|
+ 'local statusModule = require("grpcdc.status")\n'
|
|
9596
9747
|
+ 'local wire = require("grpcdc.wire")\n'
|
|
9597
|
-
+
|
|
9748
|
+
+ luaStubRequires(model)
|
|
9598
9749
|
+ 'local Channel = channelModule.Channel\n'
|
|
9599
9750
|
+ 'local Server = serverModule.Server\n'
|
|
9600
9751
|
+ 'local Status = statusModule.Status\n'
|
|
9601
9752
|
+ 'local EndOfStream = statusModule.EndOfStream\n\n'
|
|
9602
|
-
+ zigMessageNames(model).map((msg) => 'local ' + msg + ' = messages.' + msg + '\n').join('')
|
|
9603
|
-
+ '\n'
|
|
9604
9753
|
+ model.services.map(luaService).join('')
|
|
9605
9754
|
+ model.services.map(luaRegisterService).join('')
|
|
9606
9755
|
+ 'return {\n'
|
|
@@ -9622,47 +9771,66 @@ function rbDeprecated(m) {
|
|
|
9622
9771
|
return m.deprecated ? ' warn "deprecated"\n' : '';
|
|
9623
9772
|
}
|
|
9624
9773
|
|
|
9625
|
-
function
|
|
9774
|
+
function rbStubRef(model, full) {
|
|
9775
|
+
const e = rbpResolve(model, full);
|
|
9776
|
+
return rbpModuleName(e) + '::' + rbpFlat(e.pkg, e.msg.fullName);
|
|
9777
|
+
}
|
|
9778
|
+
|
|
9779
|
+
function rbStubRequires(model) {
|
|
9780
|
+
if (!model.types) return 'require_relative "' + baseName(model.name) + '_pb"\n';
|
|
9781
|
+
const files = new Set();
|
|
9782
|
+
for (const svc of model.services) {
|
|
9783
|
+
for (const m of svc.methods) {
|
|
9784
|
+
files.add(rbpResolve(model, m.inputFull).file);
|
|
9785
|
+
files.add(rbpResolve(model, m.outputFull).file);
|
|
9786
|
+
}
|
|
9787
|
+
}
|
|
9788
|
+
return [...files].map((fn) => 'require_relative "' + baseName(fn) + '_pb"\n').join('');
|
|
9789
|
+
}
|
|
9790
|
+
|
|
9791
|
+
function rbClientMethodKind(model, m, fiber) {
|
|
9626
9792
|
const path = q(m.path);
|
|
9627
9793
|
const recvCls = fiber ? 'FiberRecvStream' : 'RecvStream';
|
|
9794
|
+
const resp = rbStubRef(model, m.outputFull);
|
|
9628
9795
|
switch (m.kind) {
|
|
9629
9796
|
case 'unary':
|
|
9630
9797
|
return ' def ' + m.name + '(req, metadata = nil, timeout: nil)\n'
|
|
9631
9798
|
+ rbDeprecated(m)
|
|
9632
|
-
+ ' @channel.unary(' + path + ', req, ' +
|
|
9799
|
+
+ ' @channel.unary(' + path + ', req, ' + resp + '.new, metadata, timeout: timeout)\n end\n\n';
|
|
9633
9800
|
case 'server-streaming':
|
|
9634
9801
|
return ' def ' + m.name + '(req, metadata = nil, timeout: nil)\n'
|
|
9635
9802
|
+ rbDeprecated(m)
|
|
9636
9803
|
+ ' stream = @channel.server_stream(' + path + ', req, metadata, timeout: timeout)\n'
|
|
9637
|
-
+ ' ' + recvCls + '.new(stream, ' +
|
|
9804
|
+
+ ' ' + recvCls + '.new(stream, ' + resp + ')\n end\n\n';
|
|
9638
9805
|
case 'client-streaming':
|
|
9639
9806
|
return ' def ' + m.name + '(reqs, metadata = nil, timeout: nil)\n'
|
|
9640
9807
|
+ rbDeprecated(m)
|
|
9641
|
-
+ ' @channel.client_stream(' + path + ', reqs, ' +
|
|
9808
|
+
+ ' @channel.client_stream(' + path + ', reqs, ' + resp + '.new, metadata, timeout: timeout)\n end\n\n';
|
|
9642
9809
|
default:
|
|
9643
9810
|
return ' def ' + m.name + '(reqs, metadata = nil, timeout: nil)\n'
|
|
9644
9811
|
+ rbDeprecated(m)
|
|
9645
9812
|
+ ' stream = @channel.bidi(' + path + ', reqs, metadata, timeout: timeout)\n'
|
|
9646
|
-
+ ' ' + recvCls + '.new(stream, ' +
|
|
9813
|
+
+ ' ' + recvCls + '.new(stream, ' + resp + ')\n end\n\n';
|
|
9647
9814
|
}
|
|
9648
9815
|
}
|
|
9649
9816
|
|
|
9650
|
-
function rbServerHandler(
|
|
9817
|
+
function rbServerHandler(model, m) {
|
|
9651
9818
|
const handlerVar = snake(m.name) + '_handler';
|
|
9652
9819
|
const impl = m.implName;
|
|
9820
|
+
const req = rbStubRef(model, m.inputFull);
|
|
9653
9821
|
switch (m.kind) {
|
|
9654
9822
|
case 'unary':
|
|
9655
9823
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9656
|
-
+ ' req = reqs.recv_into(' +
|
|
9824
|
+
+ ' req = reqs.recv_into(' + req + '.new)\n'
|
|
9657
9825
|
+ ' resp = impl.' + impl + '(ctx, req)\n'
|
|
9658
9826
|
+ ' sink.send(resp.marshal_dc)\n end\n\n';
|
|
9659
9827
|
case 'server-streaming':
|
|
9660
9828
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9661
|
-
+ ' req = reqs.recv_into(' +
|
|
9829
|
+
+ ' req = reqs.recv_into(' + req + '.new)\n'
|
|
9662
9830
|
+ ' impl.' + impl + '(req, SendStream.new(ctx, sink))\n end\n\n';
|
|
9663
9831
|
case 'client-streaming':
|
|
9664
9832
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9665
|
-
+ ' stream = ClientStreamImpl.new(ctx, reqs, ' +
|
|
9833
|
+
+ ' stream = ClientStreamImpl.new(ctx, reqs, ' + req + ')\n'
|
|
9666
9834
|
+ ' impl.' + impl + '(stream)\n'
|
|
9667
9835
|
+ ' if stream.resp.nil?\n'
|
|
9668
9836
|
+ ' raise Grpcdc::StatusError.new(Grpcdc::CODE_INTERNAL, "client-streaming handler never called SendAndClose")\n'
|
|
@@ -9670,7 +9838,7 @@ function rbServerHandler(pb, m) {
|
|
|
9670
9838
|
+ ' sink.send(stream.resp.marshal_dc)\n end\n\n';
|
|
9671
9839
|
default:
|
|
9672
9840
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9673
|
-
+ ' impl.' + impl + '(BidiStream.new(ctx, reqs, sink, ' +
|
|
9841
|
+
+ ' impl.' + impl + '(BidiStream.new(ctx, reqs, sink, ' + req + '))\n end\n\n';
|
|
9674
9842
|
}
|
|
9675
9843
|
}
|
|
9676
9844
|
|
|
@@ -9698,6 +9866,16 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9698
9866
|
@stream.recv(@resp_cls.new)
|
|
9699
9867
|
end
|
|
9700
9868
|
|
|
9869
|
+
# Response initial metadata (after the first recv).
|
|
9870
|
+
def headers
|
|
9871
|
+
@stream.headers&.metadata
|
|
9872
|
+
end
|
|
9873
|
+
|
|
9874
|
+
# Response trailing metadata (after the call ends).
|
|
9875
|
+
def trailers
|
|
9876
|
+
@stream.trailers
|
|
9877
|
+
end
|
|
9878
|
+
|
|
9701
9879
|
# Abandon the call early: RST so the server stops producing.
|
|
9702
9880
|
def cancel
|
|
9703
9881
|
@stream.cancel
|
|
@@ -9808,6 +9986,16 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9808
9986
|
value
|
|
9809
9987
|
end
|
|
9810
9988
|
|
|
9989
|
+
# Response initial metadata (after the first recv).
|
|
9990
|
+
def headers
|
|
9991
|
+
@stream.headers&.metadata
|
|
9992
|
+
end
|
|
9993
|
+
|
|
9994
|
+
# Response trailing metadata (after the call ends).
|
|
9995
|
+
def trailers
|
|
9996
|
+
@stream.trailers
|
|
9997
|
+
end
|
|
9998
|
+
|
|
9811
9999
|
def cancel
|
|
9812
10000
|
@stream.cancel
|
|
9813
10001
|
end
|
|
@@ -9837,19 +10025,19 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9837
10025
|
|
|
9838
10026
|
`;
|
|
9839
10027
|
|
|
9840
|
-
function rbService(
|
|
10028
|
+
function rbService(model, svc) {
|
|
9841
10029
|
const sname = svc.name;
|
|
9842
10030
|
const all = svc.methods.concat(aliasClientMethods(svc));
|
|
9843
10031
|
const allServer = svc.methods.concat(aliasServerMethods(svc));
|
|
9844
10032
|
return ' class ' + sname + 'Client\n def initialize(channel)\n @channel = channel\n end\n\n'
|
|
9845
|
-
+ all.map((m) => rbClientMethodKind(
|
|
10033
|
+
+ all.map((m) => rbClientMethodKind(model, m, false)).join('')
|
|
9846
10034
|
+ ' end\n\n'
|
|
9847
10035
|
+ ' # Fiber client: wraps a Grpcdc::FiberChannel (a sync Channel is wrapped).\n'
|
|
9848
10036
|
+ ' class ' + sname + 'ClientFiber\n def initialize(channel)\n @channel = channel.is_a?(Grpcdc::FiberChannel) ? channel : Grpcdc::FiberChannel.new(channel)\n end\n\n'
|
|
9849
|
-
+ all.map((m) => rbClientMethodKind(
|
|
10037
|
+
+ all.map((m) => rbClientMethodKind(model, m, true)).join('')
|
|
9850
10038
|
+ ' end\n\n'
|
|
9851
10039
|
+ ' def self.register_' + snake(sname) + '_server(server, impl)\n'
|
|
9852
|
-
+ allServer.map((m) => rbServerHandler(
|
|
10040
|
+
+ allServer.map((m) => rbServerHandler(model, m)).join('')
|
|
9853
10041
|
+ ' server.register_service(Grpcdc::ServiceDesc.new(\n ' + q(svc.fullName) + ',\n [\n'
|
|
9854
10042
|
+ allServer.map(rbMethodEntry).join('')
|
|
9855
10043
|
+ ' ]\n ))\n end\n';
|
|
@@ -10148,9 +10336,11 @@ function rbpMessageClass(model, pb, msg) {
|
|
|
10148
10336
|
+ ' def unmarshal_dc(data)\n'
|
|
10149
10337
|
+ ' @unknown_fields = "".b\n'
|
|
10150
10338
|
+ msg.fields.map((f) => ' @' + f.name + ' = ' + rbpDefault(model, f) + '\n').join('')
|
|
10151
|
-
+ ' r = Reader.new(data)\n loop do\n item = r.field\n break if item.nil?\n\n num, wire, varint_value, bytes_value, fixed_value, raw_value = item\n
|
|
10152
|
-
+ msg.fields.
|
|
10153
|
-
|
|
10339
|
+
+ ' r = Reader.new(data)\n loop do\n item = r.field\n break if item.nil?\n\n num, wire, varint_value, bytes_value, fixed_value, raw_value = item\n'
|
|
10340
|
+
+ (msg.fields.length
|
|
10341
|
+
? ' case num\n' + msg.fields.map((f) => rbpDecodeCase(model, f)).join('') + ' else\n @unknown_fields = @unknown_fields + raw_value\n end\n'
|
|
10342
|
+
: ' @unknown_fields = @unknown_fields + raw_value\n')
|
|
10343
|
+
+ ' end\n self\n end\n\n'
|
|
10154
10344
|
+ ' def ==(other)\n other.is_a?(' + name + ') && '
|
|
10155
10345
|
+ (msg.fields.length ? msg.fields.map((f) => '@' + f.name + ' == other.' + f.name).join(' && ') : 'true')
|
|
10156
10346
|
+ '\n end\n'
|
|
@@ -10209,10 +10399,11 @@ function emitRubyFile(model, params) {
|
|
|
10209
10399
|
name: base + '_grpc_dc.rb',
|
|
10210
10400
|
content: '# @generated by protoc-gen-grpc-dc-ruby. DO NOT EDIT.\n'
|
|
10211
10401
|
+ '# source: ' + model.name + '\n\n'
|
|
10212
|
-
+
|
|
10402
|
+
+ rbStubRequires(model)
|
|
10403
|
+
+ 'require "grpcdc"\n\n'
|
|
10213
10404
|
+ 'module ' + mod + '\n'
|
|
10214
10405
|
+ RB_STREAM_HELPERS
|
|
10215
|
-
+ model.services.map((svc) => rbService(
|
|
10406
|
+
+ model.services.map((svc) => rbService(model, svc)).join('')
|
|
10216
10407
|
+ 'end\n',
|
|
10217
10408
|
};
|
|
10218
10409
|
const pbFile = emitRubyPbFile(model);
|
|
@@ -10226,33 +10417,51 @@ function phpDeprecated(m) {
|
|
|
10226
10417
|
return m.deprecated ? ' trigger_error("deprecated", E_USER_DEPRECATED);\n' : '';
|
|
10227
10418
|
}
|
|
10228
10419
|
|
|
10229
|
-
function
|
|
10420
|
+
function phpStubRef(model, full) {
|
|
10421
|
+
const e = phpbResolve(model, full);
|
|
10422
|
+
return '\\' + phpbNamespace(e) + '\\' + phpbFlat(e.pkg, e.msg.fullName);
|
|
10423
|
+
}
|
|
10424
|
+
|
|
10425
|
+
function phpStubRequires(model) {
|
|
10426
|
+
if (!model.types) return 'require_once __DIR__ . "/' + baseName(model.name) + '_pb.php";\n';
|
|
10427
|
+
const files = new Set();
|
|
10428
|
+
for (const svc of model.services) {
|
|
10429
|
+
for (const m of svc.methods) {
|
|
10430
|
+
files.add(phpbResolve(model, m.inputFull).file);
|
|
10431
|
+
files.add(phpbResolve(model, m.outputFull).file);
|
|
10432
|
+
}
|
|
10433
|
+
}
|
|
10434
|
+
return [...files].map((fn) => 'require_once __DIR__ . "/' + baseName(fn) + '_pb.php";\n').join('');
|
|
10435
|
+
}
|
|
10436
|
+
|
|
10437
|
+
function phpClientMethodKind(model, m, fiber) {
|
|
10230
10438
|
const path = q(m.path);
|
|
10231
10439
|
const depr = phpDeprecated(m);
|
|
10232
10440
|
const recvCls = fiber ? 'FiberRecvStream' : 'RecvStream';
|
|
10233
|
-
const
|
|
10441
|
+
const reqT = phpStubRef(model, m.inputFull);
|
|
10442
|
+
const respT = phpStubRef(model, m.outputFull);
|
|
10234
10443
|
switch (m.kind) {
|
|
10235
10444
|
case 'unary':
|
|
10236
|
-
return ' public function ' + m.name + '(' +
|
|
10237
|
-
+ ' {\n' + depr + ' return $this->channel->unary(' + path + ', $req, new ' +
|
|
10445
|
+
return ' public function ' + m.name + '(' + reqT + ' $req, ?array $metadata = null, ?float $timeout = null): ' + respT + '\n'
|
|
10446
|
+
+ ' {\n' + depr + ' return $this->channel->unary(' + path + ', $req, new ' + respT + '(), $metadata, $timeout);\n }\n\n';
|
|
10238
10447
|
case 'server-streaming':
|
|
10239
|
-
return ' public function ' + m.name + '(' +
|
|
10448
|
+
return ' public function ' + m.name + '(' + reqT + ' $req, ?array $metadata = null, ?float $timeout = null): ' + recvCls + '\n'
|
|
10240
10449
|
+ ' {\n' + depr + ' $stream = $this->channel->serverStream(' + path + ', $req, $metadata, $timeout);\n'
|
|
10241
|
-
+ ' return new ' + recvCls + '($stream, ' +
|
|
10450
|
+
+ ' return new ' + recvCls + '($stream, ' + respT + '::class);\n }\n\n';
|
|
10242
10451
|
case 'client-streaming':
|
|
10243
|
-
return ' public function ' + m.name + '(array $reqs, ?array $metadata = null, ?float $timeout = null): ' +
|
|
10244
|
-
+ ' {\n' + depr + ' return $this->channel->clientStream(' + path + ', $reqs, new ' +
|
|
10452
|
+
return ' public function ' + m.name + '(array $reqs, ?array $metadata = null, ?float $timeout = null): ' + respT + '\n'
|
|
10453
|
+
+ ' {\n' + depr + ' return $this->channel->clientStream(' + path + ', $reqs, new ' + respT + '(), $metadata, $timeout);\n }\n\n';
|
|
10245
10454
|
default:
|
|
10246
10455
|
return ' public function ' + m.name + '(array $reqs, ?array $metadata = null, ?float $timeout = null): ' + recvCls + '\n'
|
|
10247
10456
|
+ ' {\n' + depr + ' $stream = $this->channel->bidi(' + path + ', $reqs, $metadata, $timeout);\n'
|
|
10248
|
-
+ ' return new ' + recvCls + '($stream, ' +
|
|
10457
|
+
+ ' return new ' + recvCls + '($stream, ' + respT + '::class);\n }\n\n';
|
|
10249
10458
|
}
|
|
10250
10459
|
}
|
|
10251
10460
|
|
|
10252
|
-
function phpServerHandler(
|
|
10461
|
+
function phpServerHandler(model, m) {
|
|
10253
10462
|
const handlerVar = '$' + snake(m.name) + 'Handler';
|
|
10254
10463
|
const impl = m.implName;
|
|
10255
|
-
const type = (t) =>
|
|
10464
|
+
const type = (t) => phpStubRef(model, m.inputFull);
|
|
10256
10465
|
const head = ' ' + handlerVar + ' = function (\\Grpcdc\\CallContext $ctx, \\Grpcdc\\RequestStream $reqs, \\Grpcdc\\ResponseSink $sink) use ($impl) {\n';
|
|
10257
10466
|
switch (m.kind) {
|
|
10258
10467
|
case 'unary':
|
|
@@ -10307,6 +10516,18 @@ class RecvStream
|
|
|
10307
10516
|
return $this->stream->recv(new $cls());
|
|
10308
10517
|
}
|
|
10309
10518
|
|
|
10519
|
+
/** Response initial metadata (after the first recv). */
|
|
10520
|
+
public function headers(): ?array
|
|
10521
|
+
{
|
|
10522
|
+
return $this->stream->headers?->metadata;
|
|
10523
|
+
}
|
|
10524
|
+
|
|
10525
|
+
/** Response trailing metadata (after the call ends). */
|
|
10526
|
+
public function trailers(): ?array
|
|
10527
|
+
{
|
|
10528
|
+
return $this->stream->trailers;
|
|
10529
|
+
}
|
|
10530
|
+
|
|
10310
10531
|
/** Abandon the call early: RST so the server stops producing. */
|
|
10311
10532
|
public function cancel(): void
|
|
10312
10533
|
{
|
|
@@ -10480,6 +10701,18 @@ class FiberRecvStream
|
|
|
10480
10701
|
}
|
|
10481
10702
|
}
|
|
10482
10703
|
|
|
10704
|
+
/** Response initial metadata (after the first recv). */
|
|
10705
|
+
public function headers(): ?array
|
|
10706
|
+
{
|
|
10707
|
+
return $this->stream->headers?->metadata;
|
|
10708
|
+
}
|
|
10709
|
+
|
|
10710
|
+
/** Response trailing metadata (after the call ends). */
|
|
10711
|
+
public function trailers(): ?array
|
|
10712
|
+
{
|
|
10713
|
+
return $this->stream->trailers;
|
|
10714
|
+
}
|
|
10715
|
+
|
|
10483
10716
|
public function cancel(): void
|
|
10484
10717
|
{
|
|
10485
10718
|
$this->stream->cancel();
|
|
@@ -10498,19 +10731,19 @@ class FiberRecvStream
|
|
|
10498
10731
|
|
|
10499
10732
|
`;
|
|
10500
10733
|
|
|
10501
|
-
function phpService(
|
|
10734
|
+
function phpService(model, svc) {
|
|
10502
10735
|
const sname = svc.name;
|
|
10503
10736
|
const all = svc.methods.concat(aliasClientMethods(svc));
|
|
10504
10737
|
const allServer = svc.methods.concat(aliasServerMethods(svc));
|
|
10505
10738
|
return 'class ' + sname + 'Client\n{\n private \\Grpcdc\\Channel $channel;\n\n public function __construct(\\Grpcdc\\Channel $channel)\n {\n $this->channel = $channel;\n }\n\n'
|
|
10506
|
-
+ all.map((m) => phpClientMethodKind(
|
|
10739
|
+
+ all.map((m) => phpClientMethodKind(model, m, false)).join('')
|
|
10507
10740
|
+ '}\n\n'
|
|
10508
10741
|
+ '// Fiber client: wraps a Grpcdc\\FiberChannel (a sync Channel is wrapped).\n'
|
|
10509
10742
|
+ 'class ' + sname + 'ClientFiber\n{\n private \\Grpcdc\\FiberChannel $channel;\n\n public function __construct($channel)\n {\n $this->channel = $channel instanceof \\Grpcdc\\FiberChannel ? $channel : new \\Grpcdc\\FiberChannel($channel);\n }\n\n'
|
|
10510
|
-
+ all.map((m) => phpClientMethodKind(
|
|
10743
|
+
+ all.map((m) => phpClientMethodKind(model, m, true)).join('')
|
|
10511
10744
|
+ '}\n\n'
|
|
10512
10745
|
+ 'function register' + sname + 'Server(\\Grpcdc\\Server $server, object $impl): void\n{\n'
|
|
10513
|
-
+ allServer.map((m) => phpServerHandler(
|
|
10746
|
+
+ allServer.map((m) => phpServerHandler(model, m)).join('')
|
|
10514
10747
|
+ ' $server->registerService(new \\Grpcdc\\ServiceDesc(\n ' + q(svc.fullName) + ',\n [\n'
|
|
10515
10748
|
+ allServer.map(phpMethodEntry).join('')
|
|
10516
10749
|
+ ' ]\n ));\n}\n';
|
|
@@ -10538,9 +10771,12 @@ function phpbFieldName(f) {
|
|
|
10538
10771
|
return f.jsonName ? f.jsonName : phpbCamel(f.name);
|
|
10539
10772
|
}
|
|
10540
10773
|
|
|
10774
|
+
const PHPB_RESERVED = new Set(('abstract and array as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile enum eval exit extends final finally fn for foreach function global goto if implements include include_once instanceof insteadof interface isset list match namespace new or parent print private protected public readonly require require_once return self static switch throw trait try unset use var while xor yield int float bool string true false null void iterable object mixed never resource numeric').split(' '));
|
|
10775
|
+
|
|
10541
10776
|
function phpbFlat(pkg, full) {
|
|
10542
10777
|
const rel = pkg && full.startsWith(pkg + '.') ? full.slice(pkg.length + 1) : full;
|
|
10543
|
-
|
|
10778
|
+
const flat = rel.split('.').join('_');
|
|
10779
|
+
return PHPB_RESERVED.has(flat.toLowerCase()) ? flat + '_' : flat;
|
|
10544
10780
|
}
|
|
10545
10781
|
|
|
10546
10782
|
function phpbResolve(model, typeName) {
|
|
@@ -10896,10 +11132,10 @@ function emitPhpFile(model, params) {
|
|
|
10896
11132
|
content: '<?php\n// @generated by protoc-gen-grpc-dc-php. DO NOT EDIT.\n'
|
|
10897
11133
|
+ '// source: ' + model.name + '\n\n'
|
|
10898
11134
|
+ 'namespace ' + ns + ';\n\n'
|
|
10899
|
-
+
|
|
11135
|
+
+ phpStubRequires(model)
|
|
10900
11136
|
+ 'require_once __DIR__ . "/../grpcdc.php";\n\n'
|
|
10901
11137
|
+ PHP_STREAM_HELPERS
|
|
10902
|
-
+ model.services.map((svc) => phpService(
|
|
11138
|
+
+ model.services.map((svc) => phpService(model, svc)).join(''),
|
|
10903
11139
|
};
|
|
10904
11140
|
const pbFile = emitPhpPbFile(model);
|
|
10905
11141
|
return pbFile ? [stub, pbFile] : stub;
|