/*
* This file is part of the DXX-Rebirth project .
* It is copyright by its individual contributors, as recorded in the
* project's Git history. See COPYING.txt at the top level for license
* terms and a link to the Git history.
*/
#pragma once
#include
#include "serial.h"
class PHYSFSX_short_read : public std::runtime_error
{
public:
PHYSFSX_short_read(PHYSFS_file *) :
runtime_error("short read in PHYSFS file")
{
}
};
class PHYSFSX_short_write : public std::runtime_error
{
public:
PHYSFSX_short_write(PHYSFS_file *) :
runtime_error("short write in PHYSFS file")
{
}
};
template
void PHYSFSX_serialize_read(PHYSFS_file *fp, T &t)
{
const size_t maximum_size = serial::message_type::maximum_size;
uint8_t buf[maximum_size];
if (PHYSFS_read(fp, buf, sizeof(buf[0]), maximum_size) != maximum_size)
throw E(fp);
serial::reader::bytebuffer_t b(buf);
serial::process_buffer(b, t);
}
template
void PHYSFSX_serialize_write(PHYSFS_file *fp, const T &t)
{
const size_t maximum_size = serial::message_type::maximum_size;
uint8_t buf[maximum_size];
serial::writer::bytebuffer_t b(buf);
serial::process_buffer(b, t);
if (PHYSFS_write(fp, buf, sizeof(buf[0]), maximum_size) != maximum_size)
throw E(fp);
}