binaryparse 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/blocker.rb +43 -0
- metadata +2 -2
data/lib/blocker.rb
CHANGED
@@ -234,6 +234,10 @@ module BinaryBlocker
|
|
234
234
|
@lookup
|
235
235
|
end
|
236
236
|
|
237
|
+
def keys
|
238
|
+
@lookup.keys.sort_by { |k| @lookup[k] }
|
239
|
+
end
|
240
|
+
|
237
241
|
def lookup=(l)
|
238
242
|
@lookup=l
|
239
243
|
end
|
@@ -553,6 +557,44 @@ module BinaryBlocker
|
|
553
557
|
end
|
554
558
|
BinaryBlocker.register_klass(:date, PackedDateEncoder)
|
555
559
|
|
560
|
+
class PackedDateEncoderMMDDYYYY < PackedNumberEncoder
|
561
|
+
def initialize_options(*opts)
|
562
|
+
super
|
563
|
+
@opts[:length] = 8
|
564
|
+
end
|
565
|
+
|
566
|
+
def internal_block(val)
|
567
|
+
if val
|
568
|
+
super val.month * 1000000 + val.mday * 10000 + val.year
|
569
|
+
else
|
570
|
+
super 0
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
def internal_deblock(io)
|
575
|
+
buffer = io.read(@bytes)
|
576
|
+
result = buffer.unpack(@format)
|
577
|
+
month, day, year = result.first.unpack("A2A2A4").map { |v| v.to_i }
|
578
|
+
if month.zero?
|
579
|
+
nil
|
580
|
+
else
|
581
|
+
Date.civil(year, month, day)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
def valid?
|
586
|
+
case @value
|
587
|
+
when Date : true
|
588
|
+
when Time : true
|
589
|
+
when nil : true
|
590
|
+
else
|
591
|
+
false
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
end
|
596
|
+
BinaryBlocker.register_klass(:date_MMDDYYYY, PackedDateEncoderMMDDYYYY)
|
597
|
+
|
556
598
|
class PackedDateTimeEncoder < PackedNumberEncoder
|
557
599
|
def initialize_options(*opts)
|
558
600
|
super
|
@@ -630,6 +672,7 @@ module BinaryBlocker
|
|
630
672
|
end
|
631
673
|
end
|
632
674
|
BinaryBlocker.register_klass(:time_hhmm, PackedDateTimeHHMMEncoder)
|
675
|
+
BinaryBlocker.register_klass(:date_hhmm, PackedDateTimeHHMMEncoder)
|
633
676
|
|
634
677
|
|
635
678
|
class OneOfEncoder < Encoder
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: binaryparse
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.2.4
|
7
|
+
date: 2006-12-04 00:00:00 -05:00
|
8
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
9
|
require_paths:
|
10
10
|
- lib
|