Permalink
Browse files

Add stringify function to debug protocol output.

  • Loading branch information...
1 parent 1569fe2 commit 49c855c90f64d8ae775bc21e3618024e7dbdc5a0 @ahf committed Jul 1, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/pony_protocol.erl
View
@@ -1,5 +1,5 @@
-module(pony_protocol).
--export([parse/1]).
+-export([parse/1, stringify/1, stringify/3]).
-export([numeric/1]).
-export([render/1]).
@@ -64,6 +64,15 @@ parse(X) when is_binary(X) ->
parse(X) when is_list(X) ->
parse(list_to_binary(X)).
+stringify(X) ->
+ case parse(X) of
+ {ok, Prefix, Command, Arguments} -> stringify(Prefix, Command, Arguments);
+ {error, _} -> "Error: Invalid message."
+ end.
+
+stringify(P, C, A) ->
+ io_lib:format("~p~n", [[{prefix, P}, {command, C}, {args, A}]]).
+
numeric(N) when is_atom(N) ->
case N of
'RPL_WELCOME' -> 0;

0 comments on commit 49c855c

Please sign in to comment.