Formatted

This commit is contained in:
Eishun Kondoh 2018-01-30 22:47:31 +09:00
parent 5fc01a9bec
commit 7635272fbd
150 changed files with 5055 additions and 4032 deletions

View file

@ -1,5 +1,4 @@
defmodule Openflow.MeterBand do
def read(meter_band_bin) do
do_read([], meter_band_bin)
end
@ -7,6 +6,7 @@ defmodule Openflow.MeterBand do
def to_binary(meter_bands) when is_list(meter_bands) do
to_binary(<<>>, meter_bands)
end
def to_binary(meter_band) do
to_binary([meter_band])
end
@ -14,15 +14,17 @@ defmodule Openflow.MeterBand do
# private functions
defp do_read(acc, <<>>), do: Enum.reverse(acc)
defp do_read(acc, <<type::16, length::16, _::bytes>> = binary) do
<<meter_band_bin::size(length)-bytes, rest::bytes>> = binary
codec = Openflow.Enums.to_atom(type, :meter_band_type)
do_read([codec.read(meter_band_bin)|acc], rest)
do_read([codec.read(meter_band_bin) | acc], rest)
end
defp to_binary(acc, []), do: acc
defp to_binary(acc, [meter_band|rest]) do
defp to_binary(acc, [meter_band | rest]) do
codec = meter_band.__struct__
to_binary(<<acc::bytes, (codec.to_binary(meter_band))::bytes>>, rest)
to_binary(<<acc::bytes, codec.to_binary(meter_band)::bytes>>, rest)
end
end