Deprecated readString() method so it is always clear if you want to read a binary encoded string or the file as string. Also added possibility to open a memory stream from any span.

This commit is contained in:
2024-06-10 23:11:25 +02:00
parent 463f4ca19c
commit c214398fac
2 changed files with 27 additions and 7 deletions

View File

@@ -34,7 +34,7 @@ namespace mijin
void Stream::flush() {}
StreamError Stream::readString(std::string& outString)
StreamError Stream::readBinaryString(std::string& outString)
{
std::uint32_t length; // NOLINT(cppcoreguidelines-init-variables)
StreamError error = read(length);
@@ -52,7 +52,7 @@ StreamError Stream::readString(std::string& outString)
return StreamError::SUCCESS;
}
StreamError Stream::writeString(std::string_view str)
StreamError Stream::writeBinaryString(std::string_view str)
{
assert(str.length() <= std::numeric_limits<std::uint32_t>::max());
const std::uint32_t length = static_cast<std::uint32_t>(str.length());
@@ -275,10 +275,10 @@ void MemoryStream::openRW(std::span<std::uint8_t> data)
canWrite_ = true;
}
void MemoryStream::openRO(std::span<const std::uint8_t> data)
void MemoryStream::openROImpl(const void* data, std::size_t bytes)
{
assert(!isOpen());
data_ = std::span<std::uint8_t>(const_cast<std::uint8_t*>(data.data()), data.size()); // NOLINT(cppcoreguidelines-pro-type-const-cast) we'll be fine
data_ = std::span<std::uint8_t>(const_cast<std::uint8_t*>(static_cast<const std::uint8_t*>(data)), bytes); // NOLINT(cppcoreguidelines-pro-type-const-cast) we'll be fine
pos_ = 0;
canWrite_ = false;
}