summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rabbit.hrl1
-rw-r--r--src/rabbit_basic.erl6
-rw-r--r--src/rabbit_binary_generator.erl24
-rw-r--r--src/rabbit_binary_parser.erl9
-rw-r--r--src/rabbit_channel.erl3
-rw-r--r--src/rabbit_framing_channel.erl6
6 files changed, 30 insertions, 19 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 8c713a50..96cf844e 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -45,6 +45,7 @@
properties_bin, %% either 'none', or an encoded properties binary
%% Note: at most one of properties and properties_bin can be
%% 'none' at once.
+ protocol, %% The protocol under which properties_bin was encoded
payload_fragments_rev %% list of binaries, in reverse order (!)
}).
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl
index 4a1d50df..357333a9 100644
--- a/src/rabbit_basic.erl
+++ b/src/rabbit_basic.erl
@@ -86,16 +86,16 @@ build_content(Properties, BodyBin) ->
#content{class_id = ClassId,
properties = Properties,
properties_bin = none,
+ protocol = rabbit_framing_amqp_0_9_1,
payload_fragments_rev = [BodyBin]}.
from_content(Content) ->
#content{class_id = ClassId,
properties = Props,
payload_fragments_rev = FragmentsRev} =
- %% basic.publish hasn't changed so we can just hard-code amqp_0_9_1
- rabbit_binary_parser:ensure_content_decoded(Content,
- rabbit_framing_amqp_0_9_1),
+ rabbit_binary_parser:ensure_content_decoded(Content),
{ClassId, _MethodId} =
+ %% basic.publish hasn't changed so we can just hard-code amqp_0_9_1
rabbit_framing_amqp_0_9_1:method_id('basic.publish'),
{Props, list_to_binary(lists:reverse(FragmentsRev))}.
diff --git a/src/rabbit_binary_generator.erl b/src/rabbit_binary_generator.erl
index 75cd643c..200bf2cd 100644
--- a/src/rabbit_binary_generator.erl
+++ b/src/rabbit_binary_generator.erl
@@ -82,18 +82,25 @@ build_simple_content_frames(ChannelInt,
#content{class_id = ClassId,
properties = ContentProperties,
properties_bin = ContentPropertiesBin,
+ protocol = ContentProtocol,
payload_fragments_rev = PayloadFragmentsRev},
FrameMax, Protocol) ->
{BodySize, ContentFrames} = build_content_frames(PayloadFragmentsRev, FrameMax, ChannelInt),
HeaderFrame = create_frame(2, ChannelInt,
[<<ClassId:16, 0:16, BodySize:64>>,
- maybe_encode_properties(ContentProperties, ContentPropertiesBin, Protocol)]),
+ maybe_encode_properties(ContentProperties,
+ ContentPropertiesBin,
+ ContentProtocol,
+ Protocol)]),
[HeaderFrame | ContentFrames].
-maybe_encode_properties(_ContentProperties, ContentPropertiesBin, _Protocol)
+maybe_encode_properties(_ContentProperties,
+ ContentPropertiesBin,
+ Protocol,
+ Protocol)
when is_binary(ContentPropertiesBin) ->
ContentPropertiesBin;
-maybe_encode_properties(ContentProperties, none, Protocol) ->
+maybe_encode_properties(ContentProperties, none, _ContentProtocol, Protocol) ->
Protocol:encode_properties(ContentProperties).
build_content_frames(FragsRev, FrameMax, ChannelInt) ->
@@ -278,13 +285,14 @@ check_empty_content_body_frame_size() ->
ComputedSize, ?EMPTY_CONTENT_BODY_FRAME_SIZE})
end.
-ensure_content_encoded(Content = #content{properties_bin = PropsBin}, _Protocol)
- when PropsBin =/= 'none' ->
+ensure_content_encoded(Content = #content{protocol = Protocol}, Protocol) ->
Content;
ensure_content_encoded(Content = #content{properties = Props}, Protocol) ->
- Content#content{properties_bin = Protocol:encode_properties(Props)}.
+ Content#content{properties_bin = Protocol:encode_properties(Props),
+ protocol = Protocol}.
-clear_encoded_content(Content = #content{properties_bin = none}) ->
+clear_encoded_content(Content = #content{properties_bin = none,
+ protocol = none}) ->
Content;
clear_encoded_content(Content = #content{properties = none}) ->
%% Only clear when we can rebuild the properties_bin later in
@@ -292,4 +300,4 @@ clear_encoded_content(Content = #content{properties = none}) ->
%% one of properties and properties_bin can be 'none'
Content;
clear_encoded_content(Content = #content{}) ->
- Content#content{properties_bin = none}.
+ Content#content{properties_bin = none, protocol = none}.
diff --git a/src/rabbit_binary_parser.erl b/src/rabbit_binary_parser.erl
index 633be6f0..b1c7c327 100644
--- a/src/rabbit_binary_parser.erl
+++ b/src/rabbit_binary_parser.erl
@@ -34,7 +34,7 @@
-include("rabbit.hrl").
-export([parse_table/1, parse_properties/2]).
--export([ensure_content_decoded/2, clear_decoded_content/1]).
+-export([ensure_content_decoded/1, clear_decoded_content/1]).
-import(lists).
@@ -44,7 +44,7 @@
-spec(parse_table/1 :: (binary()) -> amqp_table()).
-spec(parse_properties/2 :: ([amqp_property_type()], binary()) -> [any()]).
--spec(ensure_content_decoded/2 :: (content(), protocol()) -> decoded_content()).
+-spec(ensure_content_decoded/1 :: (content()) -> decoded_content()).
-spec(clear_decoded_content/1 :: (content()) -> undecoded_content()).
-endif.
@@ -159,10 +159,11 @@ parse_property(bit, Rest) ->
parse_property(table, <<Len:32/unsigned, Table:Len/binary, Rest/binary>>) ->
{parse_table(Table), Rest}.
-ensure_content_decoded(Content = #content{properties = Props}, _Protocol)
+ensure_content_decoded(Content = #content{properties = Props})
when Props =/= 'none' ->
Content;
-ensure_content_decoded(Content = #content{properties_bin = PropBin}, Protocol)
+ensure_content_decoded(Content = #content{properties_bin = PropBin,
+ protocol = Protocol})
when is_binary(PropBin) ->
Content#content{properties = Protocol:decode_properties(
Content#content.class_id, PropBin)}.
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index 213b6624..55b5d875 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -414,8 +414,7 @@ handle_method(#'basic.publish'{exchange = ExchangeNameBin,
Exchange = rabbit_exchange:lookup_or_die(ExchangeName),
%% We decode the content's properties here because we're almost
%% certain to want to look at delivery-mode and priority.
- DecodedContent = rabbit_binary_parser:ensure_content_decoded(
- Content, rabbit_framing_amqp_0_9_1),
+ DecodedContent = rabbit_binary_parser:ensure_content_decoded(Content),
IsPersistent = is_message_persistent(DecodedContent),
Message = #basic_message{exchange_name = ExchangeName,
routing_key = RoutingKey,
diff --git a/src/rabbit_framing_channel.erl b/src/rabbit_framing_channel.erl
index 1fee6b56..3d74b122 100644
--- a/src/rabbit_framing_channel.erl
+++ b/src/rabbit_framing_channel.erl
@@ -78,18 +78,20 @@ mainloop(ChannelPid, Protocol) ->
case Protocol:method_has_content(MethodName) of
true -> {ClassId, _MethodId} = Protocol:method_id(MethodName),
rabbit_channel:do(ChannelPid, Method,
- collect_content(ChannelPid, ClassId));
+ collect_content(ChannelPid, ClassId,
+ Protocol));
false -> rabbit_channel:do(ChannelPid, Method)
end,
?MODULE:mainloop(ChannelPid, Protocol).
-collect_content(ChannelPid, ClassId) ->
+collect_content(ChannelPid, ClassId, Protocol) ->
case read_frame(ChannelPid) of
{content_header, ClassId, 0, BodySize, PropertiesBin} ->
Payload = collect_content_payload(ChannelPid, BodySize, []),
#content{class_id = ClassId,
properties = none,
properties_bin = PropertiesBin,
+ protocol = Protocol,
payload_fragments_rev = Payload};
{content_header, HeaderClassId, 0, _BodySize, _PropertiesBin} ->
rabbit_misc:protocol_error(