elixir-grpc / grpc

An Elixir implementation of gRPC
https://hex.pm/packages/grpc
Apache License 2.0
1.38k stars 212 forks source link

Support for alternative wire formats? #207

Closed freshtonic closed 2 years ago

freshtonic commented 3 years ago

Currently, it seems that only Protobuf is supported as a wire format.

How coupled is this library to Protobuf and is there a plan to support alternative wire formats?

drowzy commented 2 years ago

Looking at GRPC.Message it doesn't look like being Protobuf only since the message is encoded/decoded using the codec. I might be wrong though!

For codecs see for instance.

usage:

defmodule HelloServer do
    use GRPC.Server,
      service: Helloworld.Greeter.Service,
      codecs: [GRPC.Codec.Erlpack]

    def say_hello(req, _stream) do
      Helloworld.HelloReply.new(message: "Hello, #{req.name}")
    end
  end

  defmodule HelloStub do
    use GRPC.Stub, service: Helloworld.Greeter.Service
  end
{:ok, channel} = GRPC.Stub.connect("localhost:8080")
req = Helloworld.HelloRequest.new(name: "hello")
{:ok, reply} = channel |> HelloStub.say_hello(req, codec: GRPC.Codec.Erlpack)

You can implement your own by implementing the codec behaviour.

Hope it helps!

freshtonic commented 2 years ago

Thanks @drowzy - that's great. I swear I looked at the project README and "support protocols other than Protobufs" was unchecked :)