mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 10:05:57 +08:00
20 lines
514 B
Elixir
20 lines
514 B
Elixir
defmodule LivebookProto do
|
|
@moduledoc false
|
|
|
|
alias LivebookProto.Request
|
|
|
|
@mapping (for {_id, field_prop} <- Request.__message_props__().field_props,
|
|
into: %{} do
|
|
{field_prop.type, field_prop.name_atom}
|
|
end)
|
|
|
|
def build_request_frame(%struct{} = data, id \\ -1) do
|
|
type = request_type(struct)
|
|
message = Request.new!(id: id, type: {type, data})
|
|
|
|
{:binary, Request.encode(message)}
|
|
end
|
|
|
|
defp request_type(module), do: Map.fetch!(@mapping, module)
|
|
end
|