summaryrefslogtreecommitdiff
path: root/tools/src/asset_processor/reader.h
blob: d31bf0f063c44eef7a2591c8115f3fa43f46b680 (plain)
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
#ifndef READER_H
#define READER_H

#include <vector>
#include <util/types.h>

class Reader {
  public:
    Reader(const std::vector<char>& baserom, int start, [[maybe_unused]]int size_)
        : data(baserom.data() + start) //, size(size_)
    {
    }

    [[nodiscard]] s8 read_s8() {
        // TODO range check
        return static_cast<s8>(data[static_cast<unsigned long>(cursor++)]);
    }

    [[nodiscard]] u8 read_u8() {
        return static_cast<u8>(read_s8());
    }

    [[nodiscard]] u16 read_u16() {
        return static_cast<u16>(read_u8() + (read_u8() << 8));
    }

    [[nodiscard]] u32 read_u32() {
        return static_cast<u32>(read_u16() + (read_u16() << 16));
    }

    int cursor = 0;

  private:
    const char* data;
    // const int size;
};

#endif