| 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.
# File lib/riddle/client/message.rb, line 6 6: def initialize 7: @message = "" 8: @size_method = @message.respond_to?(:bytesize) ? :bytesize : :length 9: end
Append raw data (only use if you know what you‘re doing)
# 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
# File lib/riddle/client/message.rb, line 28
28: def append_64bit_int(int)
29: @message << [int >> 32, int & 0xFFFFFFFF].pack('NN')
30: end
# 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.
# 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
# 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
# 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
# File lib/riddle/client/message.rb, line 24
24: def append_int(int)
25: @message << [int].pack('N')
26: end
Append multiple integers
# File lib/riddle/client/message.rb, line 38
38: def append_ints(*ints)
39: ints.each { |int| append_int(int) }
40: end