./ct_report/coverage/mongoose_node_num.COVER.html

1 %% Returns a numeric id from 0 to 255 for the current node.
2 %% Used to generate MAM IDs.
3 -module(mongoose_node_num).
4 -export([node_num/0, set_node_num/1]).
5
6 -type node_num() :: 0..255.
7 -export_type([node_num/0]).
8
9 %% @doc Return an integer node ID.
10 -spec node_num() -> node_num().
11 node_num() ->
12 %% We just return 0 if set_node_num/1 is not called.
13 3030 persistent_term:get(?MODULE, 0).
14
15 -spec set_node_num(node_num()) -> ignore | updated | same.
16 set_node_num(Num) ->
17 128 case node_num() =:= Num of
18 true ->
19 76 same;
20 false ->
21 52 persistent_term:put(?MODULE, Num),
22 52 updated
23 end.
Line Hits Source