Skip to content

Commit

Permalink
AppEngine: handle type casting for longinteger inputs
Browse files Browse the repository at this point in the history
Implemented `cast_value/2` functions to support string input parsing for `:longinteger` values and arrays in server-owned interfaces.

Signed-off-by: Ismet Softic <ismet.softic@secomind.com>
  • Loading branch information
Hibe7 committed Jul 8, 2024
1 parent af9afaa commit d8bfac8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [astarte_trigger_engine] Always treat event TTL for trigger policies in seconds,
not milliseconds.
- [astarte_trigger_engine] ack messages even with unreachable target (see https://github.com/astarte-platform/astarte/issues/936)
- [astarte_appengine_api] Handle type casting for `longinteger` inputs

## [1.1.1] - 2023-11-15
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,30 @@ defmodule Astarte.AppEngine.API.Device do
end
end

defp cast_value(:longinteger, string_value) when is_binary(string_value) do
case Integer.parse(string_value) do
{int_value, ""} ->
{:ok, int_value}

_ ->
{:error, :unexpected_value_type, expected: :longinteger}
end
end

defp cast_value(:longinteger, _string_value) do
{:error, :unexpected_value_type, expected: :longinteger}
end

defp cast_value(:longintegerarray, string_values) do
case map_while_ok(string_values, &cast_value(:longinteger, &1)) do
{:ok, mapped_values} ->
{:ok, mapped_values}

_ ->
{:error, :unexpected_value_type, expected: :longintegerarray}
end
end

defp cast_value(_anytype, anyvalue) do
{:ok, anyvalue}
end
Expand Down

0 comments on commit d8bfac8

Please sign in to comment.