Class: MTProto::TL::RawResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/tl/objects/raw_response.rb

Overview

Pseudo TL object used as response_class when we want rpc.call to hand back the raw bytes of whatever the server returns, without imposing a specific TL schema. Useful when a method can legally return one of several constructor variants (e.g. messages.sendMessage may return updateShortSentMessage, updates, or updatesCombined depending on context) and we just want to capture the wire bytes for fixtures.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_bytes:, constructor_id:, constructor_name:) ⇒ RawResponse

Returns a new instance of RawResponse.



16
17
18
19
20
# File 'lib/mtproto/tl/objects/raw_response.rb', line 16

def initialize(raw_bytes:, constructor_id:, constructor_name:)
  @raw_bytes = raw_bytes
  @constructor_id = constructor_id
  @constructor_name = constructor_name
end

Instance Attribute Details

#constructor_idObject (readonly)

Returns the value of attribute constructor_id.



14
15
16
# File 'lib/mtproto/tl/objects/raw_response.rb', line 14

def constructor_id
  @constructor_id
end

#constructor_nameObject (readonly)

Returns the value of attribute constructor_name.



14
15
16
# File 'lib/mtproto/tl/objects/raw_response.rb', line 14

def constructor_name
  @constructor_name
end

#raw_bytesObject (readonly)

Returns the value of attribute raw_bytes.



14
15
16
# File 'lib/mtproto/tl/objects/raw_response.rb', line 14

def raw_bytes
  @raw_bytes
end

Class Method Details

.deserialize(bytes) ⇒ Object



22
23
24
25
26
# File 'lib/mtproto/tl/objects/raw_response.rb', line 22

def self.deserialize(bytes)
  constructor = bytes[0, 4].unpack1('L<')
  name = ConstructorNames::NAMES[constructor] || "0x#{constructor.to_s(16)}"
  new(raw_bytes: bytes, constructor_id: constructor, constructor_name: name)
end