kaitai-struct 0.6 → 0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/kaitai/struct/struct.rb +51 -47
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f864fb7a549cb0ffb83d39e1e1a8f3e58feba59b
|
4
|
+
data.tar.gz: f398b795f794ac82e4ab78838dc4f7eb1f773cbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9682c42a2b4636b58255f6b0ed111ba399e182e34269515707471206ae217bd72e26c336749b7737a3c5fa6a9b48eb640cfe0a21bfb4db464420797ef3dce7fb
|
7
|
+
data.tar.gz: 1d6cf8627185ada694d03f2303259f21341f34e4091197907bcc9397b703dc7ba232c7fa36d5bd1244f707ba0dcb2ce1a7a690df65fa8a8fe599ffd5814d6510
|
data/README.md
CHANGED
@@ -8,9 +8,8 @@ formats, network stream packet formats, etc.
|
|
8
8
|
|
9
9
|
Further reading:
|
10
10
|
|
11
|
-
* [About Kaitai Struct](
|
12
|
-
* [About API implemented in this library](
|
13
|
-
* [Ruby-specific notes](https://github.com/kaitai-io/kaitai_struct/wiki/Ruby)
|
11
|
+
* [About Kaitai Struct](http://kaitai.io/)
|
12
|
+
* [About API implemented in this library](http://doc.kaitai.io/stream_api.html)
|
14
13
|
|
15
14
|
## Installing
|
16
15
|
|
@@ -43,7 +42,7 @@ by Ruby source code generate by Kaitai Struct compiler.
|
|
43
42
|
|
44
43
|
## Licensing
|
45
44
|
|
46
|
-
Copyright 2015-
|
45
|
+
Copyright 2015-2017 Kaitai Project: MIT license
|
47
46
|
|
48
47
|
Permission is hereby granted, free of charge, to any person obtaining
|
49
48
|
a copy of this software and associated documentation files (the
|
data/lib/kaitai/struct/struct.rb
CHANGED
@@ -3,7 +3,7 @@ require 'stringio'
|
|
3
3
|
module Kaitai
|
4
4
|
module Struct
|
5
5
|
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.7'
|
7
7
|
|
8
8
|
##
|
9
9
|
# Common base class for all structured generated by Kaitai Struct.
|
@@ -113,9 +113,7 @@ class Stream
|
|
113
113
|
# Test endianness of the platform
|
114
114
|
@@big_endian = [0x0102].pack('s') == [0x0102].pack('n')
|
115
115
|
|
116
|
-
#
|
117
|
-
# Stream positioning
|
118
|
-
# ========================================================================
|
116
|
+
# @!group Stream positioning
|
119
117
|
|
120
118
|
##
|
121
119
|
# Check if stream pointer is at the end of stream.
|
@@ -137,9 +135,9 @@ class Stream
|
|
137
135
|
# @return [Fixnum] size of the stream in bytes
|
138
136
|
def size; @_io.size; end
|
139
137
|
|
140
|
-
#
|
141
|
-
|
142
|
-
#
|
138
|
+
# @!endgroup
|
139
|
+
|
140
|
+
# @!group Integer numbers
|
143
141
|
|
144
142
|
# ------------------------------------------------------------------------
|
145
143
|
# Signed
|
@@ -247,9 +245,9 @@ class Stream
|
|
247
245
|
end
|
248
246
|
end
|
249
247
|
|
250
|
-
#
|
251
|
-
|
252
|
-
#
|
248
|
+
# @!endgroup
|
249
|
+
|
250
|
+
# @!group Floating point numbers
|
253
251
|
|
254
252
|
# ------------------------------------------------------------------------
|
255
253
|
# Big-endian
|
@@ -275,9 +273,9 @@ class Stream
|
|
275
273
|
read_bytes(8).unpack('E')[0]
|
276
274
|
end
|
277
275
|
|
278
|
-
#
|
279
|
-
|
280
|
-
#
|
276
|
+
# @!endgroup
|
277
|
+
|
278
|
+
# @!group Unaligned bit values
|
281
279
|
|
282
280
|
def align_to_byte
|
283
281
|
@bits_left = 0
|
@@ -314,9 +312,9 @@ class Stream
|
|
314
312
|
res
|
315
313
|
end
|
316
314
|
|
317
|
-
#
|
318
|
-
|
319
|
-
#
|
315
|
+
# @!endgroup
|
316
|
+
|
317
|
+
# @!group Byte arrays
|
320
318
|
|
321
319
|
##
|
322
320
|
# Reads designated number of bytes from the stream.
|
@@ -342,6 +340,26 @@ class Stream
|
|
342
340
|
@_io.read
|
343
341
|
end
|
344
342
|
|
343
|
+
def read_bytes_term(term, include_term, consume_term, eos_error)
|
344
|
+
r = ''
|
345
|
+
loop {
|
346
|
+
if @_io.eof?
|
347
|
+
if eos_error
|
348
|
+
raise EOFError.new("end of stream reached, but no terminator #{term} found")
|
349
|
+
else
|
350
|
+
return r
|
351
|
+
end
|
352
|
+
end
|
353
|
+
c = @_io.getc
|
354
|
+
if c.ord == term
|
355
|
+
r << c if include_term
|
356
|
+
@_io.seek(@_io.pos - 1) unless consume_term
|
357
|
+
return r
|
358
|
+
end
|
359
|
+
r << c
|
360
|
+
}
|
361
|
+
end
|
362
|
+
|
345
363
|
##
|
346
364
|
# Reads next len bytes from the stream and ensures that they match
|
347
365
|
# expected fixed byte array. If they differ, throws a
|
@@ -357,41 +375,27 @@ class Stream
|
|
357
375
|
actual
|
358
376
|
end
|
359
377
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
378
|
+
def self.bytes_strip_right(bytes, pad_byte)
|
379
|
+
new_len = bytes.length
|
380
|
+
while bytes.getbyte(new_len - 1) == pad_byte
|
381
|
+
new_len -= 1
|
382
|
+
end
|
383
|
+
bytes[0, new_len]
|
366
384
|
end
|
367
385
|
|
368
|
-
def
|
369
|
-
|
386
|
+
def self.bytes_terminate(bytes, term, include_term)
|
387
|
+
new_len = 0
|
388
|
+
max_len = bytes.length
|
389
|
+
while bytes.getbyte(new_len) != term and new_len < max_len
|
390
|
+
new_len += 1
|
391
|
+
end
|
392
|
+
new_len += 1 if include_term and new_len < max_len
|
393
|
+
bytes[0, new_len]
|
370
394
|
end
|
371
395
|
|
372
|
-
|
373
|
-
r = ''
|
374
|
-
loop {
|
375
|
-
if @_io.eof?
|
376
|
-
if eos_error
|
377
|
-
raise EOFError.new("end of stream reached, but no terminator #{term} found")
|
378
|
-
else
|
379
|
-
return r.force_encoding(encoding)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
c = @_io.getc
|
383
|
-
if c.ord == term
|
384
|
-
r << c if include_term
|
385
|
-
@_io.seek(@_io.pos - 1) unless consume_term
|
386
|
-
return r.force_encoding(encoding)
|
387
|
-
end
|
388
|
-
r << c
|
389
|
-
}
|
390
|
-
end
|
396
|
+
# @!endgroup
|
391
397
|
|
392
|
-
#
|
393
|
-
# Byte array processing
|
394
|
-
# ========================================================================
|
398
|
+
# @!group Byte array processing
|
395
399
|
|
396
400
|
##
|
397
401
|
# Performs a XOR processing with given data, XORing every byte of
|
@@ -461,7 +465,7 @@ class Stream
|
|
461
465
|
data.bytes.map { |x| (x << amount) | (x >> anti_amount) }.pack('C*')
|
462
466
|
end
|
463
467
|
|
464
|
-
#
|
468
|
+
# @!endgroup
|
465
469
|
|
466
470
|
##
|
467
471
|
# Resolves value using enum: if the value is not found in the map,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaitai-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Yakshin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Kaitai Struct is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
|