summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2010-07-02 17:11:48 +0100
committerSimon MacMullen <simon@rabbitmq.com>2010-07-02 17:11:48 +0100
commit98054097344a20ce3a03724295d9e240643efc22 (patch)
tree4497ec12ff12349340666064ed2c7ce4273bd7b8
parent055b445e6ff692c1354899e3889c3f3ea5a7bda6 (diff)
downloadrabbitmq-server-98054097344a20ce3a03724295d9e240643efc22.tar.gz
Remove remaining hard coding of rabbit_framing_amqp_0_9_1 from the codec.
-rw-r--r--src/rabbit_basic.erl5
-rw-r--r--src/rabbit_binary_generator.erl28
-rw-r--r--src/rabbit_binary_parser.erl10
-rw-r--r--src/rabbit_channel.erl4
-rw-r--r--src/rabbit_tests.erl3
-rw-r--r--src/rabbit_writer.erl2
6 files changed, 28 insertions, 24 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl
index 7b581b8d..4a1d50df 100644
--- a/src/rabbit_basic.erl
+++ b/src/rabbit_basic.erl
@@ -92,8 +92,9 @@ from_content(Content) ->
#content{class_id = ClassId,
properties = Props,
payload_fragments_rev = FragmentsRev} =
- rabbit_binary_parser:ensure_content_decoded(Content),
- %% basic.publish hasn't changed so we can just hard-code amqp_0_9_1
+ %% 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),
{ClassId, _MethodId} =
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 d159f309..75cd643c 100644
--- a/src/rabbit_binary_generator.erl
+++ b/src/rabbit_binary_generator.erl
@@ -42,11 +42,11 @@
-define(EMPTY_CONTENT_BODY_FRAME_SIZE, 8).
-export([build_simple_method_frame/3,
- build_simple_content_frames/3,
+ build_simple_content_frames/4,
build_heartbeat_frame/0]).
-export([generate_table/1, encode_properties/2]).
-export([check_empty_content_body_frame_size/0]).
--export([ensure_content_encoded/1, clear_encoded_content/1]).
+-export([ensure_content_encoded/2, clear_encoded_content/1]).
-import(lists).
@@ -58,13 +58,14 @@
-spec(build_simple_method_frame/3 ::
(channel_number(), amqp_method_record(), protocol()) -> frame()).
--spec(build_simple_content_frames/3 ::
- (channel_number(), content(), non_neg_integer()) -> [frame()]).
+-spec(build_simple_content_frames/4 ::
+ (channel_number(), content(), non_neg_integer(), protocol()) ->
+ [frame()]).
-spec(build_heartbeat_frame/0 :: () -> frame()).
-spec(generate_table/1 :: (amqp_table()) -> binary()).
-spec(encode_properties/2 :: ([amqp_property_type()], [any()]) -> binary()).
-spec(check_empty_content_body_frame_size/0 :: () -> 'ok').
--spec(ensure_content_encoded/1 :: (content()) -> encoded_content()).
+-spec(ensure_content_encoded/2 :: (content(), protocol()) -> encoded_content()).
-spec(clear_encoded_content/1 :: (content()) -> unencoded_content()).
-endif.
@@ -82,18 +83,18 @@ build_simple_content_frames(ChannelInt,
properties = ContentProperties,
properties_bin = ContentPropertiesBin,
payload_fragments_rev = PayloadFragmentsRev},
- FrameMax) ->
+ 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)]),
+ maybe_encode_properties(ContentProperties, ContentPropertiesBin, Protocol)]),
[HeaderFrame | ContentFrames].
-maybe_encode_properties(_ContentProperties, ContentPropertiesBin)
+maybe_encode_properties(_ContentProperties, ContentPropertiesBin, _Protocol)
when is_binary(ContentPropertiesBin) ->
ContentPropertiesBin;
-maybe_encode_properties(ContentProperties, none) ->
- rabbit_framing_amqp_0_9_1:encode_properties(ContentProperties).
+maybe_encode_properties(ContentProperties, none, Protocol) ->
+ Protocol:encode_properties(ContentProperties).
build_content_frames(FragsRev, FrameMax, ChannelInt) ->
BodyPayloadMax = if FrameMax == 0 ->
@@ -277,12 +278,11 @@ check_empty_content_body_frame_size() ->
ComputedSize, ?EMPTY_CONTENT_BODY_FRAME_SIZE})
end.
-ensure_content_encoded(Content = #content{properties_bin = PropsBin})
+ensure_content_encoded(Content = #content{properties_bin = PropsBin}, _Protocol)
when PropsBin =/= 'none' ->
Content;
-ensure_content_encoded(Content = #content{properties = Props}) ->
- Content #content{properties_bin =
- rabbit_framing_amqp_0_9_1:encode_properties(Props)}.
+ensure_content_encoded(Content = #content{properties = Props}, Protocol) ->
+ Content#content{properties_bin = Protocol:encode_properties(Props)}.
clear_encoded_content(Content = #content{properties_bin = none}) ->
Content;
diff --git a/src/rabbit_binary_parser.erl b/src/rabbit_binary_parser.erl
index 7a32acae..633be6f0 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/1, clear_decoded_content/1]).
+-export([ensure_content_decoded/2, 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/1 :: (content()) -> decoded_content()).
+-spec(ensure_content_decoded/2 :: (content(), protocol()) -> decoded_content()).
-spec(clear_decoded_content/1 :: (content()) -> undecoded_content()).
-endif.
@@ -159,12 +159,12 @@ 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})
+ensure_content_decoded(Content = #content{properties = Props}, _Protocol)
when Props =/= 'none' ->
Content;
-ensure_content_decoded(Content = #content{properties_bin = PropBin})
+ensure_content_decoded(Content = #content{properties_bin = PropBin}, Protocol)
when is_binary(PropBin) ->
- Content#content{properties = rabbit_framing_amqp_0_9_1:decode_properties(
+ Content#content{properties = Protocol:decode_properties(
Content#content.class_id, PropBin)}.
clear_decoded_content(Content = #content{properties = none}) ->
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index da91bef8..c3440f84 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -414,7 +414,9 @@ 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),
+ DecodedContent =
+ rabbit_binary_parser:ensure_content_decoded(Content,
+ rabbit_framing_amqp_0_9_1),
IsPersistent = is_message_persistent(DecodedContent),
Message = #basic_message{exchange_name = ExchangeName,
routing_key = RoutingKey,
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 960d9a9c..53f73b9d 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -361,7 +361,8 @@ test_content_framing(FrameMax, Fragments) ->
1,
#content{class_id = 0, properties_bin = <<>>,
payload_fragments_rev = Fragments},
- FrameMax),
+ FrameMax,
+ rabbit_framing_amqp_0_9_1),
%% header is formatted correctly and the size is the total of the
%% fragments
<<_FrameHeader:7/binary, _ClassAndWeight:4/binary,
diff --git a/src/rabbit_writer.erl b/src/rabbit_writer.erl
index 17b8f53e..1e1a547b 100644
--- a/src/rabbit_writer.erl
+++ b/src/rabbit_writer.erl
@@ -174,7 +174,7 @@ assemble_frames(Channel, MethodRecord, Content, FrameMax, Protocol) ->
MethodFrame = rabbit_binary_generator:build_simple_method_frame(
Channel, MethodRecord, Protocol),
ContentFrames = rabbit_binary_generator:build_simple_content_frames(
- Channel, Content, FrameMax),
+ Channel, Content, FrameMax, Protocol),
[MethodFrame | ContentFrames].
tcp_send(Sock, Data) ->