SerializableJSONStateConnection.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-14
  6. * Changed: 2020-09-14
  7. *
  8. * */
  9. #include "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::_update()
  28. {
  29. this->jsonObject = {
  30. {"condition", this->value->isPassable()},
  31. {"connectionId", this->value->getConnectionId()},
  32. {"stateId", this->value->getStateId()}
  33. };
  34. }