mirror of
https://github.com/valitydev/snowflake.git
synced 2024-11-06 17:15:20 +00:00
* src/snowflake.erl: Added serialization/deserialization methods.
snowflake:serialize/1 and snowflake:deserialize/1 are wrappers around base64:encode. So from here out we pick base64 as cannonical serialization format.
This commit is contained in:
parent
accd056d53
commit
0b639933b5
@ -77,6 +77,16 @@ new(Server, Name) when is_atom(Name) ->
|
||||
{Name, Pid, _, _} -> new(Pid)
|
||||
end.
|
||||
|
||||
|
||||
-spec
|
||||
serialize(uuid()) -> binary().
|
||||
serialize(UUID) -> base64:encode(UUID).
|
||||
|
||||
-spec
|
||||
deserialize(binary() | nonempty_string()) -> uuid().
|
||||
deserialize(Bin) when is_binary(Bin) -> base64:decode(Bin);
|
||||
deserialize(Str) when is_list(Str) -> base64:decode(list_to_binary(Str)).
|
||||
|
||||
%% -----------
|
||||
%% Private API
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user