Skip to content

Commit

Permalink
Fix serialize nb of subsets
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmanzanera committed Apr 7, 2023
1 parent c6be90a commit 27d59af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/archethic/p2p/message/get_network_stats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ defmodule Archethic.P2P.Message.GetNetworkStats do
iex> %GetNetworkStats{subsets: [<<0>>]} |> GetNetworkStats.serialize()
<<
# Length of subsets
1,
0, 1,
# Subset
0
>>
"""
def serialize(%__MODULE__{subsets: subsets}) do
<<length(subsets)::8, :erlang.list_to_binary(subsets)::binary>>
<<length(subsets)::16, :erlang.list_to_binary(subsets)::binary>>
end

@doc """
Deserialize the binary into the get network stats message
## Examples
iex> <<1, 0>> |> GetNetworkStats.deserialize()
iex> <<0, 1, 0>> |> GetNetworkStats.deserialize()
{
%GetNetworkStats{subsets: [<<0>>]},
""
}
"""
def deserialize(<<length::8, subsets_binary::binary-size(length), rest::bitstring>>) do
def deserialize(<<length::16, subsets_binary::binary-size(length), rest::bitstring>>) do
subsets =
subsets_binary
|> :erlang.binary_to_list()
Expand Down
8 changes: 4 additions & 4 deletions lib/archethic/p2p/message/network_stats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Archethic.P2P.Message.NetworkStats do
...> }}} |> NetworkStats.serialize()
<<
# Nb subsets
1,
0, 1,
# Subset
0,
# Nb node stats
Expand All @@ -55,7 +55,7 @@ defmodule Archethic.P2P.Message.NetworkStats do
end)
|> :erlang.list_to_binary()

<<nb_subsets::8, stats_binary::binary>>
<<nb_subsets::16, stats_binary::binary>>
end

defp serialize_subset_stats(subset, stats) do
Expand Down Expand Up @@ -83,7 +83,7 @@ defmodule Archethic.P2P.Message.NetworkStats do
## Examples
iex> <<1, 0, 1, 1, 0, 0, 75, 23, 134, 64, 221, 117, 107, 77, 233, 123, 201, 244, 18, 151,
iex> <<0, 1, 0, 1, 1, 0, 0, 75, 23, 134, 64, 221, 117, 107, 77, 233, 123, 201, 244, 18, 151,
...> 8, 255, 53, 137, 251, 197, 67, 25, 38, 95, 2, 62, 216, 131, 112, 116, 238,
...> 180, 1, 3, 1, 100, 1, 110, 1, 80>> |> NetworkStats.deserialize()
{
Expand All @@ -99,7 +99,7 @@ defmodule Archethic.P2P.Message.NetworkStats do
}
"""
@spec deserialize(bitstring()) :: {t(), bitstring()}
def deserialize(<<nb_subsets::8, rest::bitstring>>) do
def deserialize(<<nb_subsets::16, rest::bitstring>>) do
{stats, rest} = get_subsets_stats(rest, nb_subsets, %{})

{
Expand Down
2 changes: 1 addition & 1 deletion test/archethic/beacon_chain/summary_aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Archethic.BeaconChain.SummaryAggregateTest do
node_availabilities: <<>>,
node_average_availabilities: [],
end_of_node_synchronizations: [],
network_patches: ["9C6", "DEF"]
network_patches: ["BA6", "DEF"]
}
}
} =
Expand Down

0 comments on commit 27d59af

Please sign in to comment.