Class: Sphinx::Response

Inherits:
Object
  • Object
show all
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

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.

Returns:

  • (Boolean)


23
24
25
# File 'lib/sphinx/sphinx/response.rb', line 23

def eof?
  @position >= @size
end

#get_floatObject

Get float from stream.

Raises:

  • (EOFError)


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_intObject

Get int from stream.

Raises:

  • (EOFError)


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_int64Object

Get 64-bit int from stream.

Raises:

  • (EOFError)


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.

Raises:

  • (EOFError)


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_stringObject

Get string from stream.

Raises:

  • (EOFError)


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

#positionObject

Gets current stream position.



13
14
15
# File 'lib/sphinx/sphinx/response.rb', line 13

def position
  @position
end

#sizeObject

Gets response size.



18
19
20
# File 'lib/sphinx/sphinx/response.rb', line 18

def size
  @size
end