Class: Mysql::Protocol::InitialPacket

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/protocol.rb

Overview

Initial packet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ InitialPacket

Returns a new instance of InitialPacket.



671
672
673
# File 'lib/mysql/protocol.rb', line 671

def initialize(*args)
  @protocol_version, @server_version, @thread_id, @server_capabilities, @server_charset, @server_status, @scramble_buff, @auth_plugin = args
end

Instance Attribute Details

#auth_pluginObject (readonly)

Returns the value of attribute auth_plugin.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def auth_plugin
  @auth_plugin
end

#protocol_versionObject (readonly)

Returns the value of attribute protocol_version.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def protocol_version
  @protocol_version
end

#scramble_buffObject (readonly)

Returns the value of attribute scramble_buff.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def scramble_buff
  @scramble_buff
end

#server_capabilitiesObject (readonly)

Returns the value of attribute server_capabilities.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def server_capabilities
  @server_capabilities
end

#server_charsetObject (readonly)

Returns the value of attribute server_charset.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def server_charset
  @server_charset
end

#server_statusObject (readonly)

Returns the value of attribute server_status.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def server_status
  @server_status
end

#server_versionObject (readonly)

Returns the value of attribute server_version.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def server_version
  @server_version
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



669
670
671
# File 'lib/mysql/protocol.rb', line 669

def thread_id
  @thread_id
end

Class Method Details

.parse(pkt) ⇒ Object

Raises:



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/mysql/protocol.rb', line 644

def self.parse(pkt)
  protocol_version = pkt.utiny
  server_version = pkt.string
  thread_id = pkt.ulong
  scramble_buff = pkt.read(8)
  f0 = pkt.utiny
  server_capabilities = pkt.ushort
  server_charset = pkt.utiny
  server_status = pkt.ushort
  server_capabilities2 = pkt.ushort
  scramble_length = pkt.utiny
  _f1 = pkt.read(10)
  rest_scramble_buff = pkt.string
  auth_plugin = pkt.string

  server_capabilities |= server_capabilities2 << 16
  scramble_buff.concat rest_scramble_buff

  raise ProtocolError, "unsupported version: #{protocol_version}" unless protocol_version == VERSION
  raise ProtocolError, "invalid packet: f0=#{f0}" unless f0 == 0
  raise ProtocolError, "invalid packet: scramble_length(#{scramble_length}) != length of scramble(#{scramble_buff.size + 1})" unless scramble_length == scramble_buff.size + 1

  self.new protocol_version, server_version, thread_id, server_capabilities, server_charset, server_status, scramble_buff, auth_plugin
end