to_hexstr/1, from_hexstr/1

This commit is contained in:
Feng Lee 2016-08-23 10:13:13 +08:00
parent a0e2d2981a
commit b0f082ebe0
2 changed files with 14 additions and 2 deletions

View File

@ -29,7 +29,7 @@
%% @end
-module(emqttd_guid).
-export([gen/0, new/0, timestamp/1]).
-export([gen/0, new/0, timestamp/1, to_hexstr/1, from_hexstr/1]).
-define(MAX_SEQ, 16#FFFF).
@ -120,3 +120,9 @@ npid() ->
PidByte3:8, PidByte4:8>>,
NPid.
to_hexstr(<<I:128>>) ->
list_to_binary(integer_to_list(I, 16)).
from_hexstr(S) ->
I = list_to_integer(binary_to_list(S), 16), <<I:128>>.

View File

@ -16,6 +16,8 @@
-module(emqttd_lib_SUITE).
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-define(SOCKOPTS, [
@ -35,7 +37,7 @@ all() -> [{group, guid}, {group, opts},
{group, node}, {group, base62}].
groups() ->
[{guid, [], [guid_gen]},
[{guid, [], [guid_gen, guid_hexstr]},
{opts, [], [opts_merge]},
{?PQ, [], [priority_queue_plen,
priority_queue_out2]},
@ -56,6 +58,10 @@ guid_gen(_) ->
Ts2 = emqttd_guid:timestamp(emqttd_guid:gen()),
true = Ts2 > Ts1.
guid_hexstr(_) ->
Guid = emqttd_guid:gen(),
?assertEqual(Guid, emqttd_guid:from_hexstr(emqttd_guid:to_hexstr(Guid))).
%%--------------------------------------------------------------------
%% emqttd_opts
%%--------------------------------------------------------------------