This commit is contained in:
Feng 2015-08-16 00:36:56 +08:00
parent 27336f9859
commit 2f1c03a469
3 changed files with 10 additions and 3 deletions

View File

@ -38,6 +38,8 @@
-module(emqttd_guid). -module(emqttd_guid).
-author("Feng Lee <feng@emqtt.io>").
-export([gen/0, new/0, timestamp/1]). -export([gen/0, new/0, timestamp/1]).
-define(MAX_SEQ, 16#FFFF). -define(MAX_SEQ, 16#FFFF).
@ -54,17 +56,21 @@ gen() ->
undefined -> new(); undefined -> new();
{_Ts, NPid, Seq} -> next(NPid, Seq) {_Ts, NPid, Seq} -> next(NPid, Seq)
end, end,
put(guid, Guid), enc(Guid). put(guid, Guid), bin(Guid).
new() -> new() ->
{ts(), npid(), 0}. {ts(), npid(), 0}.
-spec timestamp(guid()) -> integer().
timestamp(<<Ts:64, _/binary>>) ->
Ts.
next(NPid, Seq) when Seq >= ?MAX_SEQ -> next(NPid, Seq) when Seq >= ?MAX_SEQ ->
{ts(), NPid, 0}; {ts(), NPid, 0};
next(NPid, Seq) -> next(NPid, Seq) ->
{ts(), NPid, Seq + 1}. {ts(), NPid, Seq + 1}.
enc({Ts, NPid, Seq}) -> bin({Ts, NPid, Seq}) ->
<<Ts:64, NPid:48, Seq:16>>. <<Ts:64, NPid:48, Seq:16>>.
ts() -> ts() ->

View File

@ -26,6 +26,7 @@
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
%% TODO: issue #103 %% TODO: issue #103
%% 0.12.0 ???
-module(emqttd_log). -module(emqttd_log).

View File

@ -28,5 +28,5 @@
-author("Feng Lee <feng@emqtt.io>"). -author("Feng Lee <feng@emqtt.io>").
%% TODO:... 0.10.0... %% TODO:... 0.11.0...