class Mysql::Packet
Public Class Methods
lcb(num)
click to toggle source
convert Numeric to LengthCodedBinary
# File lib/mysql/packet.rb, line 5 def self.lcb(num) return "\xfb" if num.nil? return [num].pack("C") if num < 251 return [252, num].pack("Cv") if num < 65536 return [253, num&0xffff, num>>16].pack("CvC") if num < 16777216 return [254, num&0xffffffff, num>>32].pack("CVV") end
lcs(str)
click to toggle source
convert String to LengthCodedString
# File lib/mysql/packet.rb, line 14 def self.lcs(str) str = Charset.to_binary str.dup lcb(str.length)+str end
new(data)
click to toggle source
# File lib/mysql/packet.rb, line 19 def initialize(data) @data = data end
Public Instance Methods
eof?()
click to toggle source
# File lib/mysql/packet.rb, line 69 def eof? @data[0] == ?\xfe && @data.length == 5 end
lcb()
click to toggle source
# File lib/mysql/packet.rb, line 23 def lcb return nil if @data.empty? case v = utiny when 0xfb return nil when 0xfc return ushort when 0xfd c, v = utiny, ushort return (v << 8)+c when 0xfe v1, v2 = ulong, ulong return (v2 << 32)+v1 else return v end end
lcs()
click to toggle source
# File lib/mysql/packet.rb, line 41 def lcs len = self.lcb return nil unless len @data.slice!(0, len) end
read(len)
click to toggle source
# File lib/mysql/packet.rb, line 47 def read(len) @data.slice!(0, len) end
string()
click to toggle source
# File lib/mysql/packet.rb, line 51 def string str = @data.unpack('Z*').first @data.slice!(0, str.length+1) str end
to_s()
click to toggle source
# File lib/mysql/packet.rb, line 73 def to_s @data end
ulong()
click to toggle source
# File lib/mysql/packet.rb, line 65 def ulong @data.slice!(0, 4).unpack('V').first end
ushort()
click to toggle source
# File lib/mysql/packet.rb, line 61 def ushort @data.slice!(0, 2).unpack('v').first end
utiny()
click to toggle source
# File lib/mysql/packet.rb, line 57 def utiny @data.slice!(0, 1).unpack('C').first end