2018-08-26 01:16:37 +02:00
|
|
|
/* This file is part of the sirit project.
|
|
|
|
* Copyright (c) 2018 ReinUsesLisp
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
2018-11-16 08:10:10 +01:00
|
|
|
* Lesser General Public License version 3 or any later version.
|
2018-08-26 01:16:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
namespace Sirit {
|
|
|
|
|
2018-10-17 08:44:48 +02:00
|
|
|
Stream::Stream(std::vector<u8>& bytes) : bytes(bytes) {}
|
2018-08-26 01:16:37 +02:00
|
|
|
|
|
|
|
Stream::~Stream() = default;
|
|
|
|
|
2019-03-16 05:15:45 +01:00
|
|
|
void Stream::Write(std::string_view string) {
|
2019-03-16 05:17:18 +01:00
|
|
|
bytes.insert(bytes.end(), string.begin(), string.end());
|
|
|
|
|
2018-10-03 05:32:45 +02:00
|
|
|
const auto size{string.size()};
|
|
|
|
for (std::size_t i = 0; i < 4 - size % 4; i++) {
|
2018-08-26 01:16:37 +02:00
|
|
|
Write(static_cast<u8>(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stream::Write(u64 value) {
|
2019-03-15 00:35:58 +01:00
|
|
|
const auto* const mem = reinterpret_cast<const u8*>(&value);
|
|
|
|
bytes.insert(bytes.end(), mem, mem + sizeof(u64));
|
2018-08-26 01:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Stream::Write(u32 value) {
|
2019-03-15 00:35:58 +01:00
|
|
|
const auto* const mem = reinterpret_cast<const u8*>(&value);
|
|
|
|
bytes.insert(bytes.end(), mem, mem + sizeof(u32));
|
2018-08-26 01:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Stream::Write(u16 value) {
|
2019-03-15 00:35:58 +01:00
|
|
|
const auto* const mem{reinterpret_cast<const u8*>(&value)};
|
|
|
|
bytes.insert(bytes.end(), mem, mem + sizeof(u16));
|
2018-08-26 01:16:37 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 07:26:21 +01:00
|
|
|
void Stream::Write(u8 value) {
|
|
|
|
bytes.push_back(value);
|
|
|
|
}
|
2018-08-26 01:16:37 +02:00
|
|
|
|
|
|
|
} // namespace Sirit
|