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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/mtproto/type/rpc/messages/updates.rb', line 17
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
case constructor
when CONSTRUCTOR_UPDATE_SHORT_SENT_MESSAGE
flags = response[offset, 4].unpack1('L<')
offset += 4
message_id = response[offset, 4].unpack1('L<')
offset += 4
pts = response[offset, 4].unpack1('L<')
offset += 4
pts_count = response[offset, 4].unpack1('L<')
offset += 4
date = response[offset, 4].unpack1('L<')
offset += 4
{
sent: true,
message_id: message_id,
date: date,
pts: pts,
pts_count: pts_count
}
when CONSTRUCTOR_UPDATE_SHORT_MESSAGE, CONSTRUCTOR_UPDATE_SHORT_CHAT_MESSAGE
flags = response[offset, 4].unpack1('L<')
offset += 4
message_id = response[offset, 4].unpack1('L<')
{
sent: true,
message_id: message_id
}
when CONSTRUCTOR_UPDATES, CONSTRUCTOR_UPDATE_SHORT
{
sent: true
}
else
raise "Unknown Updates constructor: 0x#{constructor.to_s(16)}"
end
end
|