2025-05-21 03:29:47 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-09 11:20:14 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-09 11:20:14 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-09 11:20:14 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-09 11:20:14 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_STDSERIALIZER
|
|
|
|
|
#define INCLUDED_STDSERIALIZER
|
|
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
#include "lib/code_annotation.h"
|
|
|
|
|
#include "lib/types.h"
|
|
|
|
|
#include "simulation2/serialization/BinarySerializer.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2010-07-04 10:03:45 -07:00
|
|
|
#include <cstring>
|
2025-08-07 10:53:23 -07:00
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
|
|
class ScriptInterface;
|
2010-07-04 10:03:45 -07:00
|
|
|
|
2011-10-27 13:10:53 -07:00
|
|
|
#define DEBUG_SERIALIZER_ANNOTATE 0 // annotate the stream to help debugging if you're reading the output in a hex editor
|
|
|
|
|
|
2010-05-25 12:01:30 -07:00
|
|
|
class CStdSerializerImpl
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
2010-05-25 12:12:00 -07:00
|
|
|
NONCOPYABLE(CStdSerializerImpl);
|
2010-01-09 11:20:14 -08:00
|
|
|
public:
|
2010-05-25 12:01:30 -07:00
|
|
|
CStdSerializerImpl(std::ostream& stream);
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2015-10-14 20:31:30 -07:00
|
|
|
~CStdSerializerImpl()
|
|
|
|
|
{
|
|
|
|
|
m_Stream.flush();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-21 03:29:47 -07:00
|
|
|
void Put([[maybe_unused]] const char* name, const u8* data, size_t len)
|
2010-05-25 12:01:30 -07:00
|
|
|
{
|
2011-10-27 13:10:53 -07:00
|
|
|
#if DEBUG_SERIALIZER_ANNOTATE
|
|
|
|
|
m_Stream.put('<');
|
2010-05-25 12:01:30 -07:00
|
|
|
m_Stream.write(name, strlen(name));
|
2011-10-27 13:10:53 -07:00
|
|
|
m_Stream.put('>');
|
2010-05-25 12:01:30 -07:00
|
|
|
#endif
|
2010-09-05 02:38:30 -07:00
|
|
|
m_Stream.write((const char*)data, (std::streamsize)len);
|
2010-05-25 12:01:30 -07:00
|
|
|
}
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2011-01-12 04:29:00 -08:00
|
|
|
std::ostream& GetStream()
|
|
|
|
|
{
|
|
|
|
|
return m_Stream;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
private:
|
|
|
|
|
std::ostream& m_Stream;
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-25 12:01:30 -07:00
|
|
|
class CStdSerializer : public CBinarySerializer<CStdSerializerImpl>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-08-23 17:32:42 -07:00
|
|
|
CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream);
|
2011-01-12 04:29:00 -08:00
|
|
|
|
|
|
|
|
virtual std::ostream& GetStream();
|
2010-05-25 12:01:30 -07:00
|
|
|
};
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
#endif // INCLUDED_STDSERIALIZER
|