Skip to content

Commit

Permalink
Cleanup defp and extension object implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
DanLindeman committed Jul 16, 2021
1 parent 922f0cf commit c4dad68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
21 changes: 7 additions & 14 deletions lib/data_types/extension_object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@ defmodule ExOpcua.DataTypes.ExtensionObject do
end

def take(bin) do
with {node, <<encoding_mask, rest::binary>>} <- NodeId.take(bin) do
with {node, <<1, rest::binary>>} <- NodeId.take(bin) do
<<size::int(32), data::binary-size(size), rest::binary>> = rest
data_type = Map.get(@data_types, node.identifier, :not_implemented)

value =
case encoding_mask do
0 ->
:not_implemented

1 ->
case Map.get(@data_types, node.identifier) do
nil ->
:not_implemented

data_type ->
{value, _} = data_type.take(data)
value
end
if data_type != :not_implemented do
{value, _} = data_type.take(data)
value
else
:not_implemented
end

{value, rest}
Expand Down
10 changes: 5 additions & 5 deletions lib/data_types/server_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ defmodule ExOpcua.DataTypes.ServerStatus do
|> parse_shutdown_reason()
end

def parse_timestamp({acc, <<ts::int(64), rest::binary>>}, key) do
defp parse_timestamp({acc, <<ts::int(64), rest::binary>>}, key) do
timestamp = Timestamp.to_datetime(ts)
{Map.put(acc, key, timestamp), rest}
end

def parse_server_state({acc, <<state::int(32), rest::binary>>}) do
defp parse_server_state({acc, <<state::int(32), rest::binary>>}) do
{Map.put(acc, :server_state, state), rest}
end

def parse_build_info({acc, rest}) do
defp parse_build_info({acc, rest}) do
{value, rest} = BuildInfo.take(rest)
{Map.put(acc, :build_info, value), rest}
end

def parse_seconds_till_shutdown({acc, <<value::int(32), rest::binary>>}) do
defp parse_seconds_till_shutdown({acc, <<value::int(32), rest::binary>>}) do
{Map.put(acc, :seconds_till_shutdown, value), rest}
end

def parse_shutdown_reason({acc, rest}) do
defp parse_shutdown_reason({acc, rest}) do
{value, rest} = LocalizedText.take(rest)
{Map.put(acc, :shutdown_reason, value), rest}
end
Expand Down
12 changes: 6 additions & 6 deletions lib/parameter_types/data_value.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ defmodule ExOpcua.ParameterTypes.DataValue do
|> parse_timestamp(has_server_picoseconds, :server_picoseconds)
end

def parse_value({acc, <<rest::binary>>}, 1) do
defp parse_value({acc, <<rest::binary>>}, 1) do
{value, rest} = DataTypes.take_data_type(rest)
{Map.put(acc, :value, value), rest}
end

def parse_value({acc, rest}, 0) do
defp parse_value({acc, rest}, 0) do
{acc, rest}
end

def parse_status_code({acc, rest}, 1) do
defp parse_status_code({acc, rest}, 1) do
{status_code, rest} = StatusCode.take(rest)
{Map.put(acc, :status_code, status_code.severity), rest}
end

def parse_status_code({acc, rest}, 0), do: {acc, rest}
defp parse_status_code({acc, rest}, 0), do: {acc, rest}

def parse_timestamp({acc, <<ts::int(64), rest::binary>>}, 1, key) do
defp parse_timestamp({acc, <<ts::int(64), rest::binary>>}, 1, key) do
timestamp = Timestamp.to_datetime(ts)
{Map.put(acc, key, timestamp), rest}
end

def parse_timestamp({acc, rest}, 0, _key), do: {acc, rest}
defp parse_timestamp({acc, rest}, 0, _key), do: {acc, rest}
end
2 changes: 1 addition & 1 deletion lib/parameter_types/read_value_id.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule ExOpcua.ParameterTypes.ReadValueId do
@type t :: %__MODULE__{
node_id: NodeId.t(),
attribute_id: integer(),
# index_range: NumericRange.t(), # TODO
index_range: NumericRange.t(),
data_encoding: QualifiedName.t()
}

Expand Down

0 comments on commit c4dad68

Please sign in to comment.