bit-struct 0.13.4 → 0.13.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +3 -1
- data/lib/bit-struct.rb +8 -0
- data/lib/bit-struct/bit-struct.rb +20 -1
- data/lib/bit-struct/fields.rb +10 -10
- data/lib/bit-struct/signed-field.rb +2 -2
- data/lib/bit-struct/unsigned-field.rb +2 -2
- metadata +7 -7
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ end
|
|
16
16
|
ensure_in_path 'lib'
|
17
17
|
require 'bit-struct/bit-struct'
|
18
18
|
|
19
|
-
task :default => 'spec:run'
|
19
|
+
#task :default => 'spec:run'
|
20
20
|
|
21
21
|
PROJ.name = 'bit-struct'
|
22
22
|
PROJ.authors = 'Joel VanderWerf'
|
@@ -28,8 +28,10 @@ PROJ.summary = "Library for packed binary data stored in ruby Strings"
|
|
28
28
|
PROJ.description = <<END
|
29
29
|
Library for packed binary data stored in ruby Strings. Useful for accessing fields in network packets and binary files.
|
30
30
|
END
|
31
|
+
PROJ.changes = File.read(PROJ.history_file)[/^\w.*?(?=^\w)/m]
|
31
32
|
|
32
33
|
PROJ.spec.opts << '--color'
|
34
|
+
PROJ.test.files = Dir["test/*.rb"]
|
33
35
|
|
34
36
|
task :release => ["gem:release", "doc:release"]
|
35
37
|
|
data/lib/bit-struct.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# A Convenience to load all field classes and yaml handling.
|
2
2
|
|
3
|
+
if "a"[0].kind_of? Fixnum
|
4
|
+
unless Fixnum.methods.include? :ord
|
5
|
+
class Fixnum
|
6
|
+
def ord; self; end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
require 'bit-struct/bit-struct'
|
4
12
|
require 'bit-struct/fields'
|
5
13
|
require 'bit-struct/yaml'
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# The String#replace method is useful.
|
10
10
|
#
|
11
11
|
class BitStruct < String
|
12
|
-
VERSION = "0.13.
|
12
|
+
VERSION = "0.13.5"
|
13
13
|
|
14
14
|
class Field
|
15
15
|
# Offset of field in bits.
|
@@ -385,6 +385,25 @@ class BitStruct < String
|
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|
388
|
+
## temporary hack for 1.9
|
389
|
+
if "a"[0].kind_of? String
|
390
|
+
def [](*args)
|
391
|
+
if args.size == 1 and args[0].kind_of?(Fixnum)
|
392
|
+
super.ord
|
393
|
+
else
|
394
|
+
super
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def []=(*args)
|
399
|
+
if args.size == 2 and (i=args[0]).kind_of?(Fixnum)
|
400
|
+
super(i, args[1].chr)
|
401
|
+
else
|
402
|
+
super
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
388
407
|
class << self
|
389
408
|
# The unique "prototype" object from which new instances are copied.
|
390
409
|
# The fields of this instance can be modified in the class definition
|
data/lib/bit-struct/fields.rb
CHANGED
@@ -15,7 +15,7 @@ class BitStruct
|
|
15
15
|
add_field(name, length, opts)
|
16
16
|
end
|
17
17
|
alias string char
|
18
|
-
autoload :CharField, "bit-struct/char-field"
|
18
|
+
BitStruct.autoload :CharField, "bit-struct/char-field"
|
19
19
|
|
20
20
|
# Define a floating point field in the current subclass of BitStruct,
|
21
21
|
# with the given _name_ and _length_ (in bits).
|
@@ -33,7 +33,7 @@ class BitStruct
|
|
33
33
|
opts = parse_options(rest, name, FloatField)
|
34
34
|
add_field(name, length, opts)
|
35
35
|
end
|
36
|
-
autoload :FloatField, "bit-struct/float-field"
|
36
|
+
BitStruct.autoload :FloatField, "bit-struct/float-field"
|
37
37
|
|
38
38
|
# Define an octet string field in the current subclass of BitStruct,
|
39
39
|
# with the given _name_ and _length_ (in bits). Trailing nulls are
|
@@ -48,7 +48,7 @@ class BitStruct
|
|
48
48
|
opts = parse_options(rest, name, HexOctetField)
|
49
49
|
add_field(name, length, opts)
|
50
50
|
end
|
51
|
-
autoload :HexOctetField, "bit-struct/hex-octet-field"
|
51
|
+
BitStruct.autoload :HexOctetField, "bit-struct/hex-octet-field"
|
52
52
|
|
53
53
|
# Define a nested field in the current subclass of BitStruct,
|
54
54
|
# with the given _name_ and _nested_class_. Length is determined from
|
@@ -118,7 +118,7 @@ class BitStruct
|
|
118
118
|
field
|
119
119
|
end
|
120
120
|
alias struct nest
|
121
|
-
autoload :NestedField, "bit-struct/nested-field"
|
121
|
+
BitStruct.autoload :NestedField, "bit-struct/nested-field"
|
122
122
|
|
123
123
|
# Define an octet string field in the current subclass of BitStruct,
|
124
124
|
# with the given _name_ and _length_ (in bits). Trailing nulls are
|
@@ -133,7 +133,7 @@ class BitStruct
|
|
133
133
|
opts = parse_options(rest, name, OctetField)
|
134
134
|
add_field(name, length, opts)
|
135
135
|
end
|
136
|
-
autoload :OctetField, "bit-struct/octet-field"
|
136
|
+
BitStruct.autoload :OctetField, "bit-struct/octet-field"
|
137
137
|
|
138
138
|
# Define a padding field in the current subclass of BitStruct,
|
139
139
|
# with the given _name_ and _length_ (in bits).
|
@@ -147,7 +147,7 @@ class BitStruct
|
|
147
147
|
add_field(name, length, opts)
|
148
148
|
end
|
149
149
|
alias padding pad
|
150
|
-
autoload :PadField, "bit-struct/pad-field"
|
150
|
+
BitStruct.autoload :PadField, "bit-struct/pad-field"
|
151
151
|
|
152
152
|
# Define a signed integer field in the current subclass of BitStruct,
|
153
153
|
# with the given _name_ and _length_ (in bits).
|
@@ -169,7 +169,7 @@ class BitStruct
|
|
169
169
|
opts = parse_options(rest, name, SignedField)
|
170
170
|
add_field(name, length, opts)
|
171
171
|
end
|
172
|
-
autoload :SignedField, "bit-struct/signed-field"
|
172
|
+
BitStruct.autoload :SignedField, "bit-struct/signed-field"
|
173
173
|
|
174
174
|
# Define a printable text string field in the current subclass of BitStruct,
|
175
175
|
# with the given _name_ and _length_ (in bits). Trailing nulls are
|
@@ -185,7 +185,7 @@ class BitStruct
|
|
185
185
|
opts = parse_options(rest, name, TextField)
|
186
186
|
add_field(name, length, opts)
|
187
187
|
end
|
188
|
-
autoload :TextField, "bit-struct/text-field"
|
188
|
+
BitStruct.autoload :TextField, "bit-struct/text-field"
|
189
189
|
|
190
190
|
# Define a unsigned integer field in the current subclass of BitStruct,
|
191
191
|
# with the given _name_ and _length_ (in bits).
|
@@ -207,7 +207,7 @@ class BitStruct
|
|
207
207
|
opts = parse_options(rest, name, UnsignedField)
|
208
208
|
add_field(name, length, opts)
|
209
209
|
end
|
210
|
-
autoload :UnsignedField, "bit-struct/unsigned-field"
|
210
|
+
BitStruct.autoload :UnsignedField, "bit-struct/unsigned-field"
|
211
211
|
|
212
212
|
# Define a vector field in the current subclass of BitStruct,
|
213
213
|
# with the given _name_.
|
@@ -293,7 +293,7 @@ class BitStruct
|
|
293
293
|
field = add_field(name, bit_length, opts)
|
294
294
|
field
|
295
295
|
end
|
296
|
-
autoload :VectorField, "bit-struct/vector-field"
|
296
|
+
BitStruct.autoload :VectorField, "bit-struct/vector-field"
|
297
297
|
end
|
298
298
|
|
299
299
|
autoload :Vector, "bit-struct/vector"
|
@@ -48,8 +48,8 @@ class BitStruct
|
|
48
48
|
|
49
49
|
if length_byte == 1
|
50
50
|
rest = 8 - length_bit
|
51
|
-
mask = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
|
52
|
-
mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
|
51
|
+
mask = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0].ord
|
52
|
+
mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0].ord
|
53
53
|
|
54
54
|
cl.class_eval do
|
55
55
|
if divisor
|
@@ -39,8 +39,8 @@ class BitStruct
|
|
39
39
|
|
40
40
|
if length_byte == 1
|
41
41
|
rest = 8 - length_bit
|
42
|
-
mask = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
|
43
|
-
mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
|
42
|
+
mask = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0].ord
|
43
|
+
mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0].ord
|
44
44
|
|
45
45
|
cl.class_eval do
|
46
46
|
if divisor
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bit-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel VanderWerf
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -34,9 +34,7 @@ extra_rdoc_files:
|
|
34
34
|
- History.txt
|
35
35
|
- README.txt
|
36
36
|
files:
|
37
|
-
- .bnsignore.bck
|
38
37
|
- .gitignore
|
39
|
-
- .gitignore.bck
|
40
38
|
- History.txt
|
41
39
|
- README.txt
|
42
40
|
- Rakefile
|
@@ -118,9 +116,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
116
|
requirements: []
|
119
117
|
|
120
118
|
rubyforge_project: bit-struct
|
121
|
-
rubygems_version: 1.3.
|
119
|
+
rubygems_version: 1.3.5
|
122
120
|
signing_key:
|
123
121
|
specification_version: 3
|
124
122
|
summary: Library for packed binary data stored in ruby Strings
|
125
|
-
test_files:
|
126
|
-
|
123
|
+
test_files:
|
124
|
+
- test/test-endian.rb
|
125
|
+
- test/test.rb
|
126
|
+
- test/test-vector.rb
|