Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode protobuf to iodata for better performance #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/grpc/client/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule GRPC.Client.Adapter do

@callback disconnect(channel :: Channel.t()) :: {:ok, Channel.t()} | {:error, any()}

@callback send_request(stream :: Stream.t(), contents :: binary(), opts :: keyword()) ::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change, so let's hold off until we're ready for a new minor release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed :)

@callback send_request(stream :: Stream.t(), contents :: iodata(), opts :: keyword()) ::
Stream.t()

@doc """
Expand All @@ -36,7 +36,7 @@ defmodule GRPC.Client.Adapter do
Opts:
- :send_end_stream (optional) - ends the request stream
"""
@callback send_data(stream :: Stream.t(), message :: binary(), opts :: keyword()) :: Stream.t()
@callback send_data(stream :: Stream.t(), message :: iodata(), opts :: keyword()) :: Stream.t()

@doc """
Similarly to the option sent on `send_data/2` - :send_end_stream -
Expand Down
2 changes: 1 addition & 1 deletion lib/grpc/codec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule GRPC.Codec do

@doc ~s(Name is identity of the codec, which will be suffix after content-type "application/grpc+" such as "proto".)
@callback name() :: String.t()
@callback encode(any) :: binary
@callback encode(any) :: iodata()
@callback decode(any, module :: atom) :: any

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/grpc/codec/proto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"proto"
end

def encode(%mod{} = struct) do

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / Interop tests

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / Check release

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / OTP 24.x / Elixir 1.15.x

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / OTP 25.x / Elixir 1.15.x

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / OTP 26.1.x / Elixir 1.15.x

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 8 in lib/grpc/codec/proto.ex

View workflow job for this annotation

GitHub Actions / OTP 24.x / Elixir 1.12.x

variable "mod" is unused (if the variable is not meant to be used, prefix it with an underscore)
mod.encode(struct)
Protobuf.Encoder.encode_to_iodata(struct)
end

def decode(binary, module) do
Expand Down
2 changes: 1 addition & 1 deletion lib/grpc/compressor.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule GRPC.Compressor do
@callback name() :: String.t()
@callback compress(binary) :: binary
@callback compress(iodata()) :: binary
@callback decompress(binary) :: binary
end
Loading