LCOV - code coverage report
Current view: top level - source/simulation2/serialization - StdSerializer.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 5 9 55.6 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_STDSERIALIZER
      19             : #define INCLUDED_STDSERIALIZER
      20             : 
      21             : #include "lib/code_annotation.h"
      22             : #include "simulation2/serialization/BinarySerializer.h"
      23             : 
      24             : #include <cstring>
      25             : #include <ostream>
      26             : 
      27             : namespace Script { class Interface; }
      28             : 
      29             : #define DEBUG_SERIALIZER_ANNOTATE 0 // annotate the stream to help debugging if you're reading the output in a hex editor
      30             : 
      31             : class CStdSerializerImpl
      32             : {
      33             :     NONCOPYABLE(CStdSerializerImpl);
      34             : public:
      35             :     CStdSerializerImpl(std::ostream& stream);
      36             : 
      37           0 :     ~CStdSerializerImpl()
      38             :     {
      39           0 :         m_Stream.flush();
      40           0 :     }
      41             : 
      42      433259 :     void Put([[maybe_unused]] const char* name, const std::uint8_t* data, size_t len)
      43             :     {
      44             : #if DEBUG_SERIALIZER_ANNOTATE
      45             :         m_Stream.put('<');
      46             :         m_Stream.write(name, strlen(name));
      47             :         m_Stream.put('>');
      48             : #endif
      49      433259 :         m_Stream.write((const char*)data, (std::streamsize)len);
      50           0 :     }
      51             : 
      52           9 :     std::ostream& GetStream()
      53             :     {
      54           9 :         return m_Stream;
      55             :     }
      56             : 
      57             : private:
      58             :     std::ostream& m_Stream;
      59             : };
      60             : 
      61         131 : class CStdSerializer : public CBinarySerializer<CStdSerializerImpl>
      62             : {
      63             : public:
      64             :     CStdSerializer(const Script::Interface& scriptInterface, std::ostream& stream);
      65             : 
      66             :     virtual std::ostream& GetStream();
      67             : };
      68             : 
      69             : #endif // INCLUDED_STDSERIALIZER

Generated by: LCOV version 1.16