#pragma once

#include <istream>
#include <ostream>
#include <string>
#include <optional>

#include "ByteUtils.h"

class BinaryStream
{
public:

    template<typename T>
    static bool write(std::basic_ostream<char>* stream, T data)
    {
        stream->write(reinterpret_cast<char*>(&data), sizeof(data));
        return true;
    }

    static std::optional<int> getNextByteAsInt(std::basic_istream<char>* stream);

    static bool getNextNBytes(std::basic_istream<char>* stream, char* buffer, unsigned numBytes);

    static bool getNextWord(std::basic_istream<char>* stream, char* buffer);

    static bool getNextDWord(std::basic_istream<char>* stream, char* buffer);

    static bool getNextQWord(std::basic_istream<char>* stream, char* buffer);

    static std::optional<ByteUtils::Word> getNextWord(std::basic_istream<char>* stream, bool reverse = true);

    static std::optional<ByteUtils::DWord> getNextDWord(std::basic_istream<char>* stream);

    static std::optional<ByteUtils::QWord> getNextQWord(std::basic_istream<char>* stream);

    static bool checkNextDWord(std::basic_istream<char>* stream, const char* target);

    static bool getNextString(std::basic_istream<char>* stream, std::string& target, unsigned numBytes);
};
