Class: MTP::Data

Inherits:
Container show all
Defined in:
lib/mtp/container.rb

Instance Attribute Summary collapse

Attributes inherited from Container

#code, #length, #length_read, #payload, #transaction_id

Instance Method Summary collapse

Methods inherited from Container

#pack, #pack_payload, parse, #to_s

Constructor Details

#initialize(payload = nil, size = nil) ⇒ Data

Returns a new instance of Data.



85
86
87
88
# File 'lib/mtp/container.rb', line 85

def initialize(payload = nil, size = nil)
  @payload = payload
  @size = size
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



83
84
85
# File 'lib/mtp/container.rb', line 83

def size
  @size
end

Instance Method Details

#pack_headerObject



94
95
96
97
98
99
100
101
# File 'lib/mtp/container.rb', line 94

def pack_header
  if size.nil?
    blob = [ type, code, transaction_id ].pack_without_mtp("SSI") + pack_payload
    return [ blob.length + 4, type, code, transaction_id ].pack_without_mtp("ISSI") 
  else
    blob = [ 12  + size, type, code, transaction_id ].pack_without_mtp("ISSI")
  end
end

#typeObject



90
91
92
# File 'lib/mtp/container.rb', line 90

def type 
  2
end