diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2010-07-09 11:56:10 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2010-07-09 11:56:10 +0100 |
| commit | 459ee51cab12da7a45e590ab26fbd98e23108981 (patch) | |
| tree | 7c62275f592c0f0c47d1e63aabf44e55a576ba5a /src | |
| parent | 57636ecb35a82f9ff35a69e9637c2b183e044acd (diff) | |
| download | rabbitmq-server-git-459ee51cab12da7a45e590ab26fbd98e23108981.tar.gz | |
Store protocol with encoded properties, use it to transcode if needed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_basic.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_binary_generator.erl | 24 | ||||
| -rw-r--r-- | src/rabbit_binary_parser.erl | 9 | ||||
| -rw-r--r-- | src/rabbit_channel.erl | 3 | ||||
| -rw-r--r-- | src/rabbit_framing_channel.erl | 6 |
5 files changed, 29 insertions, 19 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index 4a1d50df03..357333a948 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 75cd643c1e..200bf2cd44 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 633be6f0ca..b1c7c3278c 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 213b6624d5..55b5d87571 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 1fee6b5636..3d74b122d9 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( |
