/usr/lib/ruby/vendor_ruby/sphinx/response.rb is in libsphinx-ruby 2.0.4-1.1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | module Sphinx
# Unpack internal Sphinx representation of ints, floats, strings, and arrays.
# needed by Sphinx search engine.
class Response
# Initialize new request.
def initialize(response)
@response = response
@position = 0
@size = response.length
end
# Gets current stream position.
def position
@position
end
# Gets response size.
def size
@size
end
# Returns <tt>true</tt> when response stream is out.
def eof?
@position >= @size
end
# Get int from stream.
def get_int
raise EOFError if @position + 4 > @size
value = @response[@position, 4].unpack('N*').first
@position += 4
return value
end
# Get 64-bit int from stream.
def get_int64
raise EOFError if @position + 8 > @size
hi, lo = @response[@position, 8].unpack('N*N*')
@position += 8
return (hi << 32) + lo
end
# Get array of <tt>count</tt> ints from stream.
def get_ints(count)
length = 4 * count
raise EOFError if @position + length > @size
values = @response[@position, length].unpack('N*' * count)
@position += length
return values
end
# Get string from stream.
def get_string
length = get_int
raise EOFError if @position + length > @size
value = length > 0 ? @response[@position, length] : ''
@position += length
return value
end
# Get float from stream.
def get_float
raise EOFError if @position + 4 > @size
uval = @response[@position, 4].unpack('N*').first;
@position += 4
return ([uval].pack('L')).unpack('f*').first
end
end
end
|