sirit/src/stream.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

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 {
Stream::Stream(std::vector<u8>& bytes) : bytes(bytes) {}
2018-08-26 01:16:37 +02:00
Stream::~Stream() = default;
void Stream::Write(std::string_view string) {
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) {
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) {
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) {
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