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.
2019-07-14 23:48:59 +02:00
* Copyright (c) 2019 sirit
* This software may be used and distributed according to the terms of the
* 3-Clause BSD License
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