Skip to content

Commit f9b112d

Browse files
committed
Rename kstream to kistream, add compat typedef.
1 parent c89db17 commit f9b112d

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

kaitai/exceptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class undecided_endianness_error: public kstruct_error {
4343
*/
4444
class validation_failed_error: public kstruct_error {
4545
public:
46-
validation_failed_error(const std::string what, const kstream* io, const std::string src_path):
46+
validation_failed_error(const std::string what, const kistream* io, const std::string src_path):
4747
kstruct_error(std::string("at pos ") + /*std::to_string(io->pos())*/ + ": validation failed:" + what, src_path),
4848
m_io(io)
4949
{
@@ -52,7 +52,7 @@ class validation_failed_error: public kstruct_error {
5252
// "at pos #{io.pos}: validation failed: #{msg}"
5353

5454
protected:
55-
const kstream* m_io;
55+
const kistream* m_io;
5656
};
5757

5858
/**
@@ -62,7 +62,7 @@ class validation_failed_error: public kstruct_error {
6262
template<typename T>
6363
class validation_not_equal_error: public validation_failed_error {
6464
public:
65-
validation_not_equal_error<T>(const T& expected, const T& actual, const kstream* io, const std::string src_path):
65+
validation_not_equal_error<T>(const T& expected, const T& actual, const kistream* io, const std::string src_path):
6666
validation_failed_error("not equal", io, src_path),
6767
m_expected(expected),
6868
m_actual(actual)

kaitai/kaitaistream.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@
66
// Kaitai Struct runtime API version: x.y.z = 'xxxyyyzzz' decimal
77
#define KAITAI_STRUCT_VERSION 9000L
88

9+
namespace kaitai {
10+
11+
// This typedef exists for API compatibility with previous versions of the
12+
// KaitaiStruct C++ runtime.
13+
typedef kistream kstream;
14+
15+
}
16+
917
#endif

kaitai/kaitaistruct.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace kaitai {
77

88
class kstruct {
99
public:
10-
kstruct(kstream *_io) { m__io = _io; }
10+
kstruct(kistream *_io) { m__io = _io; }
1111
virtual ~kstruct() {}
1212
protected:
13-
kstream *m__io;
13+
kistream *m__io;
1414
public:
15-
kstream *_io() { return m__io; }
15+
kistream *_io() { return m__io; }
1616
};
1717

1818
}

kaitai/kistream.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
#include <vector>
66
#include <stdexcept>
77

8-
kaitai::kstream::kstream(std::istream* io): kio(io) {
8+
kaitai::kistream::kistream(std::istream* io): kio(io) {
99
m_io = io;
1010
init();
1111
}
1212

13-
kaitai::kstream::kstream(std::string& data): m_io_str(data) {
13+
kaitai::kistream::kistream(std::string& data): m_io_str(data) {
1414
kio::init(m_io);
1515
m_io = &m_io_str;
1616
init();
1717
}
1818

19-
void kaitai::kstream::init() {
19+
void kaitai::kistream::init() {
2020
align_to_byte();
2121
}
2222

2323
// ========================================================================
2424
// Stream positioning
2525
// ========================================================================
2626

27-
bool kaitai::kstream::is_eof() const {
27+
bool kaitai::kistream::is_eof() const {
2828
if (m_bits_left > 0) {
2929
return false;
3030
}
@@ -44,15 +44,15 @@ bool kaitai::kstream::is_eof() const {
4444
}
4545
}
4646

47-
void kaitai::kstream::seek(uint64_t pos) {
47+
void kaitai::kistream::seek(uint64_t pos) {
4848
m_io->seekg(pos);
4949
}
5050

51-
uint64_t kaitai::kstream::pos() {
51+
uint64_t kaitai::kistream::pos() {
5252
return m_io->tellg();
5353
}
5454

55-
uint64_t kaitai::kstream::size() {
55+
uint64_t kaitai::kistream::size() {
5656
std::iostream::pos_type cur_pos = m_io->tellg();
5757
m_io->seekg(0, std::ios::end);
5858
std::iostream::pos_type len = m_io->tellg();
@@ -68,7 +68,7 @@ uint64_t kaitai::kstream::size() {
6868
// Signed
6969
// ------------------------------------------------------------------------
7070

71-
int8_t kaitai::kstream::read_s1() {
71+
int8_t kaitai::kistream::read_s1() {
7272
char t;
7373
m_io->get(t);
7474
return t;
@@ -78,7 +78,7 @@ int8_t kaitai::kstream::read_s1() {
7878
// Big-endian
7979
// ........................................................................
8080

81-
int16_t kaitai::kstream::read_s2be() {
81+
int16_t kaitai::kistream::read_s2be() {
8282
int16_t t;
8383
m_io->read(reinterpret_cast<char *>(&t), 2);
8484
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -87,7 +87,7 @@ int16_t kaitai::kstream::read_s2be() {
8787
return t;
8888
}
8989

90-
int32_t kaitai::kstream::read_s4be() {
90+
int32_t kaitai::kistream::read_s4be() {
9191
int32_t t;
9292
m_io->read(reinterpret_cast<char *>(&t), 4);
9393
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -96,7 +96,7 @@ int32_t kaitai::kstream::read_s4be() {
9696
return t;
9797
}
9898

99-
int64_t kaitai::kstream::read_s8be() {
99+
int64_t kaitai::kistream::read_s8be() {
100100
int64_t t;
101101
m_io->read(reinterpret_cast<char *>(&t), 8);
102102
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -109,7 +109,7 @@ int64_t kaitai::kstream::read_s8be() {
109109
// Little-endian
110110
// ........................................................................
111111

112-
int16_t kaitai::kstream::read_s2le() {
112+
int16_t kaitai::kistream::read_s2le() {
113113
int16_t t;
114114
m_io->read(reinterpret_cast<char *>(&t), 2);
115115
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -118,7 +118,7 @@ int16_t kaitai::kstream::read_s2le() {
118118
return t;
119119
}
120120

121-
int32_t kaitai::kstream::read_s4le() {
121+
int32_t kaitai::kistream::read_s4le() {
122122
int32_t t;
123123
m_io->read(reinterpret_cast<char *>(&t), 4);
124124
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -127,7 +127,7 @@ int32_t kaitai::kstream::read_s4le() {
127127
return t;
128128
}
129129

130-
int64_t kaitai::kstream::read_s8le() {
130+
int64_t kaitai::kistream::read_s8le() {
131131
int64_t t;
132132
m_io->read(reinterpret_cast<char *>(&t), 8);
133133
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -140,7 +140,7 @@ int64_t kaitai::kstream::read_s8le() {
140140
// Unsigned
141141
// ------------------------------------------------------------------------
142142

143-
uint8_t kaitai::kstream::read_u1() {
143+
uint8_t kaitai::kistream::read_u1() {
144144
char t;
145145
m_io->get(t);
146146
return t;
@@ -150,7 +150,7 @@ uint8_t kaitai::kstream::read_u1() {
150150
// Big-endian
151151
// ........................................................................
152152

153-
uint16_t kaitai::kstream::read_u2be() {
153+
uint16_t kaitai::kistream::read_u2be() {
154154
uint16_t t;
155155
m_io->read(reinterpret_cast<char *>(&t), 2);
156156
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -159,7 +159,7 @@ uint16_t kaitai::kstream::read_u2be() {
159159
return t;
160160
}
161161

162-
uint32_t kaitai::kstream::read_u4be() {
162+
uint32_t kaitai::kistream::read_u4be() {
163163
uint32_t t;
164164
m_io->read(reinterpret_cast<char *>(&t), 4);
165165
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -168,7 +168,7 @@ uint32_t kaitai::kstream::read_u4be() {
168168
return t;
169169
}
170170

171-
uint64_t kaitai::kstream::read_u8be() {
171+
uint64_t kaitai::kistream::read_u8be() {
172172
uint64_t t;
173173
m_io->read(reinterpret_cast<char *>(&t), 8);
174174
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -181,7 +181,7 @@ uint64_t kaitai::kstream::read_u8be() {
181181
// Little-endian
182182
// ........................................................................
183183

184-
uint16_t kaitai::kstream::read_u2le() {
184+
uint16_t kaitai::kistream::read_u2le() {
185185
uint16_t t;
186186
m_io->read(reinterpret_cast<char *>(&t), 2);
187187
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -190,7 +190,7 @@ uint16_t kaitai::kstream::read_u2le() {
190190
return t;
191191
}
192192

193-
uint32_t kaitai::kstream::read_u4le() {
193+
uint32_t kaitai::kistream::read_u4le() {
194194
uint32_t t;
195195
m_io->read(reinterpret_cast<char *>(&t), 4);
196196
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -199,7 +199,7 @@ uint32_t kaitai::kstream::read_u4le() {
199199
return t;
200200
}
201201

202-
uint64_t kaitai::kstream::read_u8le() {
202+
uint64_t kaitai::kistream::read_u8le() {
203203
uint64_t t;
204204
m_io->read(reinterpret_cast<char *>(&t), 8);
205205
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -216,7 +216,7 @@ uint64_t kaitai::kstream::read_u8le() {
216216
// Big-endian
217217
// ........................................................................
218218

219-
float kaitai::kstream::read_f4be() {
219+
float kaitai::kistream::read_f4be() {
220220
uint32_t t;
221221
m_io->read(reinterpret_cast<char *>(&t), 4);
222222
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -225,7 +225,7 @@ float kaitai::kstream::read_f4be() {
225225
return reinterpret_cast<float&>(t);
226226
}
227227

228-
double kaitai::kstream::read_f8be() {
228+
double kaitai::kistream::read_f8be() {
229229
uint64_t t;
230230
m_io->read(reinterpret_cast<char *>(&t), 8);
231231
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -238,7 +238,7 @@ double kaitai::kstream::read_f8be() {
238238
// Little-endian
239239
// ........................................................................
240240

241-
float kaitai::kstream::read_f4le() {
241+
float kaitai::kistream::read_f4le() {
242242
uint32_t t;
243243
m_io->read(reinterpret_cast<char *>(&t), 4);
244244
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -247,7 +247,7 @@ float kaitai::kstream::read_f4le() {
247247
return reinterpret_cast<float&>(t);
248248
}
249249

250-
double kaitai::kstream::read_f8le() {
250+
double kaitai::kistream::read_f8le() {
251251
uint64_t t;
252252
m_io->read(reinterpret_cast<char *>(&t), 8);
253253
#if __BYTE_ORDER == __BIG_ENDIAN
@@ -260,12 +260,12 @@ double kaitai::kstream::read_f8le() {
260260
// Unaligned bit values
261261
// ========================================================================
262262

263-
void kaitai::kstream::align_to_byte() {
263+
void kaitai::kistream::align_to_byte() {
264264
m_bits_left = 0;
265265
m_bits = 0;
266266
}
267267

268-
uint64_t kaitai::kstream::read_bits_int(int n) {
268+
uint64_t kaitai::kistream::read_bits_int(int n) {
269269
int bits_needed = n - m_bits_left;
270270
if (bits_needed > 0) {
271271
// 1 bit => 1 byte
@@ -303,7 +303,7 @@ uint64_t kaitai::kstream::read_bits_int(int n) {
303303
// Byte arrays
304304
// ========================================================================
305305

306-
std::string kaitai::kstream::read_bytes(std::streamsize len) {
306+
std::string kaitai::kistream::read_bytes(std::streamsize len) {
307307
std::vector<char> result(len);
308308

309309
// 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) {
319319
return std::string(result.begin(), result.end());
320320
}
321321

322-
std::string kaitai::kstream::read_bytes_full() {
322+
std::string kaitai::kistream::read_bytes_full() {
323323
std::iostream::pos_type p1 = m_io->tellg();
324324
m_io->seekg(0, std::ios::end);
325325
std::iostream::pos_type p2 = m_io->tellg();
@@ -336,7 +336,7 @@ std::string kaitai::kstream::read_bytes_full() {
336336
return result;
337337
}
338338

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) {
340340
std::string result;
341341
std::getline(*m_io, result, term);
342342
if (m_io->eof()) {
@@ -354,7 +354,7 @@ std::string kaitai::kstream::read_bytes_term(char term, bool include, bool consu
354354
return result;
355355
}
356356

357-
std::string kaitai::kstream::ensure_fixed_contents(std::string expected) {
357+
std::string kaitai::kistream::ensure_fixed_contents(std::string expected) {
358358
std::string actual = read_bytes(expected.length());
359359

360360
if (actual != expected) {
@@ -372,7 +372,7 @@ std::string kaitai::kstream::ensure_fixed_contents(std::string expected) {
372372
#ifdef KS_ZLIB
373373
#include <zlib.h>
374374

375-
std::string kaitai::kstream::process_zlib(std::string data) {
375+
std::string kaitai::kistream::process_zlib(std::string data) {
376376
int ret;
377377

378378
unsigned char *src_ptr = reinterpret_cast<unsigned char*>(&data[0]);

kaitai/kistream.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace kaitai {
1212

1313
/**
14-
* Kaitai Stream class (kaitai::kstream) is an implementation of
14+
* Kaitai Stream class (kaitai::kistream) is an implementation of
1515
* <a href="https://github.com/kaitai-io/kaitai_struct/wiki/Kaitai-Struct-stream-API">Kaitai Struct stream API</a>
1616
* for C++/STL. It's implemented as a wrapper over generic STL std::istream.
1717
*
@@ -33,14 +33,14 @@ class kistream : public virtual kio {
3333
* Constructs new Kaitai Stream object, wrapping a given std::istream.
3434
* \param io istream object to use for this Kaitai Stream
3535
*/
36-
kstream(std::istream* io);
36+
kistream(std::istream* io);
3737

3838
/**
3939
* Constructs new Kaitai Stream object, wrapping a given in-memory data
4040
* buffer.
4141
* \param data data buffer to use for this Kaitai Stream
4242
*/
43-
kstream(std::string& data);
43+
kistream(std::string& data);
4444

4545
/** @name Stream positioning */
4646
//@{

0 commit comments

Comments
 (0)