SerializableJSONLong.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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-26
  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. ls_std::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. std::shared_ptr<ls_std::Long> ls_std::SerializableJSONLong::getValue()
  30. {
  31. return this->value;
  32. }
  33. void ls_std::SerializableJSONLong::setValue(const std::shared_ptr<ls_std::Long> &_value)
  34. {
  35. this->_assignValue(_value);
  36. }
  37. void ls_std::SerializableJSONLong::_assignValue(const std::shared_ptr<ls_std::Long> &_value)
  38. {
  39. if(_value == nullptr) {
  40. throw ls_std::IllegalArgumentException {};
  41. }
  42. this->value = _value;
  43. }
  44. void ls_std::SerializableJSONLong::_update()
  45. {
  46. this->jsonObject = {
  47. {"value", (ls_std::long_type) this->value->getValue()}
  48. };
  49. }