Last active
April 19, 2019 10:13
-
-
Save konstantinzolotarev/fcf953e4a5cf430a7bd92c8ec133e6af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Encoder do | |
def encode( | |
username, | |
msg, | |
id \\ "mguFd-51", | |
to \\ "79040883-331c-4944-aca5-16e9351098c1@localhost" | |
) do | |
{:xmlel, "message", | |
[ | |
{"xml:lang", "en"}, | |
{"to", to}, | |
{"id", id}, | |
{"type", "chat"} | |
], | |
[ | |
{:xmlel, "body", [], [xmlcdata: msg]}, | |
{:xmlel, "username", [{"xmlns", "message:username"}], [xmlcdata: username]}, | |
{:xmlel, "type", [{"xmlns", "message:type"}], [xmlcdata: "text"]} | |
]} | |
end | |
end | |
[id, username, to, msg] = System.argv() | |
msg = | |
Encoder.encode(username, msg, id, to) | |
|> :erlang.term_to_binary() | |
|> Base.encode16() | |
# Это просто распечатывает результат | |
"0x" <> msg | |
|> IO.puts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment