#pragma once
#include <bx/file.h>
#include <cstdint>

#define SAVE_T(T)                                                                                                      \
    inline bool Save(const T* obj, uint32_t count, Serializer& serializer)                                             \
    {                                                                                                                  \
        bool isOk = true;                                                                                              \
        for (uint32_t i = 0; i < count; ++i)                                                                           \
        {                                                                                                              \
            isOk = serializer.Write(&obj[i], sizeof(obj[i])) && isOk;                                                  \
        }                                                                                                              \
        return isOk;                                                                                                   \
    }

namespace Generated
{
    struct Serializer
    {
        bx::Error Err;
        bx::FilePath Path;
        bx::FileWriter Writer;

        bool Init(const bx::FilePath& path)
        {
            Path = path;
            Writer.open(path, false, &Err);
            return Err.isOk();
        }

        bool Write(const void* data, uint32_t size)
        {
            Writer.write(data, size, &Err);
            return Err.isOk();
        }

        void Finish()
        {
            Writer.close();
        }
    };

    SAVE_T(uint8_t)
    SAVE_T(uint16_t)
    SAVE_T(uint32_t)
    SAVE_T(uint64_t)
    SAVE_T(int8_t)
    SAVE_T(int16_t)
    SAVE_T(int32_t)
    SAVE_T(int64_t)
    SAVE_T(float)
    SAVE_T(double)
    SAVE_T(bool)
    SAVE_T(char)

} // namespace Generated
