diff --git a/deps/rabbit/src/mc_amqp.erl b/deps/rabbit/src/mc_amqp.erl index 00a696f7cb7..b31de8747fc 100644 --- a/deps/rabbit/src/mc_amqp.erl +++ b/deps/rabbit/src/mc_amqp.erl @@ -346,6 +346,31 @@ prepare(read, Msg) -> Msg; prepare(store, Msg = #v1{}) -> Msg; +prepare(store, #msg_body_encoded{ + message_annotations = MA, + properties = Props, + bare_and_footer = BF, + bare_and_footer_application_properties_pos = AppPropsPos, + bare_and_footer_body_pos = uninit, + body_code = uninit}) -> + %% Message has no body section. We still convert to #v1{} so that + %% classic/quorum queues can store it on disk. We mark the body + %% position at the end of the bare_and_footer binary; since there + %% is no actual body, decoding will only see properties and + %% application-properties. + PropsPos = case Props of + undefined -> ?OMITTED_SECTION; + #'v1_0.properties'{} -> 0 + end, + #v1{message_annotations = MA, + bare_and_footer = BF, + bare_and_footer_properties_pos = PropsPos, + bare_and_footer_application_properties_pos = AppPropsPos, + bare_and_footer_body_pos = byte_size(BF), + %% body_code is unused when there is no body, but must be a valid + %% descriptor code; DATA is the most neutral choice. + body_code = ?DESCRIPTOR_CODE_DATA + }; prepare(store, #msg_body_encoded{ message_annotations = MA, properties = Props, @@ -609,6 +634,9 @@ msg_body_decoded([#'v1_0.amqp_value'{} = B | Rem], #msg_body_decoded{} = Msg) -> msg_body_decoded([#'v1_0.footer'{content = FC} | Rem], Msg) -> msg_body_decoded(Rem, Msg#msg_body_decoded{footer = FC}). +msg_body_encoded([], _Payload, Msg) -> + %% handle empty or undefined body + Msg; msg_body_encoded([#'v1_0.header'{} = H | Rem], Payload, Msg) -> msg_body_encoded(Rem, Payload, Msg#msg_body_encoded{header = H}); msg_body_encoded([_Ignore = #'v1_0.delivery_annotations'{} | Rem], Payload, Msg) ->