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,16 +1,19 @@
defmodule Openflow.Utils do
import Bitwise
def int_to_flags(acc, int, [{type, flagint}|rest]) when (int &&& flagint) == flagint do
int_to_flags([type|acc], int, rest)
def int_to_flags(acc, int, [{type, flagint} | rest]) when (int &&& flagint) == flagint do
int_to_flags([type | acc], int, rest)
end
def int_to_flags(acc, int, [_h|rest]) do
def int_to_flags(acc, int, [_h | rest]) do
int_to_flags(acc, int, rest)
end
def int_to_flags(acc, _int, []), do: Enum.reverse(acc)
def flags_to_int(acc, [], _enum), do: acc
def flags_to_int(acc0, [flag|rest], enum) do
def flags_to_int(acc0, [flag | rest], enum) do
acc = acc0 ||| Keyword.get(enum, flag, 0)
flags_to_int(acc, rest, enum)
end
@ -18,14 +21,14 @@ defmodule Openflow.Utils do
def to_hex_string(binary), do: datapath_id(binary)
def padding(length, padding) do
case (padding - rem(length, padding)) do
case padding - rem(length, padding) do
^padding -> 0
pad_len -> pad_len
pad_len -> pad_len
end
end
def pad_length(length, width) do
rem((width - rem(length, width)), width)
rem(width - rem(length, width), width)
end
def decode_string(binary) do
@ -43,6 +46,7 @@ defmodule Openflow.Utils do
:bad_enum -> int
end
end
def get_enum(int, type) do
try do
Openflow.Enums.to_int(int, type)
@ -57,7 +61,7 @@ defmodule Openflow.Utils do
binary
|> split_to_hex_string
|> Enum.join("")
|> String.downcase
|> String.downcase()
end
defp split_to_hex_string(binary) do
@ -67,7 +71,7 @@ defmodule Openflow.Utils do
defp integer_to_hex(int) do
case Integer.to_string(int, 16) do
<<d>> -> <<48, d>>
dd -> dd
dd -> dd
end
end
end