metaforce/Runtime/IOStreams.hpp

72 lines
1.7 KiB
C++
Raw Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2015-08-23 16:58:07 -07:00
2016-04-11 00:10:28 -07:00
#include "GCNTypes.hpp"
2019-05-09 21:09:01 -07:00
#include "athena/IStreamReader.hpp"
#include "athena/IStreamWriter.hpp"
#include "athena/MemoryReader.hpp"
#include "athena/MemoryWriter.hpp"
#ifdef URDE_ZIP_INPUT_STREAM
2015-08-23 16:58:07 -07:00
#include <zlib.h>
2019-05-09 21:09:01 -07:00
#endif
2015-08-23 16:58:07 -07:00
2018-12-07 21:30:43 -08:00
namespace urde {
2016-03-04 15:04:53 -08:00
using CInputStream = athena::io::IStreamReader;
using COutputStream = athena::io::IStreamWriter;
2015-08-23 16:58:07 -07:00
2018-12-07 21:30:43 -08:00
struct CBitStreamReader : athena::io::MemoryReader {
u32 x1c_val = 0;
u32 x20_bitOffset = 0;
2016-03-19 12:19:43 -07:00
public:
2018-12-07 21:30:43 -08:00
static u32 GetBitCount(u32 maxVal) {
u32 ret = 0;
while (maxVal != 0) {
maxVal /= 2;
ret++;
2016-03-19 12:19:43 -07:00
}
2018-12-07 21:30:43 -08:00
return ret;
}
CBitStreamReader(const void* data, atUint64 length) : MemoryReader(data, length) {}
2016-03-19 12:19:43 -07:00
2018-12-07 21:30:43 -08:00
s32 ReadEncoded(u32 key);
};
2018-12-07 21:30:43 -08:00
class CBitStreamWriter : public athena::io::MemoryWriter {
u32 x14_val = 0;
u32 x18_bitOffset = 0x20;
2016-03-19 21:10:29 -07:00
public:
2018-12-07 21:30:43 -08:00
static inline u32 GetBitCount(u32 maxVal) { return CBitStreamReader::GetBitCount(maxVal); }
2016-03-19 21:10:29 -07:00
2018-12-07 21:30:43 -08:00
CBitStreamWriter(atUint8* data = nullptr, atUint64 length = 0x10) : MemoryWriter(data, length) {}
2016-03-19 21:10:29 -07:00
2018-12-07 21:30:43 -08:00
void WriteEncoded(u32 val, u32 bitCount);
2017-02-03 19:46:12 -08:00
2018-12-07 21:30:43 -08:00
void Flush();
2017-02-03 19:46:12 -08:00
2018-12-07 21:30:43 -08:00
~CBitStreamWriter() { Flush(); }
2016-03-19 21:10:29 -07:00
};
2016-03-04 15:04:53 -08:00
using CMemoryInStream = athena::io::MemoryReader;
using CMemoryOutStream = athena::io::MemoryWriter;
2015-08-23 16:58:07 -07:00
2019-05-09 21:09:01 -07:00
#ifdef URDE_ZIP_INPUT_STREAM
2018-12-07 21:30:43 -08:00
class CZipInputStream : public CInputStream {
std::unique_ptr<u8[]> x24_compBuf;
std::unique_ptr<CInputStream> x28_strm;
z_stream x30_zstrm = {};
2015-08-23 16:58:07 -07:00
public:
2018-12-07 21:30:43 -08:00
CZipInputStream(std::unique_ptr<CInputStream>&& strm);
~CZipInputStream();
atUint64 readUBytesToBuf(void* buf, atUint64 len);
void seek(atInt64, athena::SeekOrigin) {}
atUint64 position() const { return 0; }
atUint64 length() const { return 0; }
2015-08-23 16:58:07 -07:00
};
2019-05-09 21:09:01 -07:00
#endif
2015-08-23 16:58:07 -07:00
2018-12-07 21:30:43 -08:00
} // namespace urde