File 0024-turtle_subscriber-shrink-handle_message-4-format_amq.patch of Package turtle
From b32da9f3b5e8ce404b4e8544b6e7bd1fd3caf039 Mon Sep 17 00:00:00 2001
From: Led <ledest@gmail.com>
Date: Wed, 28 Nov 2018 15:36:56 +0200
Subject: [PATCH 4/6] turtle_subscriber: shrink handle_message/4,
format_amqp_msg/1
---
src/turtle_subscriber.erl | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/src/turtle_subscriber.erl b/src/turtle_subscriber.erl
index 3bda0a4..2f9d5e5 100644
--- a/src/turtle_subscriber.erl
+++ b/src/turtle_subscriber.erl
@@ -263,37 +263,33 @@ handle_message(Tag, Key,
props = #'P_basic' {
content_type = Type }},
#state { invoke = Fun, invoke_state = IState, mode = Mode }) ->
- Res = case Mode of
- M when M =:= simple; M =:= single -> Fun(Key, Type, Payload, IState);
- bulk -> Fun(Key, Type, Payload, Tag, IState)
- end,
+ Res = if
+ Mode =:= bulk -> Fun(Key, Type, Payload, Tag, IState);
+ true -> Fun(Key, Type, Payload, IState)
+ end,
case Res of
%% Bulk messages
L when is_list(L) -> {L, IState};
- {L, IState2} when is_list(L) -> {L, IState2};
-
+ {L, _} when is_list(L) -> Res;
%% Single messages
ack -> {ack, IState};
- {ack, IState2} -> {ack, IState2};
+ {ack, _} -> Res;
{reply, CType, Msg} -> {reply, CType, Msg, IState};
- {reply, CType, Msg, IState2} -> {reply, CType, Msg, IState2};
+ {reply, _, _, _} -> Res;
reject -> {reject, IState};
- {reject, IState2} -> {reject, IState2};
+ {reject, _} -> Res;
remove -> {remove, IState};
- {remove, IState2} -> {remove, IState2};
- {stop, Reason, IState2} -> {stop, Reason, IState2};
- {ok, IState2} -> {ok, IState2};
+ {remove, _} -> Res;
+ {stop, _, _} -> Res;
+ {ok, _} -> Res;
ok -> {ok, IState}
end.
-
+
+format_amqp_msg(#amqp_msg { payload = Payload, props = Props }) when byte_size(Payload) =< 64 ->
+ {Payload, Props};
format_amqp_msg(#amqp_msg { payload = Payload, props = Props }) ->
- Pl = case byte_size(Payload) of
- K when K < 64 -> Payload;
- _ ->
- <<Cut:64/binary, _/binary>> = Payload,
- Cut
- end,
- {Pl, Props}.
+ <<Cut:64/binary, _/binary>> = Payload,
+ {Cut, Props}.
%% Compute the initial state of the function
invoke_state(#{ init_state := S }) -> S;
--
2.16.4