<commit_before>defmodule GRPC.Server do
  @moduledoc """
  A gRPC server which handles requests by calling user-defined functions.

  You should pass a `GRPC.Service` in when using the module:

      defmodule Greeter.Service do
        use GRPC.Service, name: "ping"

        rpc :SayHello, Request, Reply
        rpc :SayGoodbye, stream(Request), stream(Reply)
      end

      defmodule Greeter.Server do
        use GRPC.Server, service: Greeter.Service

        def say_hello(request, _stream) do
          Reply.new(message: "Hello")
        end

        def say_goodbye(request_enum, stream) do
          requests = Enum.map request_enum, &(&1)
          GRPC.Server.stream_send(stream, reply1)
          GRPC.Server.stream_send(stream, reply2)
        end
      end

  Your functions should accept a client request and a `GRPC.Server.Stream`.
  The client request will be a `Stream` of requests if it's streaming.
  If a reply is streaming, you need to call `stream_send/2` to send requests
  one by one instead of returning reply in the end.

  A server can be started and stoped using:

      {:ok, _, port} = GRPC.Server.start(Greeter.Server, 50051)
      :ok = GRPC.Server.stop(Greeter.Server)
  """

  defmacro __using__(opts) do
    quote bind_quoted: [service_mod: opts[:service]] do
      service_name = service_mod.__meta__(:name)
      Enum.each service_mod.__rpc_calls__, fn ({name, _, _} = rpc) ->
        func_name = name |> to_string |> Macro.underscore
        path = "/#{service_name}/#{name}"
        def __call_rpc__(unquote(path), stream) do
          GRPC.Server.call(unquote(service_mod), stream, unquote(Macro.escape(rpc)), String.to_atom(unquote(func_name)))
        end
        def __call_rpc(_, stream), do: {:error, stream, "Error"}
      end
    end
  end

  @doc false
  @spec call(atom, GRPC.Server.Stream.t,
    tuple, atom) :: {:ok, GRPC.Server.Stream.t, struct} | {:ok, struct}<commit_msg>fix __call_rpc function for compile warning<commit_after>defmodule GRPC.Server do
  @moduledoc """
  A gRPC server which handles requests by calling user-defined functions.

  You should pass a `GRPC.Service` in when using the module:

      defmodule Greeter.Service do
        use GRPC.Service, name: "ping"

        rpc :SayHello, Request, Reply
        rpc :SayGoodbye, stream(Request), stream(Reply)
      end

      defmodule Greeter.Server do
        use GRPC.Server, service: Greeter.Service

        def say_hello(request, _stream) do
          Reply.new(message: "Hello")
        end

        def say_goodbye(request_enum, stream) do
          requests = Enum.map request_enum, &(&1)
          GRPC.Server.stream_send(stream, reply1)
          GRPC.Server.stream_send(stream, reply2)
        end
      end

  Your functions should accept a client request and a `GRPC.Server.Stream`.
  The client request will be a `Stream` of requests if it's streaming.
  If a reply is streaming, you need to call `stream_send/2` to send requests
  one by one instead of returning reply in the end.

  A server can be started and stoped using:

      {:ok, _, port} = GRPC.Server.start(Greeter.Server, 50051)
      :ok = GRPC.Server.stop(Greeter.Server)
  """

  defmacro __using__(opts) do
    quote bind_quoted: [service_mod: opts[:service]] do
      service_name = service_mod.__meta__(:name)
      Enum.each service_mod.__rpc_calls__, fn ({name, _, _} = rpc) ->
        func_name = name |> to_string |> Macro.underscore
        path = "/#{service_name}/#{name}"
        def __call_rpc__(unquote(path), stream) do
          GRPC.Server.call(unquote(service_mod), stream, unquote(Macro.escape(rpc)), String.to_atom(unquote(func_name)))
        end
      end
      def __call_rpc__(_, stream), do: {:error, stream, "Error"}
    end
  end

  @doc false
  @spec call(atom, GRPC.Server.Stream.t,
    tuple, atom) :: {:ok, GRPC.Server.Stream.t, struct} | {:ok, struct}
{'fraction_non_alphanumeric': 0.10545267489711935, 'fraction_numerical': 0.004629629629629629, 'mean_word_length': 2.9046184738955825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1632975', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1199, 'n_words': 362}