make decode_csum_file_entry() very slightly less brittle
This commit is contained in:
parent
d710d90ea7
commit
a0061d6ffa
2 changed files with 13 additions and 5 deletions
|
@ -926,7 +926,9 @@ encode_csum_file_entry_bin(Offset, Size, TaggedCSum) ->
|
||||||
-spec decode_csum_file_entry(binary()) ->
|
-spec decode_csum_file_entry(binary()) ->
|
||||||
{machi_dt:file_offset(), machi_dt:chunk_size(), machi_dt:chunk_s()}.
|
{machi_dt:file_offset(), machi_dt:chunk_size(), machi_dt:chunk_s()}.
|
||||||
decode_csum_file_entry(<<_:8/unsigned-big, Offset:64/unsigned-big, Size:32/unsigned-big, TaggedCSum/binary>>) ->
|
decode_csum_file_entry(<<_:8/unsigned-big, Offset:64/unsigned-big, Size:32/unsigned-big, TaggedCSum/binary>>) ->
|
||||||
{Offset, Size, TaggedCSum}.
|
{Offset, Size, TaggedCSum};
|
||||||
|
decode_csum_file_entry(_Else) ->
|
||||||
|
error.
|
||||||
|
|
||||||
%% @doc Split a `binary()' blob of `checksum_list' data into a list of
|
%% @doc Split a `binary()' blob of `checksum_list' data into a list of
|
||||||
%% unparsed `binary()' blobs, one per entry.
|
%% unparsed `binary()' blobs, one per entry.
|
||||||
|
@ -962,7 +964,12 @@ split_checksum_list_blob_decode(Bin) ->
|
||||||
|
|
||||||
split_checksum_list_blob_decode(<<Len:8/unsigned-big, Part:Len/binary, Rest/binary>>, Acc)->
|
split_checksum_list_blob_decode(<<Len:8/unsigned-big, Part:Len/binary, Rest/binary>>, Acc)->
|
||||||
One = <<Len:8/unsigned-big, Part/binary>>,
|
One = <<Len:8/unsigned-big, Part/binary>>,
|
||||||
split_checksum_list_blob_decode(Rest, [decode_csum_file_entry(One)|Acc]);
|
case decode_csum_file_entry(One) of
|
||||||
|
error ->
|
||||||
|
split_checksum_list_blob_decode(Rest, Acc);
|
||||||
|
DecOne ->
|
||||||
|
split_checksum_list_blob_decode(Rest, [DecOne|Acc])
|
||||||
|
end;
|
||||||
split_checksum_list_blob_decode(Rest, Acc) ->
|
split_checksum_list_blob_decode(Rest, Acc) ->
|
||||||
{lists:reverse(Acc), Rest}.
|
{lists:reverse(Acc), Rest}.
|
||||||
|
|
||||||
|
|
|
@ -178,8 +178,9 @@ checksum_list(#yessir{name=Name,chunk_size=ChunkSize}, _EpochID, File) ->
|
||||||
undefined ->
|
undefined ->
|
||||||
{error, no_such_file};
|
{error, no_such_file};
|
||||||
MaxOffset ->
|
MaxOffset ->
|
||||||
CSum = make_csum(Name, ChunkSize),
|
C = machi_util:make_tagged_csum(client_sha,
|
||||||
Cs = [{Offset, ChunkSize, CSum} ||
|
make_csum(Name, ChunkSize)),
|
||||||
|
Cs = [machi_flu1:encode_csum_file_entry_bin(Offset, ChunkSize, C) ||
|
||||||
Offset <- lists:seq(?MINIMUM_OFFSET, MaxOffset, ChunkSize)],
|
Offset <- lists:seq(?MINIMUM_OFFSET, MaxOffset, ChunkSize)],
|
||||||
{ok, Cs}
|
{ok, Cs}
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in a new issue