livery_grpc_service (livery_grpc v0.1.0)

View Source

Service descriptors, derived from a gpb-generated module at runtime.

A .proto compiled by rebar3_gpb_plugin yields a module (e.g. helloworld_pb) that already carries introspection: get_package_name/0, get_service_names/0, and get_service_def/1. Rather than generate a second set of *_grpc.erl modules at build time, this module reads that introspection and produces method descriptors the server and client use: the wire path, the input/output message names, and the call kind (unary, server-streaming, client-streaming, bidirectional).

A method descriptor is the unit both sides key on: the server matches an inbound :path to one, the client builds a request from one.

Summary

Functions

Map an RPC method name to its callback function name: CamelCase to snake_case ('SayHello' -> say_hello, 'HTTPGet' -> http_get). A run of capitals is kept together, with a break before the final capital that starts the next word.

Build a path-keyed routing index from a list of registrations.

The call kind from the input/output streaming flags.

One method descriptor by service and method name.

The method descriptors of one service in a proto module.

The proto package as a binary, or <<>> when none is declared.

The wire path for a method: /package.Service/Method, or /Service/Method when the proto declares no package.

Join a package and a local name into a fully qualified name.

The fully qualified service name, e.g. <<"helloworld.Greeter">>.

All service names declared in a proto module.

Types

kind()

-type kind() :: unary | server_stream | client_stream | bidi.

method()

-type method() ::
          #{name := atom(),
            function := atom(),
            path := binary(),
            proto := module(),
            service := atom(),
            input := atom(),
            output := atom(),
            input_stream := boolean(),
            output_stream := boolean(),
            kind := kind()}.

registration()

-type registration() :: #{proto := module(), service := atom(), handler := module()}.

Functions

function_name(MethodName)

-spec function_name(atom()) -> atom().

Map an RPC method name to its callback function name: CamelCase to snake_case ('SayHello' -> say_hello, 'HTTPGet' -> http_get). A run of capitals is kept together, with a break before the final capital that starts the next word.

index(Registrations)

-spec index([registration()]) -> #{binary() => {method(), module()}}.

Build a path-keyed routing index from a list of registrations.

Each entry maps a wire path to {Method, Handler}: the method descriptor plus the callback module that serves it. The server uses this to dispatch an inbound request in one map lookup.

kind/1

-spec kind({boolean(), boolean()}) -> kind().

The call kind from the input/output streaming flags.

method(Proto, Service, MethodName)

-spec method(module(), atom(), atom()) -> {ok, method()} | error.

One method descriptor by service and method name.

methods(Proto, Service)

-spec methods(module(), atom()) -> [method()].

The method descriptors of one service in a proto module.

package(Proto)

-spec package(module()) -> binary().

The proto package as a binary, or <<>> when none is declared.

path(Proto, Service, MethodName)

-spec path(module(), atom(), atom()) -> binary().

The wire path for a method: /package.Service/Method, or /Service/Method when the proto declares no package.

qualify/2

-spec qualify(binary(), binary()) -> binary().

Join a package and a local name into a fully qualified name.

service_full_name(Proto, Service)

-spec service_full_name(module(), atom()) -> binary().

The fully qualified service name, e.g. <<"helloworld.Greeter">>.

service_names(Proto)

-spec service_names(module()) -> [atom()].

All service names declared in a proto module.