Add WriteLengthString(const std::string &str)

This commit is contained in:
Michael Cook (mackal)
2018-07-03 01:15:40 -04:00
parent d2679f065a
commit 60ac0f7888
2 changed files with 17 additions and 6 deletions
+11
View File
@@ -170,6 +170,17 @@ public:
m_pos += len;
}
void WriteLengthString(const std::string &str)
{
uint32_t len = str.length();
if (m_pos + len + sizeof(uint32_t) > m_capacity)
Grow(m_capacity + len + sizeof(uint32_t));
*(uint32_t *)(m_buffer + m_pos) = len;
m_pos += sizeof(uint32_t);
memcpy(m_buffer + m_pos, str.c_str(), len);
m_pos += len;
}
size_t size() const { return m_pos; }
size_t length() const { return size(); }
size_t capacity() const { return m_capacity; }