lib/aerospike/command/batch_command.rb in aerospike-0.1.6 vs lib/aerospike/command/batch_command.rb in aerospike-1.0.0

- old
+ new

@@ -22,11 +22,11 @@ module Aerospike private - class BatchCommand < Command + class BatchCommand < Command #:nodoc: def initialize(node) super(node) @valid = true @@ -59,11 +59,12 @@ digest = nil namespace = nil set_name = nil user_key = nil - for i in 0...field_count + i = 0 + while i < field_count read_bytes(4) fieldlen = @data_buffer.read_int32(0) read_bytes(fieldlen) @@ -78,29 +79,29 @@ when Aerospike::FieldType::TABLE set_name = @data_buffer.read(1, size).force_encoding('utf-8') when Aerospike::FieldType::KEY user_key = Aerospike::bytes_to_key_value(@data_buffer.read(1).ord, @data_buffer, 2, size-1) end + + i = i.succ end Aerospike::Key.new(namespace, set_name, user_key, digest) end # Parses the given byte buffer and populate the result object. # Returns the number of bytes that were parsed from the given buffer. def parse_record(key, op_count, generation, expiration) - bins = nil - duplicates = nil - - for i in 0...op_count + bins = op_count > 0 ? {} : nil + i = 0 + while i < op_count raise Aerospike::Exceptions::QueryTerminated.new unless valid? read_bytes(8) op_size = @data_buffer.read_int32(0).ord particle_type = @data_buffer.read(5).ord - version = @data_buffer.read(6).ord name_size = @data_buffer.read(7).ord read_bytes(name_size) name = @data_buffer.read(0, name_size).force_encoding('utf-8') @@ -112,47 +113,16 @@ # the bins are requested. We have to filter it on the client side. # TODO: Filter batch bins on server! # if !@bin_names || @bin_names.any?{|bn| bn == name} # if !@bin_names || (@bin_names == []) || @bin_names.any?{|bn| bn == name} if !@bin_names || (@bin_names.empty?) || @bin_names.any?{|bn| bn == name} - - vmap = nil - - if version > 0 || duplicates - unless duplicates - duplicates = [] - duplicates << bins - bins = nil - - for j in 0...version - duplicates << nil - end - else - for j in duplicates.length..version - duplicates << nil - end - end - - vmap = duplicates[version] - unless vmap - vmap = {} - duplicates[version] = vmap - end - else - unless bins - bins = {} - end - vmap = bins - end - vmap[name] = value + bins[name] = value end + + i = i.succ end - # Remove nil duplicates just in case there were holes in the version number space. - # TODO: this seems to be a bad idea; O(n) algorithm after another O(n) algorithm - duplicates.compact! if duplicates - - Record.new(@node, key, bins, duplicates, generation, expiration) + Record.new(@node, key, bins, generation, expiration) end def read_bytes(length) if length > @data_buffer.length # Corrupted data streams can result in a huge length.