Merge pull request #40 from moul/feature/flow-output
Feature/flow output
This commit is contained in:
commit
6cbc8f35eb
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}}
|
|
47
helpers.go
47
helpers.go
@ -70,6 +70,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
"jsType": jsType,
|
"jsType": jsType,
|
||||||
"httpVerb": httpVerb,
|
"httpVerb": httpVerb,
|
||||||
"httpPath": httpPath,
|
"httpPath": httpPath,
|
||||||
|
"shortType": shortType,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -141,31 +142,37 @@ func goType(pkg string, f *descriptor.FieldDescriptorProto) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func jsType(f *descriptor.FieldDescriptorProto) string {
|
func jsType(f *descriptor.FieldDescriptorProto) string {
|
||||||
|
template := "%s"
|
||||||
|
if isFieldRepeated(f) == true {
|
||||||
|
template = "Array<%s>"
|
||||||
|
}
|
||||||
|
|
||||||
switch *f.Type {
|
switch *f.Type {
|
||||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
|
||||||
return "number"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
|
||||||
return "number"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_INT64:
|
|
||||||
return "number"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_UINT64:
|
|
||||||
return "number"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_INT32:
|
|
||||||
return "number"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
|
||||||
return "boolean"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
|
||||||
return "string"
|
|
||||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||||
return "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:
|
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||||
return "number"
|
return fmt.Sprintf(template, "Array<number>")
|
||||||
case descriptor.FieldDescriptorProto_TYPE_UINT32:
|
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||||
return "number"
|
return fmt.Sprintf(template, "string")
|
||||||
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
||||||
return "message"
|
return fmt.Sprintf(template, "Object")
|
||||||
default:
|
default:
|
||||||
return "object"
|
return fmt.Sprintf(template, "any")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user