SerializableJSONStateConnection.cpp 1.4 KB

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