Class: MTProto::Type::RPC::Updates::State

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/type/rpc/updates/state.rb

Constant Summary collapse

CONSTRUCTOR =
0xa56c2a3e

Class Method Summary collapse

Class Method Details

.parse(response) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mtproto/type/rpc/updates/state.rb', line 13

def self.parse(response)
  offset = 0

  constructor = response[offset, 4].unpack1('L<')
  offset += 4

  if constructor == Type::GzipPacked::CONSTRUCTOR
    response = Type::GzipPacked.unpack(response)
    constructor = response[0, 4].unpack1('L<')
    offset = 4
  end

  if constructor == Type::RpcError::CONSTRUCTOR
    error = Type::RpcError.deserialize(response)
    raise MTProto::RpcError.new(error.error_code, error.error_message)
  end

  raise "Expected State constructor 0x#{CONSTRUCTOR.to_s(16)}, got 0x#{constructor.to_s(16)}" unless constructor == CONSTRUCTOR

  # updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
  pts = response[offset, 4].unpack1('L<')
  offset += 4

  qts = response[offset, 4].unpack1('L<')
  offset += 4

  date = response[offset, 4].unpack1('L<')
  offset += 4

  seq = response[offset, 4].unpack1('L<')
  offset += 4

  unread_count = response[offset, 4].unpack1('L<')

  {
    pts: pts,
    qts: qts,
    date: date,
    seq: seq,
    unread_count: unread_count
  }
end