File indexing completed on 2025-01-05 04:01:21
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <unordered_map> 0010 #include <QIODevice> 0011 0012 0013 #include "io/binary_types.hpp" 0014 0015 namespace glaxnimate::io { 0016 0017 0018 class BinaryInputStream 0019 { 0020 public: 0021 explicit BinaryInputStream(QIODevice* file); 0022 explicit BinaryInputStream(QByteArray data); 0023 0024 quint32 read_uint32_le(); 0025 Float32 read_float32_le(); 0026 VarUint read_uint_leb128(); 0027 0028 bool eof() const; 0029 bool has_error() const; 0030 0031 QByteArray read(qint64 max_size); 0032 quint8 next(); 0033 0034 private: 0035 void on_overflow(); 0036 0037 private: 0038 QByteArray data; 0039 const char* data_start; 0040 const char* data_end; 0041 bool error = false; 0042 }; 0043 0044 class BinaryOutputStream 0045 { 0046 public: 0047 explicit BinaryOutputStream(QIODevice* file); 0048 0049 void write_uint32_le(quint32 v); 0050 void write_float32_le(Float32 v); 0051 void write_uint_leb128(VarUint v); 0052 void write_byte(quint8 v); 0053 void write(const QByteArray& data); 0054 0055 private: 0056 QIODevice* file = nullptr; 0057 }; 0058 0059 } // namespace glaxnimate::io