💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.9 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "resources/deserializer.hpp"
  20. #include <string>
  21. template <>
  22. void deserializer<bool>::deserialize(bool& value, deserialize_context& ctx)
  23. {
  24. std::uint8_t temp;
  25. ctx.read8(reinterpret_cast<std::byte*>(&temp), 1);
  26. value = (temp) ? true : false;
  27. };
  28. template <>
  29. void deserializer<std::uint8_t>::deserialize(std::uint8_t& value, deserialize_context& ctx)
  30. {
  31. ctx.read8(reinterpret_cast<std::byte*>(&value), 1);
  32. };
  33. template <>
  34. void deserializer<std::uint16_t>::deserialize(std::uint16_t& value, deserialize_context& ctx)
  35. {
  36. ctx.read16(reinterpret_cast<std::byte*>(&value), 1);
  37. };
  38. template <>
  39. void deserializer<std::uint32_t>::deserialize(std::uint32_t& value, deserialize_context& ctx)
  40. {
  41. ctx.read32(reinterpret_cast<std::byte*>(&value), 1);
  42. };
  43. template <>
  44. void deserializer<std::uint64_t>::deserialize(std::uint64_t& value, deserialize_context& ctx)
  45. {
  46. ctx.read64(reinterpret_cast<std::byte*>(&value), 1);
  47. };
  48. template <>
  49. void deserializer<std::int8_t>::deserialize(std::int8_t& value, deserialize_context& ctx)
  50. {
  51. ctx.read8(reinterpret_cast<std::byte*>(&value), 1);
  52. };
  53. template <>
  54. void deserializer<std::int16_t>::deserialize(std::int16_t& value, deserialize_context& ctx)
  55. {
  56. ctx.read16(reinterpret_cast<std::byte*>(&value), 1);
  57. };
  58. template <>
  59. void deserializer<std::int32_t>::deserialize(std::int32_t& value, deserialize_context& ctx)
  60. {
  61. ctx.read32(reinterpret_cast<std::byte*>(&value), 1);
  62. };
  63. template <>
  64. void deserializer<std::int64_t>::deserialize(std::int64_t& value, deserialize_context& ctx)
  65. {
  66. ctx.read64(reinterpret_cast<std::byte*>(&value), 1);
  67. };
  68. template <>
  69. void deserializer<float>::deserialize(float& value, deserialize_context& ctx)
  70. {
  71. ctx.read32(reinterpret_cast<std::byte*>(&value), 1);
  72. };
  73. template <>
  74. void deserializer<double>::deserialize(double& value, deserialize_context& ctx)
  75. {
  76. ctx.read64(reinterpret_cast<std::byte*>(&value), 1);
  77. };
  78. template <>
  79. void deserializer<std::string>::deserialize(std::string& value, deserialize_context& ctx)
  80. {
  81. std::uint64_t length = 0;
  82. ctx.read64(reinterpret_cast<std::byte*>(&length), 1);
  83. value.resize(static_cast<std::size_t>(length));
  84. ctx.read8(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
  85. };
  86. template <>
  87. void deserializer<std::u8string>::deserialize(std::u8string& value, deserialize_context& ctx)
  88. {
  89. std::uint64_t length = 0;
  90. ctx.read64(reinterpret_cast<std::byte*>(&length), 1);
  91. value.resize(static_cast<std::size_t>(length));
  92. ctx.read8(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
  93. };
  94. template <>
  95. void deserializer<std::u16string>::deserialize(std::u16string& value, deserialize_context& ctx)
  96. {
  97. std::uint64_t length = 0;
  98. ctx.read64(reinterpret_cast<std::byte*>(&length), 1);
  99. value.resize(static_cast<std::size_t>(length));
  100. ctx.read16(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
  101. };
  102. template <>
  103. void deserializer<std::u32string>::deserialize(std::u32string& value, deserialize_context& ctx)
  104. {
  105. std::uint64_t length = 0;
  106. ctx.read64(reinterpret_cast<std::byte*>(&length), 1);
  107. value.resize(static_cast<std::size_t>(length));
  108. ctx.read32(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
  109. };