This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundlereader.h
75 lines (61 loc) · 1.64 KB
/
bundlereader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef BUNDLEREADER_H
#define BUNDLEREADER_H
#include "endianreader.h"
#include "ibundlereadable.h"
#include "bundletype.h"
#include "bundleversion.h"
#include <vector>
namespace VRCE::BundleFiles {
class BundleReader : public EndianReader
{
public:
BundleReader(const VRCE::BinaryReader& reader, EndianType endianess)
: EndianReader(reader, endianess)
, m_signature()
, m_generation()
, m_flags()
{
}
BundleReader(const VRCE::BinaryReader& reader, EndianType endianess, BundleFiles::BundleType signature, BundleFiles::BundleVersion generation, BundleFiles::BundleFlags flags)
: EndianReader(reader, endianess)
, m_signature(signature)
, m_generation(generation)
, m_flags(flags)
{
}
template <implementsBundleReadable T>
T readObject()
{
T obj;
obj.read(*this);
return obj;
}
template <implementsBundleReadable T>
std::vector<T> readObjectVector()
{
std::int32_t vecSize = read32s(); // TODO: BUG: possible crash if negative number is read
std::vector<T> vec(vecSize);
for (std::int32_t i = 0; i < vecSize; i++) {
vec[i].read(*this);
}
return vec;
}
BundleFiles::BundleType signature() const
{
return m_signature;
}
BundleFiles::BundleVersion generation() const
{
return m_generation;
}
BundleFiles::BundleFlags flags() const
{
return m_flags;
}
private:
BundleFiles::BundleType m_signature;
BundleFiles::BundleVersion m_generation;
BundleFiles::BundleFlags m_flags;
};
}
#endif // BUNDLEREADER_H