Current section

Files

Jump to
pulsar_elixir lib pulsar framing.ex~
Raw

lib/pulsar/framing.ex~

defmodule Pulsar.Framing do
# https://pulsar.apache.org/docs/next/developing-binary-protocol/#framing
alias Pulsar.Proto
def encode(%Proto.CommandPing{} = ping) do
encoded =
%Proto.BaseCommand{type: :PING, ping: ping}
|> Proto.BaseCommand.encode
size = byte_size(encoded)
<<(size + 4)::32, size::32, encoded::binary>>
end
def encode(%Proto.CommandPong{} = pong) do
encoded =
%Proto.BaseCommand{type: :PONG, ping: pong}
|> Proto.BaseCommand.encode
size = byte_size(encoded)
<<(size + 4)::32, size::32, encoded::binary>>
end
end