Class: Object

Inherits:
BasicObject
Defined in:
lib/airvideo.rb

Overview

Add the #to_avmap method for ease of use in the Client

Instance Method Summary collapse

Instance Method Details

#to_avmap(reset_counter = true) ⇒ Object

Will convert an object into an AirVideo map, if the object and it’s contents are supported



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/airvideo.rb', line 410

def to_avmap(reset_counter = true)
  @@to_avmap_counter = 0 if reset_counter
  
  case self
  when Array
    letter = (self.is_a? AirVideo::AvMap::BitrateList) ? "e" : "a"
    self.push nil if self.length == 0 # Must have at least one entry in the hash, I think
    "#{letter}#{[(@@to_avmap_counter += 1) - 1].pack("N")}#{[self.length].pack("N")}"+self.collect do |item|
      item.to_avmap(false)
    end.join
  when AirVideo::AvMap::Hash
    version = case self.name
    when "air.video.ConversionRequest"
      221
    else
      1
    end
    "o#{[(@@to_avmap_counter += 1) - 1].pack("N")}#{[self.name.length].pack("N")}#{self.name}#{[version].pack("N")}#{[self.length].pack("N")}"+self.to_a.collect do |key,val|
      "#{[key.length].pack("N")}#{key}"+val.to_avmap(false)
    end.join
  when AirVideo::AvMap::BinaryData
    "x#{[(@@to_avmap_counter += 1) - 1].pack("N")}#{[self.length].pack("N")}#{self.data}"
  when String
    "s#{[(@@to_avmap_counter += 1) - 1].pack("N")}#{[self.length].pack("N")}#{self}"
  when NilClass
    "n"
  when Integer
    "i#{[self].pack('N')}"
  when Float # unsure of this is what this is meant to be
    "f#{[self].pack('G')}"
  else
    raise NotImplementedError, "Can't turn a #{self.class} into an avmap"
  end
end