Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created April 4, 2017 09:45
Show Gist options
  • Save oivoodoo/bd372b7b825f14448e7138a99eb385b0 to your computer and use it in GitHub Desktop.
Save oivoodoo/bd372b7b825f14448e7138a99eb385b0 to your computer and use it in GitHub Desktop.
example
defmodule Web.Tcp.Protocol do
require Logger
alias Web.Gateway
@moduledoc """
Server messages:
- `l:logs`
logs - should come as json array and encoded base64
- `i:vars`
vars - should come as json dictionary and encoded by base64
- `v:api_key`
api_key - should verify key using our registry
Client messages:
- `i:s:name:value` - var set by name value inside of app
"""
def process("l:" <> <<api_key :: bytes-size(8)>> <> ":" <> logs) do
Logger.debug("[protocol] api_key: #{inspect(api_key)}, logs: #{inspect(logs)}")
Gateway.logs(api_key, logs)
:ok
end
def process("i:" <> <<api_key :: bytes-size(8)>> <> ":" <> vars) do
Logger.debug("[protocol] api_key: #{inspect(api_key)}, vars: #{inspect(vars)}")
Gateway.vars(api_key, vars)
:ok
end
def process("v:" <> <<api_key :: bytes-size(8)>>) do
# search inside of database mention for api_key
# REGISTER socket in registory by api_key
Logger.debug("[protocol] api_key: #{inspect(api_key)}")
{:reg, api_key}
end
def process(_), do: :error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment