Skip to content

Commit

Permalink
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 3, 2024
1 parent fb5657d commit 32d5af3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
where database_retention_ttl exceeds the realm's maximum datastream storage
retention period, if set.

### Fixed
- [astarte_appengine_api] Handle type casting for `longinteger` inputs

## [1.1.2] - Unreleased
### Added
- [astarte_data_updater_plant] customize the number of consumer connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,29 @@ defmodule Astarte.AppEngine.API.Device do
end
end

defp cast_value(:longinteger, string_value) when is_binary(string_value) do
with {int_value, _} <- Integer.parse(string_value) do
{:ok, int_value}
else
:error ->
{: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 32d5af3

Please sign in to comment.