livery_grpc_codegen (livery_grpc v0.1.0)

View Source

Generate Erlang stubs from a compiled gpb proto module.

Two kinds of module, per service, so a service reads as plain Erlang:

  • A client stub <service>_client, giving an erpc-style call per RPC: greeter_client:say_hello(Conn, Request). Unary and server-streaming wrap livery_grpc_client:call/4, client-streaming wraps client_stream/4, and bidirectional wraps open/3 (returning a stream handle to drive with send/2, recv/1, ...).

  • A behaviour <service>_service, declaring one -callback per RPC so a handler module can -behaviour(greeter_service) and have the compiler and dialyzer check it.

generate/2,3 writes the source to a directory; client_module/2 and behaviour_module/2 return {Module, Source} for callers that compile in memory. The generated client resolves the method descriptor at call time via livery_grpc_service, so it stays correct if the proto is recompiled.

Summary

Functions

Return {Module, Source} for a service's callback behaviour module.

Return {Module, Source} for a service's client stub module.

generate/3 writing both the client and behaviour modules.

Write the chosen stub kinds for every service in Proto to OutDir. Returns the list of written file paths.

Types

kind()

-type kind() :: client | behaviour.

Functions

behaviour_module(Proto, Service)

-spec behaviour_module(module(), atom()) -> {module(), iolist()}.

Return {Module, Source} for a service's callback behaviour module.

client_module(Proto, Service)

-spec client_module(module(), atom()) -> {module(), iolist()}.

Return {Module, Source} for a service's client stub module.

generate(Proto, OutDir)

-spec generate(module(), file:name_all()) -> {ok, [file:name_all()]} | {error, term()}.

generate/3 writing both the client and behaviour modules.

generate(Proto, OutDir, Kinds)

-spec generate(module(), file:name_all(), [kind()]) -> {ok, [file:name_all()]} | {error, term()}.

Write the chosen stub kinds for every service in Proto to OutDir. Returns the list of written file paths.