How to generate grpc protobuf files
Issue #197
protoc
https://grpc.io/docs/quickstart/go.html
Install the protoc compiler that is used to generate gRPC service code. The simplest way to do this is to download pre-compiled binaries for your platform(protoc-
- .zip) from here: https://github.com/google/protobuf/releases
Unzip this file.
Update the environment variable PATH to include the path to the protoc binary file.
Go protoc plugin
https://github.com/golang/protobuf
1 | go get -u github.com/golang/protobuf/protoc-gen-go |
Swift protoc plugin
https://github.com/grpc/grpc-swift
The recommended way to use Swift gRPC is to first define an API using the
Protocol Buffer
language and then use the
Protocol Buffer Compiler
and the Swift Protobuf
and Swift gRPC plugins to
generate the necessary support code.
1 | git clone https://github.com/grpc/grpc-swift.git |
Generate
1 | protoc --swift_out=MyApp/Api --swiftgrpc_out=Client=true,Server=false:MyApp/Api --go_out=plugins=grpc:server/api api.proto |
In case we need to cd
1 | cd MyApp/Library/Models/Proto |
Empty
If remote import is needed, then the workaround is to download the that proto locally, for example empty.proto https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/empty.proto
Inside SwiftProtobuf pod, there is generated empty.pb.swift
1 | public struct Google_Protobuf_Empty { |
To consume, we can
1 | import SwiftProtobuf |
oneof mode
1 | message Person { |
Cannot convert value of type ‘Server_Person.OneOf_Mode’ to expected argument type ‘Server_Human’
Need to assign the mode
1 | var person = Person() |