BinarySpanReaderWriter: Add subspan methods
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "binary_span_reader_writer.h"
|
||||
#include "assert.h"
|
||||
#include "small_string.h"
|
||||
|
||||
BinarySpanReader::BinarySpanReader() = default;
|
||||
@ -30,6 +31,23 @@ bool BinarySpanReader::PeekCString(std::string_view* dst)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::span<const u8> BinarySpanReader::GetRemainingSpan(size_t size) const
|
||||
{
|
||||
DebugAssert(size <= GetBufferRemaining());
|
||||
return m_buf.subspan(m_pos, size);
|
||||
}
|
||||
|
||||
std::span<const u8> BinarySpanReader::GetRemainingSpan() const
|
||||
{
|
||||
return m_buf.subspan(m_pos, m_buf.size() - m_pos);
|
||||
}
|
||||
|
||||
void BinarySpanReader::IncrementPosition(size_t size)
|
||||
{
|
||||
DebugAssert(size < GetBufferRemaining());
|
||||
m_pos += size;
|
||||
}
|
||||
|
||||
bool BinarySpanReader::ReadCString(std::string* dst)
|
||||
{
|
||||
std::string_view sv;
|
||||
@ -96,6 +114,23 @@ BinarySpanWriter::BinarySpanWriter(std::span<u8> buf) : m_buf(buf)
|
||||
{
|
||||
}
|
||||
|
||||
std::span<u8> BinarySpanWriter::GetRemainingSpan(size_t size) const
|
||||
{
|
||||
DebugAssert(size <= GetBufferRemaining());
|
||||
return m_buf.subspan(m_pos, size);
|
||||
}
|
||||
|
||||
std::span<u8> BinarySpanWriter::GetRemainingSpan() const
|
||||
{
|
||||
return m_buf.subspan(m_pos, m_buf.size() - m_pos);
|
||||
}
|
||||
|
||||
void BinarySpanWriter::IncrementPosition(size_t size)
|
||||
{
|
||||
DebugAssert(size < GetBufferRemaining());
|
||||
m_pos += size;
|
||||
}
|
||||
|
||||
bool BinarySpanWriter::WriteCString(std::string_view val)
|
||||
{
|
||||
if ((m_pos + val.size() + 1) > m_buf.size()) [[unlikely]]
|
||||
|
||||
Reference in New Issue
Block a user