/* 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 * Lesser General Public License version 2.1 or any later version. */ #include "stream.h" namespace Sirit { Stream::Stream(std::vector& bytes_) : bytes(bytes_) {} Stream::~Stream() = default; void Stream::Write(std::string string) { const auto size{string.size()}; const auto data{reinterpret_cast(string.data())}; for (std::size_t i = 0; i < size; i++) { Write(data[i]); } for (std::size_t i = 0; i < 4 - size % 4; i++) { Write(static_cast(0)); } } void Stream::Write(u64 value) { const auto mem{reinterpret_cast(&value)}; Write(mem[0]); Write(mem[1]); } void Stream::Write(u32 value) { const auto mem{reinterpret_cast(&value)}; Write(mem[0]); Write(mem[1]); } void Stream::Write(u16 value) { const auto mem{reinterpret_cast(&value)}; Write(mem[0]); Write(mem[1]); } void Stream::Write(u8 value) { bytes.push_back(value); } } // namespace Sirit