lib/aerospike/command/read_command.rb in aerospike-2.13.0 vs lib/aerospike/command/read_command.rb in aerospike-2.14.0

- old
+ new

@@ -13,10 +13,12 @@ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. +require 'zlib' + require 'aerospike/record' require 'aerospike/command/single_command' require 'aerospike/policy/operate_policy' require 'aerospike/value/value' @@ -48,16 +50,44 @@ end def parse_result # Read header. begin - @conn.read(@data_buffer, MSG_TOTAL_HEADER_SIZE) + @conn.read(@data_buffer, 8) rescue => e Aerospike.logger.error("parse result error: #{e}") raise e end + # inflate if compressed + compressed_sz = compressed_size + if compressed_sz + begin + # waste 8 size bytes + @conn.read(@data_buffer, 8) + + # read compressed message + @conn.read(@data_buffer, compressed_sz - 8) + + # inflate the results + # TODO: reuse the current buffer + uncompressed = Zlib::inflate(@data_buffer.buf) + + @data_buffer = Buffer.new(-1, uncompressed) + rescue => e + Aerospike.logger.error("parse result error: #{e}") + raise e + end + else + begin + bytes_read = @conn.read(@data_buffer, MSG_TOTAL_HEADER_SIZE - 8, 8) + rescue => e + Aerospike.logger.error("parse result error: #{e}") + raise e + end + end + # A number of these are commented out because we just don't care enough to read # that section of the header. If we do care, uncomment and check! sz = @data_buffer.read_int64(0) header_length = @data_buffer.read(8).ord result_code = @data_buffer.read(13).ord & 0xFF @@ -66,10 +96,12 @@ field_count = @data_buffer.read_int16(26) # almost certainly 0 op_count = @data_buffer.read_int16(28) receive_size = (sz & 0xFFFFFFFFFFFF) - header_length # Read remaining message bytes. - if receive_size > 0 + if compressed_sz + @data_buffer.eat!(MSG_TOTAL_HEADER_SIZE) + elsif receive_size > 0 size_buffer_sz(receive_size) begin @conn.read(@data_buffer, receive_size) rescue => e