@@ -321,11 +321,8 @@ purge_or_delete_queue(LinkPair, QueueName, PathSuffix) ->
321
321
{ok , Resp } ->
322
322
case is_success (Resp ) of
323
323
true ->
324
- # 'v1_0.amqp_value' {content = Content } = amqp10_msg :body (Resp ),
325
- {map , [
326
- {{utf8 , <<" message_count" >>}, {ulong , Count }}
327
- ]
328
- } = Content ,
324
+ # 'v1_0.amqp_value' {content = {map , KVList }} = amqp10_msg :body (Resp ),
325
+ #{{utf8 , <<" message_count" >>} := {ulong , Count }} = maps :from_list (KVList ),
329
326
{ok , #{message_count => Count }};
330
327
false ->
331
328
{error , Resp }
@@ -411,34 +408,45 @@ request(#link_pair{session = Session,
411
408
{ok , queue_info ()}.
412
409
get_queue_info (Response ) ->
413
410
# 'v1_0.amqp_value' {content = {map , KVList }} = amqp10_msg :body (Response ),
414
- Map = lists :foldl (
415
- fun ({{utf8 , Key = <<" arguments" >>}, {map , KVList0 }}, Acc ) ->
416
- Map = lists :foldl (fun ({{utf8 , K }, TypeVal }, M ) ->
417
- M #{K => TypeVal }
418
- end , #{}, KVList0 ),
419
- Acc #{to_atom (Key ) => Map };
420
- ({{utf8 , Key = <<" replicas" >>}, {array , utf8 , Arr }}, Acc ) ->
421
- L = lists :map (fun ({utf8 , Replica }) ->
422
- Replica
423
- end , Arr ),
424
- Acc #{to_atom (Key ) => L };
425
- ({{utf8 , Key }, TypeVal }, Acc ) ->
426
- Acc #{to_atom (Key ) => amqp10_client_types :unpack (TypeVal )}
427
- end , #{}, KVList ),
411
+ RespMap = maps :from_list (KVList ),
412
+
413
+ RequiredQInfo = [<<" name" >>,
414
+ <<" vhost" >>,
415
+ <<" durable" >>,
416
+ <<" exclusive" >>,
417
+ <<" auto_delete" >>,
418
+ <<" type" >>,
419
+ <<" message_count" >>,
420
+ <<" consumer_count" >>],
421
+ Map0 = lists :foldl (fun (Key , M ) ->
422
+ {ok , TypeVal } = maps :find ({utf8 , Key }, RespMap ),
423
+ M #{binary_to_atom (Key ) => amqp10_client_types :unpack (TypeVal )}
424
+ end , #{}, RequiredQInfo ),
425
+
426
+ {ok , {map , ArgsKVList }} = maps :find ({utf8 , <<" arguments" >>}, RespMap ),
427
+ ArgsMap = lists :foldl (fun ({{utf8 , K }, TypeVal }, M ) ->
428
+ M #{K => TypeVal }
429
+ end , #{}, ArgsKVList ),
430
+ Map1 = Map0 #{arguments => ArgsMap },
431
+
432
+ Map2 = case maps :find ({utf8 , <<" replicas" >>}, RespMap ) of
433
+ {ok , {array , utf8 , Arr }} ->
434
+ Replicas = lists :map (fun ({utf8 , Replica }) ->
435
+ Replica
436
+ end , Arr ),
437
+ Map1 #{replicas => Replicas };
438
+ error ->
439
+ Map1
440
+ end ,
441
+
442
+ Map = case maps :find ({utf8 , <<" leader" >>}, RespMap ) of
443
+ {ok , {utf8 , Leader }} ->
444
+ Map2 #{leader => Leader };
445
+ error ->
446
+ Map2
447
+ end ,
428
448
{ok , Map }.
429
449
430
- to_atom (<<" name" >>) -> name ;
431
- to_atom (<<" vhost" >>) -> vhost ;
432
- to_atom (<<" durable" >>) -> durable ;
433
- to_atom (<<" exclusive" >>) -> exclusive ;
434
- to_atom (<<" auto_delete" >>) -> auto_delete ;
435
- to_atom (<<" arguments" >>) -> arguments ;
436
- to_atom (<<" type" >>) -> type ;
437
- to_atom (<<" message_count" >>) -> message_count ;
438
- to_atom (<<" consumer_count" >>) -> consumer_count ;
439
- to_atom (<<" replicas" >>) -> replicas ;
440
- to_atom (<<" leader" >>) -> leader .
441
-
442
450
-spec encode_arguments (arguments ()) ->
443
451
{map , list (tuple ())}.
444
452
encode_arguments (Arguments ) ->
0 commit comments