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.Action.NxFlowSpec do
def read(flow_spec_bin) do
do_read([], flow_spec_bin)
end
@ -7,6 +6,7 @@ defmodule Openflow.Action.NxFlowSpec do
def to_binary(flow_specs) when is_list(flow_specs) do
to_binary(<<>>, flow_specs)
end
def to_binary(flow_spec) do
to_binary([flow_spec])
end
@ -15,15 +15,17 @@ defmodule Openflow.Action.NxFlowSpec do
defp do_read(acc, <<>>), do: Enum.reverse(acc)
defp do_read(acc, <<0::16, _::bitstring>>), do: Enum.reverse(acc)
defp do_read(acc, <<_::2, _::1, type::2, _::bitstring>> = binary) do
codec = Openflow.Enums.to_atom(type, :nx_flow_spec_type)
{flow_spec, rest} = codec.read(binary)
do_read([flow_spec|acc], rest)
do_read([flow_spec | acc], rest)
end
defp to_binary(acc, []), do: acc
defp to_binary(acc, [flow_spec|rest]) do
defp to_binary(acc, [flow_spec | rest]) do
codec = flow_spec.__struct__
to_binary(<<acc::bytes, (codec.to_binary(flow_spec))::bytes>>, rest)
to_binary(<<acc::bytes, codec.to_binary(flow_spec)::bytes>>, rest)
end
end