Compare commits

...

3 Commits

Author SHA1 Message Date
Patrick Wuttke
d8b03893b3 Merge branch 'master' of https://git.mewin.de/mewin/mijin2 2025-07-14 10:08:04 +02:00
Patrick Wuttke
7939d458b3 Added Stream functions for reading and writing 0-terminated strings. 2025-07-14 10:07:57 +02:00
Patrick Wuttke
b5546067a8 Added missing include. 2025-07-14 10:07:37 +02:00
3 changed files with 42 additions and 1 deletions

View File

@ -113,6 +113,42 @@ StreamError Stream::writeBinaryString(std::string_view str)
return writeSpan(str.begin(), str.end());
}
StreamError Stream::readZString(std::string& outString)
{
char chr = '\0';
std::string result;
while (true)
{
if (isAtEnd())
{
return StreamError::IO_ERROR;
}
if (StreamError error = read(chr); error != StreamError::SUCCESS)
{
return error;
}
if (chr == '\0')
{
outString = std::move(result);
return StreamError::SUCCESS;
}
result.push_back(chr);
}
}
StreamError Stream::writeZString(std::string_view str)
{
static const char ZERO = '\0';
if (StreamError error = writeRaw(str.data(), str.size() * sizeof(char)); error != StreamError::SUCCESS)
{
return error;
}
return write(ZERO);
}
mijin::Task<StreamError> Stream::c_readBinaryString(std::string& outString)
{
std::uint32_t length; // NOLINT(cppcoreguidelines-init-variables)

View File

@ -221,7 +221,7 @@ public:
}
template<typename T>
StreamError write(const T& value) requires(std::is_trivial_v<T>)
StreamError write(const T& value)
{
return writeRaw(&value, sizeof(T));
}
@ -261,6 +261,9 @@ public:
StreamError readBinaryString(std::string& outString);
StreamError writeBinaryString(std::string_view str);
StreamError readZString(std::string& outString);
StreamError writeZString(std::string_view str);
mijin::Task<StreamError> c_readBinaryString(std::string& outString);
mijin::Task<StreamError> c_writeBinaryString(std::string_view str);

View File

@ -8,6 +8,8 @@
#include <atomic>
#include <cstddef>
#include "../debug/assert.hpp"
namespace mijin
{