10
11
12
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
|
# File 'lib/mtproto/type/rpc/pong.rb', line 10
def self.parse(body)
constructor = body[0, 4].unpack1('L<')
if constructor == CONSTRUCTOR_BAD_MSG_NOTIFICATION
bad_msg = BadMsgNotification.deserialize(body)
raise "Bad message notification: #{bad_msg.error_message} (code: #{bad_msg.error_code}, msg_id: #{bad_msg.bad_msg_id}, seqno: #{bad_msg.bad_msg_seqno})"
end
if constructor == MsgContainer::CONSTRUCTOR
container = MsgContainer.deserialize(body)
pong_message = container.messages.find do |msg|
msg[:body][0, 4].unpack1('L<') == CONSTRUCTOR
end
raise 'No pong message found in container' unless pong_message
offset = 4
msg_id = pong_message[:body][offset, 8].unpack1('Q<')
offset += 8
ping_id = pong_message[:body][offset, 8].unpack1('Q<')
return { msg_id: msg_id, ping_id: ping_id }
end
raise "Unexpected constructor: 0x#{constructor.to_s(16)}" unless constructor == CONSTRUCTOR
offset = 4
msg_id = body[offset, 8].unpack1('Q<')
offset += 8
ping_id = body[offset, 8].unpack1('Q<')
{ msg_id: msg_id, ping_id: ping_id }
end
|