Class: EM::Tycoon::Protocol::Binary::GetMessage
- Defined in:
- lib/em/tycoon/protocol/binary/get_message.rb
Constant Summary collapse
- HEADER_BYTES_PER_RECORD =
( 2 + # (uint16_t): (iteration): the index of the target database. 4 + # (uint32_t): (iteration): the size of the key. 4 + # (uint32_t): (iteration): the size of the value. 8 # (int64_t): (iteration): the expiration time. )
- PARSE_PHASES =
(int64_t): (iteration): the expiration time.
EM::Tycoon::Protocol::Message::PARSE_PHASES+[:header,:keys_and_values]
- HEADER_UNPACK_FORMAT =
"nNNH16"
- NO_EXPIRATION_TIME_RESPONSE =
Best I can figure it, Mikio is passing in 63 bits of 1s in set_bulk messages inside his own utilities to force KT to detect an overflow of the real max XT time (which is 40 bits of 1s) and then returns that real max XT time in the get_bulk reply… I think
0x000000ffffffffff
Constants inherited from Message
Message::DEFAULT_OPTS, Message::FLAGS, Message::KV_PACK_FMT, Message::MAGIC, Message::MSG_TYPES, Message::NO_EXPIRATION_TIME, Message::NO_XT_HEX
Instance Attribute Summary
Attributes inherited from Message
#buffer, #bytes_expected, #data, #item_count, #magic, #parse_phase, #parsed, #type
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = {}, opts = {}) ⇒ GetMessage
constructor
A new instance of GetMessage.
- #keysize ⇒ Object
- #parse_chunk(data) ⇒ Object
- #valuesize ⇒ Object
Methods inherited from Message
#[], check_msg_type, message_for, msg_type_for, #parse, #parsed?
Constructor Details
#initialize(data = {}, opts = {}) ⇒ GetMessage
Returns a new instance of GetMessage.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/em/tycoon/protocol/binary/get_message.rb', line 18 def initialize(data={},opts={}) super(:get,data) @key_fmt = String.new @value_fmt = String.new @xts = Array.new @db_idxs = Array.new @keys_parsed = 0 @keysize = 0 @valuesize = 0 @dbidx = 0 @xt = 0 end |
Class Method Details
.generate(data, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/em/tycoon/protocol/binary/get_message.rb', line 31 def self.generate(data,opts={}) data = [data.to_s] unless data.kind_of?(Array) msg_array = [MAGIC[:get], 0, data.length] data.each {|k| msg_array += [0, k.bytesize, k] } return msg_array.pack("CNN#{'nNa*'*data.length}") end |
Instance Method Details
#keysize ⇒ Object
79 80 81 |
# File 'lib/em/tycoon/protocol/binary/get_message.rb', line 79 def keysize @key_sizes.inject {|sum,x| sum += x} end |
#parse_chunk(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/em/tycoon/protocol/binary/get_message.rb', line 40 def parse_chunk(data) return 0 unless data && data.bytesize > 0 msg_hsh = {} bytes_parsed = 0 case parse_phase when :magic,:item_count @magic, @item_count = data.unpack("CN") @parse_phase = :header @bytes_expected += HEADER_BYTES_PER_RECORD bytes_parsed = 5 @data = Hash.new when :header @dbidx,@keysize,@valuesize,@xt = data.unpack(HEADER_UNPACK_FORMAT) @xt = @xt.to_i(16) @bytes_expected += (@keysize+@valuesize) bytes_parsed = HEADER_BYTES_PER_RECORD @parse_phase = :keys_and_values when :keys_and_values k,v = data.unpack("a#{@keysize}a#{@valuesize}") @data[k] = { :value => v, :dbidx => @dbidx, :xt => (@xt == NO_EXPIRATION_TIME_RESPONSE) ? nil : Time.at(@xt) } bytes_parsed = (@keysize+@valuesize) @keysize = 0 @valuesize = 0 @dbidx = 0 @xt = nil if (@keys_parsed+=1) == item_count @parse_phase = :done else @parse_phase = :header @bytes_expected += HEADER_BYTES_PER_RECORD end end return bytes_parsed end |
#valuesize ⇒ Object
83 84 85 |
# File 'lib/em/tycoon/protocol/binary/get_message.rb', line 83 def valuesize @value_sizes.inject {|sum,x| sum += x} end |