diff options
| author | Ben Hood <0x6e6562@gmail.com> | 2009-08-05 14:19:36 +0100 |
|---|---|---|
| committer | Ben Hood <0x6e6562@gmail.com> | 2009-08-05 14:19:36 +0100 |
| commit | 2f70ccc19b9a7534b1f5919492cd880f2a69fd54 (patch) | |
| tree | 8dace679010332469dced33969d96045403cab42 /src | |
| parent | 98b19bb6227d7ed886a81522b6d67734adf66d0f (diff) | |
| download | rabbitmq-server-git-2f70ccc19b9a7534b1f5919492cd880f2a69fd54.tar.gz | |
Added a helper function to make dealing with the crazy content record a bit more sane
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_basic.erl | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index 2dc619c1fb..0f6aeb7ad7 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'{}) -> |
