3

在 Erlang R15B 下测试。

-spec parse_packet(integer(), binary()) -> list().

parse_packet(16013, <<0:16, _/binary>>) -> [];
parse_packet(16013, <<ListNum:16, ListBin/binary>>) ->
SizePerMount = byte_size(ListBin) div ListNum,
(1)Fun = fun(_, [<<MountBin:SizePerMount/binary, T/binary>>, Acc]) ->
              <<MountId:32, _:32, GoodsTypeId:32, _/binary>> = MountBin,
              [T, [{GoodsTypeId, MountId}|Acc]]
      end,
[_, MountIds] = lists:foldl(Fun, [ListBin, []], lists:seq(1, ListNum)),
(2)lager:info("MountList:~p", [MountIds]),
MountIds.

Dialyzer 在 (1) 和 (2) 处抱怨“创造的乐趣没有本地回报”。

我认为以下更新应该足以通过(1):

Fun = fun(_, [<<MountBin:SizePerMount/binary, T/binary>>, Acc]) ->
              <<MountId:32, _:32, GoodsTypeId:32, _/binary>> = MountBin,
              [T, [{GoodsTypeId, MountId}|Acc]]
         (_, [T, Acc]) ->
              [T, Acc]
      end,

但我认为应该有其他方式告诉 Dialyzer 更多类型信息。

谁能给点建议?先感谢您。

4

0 回答 0