Skip to content

Commit 535567b

Browse files
author
Matthew Sackman
committed
Merging heads of default
2 parents d0cea8a + 3ccb10b commit 535567b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/rabbit_misc.erl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
protocol_error/3, protocol_error/4, protocol_error/1]).
2626
-export([not_found/1, assert_args_equivalence/4]).
2727
-export([dirty_read/1]).
28-
-export([table_lookup/2]).
28+
-export([table_lookup/2, set_table_value/4]).
2929
-export([r/3, r/2, r_arg/4, rs/1]).
3030
-export([enable_cover/0, report_cover/0]).
3131
-export([enable_cover/1, report_cover/1]).
@@ -56,6 +56,7 @@
5656
-export([const_ok/0, const/1]).
5757
-export([ntoa/1, ntoab/1]).
5858
-export([is_process_alive/1]).
59+
-export([pget/2, pget/3, pget_or_die/2]).
5960

6061
%%----------------------------------------------------------------------------
6162

@@ -104,6 +105,11 @@
104105
-spec(table_lookup/2 ::
105106
(rabbit_framing:amqp_table(), binary())
106107
-> 'undefined' | {rabbit_framing:amqp_field_type(), any()}).
108+
-spec(set_table_value/4 ::
109+
(rabbit_framing:amqp_table(), binary(),
110+
rabbit_framing:amqp_field_type(), rabbit_framing:amqp_value())
111+
-> rabbit_framing:amqp_table()).
112+
107113
-spec(r/2 :: (rabbit_types:vhost(), K)
108114
-> rabbit_types:r3(rabbit_types:vhost(), K, '_')
109115
when is_subtype(K, atom())).
@@ -196,6 +202,9 @@
196202
-spec(ntoa/1 :: (inet:ip_address()) -> string()).
197203
-spec(ntoab/1 :: (inet:ip_address()) -> string()).
198204
-spec(is_process_alive/1 :: (pid()) -> boolean()).
205+
-spec(pget/2 :: (term(), [term()]) -> term()).
206+
-spec(pget/3 :: (term(), [term()], term()) -> term()).
207+
-spec(pget_or_die/2 :: (term(), [term()]) -> term() | no_return()).
199208

200209
-endif.
201210

@@ -268,6 +277,10 @@ table_lookup(Table, Key) ->
268277
false -> undefined
269278
end.
270279

280+
set_table_value(Table, Key, Type, Value) ->
281+
sort_field_table(
282+
lists:keystore(Key, 1, Table, {Key, Type, Value})).
283+
271284
r(#resource{virtual_host = VHostPath}, Kind, Name)
272285
when is_binary(Name) ->
273286
#resource{virtual_host = VHostPath, kind = Kind, name = Name};
@@ -897,3 +910,12 @@ is_process_alive(Pid) ->
897910
true -> true;
898911
_ -> false
899912
end.
913+
914+
pget(K, P) -> proplists:get_value(K, P).
915+
pget(K, P, D) -> proplists:get_value(K, P, D).
916+
917+
pget_or_die(K, P) ->
918+
case proplists:get_value(K, P) of
919+
undefined -> exit({error, key_missing, K});
920+
V -> V
921+
end.

0 commit comments

Comments
 (0)