Skip to content

Instantly share code, notes, and snippets.

@argv0
Created November 22, 2012 03:57
Show Gist options
  • Save argv0/4129376 to your computer and use it in GitHub Desktop.
Save argv0/4129376 to your computer and use it in GitHub Desktop.
vclock_to_binary([], Acc, Size) ->
VclockSize = size(Acc),
<<VclockSize:32/integer, Acc/binary>>;
vclock_to_binary([{AId, {Count, TS}}|T], Acc, Size) ->
AIdSize = size(AId),
vclock_to_binary(T, <<AIdSize:8/integer, AId:AIdSize/binary, Count:64/integer, TS:32/integer, Acc/binary>>, Size+1).
binary_to_vclock(<<VclockSize:32/integer, VclockBin:VclockSize/binary, Rest/binary>>) ->
binary_to_vclock(VclockBin, []).
binary_to_vclock(<<>>, Acc) ->
lists:reverse(Acc);
binary_to_vclock(<<AIdSize:8/integer, AId:AIdSize/binary, Count:64/integer, TS:32/integer, Rest/binary>>, Acc) ->
binary_to_vclock(Rest, [{AId, {Count, TS}}|Acc]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment