class Okuyama::Protocol::Version1
Attributes
debug[RW]
Public Class Methods
new(options=nil)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 5 def initialize(options=nil) if options then @base64_encode_flag = options[:base64_encode_flag] end @base64_encode_flag = true if @base64_encode_flag.nil? end
Public Instance Methods
decode(text)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 31 def decode(text) return text if ! @base64_encode_flag return Base64.decode64(text) end
encode(text)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 26 def encode(text) return text if ! @base64_encode_flag return Base64.encode64(text).split.join end
parse_line_result(result, to_i_flag=nil)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 51 def parse_line_result(result, to_i_flag=nil) record = result.split(/,/) opcode = record.shift exit_code = record.shift case exit_code when 'false' case opcode when '4' return [] when '43' return [] else return nil end when 'error' raise Okuyama::ServerError, record[0] end case opcode when '0' # init_count result = record[0] result = result.to_i if to_i_flag return result when '2' # get_value ret = record[0] ret = self.decode(record[0]) return ret when '4' # get_tag_keys return record[0].split(/:/).map{|b|self.decode(b)} when '13' # incr_value if to_i_flag then result = Base64.decode64(record[0]).chomp result = result.to_i else result = self.decode(record[0]) end return result when '14' # decr_value if to_i_flag then result = Base64.decode64(record[0]).chomp result = result.to_i else result = self.decode(record[0]) end return result when '15' # get_value_version_check record[0] = self.decode(record[0]) return record when '22' # get_multi_value return self.decode(record[0]) when '23' # get_tag_values record[0] = self.decode(record[0]) record[1] = self.decode(record[1]) return record when '43' # search_value return record[0].split(/:/).map{|b|self.decode(b)} else return true end return record end
print_encode(socket, text)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 16 def print_encode(socket, text) if @base64_encode_flag then Base64.encode64(text).split.each do |line| socket.print line end else socket.print text end end
version()
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 12 def version return '1.0.0' end
Protected Instance Methods
print_group(socket, group)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 244 def print_group(socket, group) if group then self.print_encode socket, group else socket.print "(B)" end end
print_key_list(socket, key_list)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 260 def print_key_list(socket, key_list) lsize = key_list.size k = key_list[0] self.print_encode socket, k if k (lsize-1).times do |i| socket.print ':' self.print_encode socket, key_list[i+1] end end
Also aliased as: print_query_list
print_tag_list(socket, tag_list)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 252 def print_tag_list(socket, tag_list) if tag_list then self.print_key_list(socket, tag_list) else socket.print "(B)" end end
send_get_multi_value(socket, opcode, key_list)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 181 def send_get_multi_value(socket, opcode, key_list) socket.print opcode key_list.each do |key| socket.print "," self.print_encode socket, key end socket.puts end
send_get_tag_keys(socket, opcode, tag, flag)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 145 def send_get_tag_keys(socket, opcode, tag, flag) socket.print opcode socket.print "," self.print_encode socket, tag socket.print "," socket.print flag socket.puts end
send_get_tag_values(socket, opcode, tag)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 190 def send_get_tag_values(socket, opcode, tag) socket.print opcode socket.print "," self.print_encode socket, tag socket.puts end
send_get_value(socket, opcode, key)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 138 def send_get_value(socket, opcode, key) socket.print opcode socket.print "," self.print_encode socket, key socket.puts end
Also aliased as: send_get_value_version_check
send_incr_value(socket, opcode, key, val)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 167 def send_incr_value(socket, opcode, key, val) dlock = '0' socket.print opcode socket.print "," self.print_encode socket, key socket.print "," socket.print dlock socket.print "," self.print_encode socket, val socket.puts end
Also aliased as: send_decr_value
send_init_count(socket, opcode)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 116 def send_init_count(socket, opcode) socket.puts opcode end
send_remove_tag_from_key(socket, opcode, tag, key)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 197 def send_remove_tag_from_key(socket, opcode, tag, key) dlock = '0' socket.print opcode socket.print "," self.print_encode socket, tag socket.print "," self.print_encode socket, key socket.print "," socket.print dlock socket.puts end
send_remove_value(socket, opcode, key, dlock='0')
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 154 def send_remove_value(socket, opcode, key, dlock='0') socket.print opcode socket.print "," self.print_encode socket, key socket.print "," socket.print dlock socket.puts end
send_search_value(socket, opcode, query_list, condition='1', group=nil, nsize='3')
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 230 def send_search_value(socket, opcode, query_list, condition='1', group=nil, nsize='3') socket.print opcode socket.print "," self.print_query_list(socket, query_list) socket.print "," socket.print condition socket.print "," self.print_group socket, group socket.print "," socket.print nsize socket.puts end
send_set_value(socket, opcode, key, tag_list, val, version=nil)
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 119 def send_set_value(socket, opcode, key, tag_list, val, version=nil) dlock = '0' socket.print opcode socket.print "," self.print_encode socket, key socket.print "," self.print_tag_list socket, tag_list socket.print "," socket.print dlock socket.print "," self.print_encode socket, val if version then socket.print "," socket.print version end socket.puts end
Also aliased as: send_set_new_value, send_set_value_version_check
send_set_value_and_create_index(socket, opcode, key, val, tag_list=nil, group=nil, min_index_n='1', max_index_n='3')
click to toggle source
# File lib/okuyama/protocol/version1.rb, line 209 def send_set_value_and_create_index(socket, opcode, key, val, tag_list=nil, group=nil, min_index_n='1', max_index_n='3') dlock = '0' socket.print opcode socket.print "," self.print_encode socket, key socket.print "," self.print_tag_list socket, tag_list socket.print "," socket.print dlock socket.print "," self.print_encode socket, val socket.print "," self.print_group socket, group socket.print "," socket.print min_index_n socket.print "," socket.print max_index_n socket.puts end
send_set_value_version_check(socket, opcode, key, tag_list, val, version=nil)
Alias for: send_set_value