protoc-gen-go-micro/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl

81 lines
2.4 KiB
Cheetah
Raw Normal View History

2017-01-05 20:06:24 +03:00
// @flow
2016-12-13 21:10:02 +03:00
// GENERATED CODE -- DO NOT EDIT!
2016-12-16 18:24:05 +03:00
{{$Package:=.File.Package}}
2017-01-05 20:06:24 +03:00
import grpc from 'grpc'
import pbFile from './pbFile.js'
2017-01-06 13:41:42 +03:00
{{range .File.EnumType}}
export type {{.Name}} = {|
{{range .Value}}
{{.Name}}?: {{.Number}};
{{end}}
|};
{{end}}
2017-01-05 20:06:24 +03:00
{{range .File.MessageType}}
2017-01-10 14:24:06 +03:00
{{$MessageType := .Name}}
{{range .EnumType}}
2017-01-10 14:24:06 +03:00
export type {{$MessageType}}${{.Name}} = {|
{{range .Value}}
{{.Name}}?: {{.Number}};
{{end}}
2017-01-05 20:06:24 +03:00
|};
{{end}}
{{range .NestedType}}
2017-01-10 14:24:06 +03:00
export type {{$MessageType}}${{.Name}} = {|
{{range .Field}}
{{.Name}}?: {{. | jsType}};
{{end}}
|};
{{end}}
export type {{.Name}} = {|
{{range .Field}}
{{.Name}}?: {{. | jsType}};
{{end}}
|};
{{end}}
{{range .File.Service}}{{range .Method}}
2017-01-05 20:06:24 +03:00
function serialize_{{$Package}}_{{.InputType | shortType}}(arg: {{.InputType | shortType}}) {
if (!(arg instanceof pbFile.{{.InputType | shortType}})) {
throw new Error('Expected argument of type {{.InputType | shortType}}')
}
2017-01-05 20:06:24 +03:00
return new Buffer(arg.serializeBinary())
2016-12-13 21:10:02 +03:00
}
2017-01-05 20:06:24 +03:00
function deserialize_{{$Package}}_{{.InputType | shortType}}(buffer_arg: Array<number>) {
return pbFile.{{.InputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
2016-12-13 21:10:02 +03:00
}
2017-01-05 20:06:24 +03:00
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg: {{.OutputType | shortType}}) {
if (!(arg instanceof pbFile.{{.OutputType | shortType}})) {
throw new Error('Expected argument of type {{.OutputType | shortType}}')
}
2017-01-05 20:06:24 +03:00
return new Buffer(arg.serializeBinary())
2016-12-13 21:10:02 +03:00
}
2017-01-05 20:06:24 +03:00
function deserialize_{{$Package}}_{{.OutputType | shortType}}(buffer_arg: Array<number>) {
return pbFile.{{.OutputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg))
2016-12-20 13:31:46 +03:00
}
{{end}}{{end}}
{{range .File.Service}}
2017-01-05 20:06:24 +03:00
export const {{.Name}}Service = {
2016-12-20 13:31:46 +03:00
{{$serviceName:=.Name}}
{{range .Method}}{{.Name | lowerCamelCase}}: {
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
requestStream: {{.ClientStreaming | default "false"}},
responseStream: {{.ServerStreaming | default "false"}},
2017-01-05 20:06:24 +03:00
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}},
2016-12-20 13:31:46 +03:00
},
{{end}}
}
2017-01-05 20:06:24 +03:00
export const {{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service){{end}}