11
11
init /1 ,
12
12
size /1 ,
13
13
x_header /2 ,
14
+ x_headers /1 ,
14
15
routing_headers /2 ,
15
16
convert_to /3 ,
16
17
convert_from /3 ,
@@ -273,6 +274,23 @@ x_header(Key, #content{properties = none} = Content0) ->
273
274
Content = rabbit_binary_parser :ensure_content_decoded (Content0 ),
274
275
x_header (Key , Content ).
275
276
277
+ x_headers (# content {properties = # 'P_basic' {headers = undefined }}) ->
278
+ #{};
279
+ x_headers (# content {properties = # 'P_basic' {headers = Headers }}) ->
280
+ L = lists :filtermap (
281
+ fun ({Name , Type , Val }) ->
282
+ case mc_util :is_x_header (Name ) of
283
+ true ->
284
+ {true , {Name , from_091 (Type , Val )}};
285
+ false ->
286
+ false
287
+ end
288
+ end , Headers ),
289
+ maps :from_list (L );
290
+ x_headers (# content {properties = none } = Content0 ) ->
291
+ Content = rabbit_binary_parser :ensure_content_decoded (Content0 ),
292
+ x_headers (Content ).
293
+
276
294
property (Prop , Content ) ->
277
295
mc_util :infer_type (mc_compat :get_property (Prop , Content )).
278
296
@@ -690,10 +708,23 @@ from_091(binary, V) -> {binary, V};
690
708
from_091 (timestamp , V ) -> {timestamp , V * 1000 };
691
709
from_091 (byte , V ) -> {byte , V };
692
710
from_091 (void , _V ) -> null ;
693
- from_091 (array , L ) ->
694
- {list , [from_091 (T , V ) || {T , V } <- L ]};
695
711
from_091 (table , L ) ->
696
- {map , [{wrap (symbol , K ), from_091 (T , V )} || {K , T , V } <- L ]}.
712
+ {map , [{wrap (symbol , K ), from_091 (T , V )} || {K , T , V } <- L ]};
713
+ from_091 (array , []) ->
714
+ {list , []};
715
+ from_091 (array , L0 = [{T0 , _ } | _ ]) ->
716
+ {L = [{T1 , _ } | _ ], {Monomorphic , _ }} =
717
+ lists :mapfoldl (fun ({T , V }, {Mono0 , PrevType }) ->
718
+ Mono = case Mono0 of
719
+ false -> false ;
720
+ true -> T =:= PrevType
721
+ end ,
722
+ {from_091 (T , V ), {Mono , T }}
723
+ end , {true , T0 }, L0 ),
724
+ case Monomorphic of
725
+ true -> {array , T1 , L };
726
+ false -> {list , L }
727
+ end .
697
728
698
729
map_add (_T , _Key , _Type , undefined , Acc ) ->
699
730
Acc ;
@@ -707,7 +738,6 @@ supported_header_value_type(table) ->
707
738
supported_header_value_type (_ ) ->
708
739
true .
709
740
710
-
711
741
amqp10_map_get (_K , []) ->
712
742
undefined ;
713
743
amqp10_map_get (K , Tuples ) ->
@@ -857,3 +887,24 @@ amqp10_section_header(Header, Headers) ->
857
887
858
888
amqp_encoded_binary (Section ) ->
859
889
iolist_to_binary (amqp10_framing :encode_bin (Section )).
890
+
891
+ -ifdef (TEST ).
892
+ -include_lib (" eunit/include/eunit.hrl" ).
893
+
894
+ from_091_array_test () ->
895
+ {list , []} = from_091 (array , []),
896
+ {array , utf8 , [{utf8 , <<" e1" >>}]} = from_091 (array , [{longstr , <<" e1" >>}]),
897
+ {array , utf8 , [{utf8 , <<" e1" >>},
898
+ {utf8 , <<" e2" >>}]} = from_091 (array , [{longstr , <<" e1" >>},
899
+ {longstr , <<" e2" >>}]),
900
+ {list , [{utf8 , <<" e1" >>},
901
+ {binary , <<" e2" >>}]} = from_091 (array , [{longstr , <<" e1" >>},
902
+ {binary , <<" e2" >>}]),
903
+ {list , [{utf8 , <<" e1" >>},
904
+ {binary , <<" e2" >>},
905
+ {utf8 , <<" e3" >>},
906
+ {utf8 , <<" e4" >>}]} = from_091 (array , [{longstr , <<" e1" >>},
907
+ {binary , <<" e2" >>},
908
+ {longstr , <<" e3" >>},
909
+ {longstr , <<" e4" >>}]).
910
+ -endif .
0 commit comments