diff --git a/Makefile b/Makefile index 83cdc7a..e898e34 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install: .PHONY: test test: build cd examples/dummy && make - cd examples/js-grpc && make + cd examples/flow && make .PHONY: docker.build docker.build: diff --git a/examples/js-grpc/Makefile b/examples/flow/Makefile similarity index 100% rename from examples/js-grpc/Makefile rename to examples/flow/Makefile diff --git a/examples/flow/output/test/test_grpc_js.js b/examples/flow/output/test/test_grpc_js.js new file mode 100644 index 0000000..e8a87e2 --- /dev/null +++ b/examples/flow/output/test/test_grpc_js.js @@ -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; + o?: Array; + p?: Array; + q?: Array; + r?: Array; + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) diff --git a/examples/js-grpc/protos/test.proto b/examples/flow/protos/test.proto similarity index 92% rename from examples/js-grpc/protos/test.proto rename to examples/flow/protos/test.proto index cd7ebe7..e15ee88 100644 --- a/examples/js-grpc/protos/test.proto +++ b/examples/flow/protos/test.proto @@ -11,6 +11,11 @@ service TestService { rpc TestStreamBoth(stream TestStreamBothRequest) returns (stream TestStreamBothReply); } +enum TestEnum { + ELEMENT_A = 0; + ELEMENT_B = 1; +} + message TestMessage { string a = 1; int32 b = 2; @@ -22,6 +27,10 @@ message TestMessage { repeated int64 p = 16; repeated float q = 17; repeated double r = 18; + enum s { + ELEMENT_C = 0; + ELEMENT_D = 1; + } } message TestNoStreamRequest { TestMessage message = 1; } diff --git a/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl b/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl new file mode 100644 index 0000000..8acd68d --- /dev/null +++ b/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl @@ -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) { + 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) { + 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}} diff --git a/examples/js-grpc/output/test/test_grpc_js.js b/examples/js-grpc/output/test/test_grpc_js.js deleted file mode 100644 index 4790084..0000000 --- a/examples/js-grpc/output/test/test_grpc_js.js +++ /dev/null @@ -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); diff --git a/examples/js-grpc/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl b/examples/js-grpc/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl deleted file mode 100644 index 61dc4d2..0000000 --- a/examples/js-grpc/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl +++ /dev/null @@ -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}} diff --git a/examples/js/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl b/examples/js/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl deleted file mode 100644 index d30655e..0000000 --- a/examples/js/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl +++ /dev/null @@ -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}} diff --git a/helpers.go b/helpers.go index 065f9c4..038f3ee 100644 --- a/helpers.go +++ b/helpers.go @@ -70,6 +70,7 @@ var ProtoHelpersFuncMap = template.FuncMap{ "jsType": jsType, "httpVerb": httpVerb, "httpPath": httpPath, + "shortType": shortType, } func init() { @@ -141,31 +142,37 @@ 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_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: - 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: - return "number" - case descriptor.FieldDescriptorProto_TYPE_UINT32: - return "number" + return fmt.Sprintf(template, "Array") + case descriptor.FieldDescriptorProto_TYPE_STRING: + return fmt.Sprintf(template, "string") case descriptor.FieldDescriptorProto_TYPE_ENUM: - return "message" + return fmt.Sprintf(template, "Object") default: - return "object" + return fmt.Sprintf(template, "any") } }