Formatted
This commit is contained in:
parent
5fc01a9bec
commit
7635272fbd
150 changed files with 5055 additions and 4032 deletions
|
|
@ -1,5 +1,4 @@
|
|||
defmodule Openflow.Instruction do
|
||||
|
||||
def read(instruction_bin) do
|
||||
do_read([], instruction_bin)
|
||||
end
|
||||
|
|
@ -7,6 +6,7 @@ defmodule Openflow.Instruction do
|
|||
def to_binary(instructions) when is_list(instructions) do
|
||||
to_binary(<<>>, instructions)
|
||||
end
|
||||
|
||||
def to_binary(instruction) do
|
||||
to_binary([instruction])
|
||||
end
|
||||
|
|
@ -14,15 +14,17 @@ defmodule Openflow.Instruction do
|
|||
# private functions
|
||||
|
||||
defp do_read(acc, <<>>), do: Enum.reverse(acc)
|
||||
|
||||
defp do_read(acc, <<type::16, length::16, _::bytes>> = binary) do
|
||||
<<instruction_bin::size(length)-bytes, rest::bytes>> = binary
|
||||
codec = Openflow.Enums.to_atom(type, :instruction_type)
|
||||
do_read([codec.read(instruction_bin)|acc], rest)
|
||||
do_read([codec.read(instruction_bin) | acc], rest)
|
||||
end
|
||||
|
||||
defp to_binary(acc, []), do: acc
|
||||
defp to_binary(acc, [instruction|rest]) do
|
||||
|
||||
defp to_binary(acc, [instruction | rest]) do
|
||||
codec = instruction.__struct__
|
||||
to_binary(<<acc::bytes, (codec.to_binary(instruction))::bytes>>, rest)
|
||||
to_binary(<<acc::bytes, codec.to_binary(instruction)::bytes>>, rest)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue