Class: MTProto::Type::DcOption

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/type/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, ip_address:, port:, flags:) ⇒ DcOption

Returns a new instance of DcOption.



96
97
98
99
100
101
# File 'lib/mtproto/type/config.rb', line 96

def initialize(id:, ip_address:, port:, flags:)
  @id = id
  @ip_address = ip_address
  @port = port
  @flags = flags
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



65
66
67
# File 'lib/mtproto/type/config.rb', line 65

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



65
66
67
# File 'lib/mtproto/type/config.rb', line 65

def id
  @id
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



65
66
67
# File 'lib/mtproto/type/config.rb', line 65

def ip_address
  @ip_address
end

#portObject (readonly)

Returns the value of attribute port.



65
66
67
# File 'lib/mtproto/type/config.rb', line 65

def port
  @port
end

Class Method Details

.deserialize_from(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mtproto/type/config.rb', line 67

def self.deserialize_from(data)
  offset = 0

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

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

  flags = data[offset, 4].unpack1('L<')
  offset += 4

  id = data[offset, 4].unpack1('L<')
  offset += 4

  ip_length = data[offset].ord
  offset += 1

  ip_address = data[offset, ip_length]
  offset += ip_length

  padding = (4 - ((ip_length + 1) % 4)) % 4
  offset += padding

  port = data[offset, 4].unpack1('L<')
  offset += 4

  [new(id: id, ip_address: ip_address, port: port, flags: flags), offset]
end

Instance Method Details

#cdn?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/mtproto/type/config.rb', line 115

def cdn?
  (@flags & 8) != 0
end

#ipv6?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/mtproto/type/config.rb', line 103

def ipv6?
  (@flags & 1) != 0
end

#media_only?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/mtproto/type/config.rb', line 107

def media_only?
  (@flags & 2) != 0
end

#static?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/mtproto/type/config.rb', line 119

def static?
  (@flags & 16) != 0
end

#tcpo_only?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/mtproto/type/config.rb', line 111

def tcpo_only?
  (@flags & 4) != 0
end