grpc-dc 0.32.12 → 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 +393 -81
package/package.json
CHANGED
package/plugin/gen/generators.js
CHANGED
|
@@ -3628,6 +3628,12 @@ function javaClientStreamClass(m, svc) {
|
|
|
3628
3628
|
+ ' public ' + m.output + ' recv() throws Exception {\n'
|
|
3629
3629
|
+ ' ' + m.output + ' resp = new ' + m.output + '();\n'
|
|
3630
3630
|
+ ' stream.recv(resp);\n return resp;\n }\n\n'
|
|
3631
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
3632
|
+
+ ' public Map<String, String> headers() {\n'
|
|
3633
|
+
+ ' return stream.headers() == null ? null : stream.headers().metadata;\n }\n\n'
|
|
3634
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
3635
|
+
+ ' public Map<String, String> trailers() {\n'
|
|
3636
|
+
+ ' return stream.trailers();\n }\n\n'
|
|
3631
3637
|
+ ' /** Abort this stream (sends RST, wakes a pending recv). */\n'
|
|
3632
3638
|
+ ' public void cancel() {\n'
|
|
3633
3639
|
+ ' stream.cancel();\n }\n\n'
|
|
@@ -4463,6 +4469,10 @@ function csClientStreamClass(m, svc) {
|
|
|
4463
4469
|
+ ' public ' + m.output + ' Recv()\n {\n'
|
|
4464
4470
|
+ ' var resp = new ' + m.output + '();\n'
|
|
4465
4471
|
+ ' _stream.Recv(resp);\n return resp;\n }\n\n'
|
|
4472
|
+
+ ' /// <summary>Initial metadata (response headers); null until they arrive.</summary>\n'
|
|
4473
|
+
+ ' public Dictionary<string, string> Headers => _stream.Headers?.Metadata;\n\n'
|
|
4474
|
+
+ ' /// <summary>Trailing metadata of the terminal status; null until it arrives.</summary>\n'
|
|
4475
|
+
+ ' public Dictionary<string, string> Trailers => _stream.Trailers;\n\n'
|
|
4466
4476
|
+ ' /// <summary>Abort this stream (sends RST, wakes a pending Recv).</summary>\n'
|
|
4467
4477
|
+ ' public void Cancel() => _stream.Cancel();\n\n'
|
|
4468
4478
|
+ ' /// <summary>Abandon the call if still live (RST); no-op once terminated.</summary>\n'
|
|
@@ -4692,10 +4702,26 @@ function cspFindOwner(model, f) {
|
|
|
4692
4702
|
function cspFieldName(model, f) {
|
|
4693
4703
|
const n = cspPascal(f.name);
|
|
4694
4704
|
const owner = cspFindOwner(model, f);
|
|
4695
|
-
if (owner && (owner.nested.some((m) => m.name === n) || owner.enums.some((e) => e.name === n))) return n + '_';
|
|
4705
|
+
if (owner && (owner.name === n || owner.nested.some((m) => m.name === n) || owner.enums.some((e) => e.name === n))) return n + '_';
|
|
4696
4706
|
return n;
|
|
4697
4707
|
}
|
|
4698
4708
|
|
|
4709
|
+
function csQualifyType(pkg, simple, full) {
|
|
4710
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
4711
|
+
return full[0].toUpperCase() + full.slice(1);
|
|
4712
|
+
}
|
|
4713
|
+
|
|
4714
|
+
function csQualifyServices(pkg, services) {
|
|
4715
|
+
return services.map((svc) => ({
|
|
4716
|
+
...svc,
|
|
4717
|
+
methods: svc.methods.map((m) => ({
|
|
4718
|
+
...m,
|
|
4719
|
+
input: csQualifyType(pkg, m.input, m.inputFull),
|
|
4720
|
+
output: csQualifyType(pkg, m.output, m.outputFull),
|
|
4721
|
+
})),
|
|
4722
|
+
}));
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4699
4725
|
function cspResolve(model, typeName) {
|
|
4700
4726
|
const entry = model.types.get(typeName);
|
|
4701
4727
|
if (!entry) throw new Error('unresolved type ' + typeName);
|
|
@@ -5175,7 +5201,7 @@ function emitCsharpFile(model, params) {
|
|
|
5175
5201
|
+ 'namespace ' + ns + ';\n\n'
|
|
5176
5202
|
+ '/// <summary>Generated gRPC-over-DataChannels stubs for ' + model.name + '.</summary>\n'
|
|
5177
5203
|
+ 'public static class ' + className + '\n{\n'
|
|
5178
|
-
+ model.services.map(csService).join('')
|
|
5204
|
+
+ csQualifyServices(model.package, model.services).map(csService).join('')
|
|
5179
5205
|
+ '}\n',
|
|
5180
5206
|
};
|
|
5181
5207
|
const pbFiles = emitCsharpPbFiles(model);
|
|
@@ -5229,6 +5255,10 @@ function cppClientStreamClass(m, svc) {
|
|
|
5229
5255
|
+ ' ' + m.output + ' Recv() {\n'
|
|
5230
5256
|
+ ' ' + m.output + ' resp;\n'
|
|
5231
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'
|
|
5232
5262
|
+ ' private:\n'
|
|
5233
5263
|
+ ' grpcdc::Channel::ClientStream stream_;\n };\n\n';
|
|
5234
5264
|
}
|
|
@@ -5947,21 +5977,68 @@ function xppMessageClass(model, msg, support, indent) {
|
|
|
5947
5977
|
+ msg.fields.map((f) => pad + ' ' + xppType(model, f) + ' ' + f.name + ' = ' + xppDefault(model, f) + ';\n').join('')
|
|
5948
5978
|
+ pad + ' grpcdc::Bytes unknown_fields;\n'
|
|
5949
5979
|
+ pad + ' ' + name + '() = default;\n'
|
|
5950
|
-
+ pad + ' grpcdc::Bytes MarshalDc() const override
|
|
5951
|
-
+ 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'
|
|
5952
5989
|
+ msg.fields.map((f) => xppEncodeGuard(model, f, xppEncodeField(model, f, support))).join('')
|
|
5953
|
-
+
|
|
5954
|
-
+
|
|
5955
|
-
+
|
|
5956
|
-
+
|
|
5957
|
-
+ msg.fields.map((f) =>
|
|
5958
|
-
+
|
|
5959
|
-
+
|
|
5960
|
-
+
|
|
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'
|
|
5961
5998
|
+ msg.fields.map((f) => xppDecodeCase(model, f, support)).join('')
|
|
5962
|
-
+
|
|
5963
|
-
+
|
|
5964
|
-
+
|
|
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;
|
|
5965
6042
|
}
|
|
5966
6043
|
|
|
5967
6044
|
function emitCppPbFile(model) {
|
|
@@ -5984,6 +6061,7 @@ function emitCppPbFile(model) {
|
|
|
5984
6061
|
for (const n of msg.nested) collect(n);
|
|
5985
6062
|
};
|
|
5986
6063
|
for (const m of model.messages) collect(m);
|
|
6064
|
+
const ordered = xppOrderedMessages(model);
|
|
5987
6065
|
const deps = model.dependencies || [];
|
|
5988
6066
|
const content = '// @generated by protoc-gen-grpc-dc-cpp. DO NOT EDIT.\n'
|
|
5989
6067
|
+ '#pragma once\n\n'
|
|
@@ -5999,9 +6077,12 @@ function emitCppPbFile(model) {
|
|
|
5999
6077
|
+ '\n};\n\n').join('')
|
|
6000
6078
|
+ 'namespace pb_' + base + ' {\n\n'
|
|
6001
6079
|
+ XPP_SUPPORT_BODY
|
|
6002
|
-
+ helpers.map((h) => h.decls).join('')
|
|
6003
6080
|
+ '} // namespace pb_' + base + '\n\n'
|
|
6004
|
-
+
|
|
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('')
|
|
6005
6086
|
+ (helpers.length
|
|
6006
6087
|
? 'namespace pb_' + base + ' {\n\n' + helpers.map((h) => h.defs).join('') + '} // namespace pb_' + base + '\n\n'
|
|
6007
6088
|
: '')
|
|
@@ -6009,10 +6090,22 @@ function emitCppPbFile(model) {
|
|
|
6009
6090
|
return { name: base + '_messages.hpp', content };
|
|
6010
6091
|
}
|
|
6011
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
|
+
|
|
6012
6105
|
function emitCppFile(model, params) {
|
|
6013
6106
|
const base = baseName(model.name);
|
|
6014
6107
|
const structName = pascalName(base) + 'GrpcDc';
|
|
6015
|
-
const ns = model.package
|
|
6108
|
+
const ns = xppNs(model.package);
|
|
6016
6109
|
const stub = {
|
|
6017
6110
|
name: base + '_grpc_dc.hpp',
|
|
6018
6111
|
content: '// @generated by protoc-gen-grpc-dc-cpp. DO NOT EDIT.\n'
|
|
@@ -6020,7 +6113,7 @@ function emitCppFile(model, params) {
|
|
|
6020
6113
|
+ '#pragma once\n\n'
|
|
6021
6114
|
+ '#include <future>\n#include <optional>\n\n#if __cplusplus >= 202002L\n#include "grpcdc/async.hpp"\n#endif\n'
|
|
6022
6115
|
+ '#include <memory>\n#include <vector>\n\n'
|
|
6023
|
-
+
|
|
6116
|
+
+ cppStubIncludes(model)
|
|
6024
6117
|
+ '#include "grpcdc/channel.hpp"\n#include "grpcdc/server.hpp"\n\n'
|
|
6025
6118
|
+ 'namespace ' + ns + ' {\n\n'
|
|
6026
6119
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
@@ -6069,7 +6162,12 @@ function swiftClientStreamClass(m, svc) {
|
|
|
6069
6162
|
+ ' init(_ stream: Channel.ClientStream) { self.stream = stream }\n'
|
|
6070
6163
|
+ ' func Recv() throws -> ' + m.output + ' {\n'
|
|
6071
6164
|
+ ' let resp = ' + m.output + '()\n'
|
|
6072
|
-
+ ' 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';
|
|
6073
6171
|
}
|
|
6074
6172
|
|
|
6075
6173
|
function swiftClientAsyncMethod(m, svc) {
|
|
@@ -6289,16 +6387,16 @@ function swiftService(svc) {
|
|
|
6289
6387
|
+ ' static func Register' + sname + 'ServerAsync(_ server: Server, _ impl: ' + sname + 'ServerAsync) {\n'
|
|
6290
6388
|
+ ' // Adapters are retained for the process lifetime: registration is\n'
|
|
6291
6389
|
+ ' // once-per-process and bounded by service count.\n'
|
|
6292
|
-
+ '
|
|
6293
|
-
+ ' Register' + sname + 'Server(server,
|
|
6294
|
-
+ ' 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'
|
|
6295
6393
|
+ ' #endif\n';
|
|
6296
6394
|
}
|
|
6297
6395
|
|
|
6298
6396
|
const SWIFT_RUN_BLOCKING =
|
|
6299
6397
|
'#if canImport(Foundation)\n'
|
|
6300
6398
|
+ '/// Run an async operation to completion on a blocking thread.\n'
|
|
6301
|
-
+ 'func RunBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {\n'
|
|
6399
|
+
+ 'fileprivate func RunBlocking<T>(_ body: @escaping () async throws -> T) throws -> T {\n'
|
|
6302
6400
|
+ ' let semaphore = DispatchSemaphore(value: 0)\n'
|
|
6303
6401
|
+ ' var result: Result<T, Error>!\n'
|
|
6304
6402
|
+ ' Task.detached {\n'
|
|
@@ -6575,7 +6673,7 @@ function swpDecodeCase(model, f, support) {
|
|
|
6575
6673
|
}
|
|
6576
6674
|
if (SWP_VARINT.has(f.type)) {
|
|
6577
6675
|
const conv = (src) => f.type === 14
|
|
6578
|
-
? 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 })
|
|
6579
6677
|
: swpVarintDecode(f, src);
|
|
6580
6678
|
return head
|
|
6581
6679
|
+ ' if field.wire == 2 {\n'
|
|
@@ -6774,8 +6872,7 @@ function emitSwiftFile(model, params) {
|
|
|
6774
6872
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
6775
6873
|
+ 'enum ' + enumName + ' {\n'
|
|
6776
6874
|
+ model.services.map(swiftService).join('')
|
|
6777
|
-
+ '}\n
|
|
6778
|
-
+ SWIFT_RUN_BLOCKING,
|
|
6875
|
+
+ '}\n',
|
|
6779
6876
|
};
|
|
6780
6877
|
const pbFile = emitSwiftPbFile(model);
|
|
6781
6878
|
return pbFile ? [stub, pbFile] : stub;
|
|
@@ -6821,6 +6918,10 @@ function kotlinClientStreamClass(m, svc) {
|
|
|
6821
6918
|
+ ' fun recv(): ' + m.output + ' {\n'
|
|
6822
6919
|
+ ' val resp = ' + m.output + '()\n'
|
|
6823
6920
|
+ ' stream.recv(resp)\n return resp\n }\n\n'
|
|
6921
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
6922
|
+
+ ' fun headers(): Map<String, String>? = stream.headers?.metadata\n\n'
|
|
6923
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
6924
|
+
+ ' fun trailers(): Map<String, String>? = stream.trailers\n\n'
|
|
6824
6925
|
+ ' /** Abort this stream (sends RST, wakes a pending recv). */\n'
|
|
6825
6926
|
+ ' fun cancel() = stream.cancel()\n\n'
|
|
6826
6927
|
+ ' /** Abandon the call if still live (RST); no-op once terminated. */\n'
|
|
@@ -7030,9 +7131,9 @@ function kotlinService(svc) {
|
|
|
7030
7131
|
+ ' // Adapters are retained for the process lifetime: registration is\n'
|
|
7031
7132
|
+ ' // once-per-process and bounded by service count.\n'
|
|
7032
7133
|
+ ' val adapter = ' + sname + 'ServerAsyncAdapter(impl)\n'
|
|
7033
|
-
+ '
|
|
7134
|
+
+ ' ' + lowerFirst(sname) + 'Adapters.add(adapter)\n'
|
|
7034
7135
|
+ ' register' + sname + 'Server(server, adapter)\n }\n\n'
|
|
7035
|
-
+ ' private val
|
|
7136
|
+
+ ' private val ' + lowerFirst(sname) + 'Adapters = ArrayList<' + sname + 'ServerAsyncAdapter>()\n');
|
|
7036
7137
|
}
|
|
7037
7138
|
|
|
7038
7139
|
|
|
@@ -7510,6 +7611,22 @@ function emitKotlinPbFile(model) {
|
|
|
7510
7611
|
return { name: pascalName(base) + 'Messages.kt', content };
|
|
7511
7612
|
}
|
|
7512
7613
|
|
|
7614
|
+
function kotlinQualifyType(pkg, simple, full) {
|
|
7615
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
7616
|
+
return full;
|
|
7617
|
+
}
|
|
7618
|
+
|
|
7619
|
+
function kotlinQualifyServices(pkg, services) {
|
|
7620
|
+
return services.map((svc) => ({
|
|
7621
|
+
...svc,
|
|
7622
|
+
methods: svc.methods.map((m) => ({
|
|
7623
|
+
...m,
|
|
7624
|
+
input: kotlinQualifyType(pkg, m.input, m.inputFull),
|
|
7625
|
+
output: kotlinQualifyType(pkg, m.output, m.outputFull),
|
|
7626
|
+
})),
|
|
7627
|
+
}));
|
|
7628
|
+
}
|
|
7629
|
+
|
|
7513
7630
|
function emitKotlinFile(model, params) {
|
|
7514
7631
|
const base = baseName(model.name);
|
|
7515
7632
|
const objectName = pascalName(base) + 'GrpcDc';
|
|
@@ -7523,7 +7640,7 @@ function emitKotlinFile(model, params) {
|
|
|
7523
7640
|
+ 'import java.io.EOFException\nimport java.util.concurrent.CompletableFuture\n\n'
|
|
7524
7641
|
+ '/** Generated gRPC-over-DataChannels stubs for ' + model.name + '. */\n'
|
|
7525
7642
|
+ 'object ' + objectName + ' {\n'
|
|
7526
|
-
+ model.services.map(kotlinService).join('')
|
|
7643
|
+
+ kotlinQualifyServices(model.package, model.services).map(kotlinService).join('')
|
|
7527
7644
|
+ '}\n',
|
|
7528
7645
|
};
|
|
7529
7646
|
const pbFile = emitKotlinPbFile(model);
|
|
@@ -7608,6 +7725,14 @@ function dartClientStreamClass(m, svc) {
|
|
|
7608
7725
|
+ ' Future<' + m.output + '> recv() async {\n'
|
|
7609
7726
|
+ ' final resp = ' + m.output + '();\n'
|
|
7610
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'
|
|
7611
7736
|
+ ' /// Responses as a Dart Stream (native async surface).\n'
|
|
7612
7737
|
+ ' /// Cancelling the subscription abandons the call:\n'
|
|
7613
7738
|
+ ' /// RST CANCELLED is sent so the server stops.\n'
|
|
@@ -8238,6 +8363,18 @@ function emitDartPbFile(model) {
|
|
|
8238
8363
|
return { name: base + '_messages.dart', content };
|
|
8239
8364
|
}
|
|
8240
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
|
+
|
|
8241
8378
|
function emitDartFile(model, params) {
|
|
8242
8379
|
const base = baseName(model.name);
|
|
8243
8380
|
const className = pascalName(base) + 'GrpcDc';
|
|
@@ -8247,7 +8384,7 @@ function emitDartFile(model, params) {
|
|
|
8247
8384
|
+ '// source: ' + model.name + '\n\n'
|
|
8248
8385
|
+ "import 'dart:async';\n\n"
|
|
8249
8386
|
+ "import '../grpcdc/channel.dart';\nimport '../grpcdc/endpoint.dart';\nimport '../grpcdc/server.dart';\nimport '../grpcdc/status.dart';\nimport '../grpcdc/wire.dart';\n"
|
|
8250
|
-
+
|
|
8387
|
+
+ dartStubImports(model)
|
|
8251
8388
|
+ model.services.map(dartService).join('')
|
|
8252
8389
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
8253
8390
|
+ 'class ' + className + ' {\n'
|
|
@@ -8315,6 +8452,12 @@ function zigClientStreamClass(m, svc) {
|
|
|
8315
8452
|
+ ' .message => return .{ .message = resp },\n'
|
|
8316
8453
|
+ ' .end => return .end,\n'
|
|
8317
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'
|
|
8318
8461
|
+ ' pub fn deinit(self: *' + svc + m.name + 'Client) void {\n'
|
|
8319
8462
|
+ ' self.stream.deinit();\n }\n};\n\n';
|
|
8320
8463
|
}
|
|
@@ -8376,7 +8519,7 @@ function zigServerVtableField(m, svc) {
|
|
|
8376
8519
|
function zigAdapter(m, svc) {
|
|
8377
8520
|
const name = lowerFirst(m.name);
|
|
8378
8521
|
const impl = zigSnake(m.implName);
|
|
8379
|
-
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'
|
|
8380
8523
|
+ ' const impl: *' + svc + 'Server = @ptrCast(@alignCast(ctx));\n';
|
|
8381
8524
|
switch (m.kind) {
|
|
8382
8525
|
case 'unary':
|
|
@@ -8429,8 +8572,8 @@ const ZIG_KIND_CONSTS = {
|
|
|
8429
8572
|
bidi: 'bidi',
|
|
8430
8573
|
};
|
|
8431
8574
|
|
|
8432
|
-
function zigRegisterMethod(m) {
|
|
8433
|
-
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';
|
|
8434
8577
|
}
|
|
8435
8578
|
|
|
8436
8579
|
function zigService(svc) {
|
|
@@ -8453,6 +8596,26 @@ function zigService(svc) {
|
|
|
8453
8596
|
+ svc.methods.concat(aliasServerMethods(svc)).map((m) => zigAdapter(m, sname)).join('');
|
|
8454
8597
|
}
|
|
8455
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
|
+
|
|
8456
8619
|
function zigMessageNames(model) {
|
|
8457
8620
|
const seen = [];
|
|
8458
8621
|
for (const svc of model.services) {
|
|
@@ -8470,7 +8633,7 @@ function zigRegisterService(svc) {
|
|
|
8470
8633
|
+ ' server.registerService(.{\n'
|
|
8471
8634
|
+ ' .name = ' + q(svc.fullName) + ',\n'
|
|
8472
8635
|
+ ' .methods = &.{\n'
|
|
8473
|
-
+ svc.methods.concat(aliasServerMethods(svc)).map(zigRegisterMethod).join('')
|
|
8636
|
+
+ svc.methods.concat(aliasServerMethods(svc)).map((m) => zigRegisterMethod(m, sname)).join('')
|
|
8474
8637
|
+ ' },\n });\n }\n';
|
|
8475
8638
|
}
|
|
8476
8639
|
|
|
@@ -8794,6 +8957,7 @@ function zgpMapHelpers(model, entry) {
|
|
|
8794
8957
|
: zgpEncodeSingular(model, { ...valF, label: 1 }, 'value', ' '))
|
|
8795
8958
|
+ ' return w.toBytes();\n}\n\n'
|
|
8796
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')
|
|
8797
8961
|
+ ' var result: ' + sname + ' = .{ .key = ' + zgpDefault(model, { ...keyF, label: 1 }) + ', .value = ' + (valF.type === FT.MESSAGE ? '.{}' : zgpDefault(model, { ...valF, label: 1 })) + ' };\n'
|
|
8798
8962
|
+ ' var r = PbReader.init(data);\n while (r.next()) |field| {\n switch (field.number) {\n'
|
|
8799
8963
|
+ ' ' + keyF.number + ' => { ' + zgpDecodeSingular(model, { ...keyF, label: 1 }, 'result.key', zgpSrc(keyF), '').replace(/\s+$/, '') + ' },\n'
|
|
@@ -8895,7 +9059,7 @@ function zgpMessageStruct(model, msg, indent) {
|
|
|
8895
9059
|
+ indent + ' self.unknown_fields = unknown_fields_list.toOwnedSlice(alloc) catch &.{};\n'
|
|
8896
9060
|
+ msg.fields.filter((f) => zgpIsListField(model, f)).map((f) => indent + ' self.' + f.name + ' = ' + f.name + '_list.toOwnedSlice(alloc) catch &.{};\n').join('')
|
|
8897
9061
|
+ indent + ' }\n'
|
|
8898
|
-
+ msg.nested.map((n) => zgpMessageStruct(model, n, indent + ' ')).join('')
|
|
9062
|
+
+ msg.nested.filter((n) => !n.mapEntry).map((n) => zgpMessageStruct(model, n, indent + ' ')).join('')
|
|
8899
9063
|
+ msg.enums.map((e) => zgpNestedEnum(e, indent + ' ')).join('')
|
|
8900
9064
|
+ indent + '};\n';
|
|
8901
9065
|
}
|
|
@@ -8951,14 +9115,16 @@ function emitZigFile(model, params) {
|
|
|
8951
9115
|
+ 'const std = @import("std");\n'
|
|
8952
9116
|
+ 'const grpcdc = @import("grpcdc");\n'
|
|
8953
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'
|
|
8954
|
-
+
|
|
9118
|
+
+ zigStubImports(model)
|
|
8955
9119
|
+ 'pub const Channel = channel_mod.Channel;\n'
|
|
8956
9120
|
+ 'pub const ClientStream = channel_mod.ClientStream;\n'
|
|
8957
9121
|
+ 'pub const CallContext = endpoint_mod.CallContext;\n'
|
|
8958
9122
|
+ 'pub const Server = server_mod.Server;\n'
|
|
8959
9123
|
+ 'pub const Status = status_mod.Status;\n'
|
|
8960
9124
|
+ 'pub const Metadata = channel_mod.Metadata;\n'
|
|
8961
|
-
+
|
|
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(''))
|
|
8962
9128
|
+ '\n'
|
|
8963
9129
|
+ model.services.map(zigService).join('')
|
|
8964
9130
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
@@ -9072,6 +9238,10 @@ function luaClientStreamClass(m, svc) {
|
|
|
9072
9238
|
+ 'function ' + t + ':recv()\n'
|
|
9073
9239
|
+ ' local resp = ' + m.output + '.new()\n'
|
|
9074
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'
|
|
9075
9245
|
+ '--- Abandon the call early: RST so the server stops producing.\n'
|
|
9076
9246
|
+ 'function ' + t + ':close()\n self.stream:close()\nend\n\n'
|
|
9077
9247
|
+ 'function ' + t + ':cancel()\n self.stream:cancel()\nend\n\n'
|
|
@@ -9538,6 +9708,33 @@ function emitLuaPbFile(model) {
|
|
|
9538
9708
|
return { name: base + '_messages.lua', content };
|
|
9539
9709
|
}
|
|
9540
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
|
+
|
|
9541
9738
|
function emitLuaFile(model, params) {
|
|
9542
9739
|
const base = baseName(model.name);
|
|
9543
9740
|
const stub = {
|
|
@@ -9548,13 +9745,11 @@ function emitLuaFile(model, params) {
|
|
|
9548
9745
|
+ 'local serverModule = require("grpcdc.server")\n'
|
|
9549
9746
|
+ 'local statusModule = require("grpcdc.status")\n'
|
|
9550
9747
|
+ 'local wire = require("grpcdc.wire")\n'
|
|
9551
|
-
+
|
|
9748
|
+
+ luaStubRequires(model)
|
|
9552
9749
|
+ 'local Channel = channelModule.Channel\n'
|
|
9553
9750
|
+ 'local Server = serverModule.Server\n'
|
|
9554
9751
|
+ 'local Status = statusModule.Status\n'
|
|
9555
9752
|
+ 'local EndOfStream = statusModule.EndOfStream\n\n'
|
|
9556
|
-
+ zigMessageNames(model).map((msg) => 'local ' + msg + ' = messages.' + msg + '\n').join('')
|
|
9557
|
-
+ '\n'
|
|
9558
9753
|
+ model.services.map(luaService).join('')
|
|
9559
9754
|
+ model.services.map(luaRegisterService).join('')
|
|
9560
9755
|
+ 'return {\n'
|
|
@@ -9576,47 +9771,66 @@ function rbDeprecated(m) {
|
|
|
9576
9771
|
return m.deprecated ? ' warn "deprecated"\n' : '';
|
|
9577
9772
|
}
|
|
9578
9773
|
|
|
9579
|
-
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) {
|
|
9580
9792
|
const path = q(m.path);
|
|
9581
9793
|
const recvCls = fiber ? 'FiberRecvStream' : 'RecvStream';
|
|
9794
|
+
const resp = rbStubRef(model, m.outputFull);
|
|
9582
9795
|
switch (m.kind) {
|
|
9583
9796
|
case 'unary':
|
|
9584
9797
|
return ' def ' + m.name + '(req, metadata = nil, timeout: nil)\n'
|
|
9585
9798
|
+ rbDeprecated(m)
|
|
9586
|
-
+ ' @channel.unary(' + path + ', req, ' +
|
|
9799
|
+
+ ' @channel.unary(' + path + ', req, ' + resp + '.new, metadata, timeout: timeout)\n end\n\n';
|
|
9587
9800
|
case 'server-streaming':
|
|
9588
9801
|
return ' def ' + m.name + '(req, metadata = nil, timeout: nil)\n'
|
|
9589
9802
|
+ rbDeprecated(m)
|
|
9590
9803
|
+ ' stream = @channel.server_stream(' + path + ', req, metadata, timeout: timeout)\n'
|
|
9591
|
-
+ ' ' + recvCls + '.new(stream, ' +
|
|
9804
|
+
+ ' ' + recvCls + '.new(stream, ' + resp + ')\n end\n\n';
|
|
9592
9805
|
case 'client-streaming':
|
|
9593
9806
|
return ' def ' + m.name + '(reqs, metadata = nil, timeout: nil)\n'
|
|
9594
9807
|
+ rbDeprecated(m)
|
|
9595
|
-
+ ' @channel.client_stream(' + path + ', reqs, ' +
|
|
9808
|
+
+ ' @channel.client_stream(' + path + ', reqs, ' + resp + '.new, metadata, timeout: timeout)\n end\n\n';
|
|
9596
9809
|
default:
|
|
9597
9810
|
return ' def ' + m.name + '(reqs, metadata = nil, timeout: nil)\n'
|
|
9598
9811
|
+ rbDeprecated(m)
|
|
9599
9812
|
+ ' stream = @channel.bidi(' + path + ', reqs, metadata, timeout: timeout)\n'
|
|
9600
|
-
+ ' ' + recvCls + '.new(stream, ' +
|
|
9813
|
+
+ ' ' + recvCls + '.new(stream, ' + resp + ')\n end\n\n';
|
|
9601
9814
|
}
|
|
9602
9815
|
}
|
|
9603
9816
|
|
|
9604
|
-
function rbServerHandler(
|
|
9817
|
+
function rbServerHandler(model, m) {
|
|
9605
9818
|
const handlerVar = snake(m.name) + '_handler';
|
|
9606
9819
|
const impl = m.implName;
|
|
9820
|
+
const req = rbStubRef(model, m.inputFull);
|
|
9607
9821
|
switch (m.kind) {
|
|
9608
9822
|
case 'unary':
|
|
9609
9823
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9610
|
-
+ ' req = reqs.recv_into(' +
|
|
9824
|
+
+ ' req = reqs.recv_into(' + req + '.new)\n'
|
|
9611
9825
|
+ ' resp = impl.' + impl + '(ctx, req)\n'
|
|
9612
9826
|
+ ' sink.send(resp.marshal_dc)\n end\n\n';
|
|
9613
9827
|
case 'server-streaming':
|
|
9614
9828
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9615
|
-
+ ' req = reqs.recv_into(' +
|
|
9829
|
+
+ ' req = reqs.recv_into(' + req + '.new)\n'
|
|
9616
9830
|
+ ' impl.' + impl + '(req, SendStream.new(ctx, sink))\n end\n\n';
|
|
9617
9831
|
case 'client-streaming':
|
|
9618
9832
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9619
|
-
+ ' stream = ClientStreamImpl.new(ctx, reqs, ' +
|
|
9833
|
+
+ ' stream = ClientStreamImpl.new(ctx, reqs, ' + req + ')\n'
|
|
9620
9834
|
+ ' impl.' + impl + '(stream)\n'
|
|
9621
9835
|
+ ' if stream.resp.nil?\n'
|
|
9622
9836
|
+ ' raise Grpcdc::StatusError.new(Grpcdc::CODE_INTERNAL, "client-streaming handler never called SendAndClose")\n'
|
|
@@ -9624,7 +9838,7 @@ function rbServerHandler(pb, m) {
|
|
|
9624
9838
|
+ ' sink.send(stream.resp.marshal_dc)\n end\n\n';
|
|
9625
9839
|
default:
|
|
9626
9840
|
return ' ' + handlerVar + ' = lambda do |ctx, reqs, sink|\n'
|
|
9627
|
-
+ ' impl.' + impl + '(BidiStream.new(ctx, reqs, sink, ' +
|
|
9841
|
+
+ ' impl.' + impl + '(BidiStream.new(ctx, reqs, sink, ' + req + '))\n end\n\n';
|
|
9628
9842
|
}
|
|
9629
9843
|
}
|
|
9630
9844
|
|
|
@@ -9652,6 +9866,16 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9652
9866
|
@stream.recv(@resp_cls.new)
|
|
9653
9867
|
end
|
|
9654
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
|
+
|
|
9655
9879
|
# Abandon the call early: RST so the server stops producing.
|
|
9656
9880
|
def cancel
|
|
9657
9881
|
@stream.cancel
|
|
@@ -9762,6 +9986,16 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9762
9986
|
value
|
|
9763
9987
|
end
|
|
9764
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
|
+
|
|
9765
9999
|
def cancel
|
|
9766
10000
|
@stream.cancel
|
|
9767
10001
|
end
|
|
@@ -9791,19 +10025,19 @@ const RB_STREAM_HELPERS = ` # Client receiving stream: recv raises EOFError at
|
|
|
9791
10025
|
|
|
9792
10026
|
`;
|
|
9793
10027
|
|
|
9794
|
-
function rbService(
|
|
10028
|
+
function rbService(model, svc) {
|
|
9795
10029
|
const sname = svc.name;
|
|
9796
10030
|
const all = svc.methods.concat(aliasClientMethods(svc));
|
|
9797
10031
|
const allServer = svc.methods.concat(aliasServerMethods(svc));
|
|
9798
10032
|
return ' class ' + sname + 'Client\n def initialize(channel)\n @channel = channel\n end\n\n'
|
|
9799
|
-
+ all.map((m) => rbClientMethodKind(
|
|
10033
|
+
+ all.map((m) => rbClientMethodKind(model, m, false)).join('')
|
|
9800
10034
|
+ ' end\n\n'
|
|
9801
10035
|
+ ' # Fiber client: wraps a Grpcdc::FiberChannel (a sync Channel is wrapped).\n'
|
|
9802
10036
|
+ ' class ' + sname + 'ClientFiber\n def initialize(channel)\n @channel = channel.is_a?(Grpcdc::FiberChannel) ? channel : Grpcdc::FiberChannel.new(channel)\n end\n\n'
|
|
9803
|
-
+ all.map((m) => rbClientMethodKind(
|
|
10037
|
+
+ all.map((m) => rbClientMethodKind(model, m, true)).join('')
|
|
9804
10038
|
+ ' end\n\n'
|
|
9805
10039
|
+ ' def self.register_' + snake(sname) + '_server(server, impl)\n'
|
|
9806
|
-
+ allServer.map((m) => rbServerHandler(
|
|
10040
|
+
+ allServer.map((m) => rbServerHandler(model, m)).join('')
|
|
9807
10041
|
+ ' server.register_service(Grpcdc::ServiceDesc.new(\n ' + q(svc.fullName) + ',\n [\n'
|
|
9808
10042
|
+ allServer.map(rbMethodEntry).join('')
|
|
9809
10043
|
+ ' ]\n ))\n end\n';
|
|
@@ -10102,9 +10336,11 @@ function rbpMessageClass(model, pb, msg) {
|
|
|
10102
10336
|
+ ' def unmarshal_dc(data)\n'
|
|
10103
10337
|
+ ' @unknown_fields = "".b\n'
|
|
10104
10338
|
+ msg.fields.map((f) => ' @' + f.name + ' = ' + rbpDefault(model, f) + '\n').join('')
|
|
10105
|
-
+ ' 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
|
|
10106
|
-
+ msg.fields.
|
|
10107
|
-
|
|
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'
|
|
10108
10344
|
+ ' def ==(other)\n other.is_a?(' + name + ') && '
|
|
10109
10345
|
+ (msg.fields.length ? msg.fields.map((f) => '@' + f.name + ' == other.' + f.name).join(' && ') : 'true')
|
|
10110
10346
|
+ '\n end\n'
|
|
@@ -10163,10 +10399,11 @@ function emitRubyFile(model, params) {
|
|
|
10163
10399
|
name: base + '_grpc_dc.rb',
|
|
10164
10400
|
content: '# @generated by protoc-gen-grpc-dc-ruby. DO NOT EDIT.\n'
|
|
10165
10401
|
+ '# source: ' + model.name + '\n\n'
|
|
10166
|
-
+
|
|
10402
|
+
+ rbStubRequires(model)
|
|
10403
|
+
+ 'require "grpcdc"\n\n'
|
|
10167
10404
|
+ 'module ' + mod + '\n'
|
|
10168
10405
|
+ RB_STREAM_HELPERS
|
|
10169
|
-
+ model.services.map((svc) => rbService(
|
|
10406
|
+
+ model.services.map((svc) => rbService(model, svc)).join('')
|
|
10170
10407
|
+ 'end\n',
|
|
10171
10408
|
};
|
|
10172
10409
|
const pbFile = emitRubyPbFile(model);
|
|
@@ -10180,33 +10417,51 @@ function phpDeprecated(m) {
|
|
|
10180
10417
|
return m.deprecated ? ' trigger_error("deprecated", E_USER_DEPRECATED);\n' : '';
|
|
10181
10418
|
}
|
|
10182
10419
|
|
|
10183
|
-
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) {
|
|
10184
10438
|
const path = q(m.path);
|
|
10185
10439
|
const depr = phpDeprecated(m);
|
|
10186
10440
|
const recvCls = fiber ? 'FiberRecvStream' : 'RecvStream';
|
|
10187
|
-
const
|
|
10441
|
+
const reqT = phpStubRef(model, m.inputFull);
|
|
10442
|
+
const respT = phpStubRef(model, m.outputFull);
|
|
10188
10443
|
switch (m.kind) {
|
|
10189
10444
|
case 'unary':
|
|
10190
|
-
return ' public function ' + m.name + '(' +
|
|
10191
|
-
+ ' {\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';
|
|
10192
10447
|
case 'server-streaming':
|
|
10193
|
-
return ' public function ' + m.name + '(' +
|
|
10448
|
+
return ' public function ' + m.name + '(' + reqT + ' $req, ?array $metadata = null, ?float $timeout = null): ' + recvCls + '\n'
|
|
10194
10449
|
+ ' {\n' + depr + ' $stream = $this->channel->serverStream(' + path + ', $req, $metadata, $timeout);\n'
|
|
10195
|
-
+ ' return new ' + recvCls + '($stream, ' +
|
|
10450
|
+
+ ' return new ' + recvCls + '($stream, ' + respT + '::class);\n }\n\n';
|
|
10196
10451
|
case 'client-streaming':
|
|
10197
|
-
return ' public function ' + m.name + '(array $reqs, ?array $metadata = null, ?float $timeout = null): ' +
|
|
10198
|
-
+ ' {\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';
|
|
10199
10454
|
default:
|
|
10200
10455
|
return ' public function ' + m.name + '(array $reqs, ?array $metadata = null, ?float $timeout = null): ' + recvCls + '\n'
|
|
10201
10456
|
+ ' {\n' + depr + ' $stream = $this->channel->bidi(' + path + ', $reqs, $metadata, $timeout);\n'
|
|
10202
|
-
+ ' return new ' + recvCls + '($stream, ' +
|
|
10457
|
+
+ ' return new ' + recvCls + '($stream, ' + respT + '::class);\n }\n\n';
|
|
10203
10458
|
}
|
|
10204
10459
|
}
|
|
10205
10460
|
|
|
10206
|
-
function phpServerHandler(
|
|
10461
|
+
function phpServerHandler(model, m) {
|
|
10207
10462
|
const handlerVar = '$' + snake(m.name) + 'Handler';
|
|
10208
10463
|
const impl = m.implName;
|
|
10209
|
-
const type = (t) =>
|
|
10464
|
+
const type = (t) => phpStubRef(model, m.inputFull);
|
|
10210
10465
|
const head = ' ' + handlerVar + ' = function (\\Grpcdc\\CallContext $ctx, \\Grpcdc\\RequestStream $reqs, \\Grpcdc\\ResponseSink $sink) use ($impl) {\n';
|
|
10211
10466
|
switch (m.kind) {
|
|
10212
10467
|
case 'unary':
|
|
@@ -10261,6 +10516,18 @@ class RecvStream
|
|
|
10261
10516
|
return $this->stream->recv(new $cls());
|
|
10262
10517
|
}
|
|
10263
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
|
+
|
|
10264
10531
|
/** Abandon the call early: RST so the server stops producing. */
|
|
10265
10532
|
public function cancel(): void
|
|
10266
10533
|
{
|
|
@@ -10434,6 +10701,18 @@ class FiberRecvStream
|
|
|
10434
10701
|
}
|
|
10435
10702
|
}
|
|
10436
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
|
+
|
|
10437
10716
|
public function cancel(): void
|
|
10438
10717
|
{
|
|
10439
10718
|
$this->stream->cancel();
|
|
@@ -10452,19 +10731,19 @@ class FiberRecvStream
|
|
|
10452
10731
|
|
|
10453
10732
|
`;
|
|
10454
10733
|
|
|
10455
|
-
function phpService(
|
|
10734
|
+
function phpService(model, svc) {
|
|
10456
10735
|
const sname = svc.name;
|
|
10457
10736
|
const all = svc.methods.concat(aliasClientMethods(svc));
|
|
10458
10737
|
const allServer = svc.methods.concat(aliasServerMethods(svc));
|
|
10459
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'
|
|
10460
|
-
+ all.map((m) => phpClientMethodKind(
|
|
10739
|
+
+ all.map((m) => phpClientMethodKind(model, m, false)).join('')
|
|
10461
10740
|
+ '}\n\n'
|
|
10462
10741
|
+ '// Fiber client: wraps a Grpcdc\\FiberChannel (a sync Channel is wrapped).\n'
|
|
10463
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'
|
|
10464
|
-
+ all.map((m) => phpClientMethodKind(
|
|
10743
|
+
+ all.map((m) => phpClientMethodKind(model, m, true)).join('')
|
|
10465
10744
|
+ '}\n\n'
|
|
10466
10745
|
+ 'function register' + sname + 'Server(\\Grpcdc\\Server $server, object $impl): void\n{\n'
|
|
10467
|
-
+ allServer.map((m) => phpServerHandler(
|
|
10746
|
+
+ allServer.map((m) => phpServerHandler(model, m)).join('')
|
|
10468
10747
|
+ ' $server->registerService(new \\Grpcdc\\ServiceDesc(\n ' + q(svc.fullName) + ',\n [\n'
|
|
10469
10748
|
+ allServer.map(phpMethodEntry).join('')
|
|
10470
10749
|
+ ' ]\n ));\n}\n';
|
|
@@ -10492,9 +10771,12 @@ function phpbFieldName(f) {
|
|
|
10492
10771
|
return f.jsonName ? f.jsonName : phpbCamel(f.name);
|
|
10493
10772
|
}
|
|
10494
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
|
+
|
|
10495
10776
|
function phpbFlat(pkg, full) {
|
|
10496
10777
|
const rel = pkg && full.startsWith(pkg + '.') ? full.slice(pkg.length + 1) : full;
|
|
10497
|
-
|
|
10778
|
+
const flat = rel.split('.').join('_');
|
|
10779
|
+
return PHPB_RESERVED.has(flat.toLowerCase()) ? flat + '_' : flat;
|
|
10498
10780
|
}
|
|
10499
10781
|
|
|
10500
10782
|
function phpbResolve(model, typeName) {
|
|
@@ -10850,10 +11132,10 @@ function emitPhpFile(model, params) {
|
|
|
10850
11132
|
content: '<?php\n// @generated by protoc-gen-grpc-dc-php. DO NOT EDIT.\n'
|
|
10851
11133
|
+ '// source: ' + model.name + '\n\n'
|
|
10852
11134
|
+ 'namespace ' + ns + ';\n\n'
|
|
10853
|
-
+
|
|
11135
|
+
+ phpStubRequires(model)
|
|
10854
11136
|
+ 'require_once __DIR__ . "/../grpcdc.php";\n\n'
|
|
10855
11137
|
+ PHP_STREAM_HELPERS
|
|
10856
|
-
+ model.services.map((svc) => phpService(
|
|
11138
|
+
+ model.services.map((svc) => phpService(model, svc)).join(''),
|
|
10857
11139
|
};
|
|
10858
11140
|
const pbFile = emitPhpPbFile(model);
|
|
10859
11141
|
return pbFile ? [stub, pbFile] : stub;
|
|
@@ -11076,7 +11358,11 @@ function scalaService(svc) {
|
|
|
11076
11358
|
+ ' out\n'
|
|
11077
11359
|
+ ' }\n'
|
|
11078
11360
|
+ ' def cancel(): Unit = stream.cancel()\n'
|
|
11079
|
-
+ ' def close(): Unit = stream.close()\n
|
|
11361
|
+
+ ' def close(): Unit = stream.close()\n'
|
|
11362
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
11363
|
+
+ ' def headers: Map[String, String] = if (stream.headers == null) null else stream.headers.metadata\n'
|
|
11364
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
11365
|
+
+ ' def trailers: Map[String, String] = stream.trailers\n }\n\n';
|
|
11080
11366
|
return ' /** Client for ' + svc.fullName + '. */\n'
|
|
11081
11367
|
+ ' class ' + sname + 'Client(private val channel: grpcdc.Channel) {\n'
|
|
11082
11368
|
+ classOutputs('server-streaming').map((out) => streamClass('server-streaming', out)).join('')
|
|
@@ -11140,8 +11426,18 @@ function scpCamel(s) {
|
|
|
11140
11426
|
return parts[0] + parts.slice(1).map((p) => (p ? p[0].toUpperCase() + p.slice(1) : '')).join('');
|
|
11141
11427
|
}
|
|
11142
11428
|
|
|
11429
|
+
const SCP_KEYWORDS = new Set([
|
|
11430
|
+
'abstract', 'case', 'catch', 'class', 'def', 'do', 'else', 'extends',
|
|
11431
|
+
'false', 'final', 'finally', 'for', 'forSome', 'if', 'implicit',
|
|
11432
|
+
'import', 'lazy', 'match', 'new', 'null', 'object', 'override',
|
|
11433
|
+
'package', 'private', 'protected', 'return', 'sealed', 'super',
|
|
11434
|
+
'this', 'throw', 'trait', 'try', 'true', 'type', 'val', 'var',
|
|
11435
|
+
'while', 'with', 'yield',
|
|
11436
|
+
]);
|
|
11437
|
+
|
|
11143
11438
|
function scpFieldName(f) {
|
|
11144
|
-
|
|
11439
|
+
const n = f.jsonName ? f.jsonName : scpCamel(f.name);
|
|
11440
|
+
return SCP_KEYWORDS.has(n) ? '`' + n + '`' : n;
|
|
11145
11441
|
}
|
|
11146
11442
|
|
|
11147
11443
|
function scpFlat(pkg, full) {
|
|
@@ -11524,6 +11820,22 @@ function emitScalaPbFile(model) {
|
|
|
11524
11820
|
return { name: pascalName(base) + 'Messages.scala', content };
|
|
11525
11821
|
}
|
|
11526
11822
|
|
|
11823
|
+
function scalaQualifyType(pkg, simple, full) {
|
|
11824
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
11825
|
+
return full;
|
|
11826
|
+
}
|
|
11827
|
+
|
|
11828
|
+
function scalaQualifyServices(pkg, services) {
|
|
11829
|
+
return services.map((svc) => ({
|
|
11830
|
+
...svc,
|
|
11831
|
+
methods: svc.methods.map((m) => ({
|
|
11832
|
+
...m,
|
|
11833
|
+
input: scalaQualifyType(pkg, m.input, m.inputFull),
|
|
11834
|
+
output: scalaQualifyType(pkg, m.output, m.outputFull),
|
|
11835
|
+
})),
|
|
11836
|
+
}));
|
|
11837
|
+
}
|
|
11838
|
+
|
|
11527
11839
|
function emitScalaFile(model, params) {
|
|
11528
11840
|
const base = baseName(model.name);
|
|
11529
11841
|
const objName = camelName(base) + 'GrpcDc';
|
|
@@ -11534,7 +11846,7 @@ function emitScalaFile(model, params) {
|
|
|
11534
11846
|
+ 'package ' + model.package + '\n\n'
|
|
11535
11847
|
+ '/** Generated gRPC-over-DataChannels stubs. */\n'
|
|
11536
11848
|
+ 'object ' + objName + ' {\n'
|
|
11537
|
-
+ model.services.map(scalaService).join('')
|
|
11849
|
+
+ scalaQualifyServices(model.package, model.services).map(scalaService).join('')
|
|
11538
11850
|
+ '}\n',
|
|
11539
11851
|
};
|
|
11540
11852
|
const pbFile = emitScalaPbFile(model);
|