2018-10-24 13:43:52 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ByteBuffer.h"
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class BufferStream {
|
|
|
|
public:
|
|
|
|
explicit BufferStream(ByteBuffer& buffer)
|
|
|
|
: m_buffer(buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator<<(byte value)
|
|
|
|
{
|
|
|
|
m_buffer[m_offset++] = value & 0xffu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator<<(word value)
|
|
|
|
{
|
|
|
|
m_buffer[m_offset++] = value & 0xffu;
|
|
|
|
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator<<(dword value)
|
|
|
|
{
|
|
|
|
m_buffer[m_offset++] = value & 0xffu;
|
|
|
|
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
|
|
|
|
m_buffer[m_offset++] = (byte)(value >> 16) & 0xffu;
|
|
|
|
m_buffer[m_offset++] = (byte)(value >> 24) & 0xffu;
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:17:30 +03:00
|
|
|
void operator<<(const char* str)
|
|
|
|
{
|
|
|
|
size_t len = strlen(str);
|
|
|
|
for (unsigned i = 0; i < len; ++i)
|
|
|
|
m_buffer[m_offset++] = str[i];
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:43:52 +03:00
|
|
|
void operator<<(const String& value)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < value.length(); ++i)
|
|
|
|
m_buffer[m_offset++] = value[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void fillToEnd(byte ch)
|
|
|
|
{
|
|
|
|
while (m_offset < m_buffer.size())
|
|
|
|
m_buffer[m_offset++] = ch;
|
|
|
|
}
|
|
|
|
|
2018-12-03 01:34:50 +03:00
|
|
|
size_t offset() const { return m_offset; }
|
2018-10-24 13:43:52 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ByteBuffer& m_buffer;
|
2018-12-03 01:34:50 +03:00
|
|
|
size_t m_offset { 0 };
|
2018-10-24 13:43:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::BufferStream;
|