Add StringAnsi serialization

This commit is contained in:
Wojciech Figat
2022-01-21 18:32:16 +01:00
parent 9d90b02c9a
commit 05a935660d
3 changed files with 30 additions and 0 deletions

View File

@@ -82,6 +82,11 @@ public:
String(buf.Get());
}
void String(const StringAnsi& value)
{
String(value.Get(), static_cast<unsigned>(value.Length()));
}
FORCE_INLINE void RawValue(const StringAnsi& str)
{
RawValue(str.Get(), static_cast<int32>(str.Length()));

View File

@@ -254,6 +254,19 @@ namespace Serialization
v = stream.GetText();
}
inline bool ShouldSerialize(const StringAnsi& v, const void* otherObj)
{
return !otherObj || v != *(StringAnsi*)otherObj;
}
inline void Serialize(ISerializable::SerializeStream& stream, const StringAnsi& v, const void* otherObj)
{
stream.String(v);
}
inline void Deserialize(ISerializable::DeserializeStream& stream, StringAnsi& v, ISerializeModifier* modifier)
{
v = stream.GetTextAnsi();
}
FLAXENGINE_API bool ShouldSerialize(const Version& v, const void* otherObj);
FLAXENGINE_API void Serialize(ISerializable::SerializeStream& stream, const Version& v, const void* otherObj);
FLAXENGINE_API void Deserialize(ISerializable::DeserializeStream& stream, Version& v, ISerializeModifier* modifier);

View File

@@ -1661,6 +1661,18 @@ public:
}
return result;
}
StringAnsi GetTextAnsi() const
{
StringAnsi result;
if (IsString())
{
if (data_.f.flags & kInlineStrFlag)
result.Set(data_.ss.str, data_.ss.GetLength());
else
result.Set(GetStringPointer(), data_.s.length);
}
return result;
}
//! Get the length of string.
/*! Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().