1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 21:29:56 +00:00
openmw/components/bgsm/stream.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
C++
Raw Normal View History

2024-04-17 19:53:55 +00:00
#include "stream.hpp"
namespace Bgsm
{
template <>
void BGSMStream::read<osg::Vec2f>(osg::Vec2f& vec)
{
readBufferOfType(mStream, vec._v);
}
template <>
void BGSMStream::read<osg::Vec3f>(osg::Vec3f& vec)
{
readBufferOfType(mStream, vec._v);
}
template <>
void BGSMStream::read<osg::Vec4f>(osg::Vec4f& vec)
{
readBufferOfType(mStream, vec._v);
}
template <>
void BGSMStream::read<std::string>(std::string& str)
{
std::uint32_t length;
read(length);
// Prevent potential memory allocation freezes; strings this long are not expected in BGSM
if (length > 1024)
throw std::runtime_error("Requested string length is too large: " + std::to_string(length));
str = std::string(length, '\0');
mStream->read(str.data(), length);
if (mStream->bad())
throw std::runtime_error("Failed to read sized string of " + std::to_string(length) + " chars");
std::size_t end = str.find('\0');
if (end != std::string::npos)
str.erase(end);
2024-04-17 19:53:55 +00:00
}
}