@@ -122,11 +122,11 @@ decode({described, Descriptor, {map, Fields} = Type}) ->
122122 # 'v1_0.application_properties' {} ->
123123 # 'v1_0.application_properties' {content = decode_map (Fields )};
124124 # 'v1_0.delivery_annotations' {} ->
125- # 'v1_0.delivery_annotations' {content = decode_map (Fields )};
125+ # 'v1_0.delivery_annotations' {content = decode_annotations (Fields )};
126126 # 'v1_0.message_annotations' {} ->
127- # 'v1_0.message_annotations' {content = decode_map (Fields )};
127+ # 'v1_0.message_annotations' {content = decode_annotations (Fields )};
128128 # 'v1_0.footer' {} ->
129- # 'v1_0.footer' {content = decode_map (Fields )};
129+ # 'v1_0.footer' {content = decode_annotations (Fields )};
130130 # 'v1_0.amqp_value' {} ->
131131 # 'v1_0.amqp_value' {content = Type };
132132 Else ->
@@ -149,6 +149,16 @@ decode(Other) ->
149149decode_map (Fields ) ->
150150 [{decode (K ), decode (V )} || {K , V } <- Fields ].
151151
152+ % % "The annotations type is a map where the keys are restricted to be of type symbol
153+ % % or of type ulong. All ulong keys, and all symbolic keys except those beginning
154+ % % with "x-" are reserved." [3.2.10]
155+ % % Since we already parse annotations here and neither the client nor server uses
156+ % % reserved keys, we perform strict validation and crash if any reserved keys are used.
157+ decode_annotations (Fields ) ->
158+ lists :map (fun ({{symbol , <<" x-" , _ /binary >>} = K , V }) ->
159+ {K , decode (V )}
160+ end , Fields ).
161+
152162-spec encode_described (list | map | binary | annotations | '*' ,
153163 non_neg_integer (),
154164 amqp10_frame ()) ->
@@ -216,7 +226,7 @@ pprint(Other) -> Other.
216226-include_lib (" eunit/include/eunit.hrl" ).
217227
218228encode_decode_test_ () ->
219- Data = [{{utf8 , <<" k " >>}, {binary , <<" v " >>}}],
229+ Data = [{{symbol , <<" x-my key " >>}, {binary , <<" my value " >>}}],
220230 Test = fun (M ) -> [M ] = decode_bin (iolist_to_binary (encode_bin (M ))) end ,
221231 [
222232 fun () -> Test (# 'v1_0.application_properties' {content = Data }) end ,
0 commit comments