Skip to content

Commit

Permalink
Merge pull request #74 from helium/adt/rbc-deserialization-robustness
Browse files Browse the repository at this point in the history
Attempt better serialization/deserialzation for rbc
  • Loading branch information
evanmcc committed Nov 16, 2021
2 parents c8d9af0 + 73cd438 commit 800104f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/hbbft_rbc.erl
Expand Up @@ -283,7 +283,8 @@ serialize(#rbc_data{stripes=Stripes}=Data) when Stripes /= #{} ->
#{rbc_data => term_to_binary(Data#rbc_data{stripes=#{}}), stripes =>
maps:map(fun(_K, V) ->
maps:map(fun(_K2, {Index, Size, Shard}) ->
#{index => <<Index:8/integer>>, size => <<Size:32/integer>>, shard => Shard}
%% encode as u32 because rocks seems to like dropping smakk keys??
#{index => <<Index:32/integer>>, size => <<Size:32/integer>>, shard => Shard}
end, V)
end, Stripes)};
serialize(#rbc_data{}=Data) ->
Expand All @@ -292,7 +293,13 @@ serialize(#rbc_data{}=Data) ->
deserialize(#{rbc_data := BinData}=Map) ->
Data = binary_to_term(BinData),
Data#rbc_data{stripes=maps:map(fun(_K, V) ->
maps:map(fun(_K2, #{index := <<Index:8/integer>>, size := <<Size:32/integer>>, shard := Shard}) ->
{Index, Size, Shard}
end, V)
maps:fold(fun(K2, #{index := <<Index:8/integer>>, size := <<Size:32/integer>>, shard := Shard}, Acc) ->
%% legacy decoding
maps:put(K2, {Index, Size, Shard}, Acc);
(K2, #{index := <<Index:32/integer>>, size := <<Size:32/integer>>, shard := Shard}, Acc) ->
maps:put(K2, {Index, Size, Shard}, Acc);
(_, _, Acc) ->
%% unable to deserialize???
Acc
end, #{}, V)
end, maps:get(stripes, Map, #{}))}.

0 comments on commit 800104f

Please sign in to comment.