Class Riddle::Client::Message
In: lib/riddle/client/message.rb
Parent: Object

This class takes care of the translation of ints, strings and arrays to the format required by the Sphinx service.

Methods

Public Class methods

[Source]

   # File lib/riddle/client/message.rb, line 6
6:       def initialize
7:         @message = ""
8:         @size_method = @message.respond_to?(:bytesize) ? :bytesize : :length
9:       end

Public Instance methods

Append raw data (only use if you know what you‘re doing)

[Source]

    # File lib/riddle/client/message.rb, line 12
12:       def append(*args)
13:         return if args.length == 0
14:         
15:         args.each { |arg| @message << arg }
16:       end

[Source]

    # File lib/riddle/client/message.rb, line 28
28:       def append_64bit_int(int)
29:         @message << [int >> 32, int & 0xFFFFFFFF].pack('NN')
30:       end

[Source]

    # File lib/riddle/client/message.rb, line 42
42:       def append_64bit_ints(*ints)
43:         ints.each { |int| append_64bit_int(int) }
44:       end

Append an array of strings - first appends the length of the array, then each item‘s length and value.

[Source]

    # File lib/riddle/client/message.rb, line 53
53:       def append_array(array)
54:         append_int(array.length)
55:         
56:         array.each { |item| append_string(item) }
57:       end

Append a float

[Source]

    # File lib/riddle/client/message.rb, line 33
33:       def append_float(float)
34:         @message << [float].pack('f').unpack('L*').pack("N")
35:       end

Append multiple floats

[Source]

    # File lib/riddle/client/message.rb, line 47
47:       def append_floats(*floats)
48:         floats.each { |float| append_float(float) }
49:       end

Append an integer

[Source]

    # File lib/riddle/client/message.rb, line 24
24:       def append_int(int)
25:         @message << [int].pack('N')
26:       end

Append multiple integers

[Source]

    # File lib/riddle/client/message.rb, line 38
38:       def append_ints(*ints)
39:         ints.each { |int| append_int(int) }
40:       end

Append a string‘s length, then the string itself

[Source]

    # File lib/riddle/client/message.rb, line 19
19:       def append_string(str)
20:         @message << [str.send(@size_method)].pack('N') + str
21:       end

Returns the entire message

[Source]

    # File lib/riddle/client/message.rb, line 60
60:       def to_s
61:         @message
62:       end

[Validate]