Module: MTProto::Type::SentCodeType

Defined in:
lib/mtproto/type/sent_code.rb

Class Method Summary collapse

Class Method Details

.deserialize_from(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/mtproto/type/sent_code.rb', line 67

def self.deserialize_from(data)
  constructor = data[0, 4].unpack1('L<')
  offset = 4

  case constructor
  when 0x3dbb5986 # auth.sentCodeTypeApp
    length = data[offset, 4].unpack1('L<')
    offset += 4
    [{ _: :sent_code_type_app, length: length }, offset]
  when 0xc000bba2 # auth.sentCodeTypeSms
    length = data[offset, 4].unpack1('L<')
    offset += 4
    [{ _: :sent_code_type_sms, length: length }, offset]
  when 0x5353e5a7 # auth.sentCodeTypeCall
    length = data[offset, 4].unpack1('L<')
    offset += 4
    [{ _: :sent_code_type_call, length: length }, offset]
  when 0xab03c6d9 # auth.sentCodeTypeFlashCall
    pattern_length = data[offset].ord
    offset += 1
    pattern = data[offset, pattern_length]
    offset += pattern_length
    padding = (4 - ((pattern_length + 1) % 4)) % 4
    offset += padding
    [{ _: :sent_code_type_flash_call, pattern: pattern }, offset]
  when 0x82006484 # auth.sentCodeTypeMissedCall
    prefix_length = data[offset].ord
    offset += 1
    prefix = data[offset, prefix_length]
    offset += prefix_length
    padding = (4 - ((prefix_length + 1) % 4)) % 4
    offset += padding
    length = data[offset, 4].unpack1('L<')
    offset += 4
    [{ _: :sent_code_type_missed_call, prefix: prefix, length: length }, offset]
  else
    raise "Unknown SentCodeType constructor: 0x#{constructor.to_s(16)}"
  end
end