Fix byte array deserialization from base64 encoded string

This commit is contained in:
Wojtek Figat
2021-04-22 10:58:25 +02:00
parent 2f1aeb6897
commit 64b6b4ebc9

View File

@@ -9,6 +9,7 @@
#include "Engine/Scripting/SoftObjectReference.h"
#include "Engine/Content/AssetReference.h"
#include "Engine/Content/WeakAssetReference.h"
#include "Engine/Utilities/Encryption.h"
struct Version;
struct VariantType;
@@ -522,6 +523,24 @@ namespace Serialization
for (int32 i = 0; i < v.Count(); i++)
Deserialize(streamArray[i], (T&)v[i], modifier);
}
template<typename AllocationType = HeapAllocation>
inline void Deserialize(ISerializable::DeserializeStream& stream, Array<byte, AllocationType>& v, ISerializeModifier* modifier)
{
if (stream.IsArray())
{
const auto& streamArray = stream.GetArray();
v.Resize(streamArray.Size());
for (int32 i = 0; i < v.Count(); i++)
Deserialize(streamArray[i], v[i], modifier);
}
else if (stream.IsString())
{
// byte[] encoded as Base64
const StringAnsiView streamView(stream.GetString(), stream.GetStringLength());
v.Resize(Encryption::Base64DecodeLength(*streamView, streamView.Length()));
Encryption::Base64Decode(*streamView, streamView.Length(), v.Get());
}
}
// Dictionary