class Mysql::Packet
Public Class Methods
Source
# File lib/mysql/packet.rb, line 7 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
convert Numeric to LengthCodedBinary
Source
# File lib/mysql/packet.rb, line 16 def self.lcs(str) str = Charset.to_binary str.dup lcb(str.length)+str end
convert String to LengthCodedString
Public Instance Methods
Source
# File lib/mysql/packet.rb, line 71 def eof? @data[0] == ?\xfe && @data.length == 5 end
Source
# File lib/mysql/packet.rb, line 25 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
Source
# File lib/mysql/packet.rb, line 43 def lcs len = self.lcb return nil unless len @data.slice!(0, len) end
Source
# File lib/mysql/packet.rb, line 53 def string str = @data.unpack1('Z*') @data.slice!(0, str.length+1) str end