SerializableJSONStateConnection.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-14
  6. * Changed: 2020-11-06
  7. *
  8. * */
  9. #include "../../../../../include/ls_std/serialization/logic/SerializableJSONStateConnection.hpp"
  10. ls_std::SerializableJSONStateConnection::SerializableJSONStateConnection(std::shared_ptr<ls_std::StateConnection> _value) :
  11. Class("SerializableJSONStateConnection"),
  12. value(std::move(_value))
  13. {}
  14. ls_std::byte_field ls_std::SerializableJSONStateConnection::marshal()
  15. {
  16. this->_update();
  17. return this->jsonObject.dump();
  18. }
  19. void ls_std::SerializableJSONStateConnection::unmarshal(const ls_std::byte_field &_data)
  20. {
  21. std::string jsonString = std::string(_data);
  22. this->jsonObject = nlohmann::json::parse(jsonString);
  23. this->value->setConnectionId(this->jsonObject["connectionId"]);
  24. this->value->setStateId(this->jsonObject["stateId"]);
  25. this->value->updatePassCondition(this->jsonObject["condition"]);
  26. }
  27. void ls_std::SerializableJSONStateConnection::setValue(std::shared_ptr<ls_std::StateConnection> _value)
  28. {
  29. this->value = std::move(_value);
  30. this->_clear();
  31. }
  32. void ls_std::SerializableJSONStateConnection::_clear()
  33. {
  34. this->jsonObject.clear();
  35. }
  36. void ls_std::SerializableJSONStateConnection::_update()
  37. {
  38. this->jsonObject = {
  39. {"condition", this->value->isPassable()},
  40. {"connectionId", this->value->getConnectionId()},
  41. {"stateId", this->value->getStateId()}
  42. };
  43. }