binaryparse 0.3.3 → 1.0.0
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.
- data/lib/blocker.rb +59 -6
- metadata +41 -35
data/lib/blocker.rb
CHANGED
@@ -19,7 +19,12 @@ module BinaryBlocker
|
|
19
19
|
def klasses
|
20
20
|
@klasses ||= {}
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
def pretty_print(obj)
|
24
|
+
obj.text "FOO"
|
25
|
+
#obj.text self.class.pretty_print
|
26
|
+
end
|
27
|
+
|
23
28
|
# To simplify naming of classes and laying out fields in your structures
|
24
29
|
# they can be registered:
|
25
30
|
#
|
@@ -97,7 +102,11 @@ module BinaryBlocker
|
|
97
102
|
# It also supports either a string or io parameter which will be used to
|
98
103
|
# initialize the class
|
99
104
|
class Encoder
|
100
|
-
|
105
|
+
|
106
|
+
def me
|
107
|
+
self.class.superclass.to_s
|
108
|
+
end
|
109
|
+
|
101
110
|
# Parameters: (io | buf, options_hash)
|
102
111
|
#
|
103
112
|
# Options (lambda):
|
@@ -382,6 +391,7 @@ module BinaryBlocker
|
|
382
391
|
end
|
383
392
|
end
|
384
393
|
end
|
394
|
+
puts "method missing #{sym.inspect} #{bt}"
|
385
395
|
super
|
386
396
|
end
|
387
397
|
|
@@ -417,7 +427,7 @@ module BinaryBlocker
|
|
417
427
|
end
|
418
428
|
BinaryBlocker.register_klass(sym, klass)
|
419
429
|
end
|
420
|
-
|
430
|
+
|
421
431
|
def internal_block(val)
|
422
432
|
if val.nil?
|
423
433
|
[0].pack(@format)
|
@@ -439,9 +449,9 @@ module BinaryBlocker
|
|
439
449
|
self.value != nil && (@key == nil || @key === self.value)
|
440
450
|
end
|
441
451
|
end
|
442
|
-
|
452
|
+
|
443
453
|
def inspect
|
444
|
-
"
|
454
|
+
"#{@format} - #{@length} - #{self.value.inspect}"
|
445
455
|
end
|
446
456
|
end
|
447
457
|
|
@@ -552,6 +562,34 @@ module BinaryBlocker
|
|
552
562
|
end
|
553
563
|
BinaryBlocker.register_klass(:packed, PackedNumberEncoder)
|
554
564
|
|
565
|
+
class NewPackedNumberEncoder < SimpleEncoder
|
566
|
+
def initialize(*opts)
|
567
|
+
initialize_options(*opts)
|
568
|
+
|
569
|
+
@length = @opts[:length].to_i
|
570
|
+
raise ArgumentError.new("Missing or invalid string length") unless @length > 0
|
571
|
+
@length += 1 if @length[0] == 1
|
572
|
+
@bytes = @length / 2
|
573
|
+
@format = "H#{@length}"
|
574
|
+
|
575
|
+
@key = @opts[:key]
|
576
|
+
@valid = @opts[:valid]
|
577
|
+
|
578
|
+
initialize_data(*opts)
|
579
|
+
end
|
580
|
+
|
581
|
+
def internal_block(val)
|
582
|
+
[val.to_s.rjust(@length,"\xff")].pack(@format)
|
583
|
+
end
|
584
|
+
|
585
|
+
def internal_deblock(io)
|
586
|
+
buffer = io.read(@bytes)
|
587
|
+
result = buffer.unpack(@format)
|
588
|
+
result.first.match(/(\d+)/)[0].to_i
|
589
|
+
end
|
590
|
+
end
|
591
|
+
BinaryBlocker.register_klass(:new_packed, NewPackedNumberEncoder)
|
592
|
+
|
555
593
|
class PackedDateEncoder < PackedNumberEncoder
|
556
594
|
def initialize_options(*opts)
|
557
595
|
super
|
@@ -1026,8 +1064,23 @@ module BinaryBlocker
|
|
1026
1064
|
|
1027
1065
|
class Blocker < GroupEncoder
|
1028
1066
|
def inspect
|
1029
|
-
|
1067
|
+
result = []
|
1068
|
+
@lookup.keys.sort_by {|k| @lookup[k]}.each do |k|
|
1069
|
+
result << [k, @value[@lookup[k]]]
|
1070
|
+
end
|
1071
|
+
"#{self.class}: #{result.inspect}"
|
1030
1072
|
end
|
1073
|
+
|
1074
|
+
def pretty_print(obj)
|
1075
|
+
result = []
|
1076
|
+
@lookup.keys.sort_by {|k| @lookup[k]}.each do |k|
|
1077
|
+
result << [k, @value[@lookup[k]]]
|
1078
|
+
end
|
1079
|
+
obj.text self.class.to_s
|
1080
|
+
obj.text ": "
|
1081
|
+
result.pretty_print(obj)
|
1082
|
+
end
|
1083
|
+
|
1031
1084
|
end
|
1032
1085
|
|
1033
1086
|
end
|
metadata
CHANGED
@@ -1,54 +1,60 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: binaryparse
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-12-20 00:00:00 -05:00
|
8
|
-
summary: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: phurley@gmail.com
|
12
|
-
homepage: http://binaryparse.rubyforge.org/
|
13
|
-
rubyforge_project:
|
14
|
-
description: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
15
|
-
autorequire: binaryparse
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 1.0.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Patrick Hurley
|
8
|
+
autorequire: binaryparse
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-09 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
17
|
+
email: phurley@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
31
24
|
files:
|
32
|
-
- examples
|
33
|
-
- lib
|
34
|
-
- test
|
35
25
|
- examples/cmasqls.rb
|
36
26
|
- examples/readme.txt
|
37
27
|
- examples/voter.rb
|
38
28
|
- lib/blocker.rb
|
39
29
|
- lib/buffered_io.rb
|
40
30
|
- test/test_blocker.rb
|
41
|
-
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://binaryparse.rubyforge.org/
|
33
|
+
licenses: []
|
42
34
|
|
35
|
+
post_install_message:
|
43
36
|
rdoc_options: []
|
44
37
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
51
52
|
requirements: []
|
52
53
|
|
53
|
-
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
59
|
+
test_files: []
|
54
60
|
|