-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathheader.cpp
More file actions
44 lines (38 loc) · 1.25 KB
/
header.cpp
File metadata and controls
44 lines (38 loc) · 1.25 KB
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
/* Copyright (c) 2024 Julian Benda
*
* This file is part of inkCPP which is released under MIT license.
* See file LICENSE.txt or go to
* https://github.com/JBenda/inkcpp for full license details.
*/
#include "header.h"
#include "version.h"
namespace ink::internal {
header header::parse_header(const char *data)
{
header res;
const char* ptr = data;
res.endien = *reinterpret_cast<const header::endian_types*>(ptr);
ptr += sizeof(header::endian_types);
using v_t = decltype(header::ink_version_number);
using vcpp_t = decltype(header::ink_bin_version_number);
if (res.endien == header::endian_types::same) {
res.ink_version_number =
*reinterpret_cast<const v_t*>(ptr);
ptr += sizeof(v_t);
res.ink_bin_version_number =
*reinterpret_cast<const vcpp_t*>(ptr);
} else if (res.endien == header::endian_types::differ) {
res.ink_version_number =
swap_bytes(*reinterpret_cast<const v_t*>(ptr));
ptr += sizeof(v_t);
res.ink_bin_version_number =
swap_bytes(*reinterpret_cast<const vcpp_t*>(ptr));
} else {
inkFail("Failed to parse endian encoding!");
}
if (res.ink_bin_version_number != InkBinVersion) {
inkFail("InkCpp-version mismatch: file was compiled with different InkCpp-version!");
}
return res;
}
}