5
5
#include < vector>
6
6
#include < stdexcept>
7
7
8
- kaitai::kstream::kstream (std::istream* io): kio(io) {
8
+ kaitai::kistream::kistream (std::istream* io): kio(io) {
9
9
m_io = io;
10
10
init ();
11
11
}
12
12
13
- kaitai::kstream::kstream (std::string& data): m_io_str(data) {
13
+ kaitai::kistream::kistream (std::string& data): m_io_str(data) {
14
14
kio::init (m_io);
15
15
m_io = &m_io_str;
16
16
init ();
17
17
}
18
18
19
- void kaitai::kstream ::init () {
19
+ void kaitai::kistream ::init () {
20
20
align_to_byte ();
21
21
}
22
22
23
23
// ========================================================================
24
24
// Stream positioning
25
25
// ========================================================================
26
26
27
- bool kaitai::kstream ::is_eof () const {
27
+ bool kaitai::kistream ::is_eof () const {
28
28
if (m_bits_left > 0 ) {
29
29
return false ;
30
30
}
@@ -44,15 +44,15 @@ bool kaitai::kstream::is_eof() const {
44
44
}
45
45
}
46
46
47
- void kaitai::kstream ::seek (uint64_t pos) {
47
+ void kaitai::kistream ::seek (uint64_t pos) {
48
48
m_io->seekg (pos);
49
49
}
50
50
51
- uint64_t kaitai::kstream ::pos () {
51
+ uint64_t kaitai::kistream ::pos () {
52
52
return m_io->tellg ();
53
53
}
54
54
55
- uint64_t kaitai::kstream ::size () {
55
+ uint64_t kaitai::kistream ::size () {
56
56
std::iostream::pos_type cur_pos = m_io->tellg ();
57
57
m_io->seekg (0 , std::ios::end);
58
58
std::iostream::pos_type len = m_io->tellg ();
@@ -68,7 +68,7 @@ uint64_t kaitai::kstream::size() {
68
68
// Signed
69
69
// ------------------------------------------------------------------------
70
70
71
- int8_t kaitai::kstream ::read_s1 () {
71
+ int8_t kaitai::kistream ::read_s1 () {
72
72
char t;
73
73
m_io->get (t);
74
74
return t;
@@ -78,7 +78,7 @@ int8_t kaitai::kstream::read_s1() {
78
78
// Big-endian
79
79
// ........................................................................
80
80
81
- int16_t kaitai::kstream ::read_s2be () {
81
+ int16_t kaitai::kistream ::read_s2be () {
82
82
int16_t t;
83
83
m_io->read (reinterpret_cast <char *>(&t), 2 );
84
84
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -87,7 +87,7 @@ int16_t kaitai::kstream::read_s2be() {
87
87
return t;
88
88
}
89
89
90
- int32_t kaitai::kstream ::read_s4be () {
90
+ int32_t kaitai::kistream ::read_s4be () {
91
91
int32_t t;
92
92
m_io->read (reinterpret_cast <char *>(&t), 4 );
93
93
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -96,7 +96,7 @@ int32_t kaitai::kstream::read_s4be() {
96
96
return t;
97
97
}
98
98
99
- int64_t kaitai::kstream ::read_s8be () {
99
+ int64_t kaitai::kistream ::read_s8be () {
100
100
int64_t t;
101
101
m_io->read (reinterpret_cast <char *>(&t), 8 );
102
102
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -109,7 +109,7 @@ int64_t kaitai::kstream::read_s8be() {
109
109
// Little-endian
110
110
// ........................................................................
111
111
112
- int16_t kaitai::kstream ::read_s2le () {
112
+ int16_t kaitai::kistream ::read_s2le () {
113
113
int16_t t;
114
114
m_io->read (reinterpret_cast <char *>(&t), 2 );
115
115
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -118,7 +118,7 @@ int16_t kaitai::kstream::read_s2le() {
118
118
return t;
119
119
}
120
120
121
- int32_t kaitai::kstream ::read_s4le () {
121
+ int32_t kaitai::kistream ::read_s4le () {
122
122
int32_t t;
123
123
m_io->read (reinterpret_cast <char *>(&t), 4 );
124
124
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -127,7 +127,7 @@ int32_t kaitai::kstream::read_s4le() {
127
127
return t;
128
128
}
129
129
130
- int64_t kaitai::kstream ::read_s8le () {
130
+ int64_t kaitai::kistream ::read_s8le () {
131
131
int64_t t;
132
132
m_io->read (reinterpret_cast <char *>(&t), 8 );
133
133
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -140,7 +140,7 @@ int64_t kaitai::kstream::read_s8le() {
140
140
// Unsigned
141
141
// ------------------------------------------------------------------------
142
142
143
- uint8_t kaitai::kstream ::read_u1 () {
143
+ uint8_t kaitai::kistream ::read_u1 () {
144
144
char t;
145
145
m_io->get (t);
146
146
return t;
@@ -150,7 +150,7 @@ uint8_t kaitai::kstream::read_u1() {
150
150
// Big-endian
151
151
// ........................................................................
152
152
153
- uint16_t kaitai::kstream ::read_u2be () {
153
+ uint16_t kaitai::kistream ::read_u2be () {
154
154
uint16_t t;
155
155
m_io->read (reinterpret_cast <char *>(&t), 2 );
156
156
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -159,7 +159,7 @@ uint16_t kaitai::kstream::read_u2be() {
159
159
return t;
160
160
}
161
161
162
- uint32_t kaitai::kstream ::read_u4be () {
162
+ uint32_t kaitai::kistream ::read_u4be () {
163
163
uint32_t t;
164
164
m_io->read (reinterpret_cast <char *>(&t), 4 );
165
165
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -168,7 +168,7 @@ uint32_t kaitai::kstream::read_u4be() {
168
168
return t;
169
169
}
170
170
171
- uint64_t kaitai::kstream ::read_u8be () {
171
+ uint64_t kaitai::kistream ::read_u8be () {
172
172
uint64_t t;
173
173
m_io->read (reinterpret_cast <char *>(&t), 8 );
174
174
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -181,7 +181,7 @@ uint64_t kaitai::kstream::read_u8be() {
181
181
// Little-endian
182
182
// ........................................................................
183
183
184
- uint16_t kaitai::kstream ::read_u2le () {
184
+ uint16_t kaitai::kistream ::read_u2le () {
185
185
uint16_t t;
186
186
m_io->read (reinterpret_cast <char *>(&t), 2 );
187
187
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -190,7 +190,7 @@ uint16_t kaitai::kstream::read_u2le() {
190
190
return t;
191
191
}
192
192
193
- uint32_t kaitai::kstream ::read_u4le () {
193
+ uint32_t kaitai::kistream ::read_u4le () {
194
194
uint32_t t;
195
195
m_io->read (reinterpret_cast <char *>(&t), 4 );
196
196
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -199,7 +199,7 @@ uint32_t kaitai::kstream::read_u4le() {
199
199
return t;
200
200
}
201
201
202
- uint64_t kaitai::kstream ::read_u8le () {
202
+ uint64_t kaitai::kistream ::read_u8le () {
203
203
uint64_t t;
204
204
m_io->read (reinterpret_cast <char *>(&t), 8 );
205
205
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -216,7 +216,7 @@ uint64_t kaitai::kstream::read_u8le() {
216
216
// Big-endian
217
217
// ........................................................................
218
218
219
- float kaitai::kstream ::read_f4be () {
219
+ float kaitai::kistream ::read_f4be () {
220
220
uint32_t t;
221
221
m_io->read (reinterpret_cast <char *>(&t), 4 );
222
222
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -225,7 +225,7 @@ float kaitai::kstream::read_f4be() {
225
225
return reinterpret_cast <float &>(t);
226
226
}
227
227
228
- double kaitai::kstream ::read_f8be () {
228
+ double kaitai::kistream ::read_f8be () {
229
229
uint64_t t;
230
230
m_io->read (reinterpret_cast <char *>(&t), 8 );
231
231
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -238,7 +238,7 @@ double kaitai::kstream::read_f8be() {
238
238
// Little-endian
239
239
// ........................................................................
240
240
241
- float kaitai::kstream ::read_f4le () {
241
+ float kaitai::kistream ::read_f4le () {
242
242
uint32_t t;
243
243
m_io->read (reinterpret_cast <char *>(&t), 4 );
244
244
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -247,7 +247,7 @@ float kaitai::kstream::read_f4le() {
247
247
return reinterpret_cast <float &>(t);
248
248
}
249
249
250
- double kaitai::kstream ::read_f8le () {
250
+ double kaitai::kistream ::read_f8le () {
251
251
uint64_t t;
252
252
m_io->read (reinterpret_cast <char *>(&t), 8 );
253
253
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -260,12 +260,12 @@ double kaitai::kstream::read_f8le() {
260
260
// Unaligned bit values
261
261
// ========================================================================
262
262
263
- void kaitai::kstream ::align_to_byte () {
263
+ void kaitai::kistream ::align_to_byte () {
264
264
m_bits_left = 0 ;
265
265
m_bits = 0 ;
266
266
}
267
267
268
- uint64_t kaitai::kstream ::read_bits_int (int n) {
268
+ uint64_t kaitai::kistream ::read_bits_int (int n) {
269
269
int bits_needed = n - m_bits_left;
270
270
if (bits_needed > 0 ) {
271
271
// 1 bit => 1 byte
@@ -303,7 +303,7 @@ uint64_t kaitai::kstream::read_bits_int(int n) {
303
303
// Byte arrays
304
304
// ========================================================================
305
305
306
- std::string kaitai::kstream ::read_bytes (std::streamsize len) {
306
+ std::string kaitai::kistream ::read_bytes (std::streamsize len) {
307
307
std::vector<char > result (len);
308
308
309
309
// NOTE: streamsize type is signed, negative values are only *supposed* to not be used.
@@ -319,7 +319,7 @@ std::string kaitai::kstream::read_bytes(std::streamsize len) {
319
319
return std::string (result.begin (), result.end ());
320
320
}
321
321
322
- std::string kaitai::kstream ::read_bytes_full () {
322
+ std::string kaitai::kistream ::read_bytes_full () {
323
323
std::iostream::pos_type p1 = m_io->tellg ();
324
324
m_io->seekg (0 , std::ios::end);
325
325
std::iostream::pos_type p2 = m_io->tellg ();
@@ -336,7 +336,7 @@ std::string kaitai::kstream::read_bytes_full() {
336
336
return result;
337
337
}
338
338
339
- std::string kaitai::kstream ::read_bytes_term (char term, bool include, bool consume, bool eos_error) {
339
+ std::string kaitai::kistream ::read_bytes_term (char term, bool include, bool consume, bool eos_error) {
340
340
std::string result;
341
341
std::getline (*m_io, result, term);
342
342
if (m_io->eof ()) {
@@ -354,7 +354,7 @@ std::string kaitai::kstream::read_bytes_term(char term, bool include, bool consu
354
354
return result;
355
355
}
356
356
357
- std::string kaitai::kstream ::ensure_fixed_contents (std::string expected) {
357
+ std::string kaitai::kistream ::ensure_fixed_contents (std::string expected) {
358
358
std::string actual = read_bytes (expected.length ());
359
359
360
360
if (actual != expected) {
@@ -372,7 +372,7 @@ std::string kaitai::kstream::ensure_fixed_contents(std::string expected) {
372
372
#ifdef KS_ZLIB
373
373
#include < zlib.h>
374
374
375
- std::string kaitai::kstream ::process_zlib (std::string data) {
375
+ std::string kaitai::kistream ::process_zlib (std::string data) {
376
376
int ret;
377
377
378
378
unsigned char *src_ptr = reinterpret_cast <unsigned char *>(&data[0 ]);
0 commit comments