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
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
|