|
@@ -17,14 +17,6 @@ init(Options) ->
|
|
decode(Bin, #state{tail = Tail} = State) ->
|
|
decode(Bin, #state{tail = Tail} = State) ->
|
|
decode_message(<<Bin/binary, Tail/binary>>, State).
|
|
decode_message(<<Bin/binary, Tail/binary>>, State).
|
|
|
|
|
|
-encode(Data, State = #state{}) ->
|
|
|
|
- Bin = iolist_to_binary(Data),
|
|
|
|
- <<(byte_size(Bin) + 4):?int32, Bin/binary>>.
|
|
|
|
-
|
|
|
|
-encode(Type, Data, State = #state{}) ->
|
|
|
|
- Bin = iolist_to_binary(Data),
|
|
|
|
- <<Type:8, (byte_size(Bin) + 4):?int32, Bin/binary>>.
|
|
|
|
-
|
|
|
|
decode_message(<<Type:8, Len:?int32, Rest/binary>> = Bin, State) ->
|
|
decode_message(<<Type:8, Len:?int32, Rest/binary>> = Bin, State) ->
|
|
Len2 = Len - 4,
|
|
Len2 = Len - 4,
|
|
case Rest of
|
|
case Rest of
|
|
@@ -79,3 +71,11 @@ lower_atom(Str) when is_binary(Str) ->
|
|
lower_atom(binary_to_list(Str));
|
|
lower_atom(binary_to_list(Str));
|
|
lower_atom(Str) when is_list(Str) ->
|
|
lower_atom(Str) when is_list(Str) ->
|
|
list_to_atom(string:to_lower(Str)).
|
|
list_to_atom(string:to_lower(Str)).
|
|
|
|
+
|
|
|
|
+encode(Data, State = #state{}) ->
|
|
|
|
+ Bin = iolist_to_binary(Data),
|
|
|
|
+ <<(byte_size(Bin) + 4):?int32, Bin/binary>>.
|
|
|
|
+
|
|
|
|
+encode(Type, Data, State = #state{}) ->
|
|
|
|
+ Bin = iolist_to_binary(Data),
|
|
|
|
+ <<Type:8, (byte_size(Bin) + 4):?int32, Bin/binary>>.
|