* 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:
Joseph Abrahamson 2012-06-27 12:08:52 -04:00
parent accd056d53
commit 0b639933b5

View File

@ -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