dmap 0.1.5 → 0.1.6
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/Rakefile +1 -1
- data/lib/dmap.rb +15 -9
- metadata +1 -1
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "dmap"
|
8
|
-
gem.version = "0.1.
|
8
|
+
gem.version = "0.1.6"
|
9
9
|
gem.summary = %Q{Parses Apple's DMAP strings (4-byte serialization method)}
|
10
10
|
gem.description = %Q{Apple uses a system of serialization (I think its called dmap…) where a 4-byte string tells of the information following, both its type and what it represents. Its used in the DAAP (Protocol), QuickTime mov structure and doubtless many other places.}
|
11
11
|
gem.email = "jphastings@gmail.com"
|
data/lib/dmap.rb
CHANGED
@@ -106,9 +106,10 @@ module DMAP
|
|
106
106
|
# TODO
|
107
107
|
def parse_version(content)
|
108
108
|
begin
|
109
|
-
|
109
|
+
# FIXME: Are version numbers x.y ?
|
110
|
+
@real_class = Version.new(@io.read(@io.read(4).unpack("N")[0]).unpack("nn").join("."))
|
110
111
|
rescue NoMethodError
|
111
|
-
@real_class = Version.new(0)
|
112
|
+
@real_class = Version.new(content || "1.0")
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -230,7 +231,7 @@ module DMAP
|
|
230
231
|
# current value.
|
231
232
|
def box_size=(wanted_box_size)
|
232
233
|
# Find the smallest number of bytes needed to express this number
|
233
|
-
@box_size = [wanted_box_size || 0,(Math.log(@value) / 2.07944154167984).ceil].max rescue 1 # For when value = 0
|
234
|
+
@box_size = [wanted_box_size || 0,(Math.log((Math.log(@value) / 2.07944154167984).ceil)/0.693147180559945).ceil].max rescue 1 # For when value = 0
|
234
235
|
end
|
235
236
|
|
236
237
|
def to_dmap
|
@@ -243,8 +244,7 @@ module DMAP
|
|
243
244
|
end
|
244
245
|
|
245
246
|
def self.pack_code(length,signed)
|
246
|
-
out = {1=>"C",2=>"
|
247
|
-
out.downcase if signed
|
247
|
+
out = {1=>"C",-1=>"c",2=>"n",4=>"N",8=>"Q",-8=>"q"}[length * (signed ? -1 : 1)] # FIXME: pack codes for all signed cases
|
248
248
|
return out
|
249
249
|
end
|
250
250
|
|
@@ -257,13 +257,19 @@ module DMAP
|
|
257
257
|
|
258
258
|
# A class to store version numbers
|
259
259
|
class Version
|
260
|
-
|
261
|
-
|
262
|
-
|
260
|
+
def initialize(version = "1.0")
|
261
|
+
@major,@minor = (version.to_s<<".0").split(".").collect{|n| n.to_i }
|
262
|
+
if @major > 63 or @minor > 63
|
263
|
+
raise RangeError "Neither major nor minor version numbers can be above 63. Surely that's enough?"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def to_dmap
|
268
|
+
"\000\000\000\004"<<[@major,@minor].pack("nn")
|
263
269
|
end
|
264
270
|
|
265
271
|
def inspect
|
266
|
-
"
|
272
|
+
"v#{@major}.#{@minor}"
|
267
273
|
end
|
268
274
|
end
|
269
275
|
|