Merge pull request #42 from moul/feature/flow-getter-setter
Feature/flow getter setter
This commit is contained in:
commit
4d3b9c31b6
@ -1,305 +1,311 @@
|
|||||||
// @flow
|
// @flow
|
||||||
// GENERATED CODE -- DO NOT EDIT!
|
// GENERATED CODE -- DO NOT EDIT!
|
||||||
|
|
||||||
import grpc from 'grpc'
|
import base64 from 'base64-js'
|
||||||
import pbFile from './pbFile.js'
|
import test_pb from './test_pb'
|
||||||
|
|
||||||
|
|
||||||
export type TestEnum = {|
|
export type TestEnum = {|
|
||||||
|
|
||||||
ELEMENT_A?: 0;
|
ELEMENT_A?: 0;
|
||||||
|
|
||||||
ELEMENT_B?: 1;
|
ELEMENT_B?: 1;
|
||||||
|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type TestMessage$TestNestedEnum = {|
|
export type TestMessage$TestNestedEnum = {|
|
||||||
|
|
||||||
ELEMENT_C?: 0;
|
ELEMENT_C?: 0;
|
||||||
|
|
||||||
ELEMENT_D?: 1;
|
ELEMENT_D?: 1;
|
||||||
|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
|
||||||
|
export type TestMessage$TestNestedMessage = {
|
||||||
|
getS?: () => string;
|
||||||
|
setS?: (s: string) => void;
|
||||||
|
getT?: () => number;
|
||||||
|
setT?: (t: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
export type TestMessage$TestNestedMessage = {|
|
export type TestMessage = {
|
||||||
|
getA?: () => string;
|
||||||
s?: string;
|
setA?: (a: string) => void;
|
||||||
|
getB?: () => number;
|
||||||
t?: number;
|
setB?: (b: number) => void;
|
||||||
|
getC?: () => number;
|
||||||
|};
|
setC?: (c: number) => void;
|
||||||
|
getD?: () => number;
|
||||||
|
setD?: (d: number) => void;
|
||||||
export type TestMessage = {|
|
getE?: () => number;
|
||||||
|
setE?: (e: number) => void;
|
||||||
a?: string;
|
getNList?: () => Array<string>;
|
||||||
|
setNList?: (n: Array<string>) => void;
|
||||||
b?: number;
|
addN?: (n: string) => void;
|
||||||
|
clearNList?: () => void;
|
||||||
c?: number;
|
getOList?: () => Array<number>;
|
||||||
|
setOList?: (o: Array<number>) => void;
|
||||||
d?: number;
|
addO?: (o: number) => void;
|
||||||
|
clearOList?: () => void;
|
||||||
e?: number;
|
getPList?: () => Array<number>;
|
||||||
|
setPList?: (p: Array<number>) => void;
|
||||||
n?: Array<string>;
|
addP?: (p: number) => void;
|
||||||
|
clearPList?: () => void;
|
||||||
o?: Array<number>;
|
getQList?: () => Array<number>;
|
||||||
|
setQList?: (q: Array<number>) => void;
|
||||||
p?: Array<number>;
|
addQ?: (q: number) => void;
|
||||||
|
clearQList?: () => void;
|
||||||
q?: Array<number>;
|
getRList?: () => Array<number>;
|
||||||
|
setRList?: (r: Array<number>) => void;
|
||||||
r?: Array<number>;
|
addR?: (r: number) => void;
|
||||||
|
clearRList?: () => void;
|
||||||
u?: TestEnum;
|
getU?: () => TestEnum;
|
||||||
|
setU?: (u: TestEnum) => void;
|
||||||
v?: TestMessage$TestNestedEnum;
|
getV?: () => TestMessage$TestNestedEnum;
|
||||||
|
setV?: (v: TestMessage$TestNestedEnum) => void;
|
||||||
w?: Array<TestMessage$TestNestedMessage>;
|
getWList?: () => Array<TestMessage$TestNestedMessage>;
|
||||||
|
setWList?: (w: Array<TestMessage$TestNestedMessage>) => void;
|
||||||
|};
|
addW?: (w: TestMessage$TestNestedMessage) => void;
|
||||||
|
clearWList?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestNoStreamRequest = {
|
||||||
export type TestNoStreamRequest = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestNoStreamReply = {
|
||||||
export type TestNoStreamReply = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
err_msg?: string;
|
getErrMsg?: () => string;
|
||||||
|
setErrMsg?: (err_msg: string) => void;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamRequestRequest = {
|
||||||
export type TestStreamRequestRequest = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamRequestReply = {
|
||||||
export type TestStreamRequestReply = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
err_msg?: string;
|
getErrMsg?: () => string;
|
||||||
|
setErrMsg?: (err_msg: string) => void;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamReplyRequest = {
|
||||||
export type TestStreamReplyRequest = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamReplyReply = {
|
||||||
export type TestStreamReplyReply = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
err_msg?: string;
|
getErrMsg?: () => string;
|
||||||
|
setErrMsg?: (err_msg: string) => void;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamBothRequest = {
|
||||||
export type TestStreamBothRequest = {|
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
message?: TestMessage;
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
|};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export type TestStreamBothReply = {
|
||||||
|
getMessage?: () => TestMessage;
|
||||||
|
setMessage?: (message: TestMessage) => void;
|
||||||
|
clearMessage?: () => void;
|
||||||
|
hasMessage?: () => boolean;
|
||||||
|
getErrMsg?: () => string;
|
||||||
|
setErrMsg?: (err_msg: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
export type TestStreamBothReply = {|
|
const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray)
|
||||||
|
const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))
|
||||||
message?: TestMessage;
|
|
||||||
|
|
||||||
err_msg?: string;
|
|
||||||
|
|
||||||
|};
|
|
||||||
|
|
||||||
|
|
||||||
|
function serialize_test_TestNoStreamRequest(arg : TestNoStreamRequest): string {
|
||||||
function serialize_test_TestNoStreamRequest(arg: TestNoStreamRequest) {
|
if (!(arg instanceof test_pb.TestNoStreamRequest)) {
|
||||||
if (!(arg instanceof pbFile.TestNoStreamRequest)) {
|
|
||||||
throw new Error('Expected argument of type TestNoStreamRequest')
|
throw new Error('Expected argument of type TestNoStreamRequest')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamRequest(buffer_arg: Array<number>) {
|
function deserialize_test_TestNoStreamRequest(base64Encoded: string): TestNoStreamRequest {
|
||||||
return pbFile.TestNoStreamRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestNoStreamRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestNoStreamReply(arg: TestNoStreamReply) {
|
function serialize_test_TestNoStreamReply(arg : TestNoStreamReply): string {
|
||||||
if (!(arg instanceof pbFile.TestNoStreamReply)) {
|
if (!(arg instanceof test_pb.TestNoStreamReply)) {
|
||||||
throw new Error('Expected argument of type TestNoStreamReply')
|
throw new Error('Expected argument of type TestNoStreamReply')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestNoStreamReply(buffer_arg: Array<number>) {
|
function deserialize_test_TestNoStreamReply(base64Encoded: string): TestNoStreamReply {
|
||||||
return pbFile.TestNoStreamReply.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestNoStreamReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestRequest(arg: TestStreamRequestRequest) {
|
|
||||||
if (!(arg instanceof pbFile.TestStreamRequestRequest)) {
|
function serialize_test_TestStreamRequestRequest(arg : TestStreamRequestRequest): string {
|
||||||
|
if (!(arg instanceof test_pb.TestStreamRequestRequest)) {
|
||||||
throw new Error('Expected argument of type TestStreamRequestRequest')
|
throw new Error('Expected argument of type TestStreamRequestRequest')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestRequest(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamRequestRequest(base64Encoded: string): TestStreamRequestRequest {
|
||||||
return pbFile.TestStreamRequestRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamRequestRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamRequestReply(arg: TestStreamRequestReply) {
|
function serialize_test_TestStreamRequestReply(arg : TestStreamRequestReply): string {
|
||||||
if (!(arg instanceof pbFile.TestStreamRequestReply)) {
|
if (!(arg instanceof test_pb.TestStreamRequestReply)) {
|
||||||
throw new Error('Expected argument of type TestStreamRequestReply')
|
throw new Error('Expected argument of type TestStreamRequestReply')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamRequestReply(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamRequestReply(base64Encoded: string): TestStreamRequestReply {
|
||||||
return pbFile.TestStreamRequestReply.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamRequestReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyRequest(arg: TestStreamReplyRequest) {
|
|
||||||
if (!(arg instanceof pbFile.TestStreamReplyRequest)) {
|
function serialize_test_TestStreamReplyRequest(arg : TestStreamReplyRequest): string {
|
||||||
|
if (!(arg instanceof test_pb.TestStreamReplyRequest)) {
|
||||||
throw new Error('Expected argument of type TestStreamReplyRequest')
|
throw new Error('Expected argument of type TestStreamReplyRequest')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyRequest(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamReplyRequest(base64Encoded: string): TestStreamReplyRequest {
|
||||||
return pbFile.TestStreamReplyRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamReplyRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamReplyReply(arg: TestStreamReplyReply) {
|
function serialize_test_TestStreamReplyReply(arg : TestStreamReplyReply): string {
|
||||||
if (!(arg instanceof pbFile.TestStreamReplyReply)) {
|
if (!(arg instanceof test_pb.TestStreamReplyReply)) {
|
||||||
throw new Error('Expected argument of type TestStreamReplyReply')
|
throw new Error('Expected argument of type TestStreamReplyReply')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamReplyReply(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamReplyReply(base64Encoded: string): TestStreamReplyReply {
|
||||||
return pbFile.TestStreamReplyReply.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamReplyReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamBothRequest(arg: TestStreamBothRequest) {
|
|
||||||
if (!(arg instanceof pbFile.TestStreamBothRequest)) {
|
function serialize_test_TestStreamBothRequest(arg : TestStreamBothRequest): string {
|
||||||
|
if (!(arg instanceof test_pb.TestStreamBothRequest)) {
|
||||||
throw new Error('Expected argument of type TestStreamBothRequest')
|
throw new Error('Expected argument of type TestStreamBothRequest')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothRequest(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamBothRequest(base64Encoded: string): TestStreamBothRequest {
|
||||||
return pbFile.TestStreamBothRequest.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamBothRequest.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_test_TestStreamBothReply(arg: TestStreamBothReply) {
|
function serialize_test_TestStreamBothReply(arg : TestStreamBothReply): string {
|
||||||
if (!(arg instanceof pbFile.TestStreamBothReply)) {
|
if (!(arg instanceof test_pb.TestStreamBothReply)) {
|
||||||
throw new Error('Expected argument of type TestStreamBothReply')
|
throw new Error('Expected argument of type TestStreamBothReply')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_test_TestStreamBothReply(buffer_arg: Array<number>) {
|
function deserialize_test_TestStreamBothReply(base64Encoded: string): TestStreamBothReply {
|
||||||
return pbFile.TestStreamBothReply.deserializeBinary(new Uint8Array(buffer_arg))
|
return test_pb.TestStreamBothReply.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const TestServiceService = {
|
export default {
|
||||||
|
|
||||||
testNoStream: {
|
TestService: {
|
||||||
path: '/test.TestService/TestNoStream',
|
|
||||||
requestStream: false,
|
testNoStream: {
|
||||||
responseStream: false,
|
path: '/test.TestService/TestNoStream',
|
||||||
requestType: pbFile.TestNoStreamRequest,
|
requestStream: false,
|
||||||
responseType: pbFile.TestNoStreamReply,
|
responseStream: false,
|
||||||
requestSerialize: serialize_test_TestNoStreamRequest,
|
requestType: test_pb.TestNoStreamRequest,
|
||||||
requestDeserialize: deserialize_test_TestNoStreamRequest,
|
responseType: test_pb.TestNoStreamReply,
|
||||||
responseSerialize: serialize_test_TestNoStreamReply,
|
requestSerialize: serialize_test_TestNoStreamRequest,
|
||||||
responseDeserialize: deserialize_test_TestNoStreamReply,
|
requestDeserialize: deserialize_test_TestNoStreamRequest,
|
||||||
},
|
responseSerialize: serialize_test_TestNoStreamReply,
|
||||||
testStreamRequest: {
|
responseDeserialize: deserialize_test_TestNoStreamReply,
|
||||||
path: '/test.TestService/TestStreamRequest',
|
},
|
||||||
requestStream: true,
|
testStreamRequest: {
|
||||||
responseStream: false,
|
path: '/test.TestService/TestStreamRequest',
|
||||||
requestType: pbFile.TestStreamRequestRequest,
|
requestStream: true,
|
||||||
responseType: pbFile.TestStreamRequestReply,
|
responseStream: false,
|
||||||
requestSerialize: serialize_test_TestStreamRequestRequest,
|
requestType: test_pb.TestStreamRequestRequest,
|
||||||
requestDeserialize: deserialize_test_TestStreamRequestRequest,
|
responseType: test_pb.TestStreamRequestReply,
|
||||||
responseSerialize: serialize_test_TestStreamRequestReply,
|
requestSerialize: serialize_test_TestStreamRequestRequest,
|
||||||
responseDeserialize: deserialize_test_TestStreamRequestReply,
|
requestDeserialize: deserialize_test_TestStreamRequestRequest,
|
||||||
},
|
responseSerialize: serialize_test_TestStreamRequestReply,
|
||||||
testStreamReply: {
|
responseDeserialize: deserialize_test_TestStreamRequestReply,
|
||||||
path: '/test.TestService/TestStreamReply',
|
},
|
||||||
requestStream: false,
|
testStreamReply: {
|
||||||
responseStream: true,
|
path: '/test.TestService/TestStreamReply',
|
||||||
requestType: pbFile.TestStreamReplyRequest,
|
requestStream: false,
|
||||||
responseType: pbFile.TestStreamReplyReply,
|
responseStream: true,
|
||||||
requestSerialize: serialize_test_TestStreamReplyRequest,
|
requestType: test_pb.TestStreamReplyRequest,
|
||||||
requestDeserialize: deserialize_test_TestStreamReplyRequest,
|
responseType: test_pb.TestStreamReplyReply,
|
||||||
responseSerialize: serialize_test_TestStreamReplyReply,
|
requestSerialize: serialize_test_TestStreamReplyRequest,
|
||||||
responseDeserialize: deserialize_test_TestStreamReplyReply,
|
requestDeserialize: deserialize_test_TestStreamReplyRequest,
|
||||||
},
|
responseSerialize: serialize_test_TestStreamReplyReply,
|
||||||
testStreamBoth: {
|
responseDeserialize: deserialize_test_TestStreamReplyReply,
|
||||||
path: '/test.TestService/TestStreamBoth',
|
},
|
||||||
requestStream: true,
|
testStreamBoth: {
|
||||||
responseStream: true,
|
path: '/test.TestService/TestStreamBoth',
|
||||||
requestType: pbFile.TestStreamBothRequest,
|
requestStream: true,
|
||||||
responseType: pbFile.TestStreamBothReply,
|
responseStream: true,
|
||||||
requestSerialize: serialize_test_TestStreamBothRequest,
|
requestType: test_pb.TestStreamBothRequest,
|
||||||
requestDeserialize: deserialize_test_TestStreamBothRequest,
|
responseType: test_pb.TestStreamBothReply,
|
||||||
responseSerialize: serialize_test_TestStreamBothReply,
|
requestSerialize: serialize_test_TestStreamBothRequest,
|
||||||
responseDeserialize: deserialize_test_TestStreamBothReply,
|
requestDeserialize: deserialize_test_TestStreamBothRequest,
|
||||||
},
|
responseSerialize: serialize_test_TestStreamBothReply,
|
||||||
|
responseDeserialize: deserialize_test_TestStreamBothReply,
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TestServiceClient = grpc.makeGenericClientConstructor(TestServiceService)
|
|
||||||
|
@ -1,80 +1,110 @@
|
|||||||
// @flow
|
// @flow
|
||||||
// GENERATED CODE -- DO NOT EDIT!
|
// GENERATED CODE -- DO NOT EDIT!
|
||||||
{{$Package:=.File.Package}}
|
|
||||||
import grpc from 'grpc'
|
{{- $Package:=.File.Package}}
|
||||||
import pbFile from './pbFile.js'
|
|
||||||
|
import base64 from 'base64-js'
|
||||||
|
import {{$Package}}_pb from './{{$Package}}_pb'
|
||||||
|
|
||||||
|
{{- range .File.Dependency}}
|
||||||
|
import {{. | replace "/" "_" | trimSuffix ".proto" }}_pb from '../{{. | trimSuffix ".proto" }}_pb'
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
|
{{- define "fieldMethods"}}
|
||||||
|
{{- if isFieldRepeated .}}
|
||||||
|
get{{.Name | camelCase}}List?: () => {{. | jsType}};
|
||||||
|
set{{.Name | camelCase}}List?: ({{.Name}}: {{. | jsType}}) => void;
|
||||||
|
add{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType | trimPrefix "Array<" | trimSuffix ">"}}) => void;
|
||||||
|
clear{{.Name | camelCase}}List?: () => void;
|
||||||
|
{{- else}}
|
||||||
|
get{{.Name | camelCase}}?: () => {{. | jsType}};
|
||||||
|
set{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType}}) => void;
|
||||||
|
|
||||||
|
{{- if isFieldMessage .}}
|
||||||
|
clear{{.Name | camelCase}}?: () => void;
|
||||||
|
has{{.Name | camelCase}}?: () => boolean;
|
||||||
|
{{- end}}
|
||||||
|
{{- end}}
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
{{range .File.EnumType}}
|
{{range .File.EnumType}}
|
||||||
export type {{.Name}} = {|
|
export type {{.Name}} = {|
|
||||||
{{range .Value}}
|
{{- range .Value}}
|
||||||
{{.Name}}?: {{.Number}};
|
{{.Name}}?: {{.Number}};
|
||||||
{{end}}
|
{{- end}}
|
||||||
|};
|
|};
|
||||||
{{end}}
|
{{- end}}
|
||||||
|
|
||||||
|
{{- range .File.MessageType}}
|
||||||
|
{{- $MessageType := .Name}}
|
||||||
|
|
||||||
{{range .File.MessageType}}
|
|
||||||
{{$MessageType := .Name}}
|
|
||||||
{{range .EnumType}}
|
{{range .EnumType}}
|
||||||
export type {{$MessageType}}${{.Name}} = {|
|
export type {{$MessageType}}${{.Name}} = {|
|
||||||
{{range .Value}}
|
{{- range .Value}}
|
||||||
{{.Name}}?: {{.Number}};
|
{{.Name}}?: {{.Number}};
|
||||||
{{end}}
|
{{- end}}
|
||||||
|};
|
|};
|
||||||
{{end}}
|
{{- end}}
|
||||||
|
|
||||||
{{range .NestedType}}
|
{{range .NestedType}}
|
||||||
export type {{$MessageType}}${{.Name}} = {|
|
export type {{$MessageType}}${{.Name}} = {
|
||||||
{{range .Field}}
|
{{- range .Field}}
|
||||||
{{.Name}}?: {{. | jsType}};
|
{{- template "fieldMethods" .}}
|
||||||
{{end}}
|
{{- end}}
|
||||||
|};
|
};
|
||||||
{{end}}
|
{{- end}}
|
||||||
|
|
||||||
export type {{.Name}} = {|
|
export type {{.Name}} = {
|
||||||
{{range .Field}}
|
{{- range .Field}}
|
||||||
{{.Name}}?: {{. | jsType}};
|
{{- template "fieldMethods" .}}
|
||||||
{{end}}
|
{{- end}}
|
||||||
|};
|
};
|
||||||
{{end}}
|
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
|
const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray)
|
||||||
|
const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))
|
||||||
|
|
||||||
{{range .File.Service}}{{range .Method}}
|
{{range .File.Service}}{{range .Method}}
|
||||||
function serialize_{{$Package}}_{{.InputType | shortType}}(arg: {{.InputType | shortType}}) {
|
function serialize_{{$Package}}_{{.InputType | shortType}}(arg : {{.InputType | shortType}}): string {
|
||||||
if (!(arg instanceof pbFile.{{.InputType | shortType}})) {
|
if (!(arg instanceof {{$Package}}_pb.{{.InputType | shortType}})) {
|
||||||
throw new Error('Expected argument of type {{.InputType | shortType}}')
|
throw new Error('Expected argument of type {{.InputType | shortType}}')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.InputType | shortType}}(buffer_arg: Array<number>) {
|
function deserialize_{{$Package}}_{{.InputType | shortType}}(base64Encoded: string): {{.InputType | shortType}} {
|
||||||
return pbFile.{{.InputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
|
return {{$Package}}_pb.{{.InputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg: {{.OutputType | shortType}}) {
|
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg : {{.OutputType | shortType}}): string {
|
||||||
if (!(arg instanceof pbFile.{{.OutputType | shortType}})) {
|
if (!(arg instanceof {{$Package}}_pb.{{.OutputType | shortType}})) {
|
||||||
throw new Error('Expected argument of type {{.OutputType | shortType}}')
|
throw new Error('Expected argument of type {{.OutputType | shortType}}')
|
||||||
}
|
}
|
||||||
return new Buffer(arg.serializeBinary())
|
return serializeToBase64(arg.serializeBinary())
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_{{$Package}}_{{.OutputType | shortType}}(buffer_arg: Array<number>) {
|
function deserialize_{{$Package}}_{{.OutputType | shortType}}(base64Encoded: string): {{.OutputType | shortType}} {
|
||||||
return pbFile.{{.OutputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
|
return {{$Package}}_pb.{{.OutputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
{{range .File.Service}}
|
export default {
|
||||||
export const {{.Name}}Service = {
|
{{range .File.Service}}
|
||||||
|
{{.Name}}: {
|
||||||
{{$serviceName:=.Name}}
|
{{$serviceName:=.Name}}
|
||||||
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
||||||
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
||||||
requestStream: {{.ClientStreaming | default "false"}},
|
requestStream: {{.ClientStreaming | default "false"}},
|
||||||
responseStream: {{.ServerStreaming | default "false"}},
|
responseStream: {{.ServerStreaming | default "false"}},
|
||||||
requestType: pbFile.{{.InputType | shortType}},
|
requestType: {{$Package}}_pb.{{.InputType | shortType}},
|
||||||
responseType: pbFile.{{.OutputType | shortType}},
|
responseType: {{$Package}}_pb.{{.OutputType | shortType}},
|
||||||
requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}},
|
requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}},
|
||||||
requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}},
|
requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}},
|
||||||
responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}},
|
responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}},
|
||||||
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}},
|
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}},
|
||||||
},
|
},
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const {{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service){{end}}
|
|
||||||
|
@ -57,12 +57,10 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
|
|
||||||
return strings.ToLower(s[:1]) + s[1:]
|
return strings.ToLower(s[:1]) + s[1:]
|
||||||
},
|
},
|
||||||
"snakeCase": func(s string) string {
|
|
||||||
return xstrings.ToSnakeCase(s)
|
|
||||||
},
|
|
||||||
"kebabCase": func(s string) string {
|
"kebabCase": func(s string) string {
|
||||||
return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
|
return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
|
||||||
},
|
},
|
||||||
|
"snakeCase": xstrings.ToSnakeCase,
|
||||||
"getMessageType": getMessageType,
|
"getMessageType": getMessageType,
|
||||||
"isFieldMessage": isFieldMessage,
|
"isFieldMessage": isFieldMessage,
|
||||||
"isFieldRepeated": isFieldRepeated,
|
"isFieldRepeated": isFieldRepeated,
|
||||||
@ -167,7 +165,7 @@ func jsType(f *descriptor.FieldDescriptorProto) string {
|
|||||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||||
return fmt.Sprintf(template, "boolean")
|
return fmt.Sprintf(template, "boolean")
|
||||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||||
return fmt.Sprintf(template, "Array<number>")
|
return fmt.Sprintf(template, "Uint8Array")
|
||||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||||
return fmt.Sprintf(template, "string")
|
return fmt.Sprintf(template, "string")
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user