SerializableJSONBoolean.cpp 938 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-04
  6. * Changed: 2020-11-06
  7. *
  8. * */
  9. #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONBoolean.hpp"
  10. ls_std::SerializableJSONBoolean::SerializableJSONBoolean(std::shared_ptr<ls_std::Boolean> _value) :
  11. Class("SerializableJSONBoolean"),
  12. value(std::move(_value))
  13. {}
  14. ls_std::byte_field ls_std::SerializableJSONBoolean::marshal()
  15. {
  16. this->_update();
  17. return this->jsonObject.dump();
  18. }
  19. void ls_std::SerializableJSONBoolean::unmarshal(const ls_std::byte_field& _data)
  20. {
  21. this->jsonObject = nlohmann::json::parse(_data);
  22. if(this->jsonObject.contains("value")) {
  23. *this->value = (bool) this->jsonObject["value"];
  24. }
  25. }
  26. void ls_std::SerializableJSONBoolean::_update()
  27. {
  28. this->jsonObject = {
  29. {"value", this->value->getValue()}
  30. };
  31. }