Skip to content
Permalink
Browse files

added version and as_server

  • Loading branch information...
Dreat committed May 14, 2017
1 parent e75c850 commit 591554e9b2fdc1eeddba9dbde631a4b233241b9a
Showing with 50 additions and 0 deletions.
  1. +24 −0 zmq_ex/lib/zmq_ex.ex
  2. +26 −0 zmq_ex/test/zmq_ex_test.exs
@@ -1,5 +1,29 @@
defmodule ZmqEx do

def version(%{major: major, minor: minor}) do
{:ok, <<major, minor>>}
end

def version(<<major, minor>>) do
{:ok, %{major: major, minor: minor}}
end

def as_server(<<as_server>>) do
as_server_convert(as_server)
end

defp as_server_convert(1) do
{:ok, true}
end

defp as_server_convert(0) do
{:ok, false}
end

defp as_server_convert(_) do
{:error, :wrong_as_server}
end

def encode(%{flags: flags = %{type: _, long: :short, more: _}, size: size, body: <<body>>}) do
<<encode_flags(flags), size :: size(8), body>>
end
@@ -61,4 +61,30 @@ defmodule ZmqExTest do
result = ZmqEx.decode_command(%{flags: %{type: :command, long: :long, more: false}, size: 64, body: "command2A command body"})
assert result == %{name: "command2", size: 56, data: "A command body"}
end

test "test acting as a server" do
result = ZmqEx.as_server(<<1>>)
assert result == {:ok, true}
end

test "test acting not as a server" do
result = ZmqEx.as_server(<<0>>)
assert result == {:ok, false}
end

test "test wrong as a server value" do
result = ZmqEx.as_server(<<2>>)
assert result == {:error, :wrong_as_server}
end

test "decode version" do
result = ZmqEx.version(<<3,0>>)
assert result == {:ok, %{major: 3, minor: 0}}
end

test "encode version" do
result = ZmqEx.version(%{major: 3, minor: 1})
assert result == {:ok, <<3, 1>>}
end

end

0 comments on commit 591554e

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.