SerializableJSONStateConnection.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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-15
  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. }
  32. void ls_std::SerializableJSONStateConnection::_update()
  33. {
  34. this->jsonObject = {
  35. {"condition", this->value->isPassable()},
  36. {"connectionId", this->value->getConnectionId()},
  37. {"stateId", this->value->getStateId()}
  38. };
  39. }