summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hood <0x6e6562@gmail.com>2009-08-05 14:19:36 +0100
committerBen Hood <0x6e6562@gmail.com>2009-08-05 14:19:36 +0100
commitee06e07f561ef2760a3d97b7592b11a54cfc5001 (patch)
tree8dace679010332469dced33969d96045403cab42
parent4dcf9fd3a2a50b46121ff3149e5c132626b95fdc (diff)
downloadrabbitmq-server-ee06e07f561ef2760a3d97b7592b11a54cfc5001.tar.gz
Added a helper function to make dealing with the crazy content record a bit more sane
-rw-r--r--src/rabbit_basic.erl29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl
index 2dc619c1..0f6aeb7a 100644
--- a/src/rabbit_basic.erl
+++ b/src/rabbit_basic.erl
@@ -35,6 +35,7 @@
-export([publish/1, message/4, properties/1, delivery/4]).
-export([publish/4, publish/7]).
+-export([build_content/2, from_content/1]).
%%----------------------------------------------------------------------------
@@ -53,6 +54,8 @@
-spec(publish/7 :: (exchange_name(), routing_key(), bool(), bool(),
maybe(txn()), properties_input(), binary()) ->
publish_result()).
+-spec(build_content/2 :: (amqp_properties(), binary()) -> content()).
+-spec(from_content/1 :: (content()) -> {amqp_properties(), binary()}).
-endif.
@@ -72,16 +75,30 @@ delivery(Mandatory, Immediate, Txn, Message) ->
#delivery{mandatory = Mandatory, immediate = Immediate, txn = Txn,
sender = self(), message = Message}.
+build_content(Properties, BodyBin) ->
+ {ClassId, _MethodId} = rabbit_framing:method_id('basic.publish'),
+ #content{class_id = ClassId,
+ properties = Properties,
+ properties_bin = none,
+ payload_fragments_rev = [BodyBin]}.
+
+from_content(#content{properties = Props,
+ properties_bin = none,
+ payload_fragments_rev = BodyList}) ->
+ {Props, list_to_binary(BodyList)};
+
+from_content(#content{properties = none,
+ properties_bin = PropsBin,
+ payload_fragments_rev = BodyList}) ->
+ {ClassId, _MethodId} = rabbit_framing:method_id('basic.publish'),
+ Props = rabbit_framing:decode_properties(ClassId, PropsBin),
+ {Props, list_to_binary(BodyList)}.
+
message(ExchangeName, RoutingKeyBin, RawProperties, BodyBin) ->
Properties = properties(RawProperties),
- {ClassId, _MethodId} = rabbit_framing:method_id('basic.publish'),
- Content = #content{class_id = ClassId,
- properties = Properties,
- properties_bin = none,
- payload_fragments_rev = [BodyBin]},
#basic_message{exchange_name = ExchangeName,
routing_key = RoutingKeyBin,
- content = Content,
+ content = build_content(Properties, BodyBin),
persistent_key = none}.
properties(P = #'P_basic'{}) ->