blob: 35b0a24f8101ed838663214b1ec233087f852288 (
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#pragma once
#include "util/bitset.hpp"
#include "util/io.hpp"
#include <cstdint>
#include <cstdio>
#include <stdexcept>
namespace file {
struct metadata {
static constexpr auto magic = 27981915666277746uL;
static constexpr auto magic_mask = 0xFFFFFFFFFFFFFFuL;
static constexpr auto size = 20;
enum class filetype : uint8_t {
Map = 1,
World,
Player,
TOTAL,
};
enum class flags {
Favorite,
};
filetype ftype;
uint32_t revision;
bitset<64> flags;
template <class T>
ssize_t read(io::serialized_io<T>& io)
{
uint64_t filemagic;
auto bytes = io.read(filemagic);
if ((filemagic & magic_mask) != magic) {
throw std::runtime_error("not a relogic file");
}
uint8_t type = ((filemagic >> 56) & 0xFF);
if (type == 0 || type >= int(filetype::TOTAL)) {
throw std::runtime_error("unknown file type");
}
ftype = filetype(type);
bytes += io.read(revision);
bytes += io.read(flags);
return bytes;
}
};
}
|