lib/avro/ipc.rb in avro-1.10.2 vs lib/avro/ipc.rb in avro-1.11.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
@@ -61,13 +62,16 @@
META_READER = Avro::IO::DatumReader.new(META_SCHEMA)
SYSTEM_ERROR_SCHEMA = Avro::Schema.parse('["string"]')
# protocol cache
+ # rubocop:disable Style/MutableConstant
REMOTE_HASHES = {}
REMOTE_PROTOCOLS = {}
+ # rubocop:enable Style/MutableConstant
+
BUFFER_HEADER_LENGTH = 4
BUFFER_SIZE = 8192
# Raised when an error message is sent by an Avro requestor or responder.
class AvroRemoteException < Avro::AvroError; end
@@ -98,11 +102,11 @@
end
def request(message_name, request_datum)
# Writes a request message and reads a response or error message.
# build handshake and call request
- buffer_writer = StringIO.new(''.force_encoding('BINARY'))
+ buffer_writer = StringIO.new(String.new('', encoding: 'BINARY'))
buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer)
write_handshake_request(buffer_encoder)
write_call_request(message_name, request_datum, buffer_encoder)
# send the handshake and call request; block until call response
@@ -242,11 +246,11 @@
# Called by a server to deserialize a request, compute and serialize
# a response or error. Compare to 'handle()' in Thrift.
def respond(call_request, transport=nil)
buffer_decoder = Avro::IO::BinaryDecoder.new(StringIO.new(call_request))
- buffer_writer = StringIO.new(''.force_encoding('BINARY'))
+ buffer_writer = StringIO.new(String.new('', encoding: 'BINARY'))
buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer)
error = nil
response_metadata = {}
begin
@@ -392,11 +396,11 @@
end
def read_framed_message
message = []
loop do
- buffer = StringIO.new(''.force_encoding('BINARY'))
+ buffer = StringIO.new(String.new('', encoding: 'BINARY'))
buffer_length = read_buffer_length
if buffer_length == 0
return message.join
end
while buffer.tell < buffer_length
@@ -504,11 +508,11 @@
end
def read_framed_message
message = []
loop do
- buffer = ''.force_encoding('BINARY')
+ buffer = String.new('', encoding: 'BINARY')
buffer_size = read_buffer_size
return message.join if buffer_size == 0
while buffer.bytesize < buffer_size
@@ -540,10 +544,10 @@
@remote_name = "#{host}:#{port}"
@conn = Net::HTTP.start host, port
end
def transceive(message)
- writer = FramedWriter.new(StringIO.new(''.force_encoding('BINARY')))
+ writer = FramedWriter.new(StringIO.new(String.new('', encoding: 'BINARY')))
writer.write_framed_message(message)
resp = @conn.post('/', writer.to_s, {'Content-Type' => 'avro/binary'})
FramedReader.new(StringIO.new(resp.body)).read_framed_message
end
end