Also parse "done" lines
This works well for now, but if we're going to support multi_ack_detailed at some point, we need a better way of parsing the particular pkt.
This commit is contained in:
@@ -56,12 +56,21 @@ do_unpack(Len, Rest) ->
|
|||||||
parse_pkt(In, 0) ->
|
parse_pkt(In, 0) ->
|
||||||
{flush, In};
|
{flush, In};
|
||||||
parse_pkt(In, Len) ->
|
parse_pkt(In, Len) ->
|
||||||
LenLF = Len - 5 - ?SHA_LEN, % "want " | "want " + sha, remove LF if it's there
|
{Type, NameLen, Rest0} = pkt_type(In),
|
||||||
{Type, Rest0} = pkt_type(In),
|
LenLF = Len - NameLen, % lets us optionally clean the LF
|
||||||
<<Sha:?SHA_LEN/binary, _:LenLF/binary, Rest/binary>> = Rest0,
|
{Pkt, Rest1} = case Type of
|
||||||
{{Type, geef_oid:parse(Sha)}, Rest}.
|
done ->
|
||||||
|
{done, Rest0};
|
||||||
|
_ ->
|
||||||
|
<<Sha:?SHA_LEN/binary, R/binary>> = Rest0,
|
||||||
|
{{Type, geef_oid:parse(Sha)}, R}
|
||||||
|
end,
|
||||||
|
<<_:LenLF/binary, Rest/binary>> = Rest1,
|
||||||
|
{Pkt, Rest}.
|
||||||
|
|
||||||
pkt_type(<<"have ", Rest/binary>>) ->
|
pkt_type(<<"have ", Rest/binary>>) ->
|
||||||
{have, Rest};
|
{have, 5 + ?SHA_LEN, Rest};
|
||||||
pkt_type(<<"want ", Rest/binary>>) ->
|
pkt_type(<<"want ", Rest/binary>>) ->
|
||||||
{want, Rest}.
|
{want, 5 + ?SHA_LEN, Rest};
|
||||||
|
pkt_type(<<"done", Rest/binary>>) ->
|
||||||
|
{done, 4, Rest}.
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ flush_test() ->
|
|||||||
Actual = geef_pkt:parse("0000"),
|
Actual = geef_pkt:parse("0000"),
|
||||||
?assertEqual(Expected, Actual).
|
?assertEqual(Expected, Actual).
|
||||||
|
|
||||||
|
done_test() ->
|
||||||
|
Expected = {done, <<>>},
|
||||||
|
Actual = geef_pkt:parse("0009done\n"),
|
||||||
|
?assertEqual(Expected, Actual).
|
||||||
|
|
||||||
have_test() ->
|
have_test() ->
|
||||||
Expected = {{want, geef_oid:parse("e17ca7f2d877acbf8b9a9a1cb4c243ca72e86463")}, <<>>},
|
Expected = {{want, geef_oid:parse("e17ca7f2d877acbf8b9a9a1cb4c243ca72e86463")}, <<>>},
|
||||||
Actual = geef_pkt:parse("0032want e17ca7f2d877acbf8b9a9a1cb4c243ca72e86463\n"),
|
Actual = geef_pkt:parse("0032want e17ca7f2d877acbf8b9a9a1cb4c243ca72e86463\n"),
|
||||||
|
|||||||
Reference in New Issue
Block a user