Class: Sphinx::Response
- Inherits:
-
Object
- Object
- Sphinx::Response
- Defined in:
- lib/sphinx/response.rb
Overview
Unpack internal Sphinx representation of ints, floats, strings, and arrays. needed by Sphinx search engine.
Instance Method Summary collapse
-
#eof? ⇒ Boolean
Returns
truewhen response stream is out. -
#get_float ⇒ Object
Get float from stream.
-
#get_int ⇒ Object
Get int from stream.
-
#get_int64 ⇒ Object
Get 64-bit int from stream.
-
#get_ints(count) ⇒ Object
Get array of
countints from stream. -
#get_string ⇒ Object
Get string from stream.
-
#initialize(response) ⇒ Response
constructor
Initialize new request.
-
#position ⇒ Object
Gets current stream position.
-
#size ⇒ Object
Gets response size.
Constructor Details
#initialize(response) ⇒ Response
Initialize new request.
8 9 10 11 12 |
# File 'lib/sphinx/response.rb', line 8 def initialize(response) @response = response @position = 0 @size = response.length end |
Instance Method Details
#eof? ⇒ Boolean
Returns true when response stream is out.
25 26 27 |
# File 'lib/sphinx/response.rb', line 25 def eof? @position >= @size end |
#get_float ⇒ Object
Get float from stream.
64 65 66 67 68 69 |
# File 'lib/sphinx/response.rb', line 64 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 |
#get_int ⇒ Object
Get int from stream.
30 31 32 33 34 35 |
# File 'lib/sphinx/response.rb', line 30 def get_int raise EOFError if @position + 4 > @size value = @response[@position, 4].unpack('N*').first @position += 4 return value end |
#get_int64 ⇒ Object
Get 64-bit int from stream.
38 39 40 41 42 43 |
# File 'lib/sphinx/response.rb', line 38 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_ints(count) ⇒ Object
Get array of count ints from stream.
46 47 48 49 50 51 52 |
# File 'lib/sphinx/response.rb', line 46 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 ⇒ Object
Get string from stream.
55 56 57 58 59 60 61 |
# File 'lib/sphinx/response.rb', line 55 def get_string length = get_int raise EOFError if @position + length > @size value = length > 0 ? @response[@position, length] : '' @position += length return value end |
#position ⇒ Object
Gets current stream position.
15 16 17 |
# File 'lib/sphinx/response.rb', line 15 def position @position end |
#size ⇒ Object
Gets response size.
20 21 22 |
# File 'lib/sphinx/response.rb', line 20 def size @size end |