Adjusted strings in Serializer.
This commit is contained in:
parent
d394ca8445
commit
54065f6ce3
@ -401,9 +401,11 @@ namespace ehs
|
||||
template<typename T, typename O = UInt_64>
|
||||
void WriteStr(const Str<T, O>& str)
|
||||
{
|
||||
if (sizeof(N) + sizeof(T) * str.Size() > size - offset)
|
||||
N inSize = sizeof(T) * (str.Size() + 1);
|
||||
|
||||
if (inSize > size - offset)
|
||||
{
|
||||
N remainder = sizeof(N) + sizeof(T) * str.Size() - (size - offset);
|
||||
N remainder = inSize - (size - offset);
|
||||
|
||||
Byte* r = new Byte[size + remainder];
|
||||
|
||||
@ -419,54 +421,38 @@ namespace ehs
|
||||
{
|
||||
if (endianness == Endianness::LE)
|
||||
{
|
||||
*(N*)&data[offset] = (N)str.Size();
|
||||
Util::Copy(&data[offset], &str[0], str.Size(true));
|
||||
|
||||
offset += sizeof(N);
|
||||
|
||||
for (N i = 0; i < str.Size(); ++i)
|
||||
*(T*)&data[offset + i * sizeof(T)] = str[i];
|
||||
*(T*)&data[offset + str.Size()] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
N tmpSize = (N)str.Size();
|
||||
|
||||
for (N i = 0; i < sizeof(N); ++i)
|
||||
data[offset + i] = ((Byte*)&tmpSize)[sizeof(N) - i - 1];
|
||||
|
||||
offset += sizeof(N);
|
||||
|
||||
for (N i = 0; i < str.Size(); ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
data[offset + i * sizeof(T) + b] = ((Byte*)&str[i])[sizeof(T) - i - 1];
|
||||
data[offset + sizeof(T) * i + b] = ((Byte*)&str[i])[sizeof(T) - i - 1];
|
||||
|
||||
*(T*)&data[offset + str.Size()] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endianness == Endianness::LE)
|
||||
{
|
||||
N tmpSize = (N)str.Size();
|
||||
|
||||
for (N i = 0; i < sizeof(N); ++i)
|
||||
data[offset + i] = ((Byte*)&tmpSize)[sizeof(N) - i - 1];
|
||||
|
||||
offset += sizeof(N);
|
||||
|
||||
for (N i = 0; i < str.Size(); ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
data[offset + i * sizeof(T) + b] = ((Byte*)&str[i])[sizeof(T) - i - 1];
|
||||
data[offset + sizeof(T) * i + b] = ((Byte*)&str[i])[sizeof(T) - i - 1];
|
||||
|
||||
*(T*)&data[offset + str.Size()] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(N*)&data[offset] = (N)str.Size();
|
||||
Util::Copy(&data[offset], &str[0], str.Size(true));
|
||||
|
||||
offset += sizeof(N);
|
||||
|
||||
for (N i = 0; i < str.Size(); ++i)
|
||||
*(T*)&data[offset + i * sizeof(T)] = str[i];
|
||||
*(T*)&data[offset + str.Size()] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
offset += str.Size() * sizeof(T);
|
||||
offset += inSize;
|
||||
}
|
||||
|
||||
void WriteVersion(const Version& value)
|
||||
@ -1014,12 +1000,34 @@ namespace ehs
|
||||
}
|
||||
|
||||
template<typename T, typename O>
|
||||
Str<T, O> ReadStr(const O size = 0)
|
||||
Str<T, O> ReadStr(O size = 0)
|
||||
{
|
||||
Str<T, O> result(size ? size : (O)Read<N>());
|
||||
if (!size)
|
||||
while (&data[offset + sizeof(T) * size])
|
||||
size++;
|
||||
|
||||
for (O i = 0; i < result.Size(); ++i)
|
||||
result[i] = Read<T>();
|
||||
Str<T, O> result(size);
|
||||
|
||||
if (CPU::GetEndianness() == Endianness::LE)
|
||||
{
|
||||
if (endianness == Endianness::LE)
|
||||
Util::Copy(&result[0], &data[offset], result.Size(true));
|
||||
else
|
||||
for (N i = 0; i < size; ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endianness == Endianness::LE)
|
||||
for (N i = 0; i < size; ++i)
|
||||
for (N b = 0; b < sizeof(T); ++b)
|
||||
((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b];
|
||||
else
|
||||
Util::Copy(&result[0], &data[offset], result.Size(true));
|
||||
}
|
||||
|
||||
offset += result.Size(true) + 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user