-
Notifications
You must be signed in to change notification settings - Fork 609
/
data.cpp
110 lines (96 loc) · 2.42 KB
/
data.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "data.h"
#include <cstring>
#include <cstdarg>
#include <vector>
/* PycData */
int PycData::get16()
{
/* Ensure endianness */
int result = getByte() & 0xFF;
result |= (getByte() & 0xFF) << 8;
return result;
}
int PycData::get32()
{
/* Ensure endianness */
int result = getByte() & 0xFF;
result |= (getByte() & 0xFF) << 8;
result |= (getByte() & 0xFF) << 16;
result |= (getByte() & 0xFF) << 24;
return result;
}
Pyc_INT64 PycData::get64()
{
/* Ensure endianness */
Pyc_INT64 result = (Pyc_INT64)(getByte() & 0xFF);
result |= (Pyc_INT64)(getByte() & 0xFF) << 8;
result |= (Pyc_INT64)(getByte() & 0xFF) << 16;
result |= (Pyc_INT64)(getByte() & 0xFF) << 24;
result |= (Pyc_INT64)(getByte() & 0xFF) << 32;
result |= (Pyc_INT64)(getByte() & 0xFF) << 40;
result |= (Pyc_INT64)(getByte() & 0xFF) << 48;
result |= (Pyc_INT64)(getByte() & 0xFF) << 56;
return result;
}
/* PycFile */
PycFile::PycFile(const char* filename)
{
m_stream = fopen(filename, "rb");
}
bool PycFile::atEof() const
{
int ch = fgetc(m_stream);
ungetc(ch, m_stream);
return (ch == EOF);
}
int PycFile::getByte()
{
int ch = fgetc(m_stream);
if (ch == EOF)
ungetc(ch, m_stream);
return ch;
}