Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6cbc8f35eb | ||
|
37d97c5693 | ||
|
ab2a5d5181 | ||
|
a8d641cd8d | ||
|
af1ed8a2fb | ||
|
54eb016142 | ||
|
81310a7f0f | ||
|
2c01e8b298 | ||
|
6b43c020b1 | ||
|
e8cdc47633 | ||
|
f8c091326e | ||
|
c73331e20d | ||
|
83f2bd1514 | ||
|
22d4ea9a44 | ||
|
791af18420 | ||
|
6106c552da |
2
Makefile
2
Makefile
@@ -9,7 +9,7 @@ install:
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: build
|
test: build
|
||||||
cd examples/dummy && make
|
cd examples/dummy && make
|
||||||
cd examples/js-grpc && make
|
cd examples/flow && make
|
||||||
|
|
||||||
.PHONY: docker.build
|
.PHONY: docker.build
|
||||||
docker.build:
|
docker.build:
|
||||||
|
204
examples/flow/output/test/test_grpc_js.js
Normal file
204
examples/flow/output/test/test_grpc_js.js
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
// @flow
|
||||||
|
// GENERATED CODE -- DO NOT EDIT!
|
||||||
|
|
||||||
|
import grpc from 'grpc'
|
||||||
|
import pbFile from './pbFile.js'
|
||||||
|
|
||||||
|
export type TestEnum =
|
||||||
|
| 'ELEMENT_A'
|
||||||
|
| 'ELEMENT_B'
|
||||||
|
;
|
||||||
|
|
||||||
|
export type TestMessage = {|
|
||||||
|
a?: string;
|
||||||
|
b?: number;
|
||||||
|
c?: number;
|
||||||
|
d?: number;
|
||||||
|
e?: number;
|
||||||
|
n?: Array<string>;
|
||||||
|
o?: Array<number>;
|
||||||
|
p?: Array<number>;
|
||||||
|
q?: Array<number>;
|
||||||
|
r?: Array<number>;
|
||||||
|
s?:
|
||||||
|
| 'ELEMENT_C'
|
||||||
|
| 'ELEMENT_D'
|
||||||
|
;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestNoStreamRequest = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestNoStreamReply = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
err_msg?: string;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamRequestRequest = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamRequestReply = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
err_msg?: string;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamReplyRequest = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamReplyReply = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
err_msg?: string;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamBothRequest = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type TestStreamBothReply = {|
|
||||||
|
message?: TestMessage;
|
||||||
|
err_msg?: string;
|
||||||
|
|};
|
||||||
|
|
||||||
|
|
||||||
|
function serialize_test_TestNoStreamRequest(arg: TestNoStreamRequest) {
|
||||||
|
if (!(arg instanceof pbFile.TestNoStreamRequest)) {
|
||||||
|
throw new Error('Expected argument of type TestNoStreamRequest')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestNoStreamRequest(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestNoStreamRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestNoStreamReply(arg: TestNoStreamReply) {
|
||||||
|
if (!(arg instanceof pbFile.TestNoStreamReply)) {
|
||||||
|
throw new Error('Expected argument of type TestNoStreamReply')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestNoStreamReply(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestNoStreamReply.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamRequestRequest(arg: TestStreamRequestRequest) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamRequestRequest)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamRequestRequest')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamRequestRequest(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamRequestRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamRequestReply(arg: TestStreamRequestReply) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamRequestReply)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamRequestReply')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamRequestReply(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamRequestReply.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamReplyRequest(arg: TestStreamReplyRequest) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamReplyRequest)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamReplyRequest')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamReplyRequest(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamReplyRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamReplyReply(arg: TestStreamReplyReply) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamReplyReply)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamReplyReply')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamReplyReply(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamReplyReply.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamBothRequest(arg: TestStreamBothRequest) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamBothRequest)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamBothRequest')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamBothRequest(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamBothRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_test_TestStreamBothReply(arg: TestStreamBothReply) {
|
||||||
|
if (!(arg instanceof pbFile.TestStreamBothReply)) {
|
||||||
|
throw new Error('Expected argument of type TestStreamBothReply')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_test_TestStreamBothReply(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.TestStreamBothReply.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const TestServiceService = {
|
||||||
|
|
||||||
|
testNoStream: {
|
||||||
|
path: '/test.TestService/TestNoStream',
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestType: pbFile.TestNoStreamRequest,
|
||||||
|
responseType: pbFile.TestNoStreamReply,
|
||||||
|
requestSerialize: serialize_test_TestNoStreamRequest,
|
||||||
|
requestDeserialize: deserialize_test_TestNoStreamRequest,
|
||||||
|
responseSerialize: serialize_test_TestNoStreamReply,
|
||||||
|
responseDeserialize: deserialize_test_TestNoStreamReply,
|
||||||
|
},
|
||||||
|
testStreamRequest: {
|
||||||
|
path: '/test.TestService/TestStreamRequest',
|
||||||
|
requestStream: true,
|
||||||
|
responseStream: false,
|
||||||
|
requestType: pbFile.TestStreamRequestRequest,
|
||||||
|
responseType: pbFile.TestStreamRequestReply,
|
||||||
|
requestSerialize: serialize_test_TestStreamRequestRequest,
|
||||||
|
requestDeserialize: deserialize_test_TestStreamRequestRequest,
|
||||||
|
responseSerialize: serialize_test_TestStreamRequestReply,
|
||||||
|
responseDeserialize: deserialize_test_TestStreamRequestReply,
|
||||||
|
},
|
||||||
|
testStreamReply: {
|
||||||
|
path: '/test.TestService/TestStreamReply',
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: true,
|
||||||
|
requestType: pbFile.TestStreamReplyRequest,
|
||||||
|
responseType: pbFile.TestStreamReplyReply,
|
||||||
|
requestSerialize: serialize_test_TestStreamReplyRequest,
|
||||||
|
requestDeserialize: deserialize_test_TestStreamReplyRequest,
|
||||||
|
responseSerialize: serialize_test_TestStreamReplyReply,
|
||||||
|
responseDeserialize: deserialize_test_TestStreamReplyReply,
|
||||||
|
},
|
||||||
|
testStreamBoth: {
|
||||||
|
path: '/test.TestService/TestStreamBoth',
|
||||||
|
requestStream: true,
|
||||||
|
responseStream: true,
|
||||||
|
requestType: pbFile.TestStreamBothRequest,
|
||||||
|
responseType: pbFile.TestStreamBothReply,
|
||||||
|
requestSerialize: serialize_test_TestStreamBothRequest,
|
||||||
|
requestDeserialize: deserialize_test_TestStreamBothRequest,
|
||||||
|
responseSerialize: serialize_test_TestStreamBothReply,
|
||||||
|
responseDeserialize: deserialize_test_TestStreamBothReply,
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TestServiceClient = grpc.makeGenericClientConstructor(TestServiceService)
|
@@ -11,6 +11,11 @@ service TestService {
|
|||||||
rpc TestStreamBoth(stream TestStreamBothRequest) returns (stream TestStreamBothReply);
|
rpc TestStreamBoth(stream TestStreamBothRequest) returns (stream TestStreamBothReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TestEnum {
|
||||||
|
ELEMENT_A = 0;
|
||||||
|
ELEMENT_B = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message TestMessage {
|
message TestMessage {
|
||||||
string a = 1;
|
string a = 1;
|
||||||
int32 b = 2;
|
int32 b = 2;
|
||||||
@@ -22,6 +27,10 @@ message TestMessage {
|
|||||||
repeated int64 p = 16;
|
repeated int64 p = 16;
|
||||||
repeated float q = 17;
|
repeated float q = 17;
|
||||||
repeated double r = 18;
|
repeated double r = 18;
|
||||||
|
enum s {
|
||||||
|
ELEMENT_C = 0;
|
||||||
|
ELEMENT_D = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message TestNoStreamRequest { TestMessage message = 1; }
|
message TestNoStreamRequest { TestMessage message = 1; }
|
@@ -0,0 +1,58 @@
|
|||||||
|
// @flow
|
||||||
|
// GENERATED CODE -- DO NOT EDIT!
|
||||||
|
{{$Package:=.File.Package}}
|
||||||
|
import grpc from 'grpc'
|
||||||
|
import pbFile from './pbFile.js'
|
||||||
|
{{range .File.EnumType}}
|
||||||
|
export type {{.Name}} = {{range .Value}}
|
||||||
|
| '{{.Name}}'{{end}}
|
||||||
|
;{{end}}
|
||||||
|
{{range .File.MessageType}}
|
||||||
|
export type {{.Name}} = {|{{range .Field}}
|
||||||
|
{{.Name}}?: {{. | jsType}};{{end}}{{range .EnumType}}
|
||||||
|
{{.Name}}?:{{range .Value}}
|
||||||
|
| '{{.Name}}'{{end}}
|
||||||
|
;{{end}}
|
||||||
|
|};
|
||||||
|
{{end}}
|
||||||
|
{{range .File.Service}}{{range .Method}}
|
||||||
|
function serialize_{{$Package}}_{{.InputType | shortType}}(arg: {{.InputType | shortType}}) {
|
||||||
|
if (!(arg instanceof pbFile.{{.InputType | shortType}})) {
|
||||||
|
throw new Error('Expected argument of type {{.InputType | shortType}}')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_{{$Package}}_{{.InputType | shortType}}(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.{{.InputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg: {{.OutputType | shortType}}) {
|
||||||
|
if (!(arg instanceof pbFile.{{.OutputType | shortType}})) {
|
||||||
|
throw new Error('Expected argument of type {{.OutputType | shortType}}')
|
||||||
|
}
|
||||||
|
return new Buffer(arg.serializeBinary())
|
||||||
|
}
|
||||||
|
|
||||||
|
function deserialize_{{$Package}}_{{.OutputType | shortType}}(buffer_arg: Array<number>) {
|
||||||
|
return pbFile.{{.OutputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
|
||||||
|
}
|
||||||
|
{{end}}{{end}}
|
||||||
|
{{range .File.Service}}
|
||||||
|
export const {{.Name}}Service = {
|
||||||
|
{{$serviceName:=.Name}}
|
||||||
|
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
||||||
|
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
||||||
|
requestStream: {{.ClientStreaming | default "false"}},
|
||||||
|
responseStream: {{.ServerStreaming | default "false"}},
|
||||||
|
requestType: pbFile.{{.InputType | shortType}},
|
||||||
|
responseType: pbFile.{{.OutputType | shortType}},
|
||||||
|
requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}},
|
||||||
|
requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}},
|
||||||
|
responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}},
|
||||||
|
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}},
|
||||||
|
},
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const {{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service){{end}}
|
@@ -1,146 +0,0 @@
|
|||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
var grpc = require('grpc');
|
|
||||||
var test_pb = require('./test_pb.js');
|
|
||||||
|
|
||||||
|
|
||||||
function serialize_test_TestNoStreamRequest(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestNoStreamRequest)) {
|
|
||||||
throw new Error('Expected argument of type test.TestNoStreamRequest');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamRequest(buffer_arg) {
|
|
||||||
return test_pb.TestNoStreamRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestNoStreamReply(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestNoStreamReply)) {
|
|
||||||
throw new Error('Expected argument of type test.TestNoStreamReply');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamReply(buffer_arg) {
|
|
||||||
return test_pb.TestNoStreamReply.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestRequest(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamRequestRequest)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamRequestRequest');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestRequest(buffer_arg) {
|
|
||||||
return test_pb.TestStreamRequestRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestReply(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamRequestReply)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamRequestReply');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestReply(buffer_arg) {
|
|
||||||
return test_pb.TestStreamRequestReply.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyRequest(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamReplyRequest)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamReplyRequest');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyRequest(buffer_arg) {
|
|
||||||
return test_pb.TestStreamReplyRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyReply(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamReplyReply)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamReplyReply');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyReply(buffer_arg) {
|
|
||||||
return test_pb.TestStreamReplyReply.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamBothRequest(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamBothRequest)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamBothRequest');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothRequest(buffer_arg) {
|
|
||||||
return test_pb.TestStreamBothRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_test_TestStreamBothReply(arg) {
|
|
||||||
if (!(arg instanceof test_pb.TestStreamBothReply)) {
|
|
||||||
throw new Error('Expected argument of type test.TestStreamBothReply');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothReply(buffer_arg) {
|
|
||||||
return test_pb.TestStreamBothReply.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var TestServiceService = exports.TestServiceService = {
|
|
||||||
|
|
||||||
testNoStream: {
|
|
||||||
path: '/test.TestService/TestNoStream',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: test_pb.TestNoStreamRequest,
|
|
||||||
responseType: test_pb.TestNoStreamReply,
|
|
||||||
requestSerialize: serialize_test_TestNoStreamRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestNoStreamRequest,
|
|
||||||
responseSerialize: serialize_test_TestNoStreamReply,
|
|
||||||
responseDeserialize: deserialize_test_TestNoStreamReply,
|
|
||||||
},
|
|
||||||
testStreamRequest: {
|
|
||||||
path: '/test.TestService/TestStreamRequest',
|
|
||||||
requestStream: true,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: test_pb.TestStreamRequestRequest,
|
|
||||||
responseType: test_pb.TestStreamRequestReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamRequestRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamRequestRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamRequestReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamRequestReply,
|
|
||||||
},
|
|
||||||
testStreamReply: {
|
|
||||||
path: '/test.TestService/TestStreamReply',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: true,
|
|
||||||
requestType: test_pb.TestStreamReplyRequest,
|
|
||||||
responseType: test_pb.TestStreamReplyReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamReplyRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamReplyRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamReplyReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamReplyReply,
|
|
||||||
},
|
|
||||||
testStreamBoth: {
|
|
||||||
path: '/test.TestService/TestStreamBoth',
|
|
||||||
requestStream: true,
|
|
||||||
responseStream: true,
|
|
||||||
requestType: test_pb.TestStreamBothRequest,
|
|
||||||
responseType: test_pb.TestStreamBothReply,
|
|
||||||
requestSerialize: serialize_test_TestStreamBothRequest,
|
|
||||||
requestDeserialize: deserialize_test_TestStreamBothRequest,
|
|
||||||
responseSerialize: serialize_test_TestStreamBothReply,
|
|
||||||
responseDeserialize: deserialize_test_TestStreamBothReply,
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.TestServiceClient = grpc.makeGenericClientConstructor(TestServiceService);
|
|
@@ -1,47 +0,0 @@
|
|||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
{{$Package:=.File.Package}}
|
|
||||||
'use strict';
|
|
||||||
var grpc = require('grpc');
|
|
||||||
var {{$Package}}_pb = require('./{{$Package}}_pb.js');
|
|
||||||
|
|
||||||
{{range .File.Service}}{{range .Method}}
|
|
||||||
function serialize_{{$Package}}_{{.InputType | splitArray "." | last}}(arg) {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.InputType | splitArray "." | last}})) {
|
|
||||||
throw new Error('Expected argument of type {{$Package}}.{{.InputType | splitArray "." | last}}');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.InputType | splitArray "." | last}}(buffer_arg) {
|
|
||||||
return {{$Package}}_pb.{{.InputType | splitArray "." | last}}.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_{{$Package}}_{{.OutputType | splitArray "." | last}}(arg) {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.OutputType | splitArray "." | last}})) {
|
|
||||||
throw new Error('Expected argument of type {{$Package}}.{{.OutputType | splitArray "." | last}}');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.OutputType | splitArray "." | last}}(buffer_arg) {
|
|
||||||
return {{$Package}}_pb.{{.OutputType | splitArray "." | last}}.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
{{end}}{{end}}
|
|
||||||
{{range .File.Service}}
|
|
||||||
var {{.Name}}Service = exports.{{.Name}}Service = {
|
|
||||||
{{$serviceName:=.Name}}
|
|
||||||
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
|
||||||
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
|
||||||
requestStream: {{.ClientStreaming | default "false"}},
|
|
||||||
responseStream: {{.ServerStreaming | default "false"}},
|
|
||||||
requestType: {{$Package}}_pb.{{.InputType | splitArray "." | last}},
|
|
||||||
responseType: {{$Package}}_pb.{{.OutputType | splitArray "." | last}},
|
|
||||||
requestSerialize: serialize_{{$Package}}_{{.InputType | splitArray "." | last}},
|
|
||||||
requestDeserialize: deserialize_{{$Package}}_{{.InputType | splitArray "." | last}},
|
|
||||||
responseSerialize: serialize_{{$Package}}_{{.OutputType | splitArray "." | last}},
|
|
||||||
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | splitArray "." | last}},
|
|
||||||
},
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.{{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service);{{end}}
|
|
@@ -1,44 +0,0 @@
|
|||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
{{$Package:=.File.Package}}
|
|
||||||
'use strict';
|
|
||||||
var grpc = require('grpc');
|
|
||||||
var {{$Package}}_pb = require('./{{$Package}}_pb.js');
|
|
||||||
{{range .File.Service}}{{range .Method}}
|
|
||||||
function serialize_{{$Package}}_{{.InputType | splitArray "." | last}}(arg) {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.InputType | splitArray "." | last}})) {
|
|
||||||
throw new Error('Expected argument of type {{$Package}}.{{.InputType | splitArray "." | last}}');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.InputType | splitArray "." | last}}(buffer_arg) {
|
|
||||||
return {{$Package}}_pb.{{.InputType | splitArray "." | last}}.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_{{$Package}}_{{.OutputType | splitArray "." | last}}(arg) {
|
|
||||||
if (!(arg instanceof {{$Package}}_pb.{{.OutputType | splitArray "." | last}})) {
|
|
||||||
throw new Error('Expected argument of type {{$Package}}.{{.OutputType | splitArray "." | last}}');
|
|
||||||
}
|
|
||||||
return new Buffer(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.OutputType | splitArray "." | last}}(buffer_arg) {
|
|
||||||
return {{$Package}}_pb.{{.OutputType | splitArray "." | last}}.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
{{end}}{{end}}
|
|
||||||
{{range .File.Service}}
|
|
||||||
var {{.Name}}Service = exports.{{.Name}}Service = {
|
|
||||||
{{$serviceName:=.Name}}{{range .Method}}{{.Name | lowerCamelCase}}: {
|
|
||||||
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
|
||||||
requestStream: {{.ClientStreaming | default "false"}},
|
|
||||||
responseStream: {{.ServerStreaming | default "false"}},
|
|
||||||
requestType: {{$Package}}_pb.{{.InputType | splitArray "." | last}},
|
|
||||||
responseType: {{$Package}}_pb.{{.OutputType | splitArray "." | last}},
|
|
||||||
requestSerialize: serialize_{{$Package}}_{{.InputType | splitArray "." | last}},
|
|
||||||
requestDeserialize: deserialize_{{$Package}}_{{.InputType | splitArray "." | last}},
|
|
||||||
responseSerialize: serialize_{{$Package}}_{{.OutputType | splitArray "." | last}},
|
|
||||||
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | splitArray "." | last}},
|
|
||||||
},{{end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.{{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service);{{end}}
|
|
58
helpers.go
58
helpers.go
@@ -44,11 +44,18 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
return strings.ToLower(s[:1]) + s[1:]
|
return strings.ToLower(s[:1]) + s[1:]
|
||||||
},
|
},
|
||||||
"camelCase": func(s string) string {
|
"camelCase": func(s string) string {
|
||||||
|
if len(s) > 1 {
|
||||||
return xstrings.ToCamelCase(s)
|
return xstrings.ToCamelCase(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ToUpper(s[:1])
|
||||||
},
|
},
|
||||||
"lowerCamelCase": func(s string) string {
|
"lowerCamelCase": func(s string) string {
|
||||||
cc := xstrings.ToCamelCase(s)
|
if len(s) > 1 {
|
||||||
return strings.ToLower(cc[:1]) + cc[1:]
|
s = xstrings.ToCamelCase(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ToLower(s[:1]) + s[1:]
|
||||||
},
|
},
|
||||||
"snakeCase": func(s string) string {
|
"snakeCase": func(s string) string {
|
||||||
return xstrings.ToSnakeCase(s)
|
return xstrings.ToSnakeCase(s)
|
||||||
@@ -60,8 +67,10 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"isFieldMessage": isFieldMessage,
|
"isFieldMessage": isFieldMessage,
|
||||||
"isFieldRepeated": isFieldRepeated,
|
"isFieldRepeated": isFieldRepeated,
|
||||||
"goType": goType,
|
"goType": goType,
|
||||||
|
"jsType": jsType,
|
||||||
"httpVerb": httpVerb,
|
"httpVerb": httpVerb,
|
||||||
"httpPath": httpPath,
|
"httpPath": httpPath,
|
||||||
|
"shortType": shortType,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -71,9 +80,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMessageType(f *descriptor.FileDescriptorProto, name string) *descriptor.DescriptorProto {
|
func getMessageType(f *descriptor.FileDescriptorProto, name string) *descriptor.DescriptorProto {
|
||||||
|
// name is in the form .packageName.MessageTypeName.InnerMessageTypeName...
|
||||||
|
// e.g. .article.ProductTag
|
||||||
|
splits := strings.Split(name, ".")
|
||||||
|
target := splits[len(splits)-1]
|
||||||
for _, m := range f.MessageType {
|
for _, m := range f.MessageType {
|
||||||
// name usually contains the package name
|
if target == *m.Name {
|
||||||
if strings.HasSuffix(name, *m.Name) {
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,8 +94,7 @@ func getMessageType(f *descriptor.FileDescriptorProto, name string) *descriptor.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isFieldMessage(f *descriptor.FieldDescriptorProto) bool {
|
func isFieldMessage(f *descriptor.FieldDescriptorProto) bool {
|
||||||
if f.Type != nil && *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE &&
|
if f.Type != nil && *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE {
|
||||||
f.Label != nil && *f.Label != descriptor.FieldDescriptorProto_LABEL_REPEATED {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +141,41 @@ func goType(pkg string, f *descriptor.FieldDescriptorProto) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func jsType(f *descriptor.FieldDescriptorProto) string {
|
||||||
|
template := "%s"
|
||||||
|
if isFieldRepeated(f) == true {
|
||||||
|
template = "Array<%s>"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch *f.Type {
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||||
|
return fmt.Sprintf(template, shortType(*f.TypeName))
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_FLOAT,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_INT64,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_UINT64,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_INT32,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_FIXED64,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_FIXED32,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_UINT32,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_SFIXED32,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_SFIXED64,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_SINT32,
|
||||||
|
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||||
|
return fmt.Sprintf(template, "number")
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||||
|
return fmt.Sprintf(template, "boolean")
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||||
|
return fmt.Sprintf(template, "Array<number>")
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||||
|
return fmt.Sprintf(template, "string")
|
||||||
|
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
||||||
|
return fmt.Sprintf(template, "Object")
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf(template, "any")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func shortType(s string) string {
|
func shortType(s string) string {
|
||||||
t := strings.Split(s, ".")
|
t := strings.Split(s, ".")
|
||||||
return t[len(t)-1]
|
return t[len(t)-1]
|
||||||
|
Reference in New Issue
Block a user