From a020cfd3a87ba3223fc13ff762ddafa52d256044 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 16:51:58 +0300 Subject: [PATCH] Fix Position serialization --- src/sensesp/types/position.cpp | 21 +++++++++++++++++++++ src/sensesp/types/position.h | 14 +++----------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/sensesp/types/position.cpp diff --git a/src/sensesp/types/position.cpp b/src/sensesp/types/position.cpp new file mode 100644 index 000000000..6e5bebdc4 --- /dev/null +++ b/src/sensesp/types/position.cpp @@ -0,0 +1,21 @@ +#include "sensesp/types/position.h" + +#include + +namespace sensesp { + +void convertFromJson(JsonVariantConst src, Position &dst) { + dst.longitude = src["longitude"].as(); + dst.latitude = src["latitude"].as(); + + if (src.containsKey("altitude")) { + dst.altitude = src["altitude"].as(); + } +} + +bool canConvertFromJson(JsonVariantConst src, const Position &) { + return src.containsKey("latitude") && src.containsKey("longitude"); +} + + +} // namespace sensesp diff --git a/src/sensesp/types/position.h b/src/sensesp/types/position.h index a422e7a86..88a27e737 100644 --- a/src/sensesp/types/position.h +++ b/src/sensesp/types/position.h @@ -1,6 +1,7 @@ #ifndef SENSESP_TYPES_POSITION_H_ #define SENSESP_TYPES_POSITION_H_ +#include #include namespace sensesp { @@ -46,14 +47,7 @@ struct ENUVector { * @param src The JSON document containing the position data * @param dst The address to a Position struct to write the data to */ -void convertFromJson(JsonVariantConst src, Position &dst) { - dst.longitude = src["longitude"].as(); - dst.latitude = src["latitude"].as(); - - if (src.containsKey("altitude")) { - dst.altitude = src["altitude"].as(); - } -} +void convertFromJson(JsonVariantConst src, Position &dst); /** * @brief Tells ArduinoJson whether the given JSON is a Position or not @@ -66,9 +60,7 @@ void convertFromJson(JsonVariantConst src, Position &dst) { * @return false if the given JSON doesn't contain "latitude" or "longitude" * keys */ -bool canConvertFromJson(JsonVariantConst src, const Position &) { - return src.containsKey("latitude") && src.containsKey("longitude"); -} +bool canConvertFromJson(JsonVariantConst src, const Position &); } // namespace sensesp