28 std::optional<Json::Value>
SerializeType(std::conditional_t<std::is_arithmetic_v<T> || std::is_enum_v<T>, T,
const T&> val
29#ifdef PROTOCOLCRAFT_DETAILED_PARSING
31 const typename Internal::OffsetType<T>::type* start_offset =
nullptr,
32 const typename Internal::OffsetType<T>::type* end_offset =
nullptr
36 if constexpr (Internal::IsOptional<T>)
40 return SerializeType<typename T::value_type>(val.value()
41#ifdef PROTOCOLCRAFT_DETAILED_PARSING
53 else if constexpr (Internal::IsMap<T>)
56 for (
const auto& [k, v] : val)
58 const std::optional<Json::Value> serialized = SerializeType<typename T::mapped_type>(v
59#ifdef PROTOCOLCRAFT_DETAILED_PARSING
61 (start_offset !=
nullptr && start_offset->second.find(k) != start_offset->second.end()) ? &start_offset->second.at(k) :
nullptr,
62 (end_offset !=
nullptr && end_offset->second.find(k) != end_offset->second.end()) ? &end_offset->second.at(k) :
nullptr
65 if constexpr (std::is_enum_v<typename T::key_type>)
67 map_object[std::to_string(
static_cast<std::underlying_type_t<typename T::key_type>
>(k))] = serialized.value_or(
Json::Value());
69 else if constexpr (std::is_integral_v<typename T::key_type> && !std::is_same_v<typename T::key_type, bool>)
71 map_object[std::to_string(k)] = serialized.value_or(
Json::Value());
73 else if constexpr (std::is_same_v<typename T::key_type, std::string>)
77 else if constexpr (std::is_same_v<typename T::key_type, Identifier>)
79 map_object[k.GetFull()] = serialized.value_or(
Json::Value());
83 static_assert(Internal::dependant_false<T>,
"Map key type not supported in auto JSON serialization");
87#ifdef PROTOCOLCRAFT_DETAILED_PARSING
88 return WrapJsonWithOffsets(map_object, start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
93 else if constexpr (Internal::IsVector<T> || Internal::IsArray<T>)
95 if constexpr (std::is_same_v<typename T::value_type, char>)
99#ifdef PROTOCOLCRAFT_DETAILED_PARSING
100 return WrapJsonWithOffsets(
"Vector of " + std::to_string(val.size()) +
" chars", start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
102 return "Vector of " + std::to_string(val.size()) +
" chars";
108#ifdef PROTOCOLCRAFT_DETAILED_PARSING
109 return WrapJsonWithOffsets(val, start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
115 else if constexpr (std::is_same_v<typename T::value_type, unsigned char>)
119#ifdef PROTOCOLCRAFT_DETAILED_PARSING
120 return WrapJsonWithOffsets(
"Vector of " + std::to_string(val.size()) +
" unsigned chars", start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
122 return "Vector of " + std::to_string(val.size()) +
" unsigned chars";
127#ifdef PROTOCOLCRAFT_DETAILED_PARSING
128 return WrapJsonWithOffsets(val, start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
137 output.reserve(val.size());
138 for (
size_t i = 0; i < val.size(); ++i)
140 output.push_back(SerializeType<typename T::value_type>(val[i]
141#ifdef PROTOCOLCRAFT_DETAILED_PARSING
143 (start_offset !=
nullptr && start_offset->second.size() > i) ? &start_offset->second[i] :
nullptr,
144 (end_offset !=
nullptr && end_offset->second.size() > i) ? &end_offset->second[i] :
nullptr
148#ifdef PROTOCOLCRAFT_DETAILED_PARSING
149 return WrapJsonWithOffsets(output, start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
155 else if constexpr (Internal::IsBitset<T>)
157#ifdef PROTOCOLCRAFT_DETAILED_PARSING
158 return WrapJsonWithOffsets(val.to_string(), start_offset, end_offset);
160 return val.to_string();
163 else if constexpr (Internal::IsPair<T>)
165#ifdef PROTOCOLCRAFT_DETAILED_PARSING
167 {
"first", WrapJsonWithOffsets(val.first, start_offset !=
nullptr ? &start_offset->second.first :
nullptr, end_offset !=
nullptr ? &end_offset->second.first :
nullptr).value_or(
Json::Value()) },
168 {
"second", WrapJsonWithOffsets(val.second, start_offset !=
nullptr ? &start_offset->second.second :
nullptr, end_offset !=
nullptr ? &end_offset->second.second :
nullptr).value_or(
Json::Value()) }
169 }), start_offset !=
nullptr ? &start_offset->first :
nullptr, end_offset !=
nullptr ? &end_offset->first :
nullptr);
172 {
"first", val.first },
173 {
"second", val.second }
177 else if constexpr (Internal::IsSharedPtr<T>)
183 return SerializeType<typename T::element_type>(*val
184#ifdef PROTOCOLCRAFT_DETAILED_PARSING
193#ifdef PROTOCOLCRAFT_DETAILED_PARSING
194 return WrapJsonWithOffsets(val, start_offset, end_offset);