Class: MTProto::TL::ResPq

Inherits:
Object
  • Object
show all
Extended by:
Binary
Defined in:
lib/mtproto/tl/objects/res_pq.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Binary

b_u32, b_u64, u32_b, u64_b

Instance Attribute Details

#fingerprintsObject (readonly)

Returns the value of attribute fingerprints.



8
9
10
# File 'lib/mtproto/tl/objects/res_pq.rb', line 8

def fingerprints
  @fingerprints
end

#nonceObject (readonly)

Returns the value of attribute nonce.



8
9
10
# File 'lib/mtproto/tl/objects/res_pq.rb', line 8

def nonce
  @nonce
end

#pqObject (readonly)

Returns the value of attribute pq.



8
9
10
# File 'lib/mtproto/tl/objects/res_pq.rb', line 8

def pq
  @pq
end

#server_nonceObject (readonly)

Returns the value of attribute server_nonce.



8
9
10
# File 'lib/mtproto/tl/objects/res_pq.rb', line 8

def server_nonce
  @server_nonce
end

Class Method Details

.deserialize(message) ⇒ Object



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mtproto/tl/objects/res_pq.rb', line 10

def self.deserialize(message)
  data = message.body
  constructor = b_u32(data[0, 4])
  raise "Unexpected constructor: 0x#{constructor.to_s(16)}" unless constructor == Constructors::RES_PQ

  offset = 4

  nonce = data[offset, 16].pack('C*')
  offset += 16

  server_nonce = data[offset, 16].pack('C*')
  offset += 16

  pq_length_byte = data[offset]
  offset += 1

  pq_length = if pq_length_byte == 254
                b_u32(data[offset, 3] + [0]) & 0xffffff
                offset += 3
              else
                pq_length_byte
              end

  pq = data[offset, pq_length].pack('C*')
  offset += pq_length
  offset += padding_length(pq_length + 1)

  vector_constructor = b_u32(data[offset, 4])
  offset += 4
  raise 'Expected vector constructor' unless vector_constructor == Constructors::VECTOR

  fingerprints_count = b_u32(data[offset, 4])
  offset += 4

  fingerprints = []
  fingerprints_count.times do
    fingerprints << b_u64(data[offset, 8])
    offset += 8
  end

  new(
    nonce: nonce,
    server_nonce: server_nonce,
    pq: pq,
    fingerprints: fingerprints
  )
end