lib/avro/ipc.rb in avro-1.7.7 vs lib/avro/ipc.rb in avro-1.8.0

- old
+ new

@@ -98,11 +98,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('', 'w+') + buffer_writer = StringIO.new(''.force_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 +242,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('', 'w+') + buffer_writer = StringIO.new(''.force_encoding('BINARY')) buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer) error = nil response_metadata = {} begin @@ -292,10 +292,11 @@ writers_schema = local_message.errors || SYSTEM_ERROR_SCHEMA write_error(writers_schema, error, buffer_encoder) end rescue Avro::AvroError => e error = AvroRemoteException.new(e.to_s) + # TODO does the stuff written here ever get used? buffer_encoder = Avro::IO::BinaryEncoder.new(StringIO.new) META_WRITER.write(response_metadata, buffer_encoder) buffer_encoder.write_boolean(true) self.write_error(SYSTEM_ERROR_SCHEMA, error, buffer_encoder) end @@ -391,11 +392,11 @@ end def read_framed_message message = [] loop do - buffer = StringIO.new + buffer = StringIO.new(''.force_encoding('BINARY')) buffer_length = read_buffer_length if buffer_length == 0 return message.join end while buffer.tell < buffer_length @@ -408,11 +409,11 @@ message << buffer.string end end def write_framed_message(message) - message_length = message.size + message_length = message.bytesize total_bytes_sent = 0 while message_length - total_bytes_sent > 0 if message_length - total_bytes_sent > BUFFER_SIZE buffer_length = BUFFER_SIZE else @@ -424,11 +425,11 @@ # A message is always terminated by a zero-length buffer. write_buffer_length(0) end def write_buffer(chunk) - buffer_length = chunk.size + buffer_length = chunk.bytesize write_buffer_length(buffer_length) total_bytes_sent = 0 while total_bytes_sent < buffer_length bytes_sent = self.sock.write(chunk[total_bytes_sent..-1]) if bytes_sent == 0 @@ -465,11 +466,11 @@ def initialize(writer) @writer = writer end def write_framed_message(message) - message_size = message.size + message_size = message.bytesize total_bytes_sent = 0 while message_size - total_bytes_sent > 0 if message_size - total_bytes_sent > BUFFER_SIZE buffer_size = BUFFER_SIZE else @@ -483,11 +484,11 @@ def to_s; writer.string; end private def write_buffer(chunk) - buffer_size = chunk.size + buffer_size = chunk.bytesize write_buffer_size(buffer_size) writer << chunk end def write_buffer_size(n) @@ -503,17 +504,17 @@ end def read_framed_message message = [] loop do - buffer = "" + buffer = ''.force_encoding('BINARY') buffer_size = read_buffer_size return message.join if buffer_size == 0 - while buffer.size < buffer_size - chunk = reader.read(buffer_size - buffer.size) + while buffer.bytesize < buffer_size + chunk = reader.read(buffer_size - buffer.bytesize) chunk_error?(chunk) buffer << chunk end message << buffer end @@ -539,10 +540,10 @@ @remote_name = "#{host}:#{port}" @conn = Net::HTTP.start host, port end def transceive(message) - writer = FramedWriter.new(StringIO.new) + writer = FramedWriter.new(StringIO.new(''.force_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