SerializableJSONLong.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-25
  6. * Changed: 2020-11-25
  7. *
  8. * */
  9. #include <ls_std/serialization/boxing/SerializableJSONLong.hpp>
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. ls_std::SerializableJSONLong::SerializableJSONLong(const std::shared_ptr<ls_std::Long>& _value) :
  12. Class("SerializableJSONLong")
  13. {
  14. this->_assignValue(_value);
  15. }
  16. ls_std::byte_field ls_std::SerializableJSONLong::marshal()
  17. {
  18. this->_update();
  19. return this->jsonObject.dump();
  20. }
  21. void ls_std::SerializableJSONLong::unmarshal(const ls_std::byte_field& _data)
  22. {
  23. std::string jsonString = std::string(_data);
  24. this->jsonObject = nlohmann::json::parse(jsonString);
  25. if(this->jsonObject.contains("value")) {
  26. *this->value = this->jsonObject["value"];
  27. }
  28. }
  29. void ls_std::SerializableJSONLong::_assignValue(const std::shared_ptr<ls_std::Long> &_value)
  30. {
  31. if(_value == nullptr) {
  32. throw ls_std::IllegalArgumentException {};
  33. }
  34. this->value = _value;
  35. }
  36. void ls_std::SerializableJSONLong::_update()
  37. {
  38. this->jsonObject = {
  39. {"value", (ls_std::long_type) this->value->getValue()}
  40. };
  41. }