Class: Sphinx::Response
- Inherits:
-
Object
- Object
- Sphinx::Response
- Defined in:
- lib/sphinx/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
true
when 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
count
ints 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.
6 7 8 9 10 |
# File 'lib/sphinx/sphinx/response.rb', line 6 def initialize(response) @response = response @position = 0 @size = response.length end |
Instance Method Details
#eof? ⇒ Boolean
Returns true
when response stream is out.
23 24 25 |
# File 'lib/sphinx/sphinx/response.rb', line 23 def eof? @position >= @size end |
#get_float ⇒ Object
Get float from stream.
62 63 64 65 66 67 |
# File 'lib/sphinx/sphinx/response.rb', line 62 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.
28 29 30 31 32 33 |
# File 'lib/sphinx/sphinx/response.rb', line 28 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.
36 37 38 39 40 41 |
# File 'lib/sphinx/sphinx/response.rb', line 36 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.
44 45 46 47 48 49 50 |
# File 'lib/sphinx/sphinx/response.rb', line 44 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.
53 54 55 56 57 58 59 |
# File 'lib/sphinx/sphinx/response.rb', line 53 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.
13 14 15 |
# File 'lib/sphinx/sphinx/response.rb', line 13 def position @position end |
#size ⇒ Object
Gets response size.
18 19 20 |
# File 'lib/sphinx/sphinx/response.rb', line 18 def size @size end |