From a770d283f080eb1ff75fe274573cd401a71c7693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 12 Nov 2023 23:15:08 -0300 Subject: [PATCH] Serialize Name Keys as Strings for maps --- src/common/scripting/core/types.cpp | 83 ++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/src/common/scripting/core/types.cpp b/src/common/scripting/core/types.cpp index b9949a5ea95..705d38c9b52 100644 --- a/src/common/scripting/core/types.cpp +++ b/src/common/scripting/core/types.cpp @@ -2541,19 +2541,40 @@ static void PMapValueWriter(FSerializer &ar, const M *map, const PMap *m) { TMapConstIterator it(*map); const typename M::Pair * p; - while(it.NextPair(p)) + if(m->KeyType == TypeName) { - if constexpr(std::is_same_v) + while(it.NextPair(p)) { - m->ValueType->WriteValue(ar,p->Key.GetChars(),static_cast(&p->Value)); + if constexpr(std::is_same_v) + { + m->ValueType->WriteValue(ar,FName(ENamedName(p->Key)).GetChars(),static_cast(&p->Value)); + } + else + { + #ifdef __GNUC__ + __builtin_unreachable(); + #elif defined(_MSC_VER) + __assume(0); + #endif + } } - else if constexpr(std::is_same_v) + } + else + { + while(it.NextPair(p)) { - FString key; - key.Format("%u",p->Key); - m->ValueType->WriteValue(ar,key.GetChars(),static_cast(&p->Value)); + if constexpr(std::is_same_v) + { + m->ValueType->WriteValue(ar,p->Key.GetChars(),static_cast(&p->Value)); + } + else if constexpr(std::is_same_v) + { + FString key; + key.Format("%u",p->Key); + m->ValueType->WriteValue(ar,key.GetChars(),static_cast(&p->Value)); + } + //else unknown key type } - //else unknown key type } } @@ -2582,22 +2603,20 @@ template static bool PMapValueReader(FSerializer &ar, M *map, const PMap *m) { const char * k; - while((k = ar.GetKey())) + if(m->KeyType == TypeName) { typename M::ValueType * val; - if constexpr(std::is_same_v) + if constexpr(std::is_same_v) { - val = &map->InsertNew(k); + val = &map->InsertNew(FName(k).GetIndex()); } - else if constexpr(std::is_same_v) + else { - FString s(k); - if(!s.IsInt()) - { - ar.EndObject(); - return false; - } - val = &map->InsertNew(static_cast(s.ToULong())); + #ifdef __GNUC__ + __builtin_unreachable(); + #elif defined(_MSC_VER) + __assume(0); + #endif } if (!m->ValueType->ReadValue(ar,nullptr,static_cast(val))) { @@ -2605,6 +2624,32 @@ static bool PMapValueReader(FSerializer &ar, M *map, const PMap *m) return false; } } + else + { + while((k = ar.GetKey())) + { + typename M::ValueType * val; + if constexpr(std::is_same_v) + { + val = &map->InsertNew(k); + } + else if constexpr(std::is_same_v) + { + FString s(k); + if(!s.IsInt()) + { + ar.EndObject(); + return false; + } + val = &map->InsertNew(static_cast(s.ToULong())); + } + if (!m->ValueType->ReadValue(ar,nullptr,static_cast(val))) + { + ar.EndObject(); + return false; + } + } + } ar.EndObject(); return true; }