Class: RSpec::Core::Bisect::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/bisect/utilities.rb

Overview

Wraps a pipe to support sending objects between a child and parent process. Where supported, encoding is explicitly set to ensure binary data is able to pass from child to parent.

Constant Summary collapse

MARSHAL_DUMP_ENCODING =
Marshal.dump("").encoding

Instance Method Summary collapse

Constructor Details

#initializeChannel

Returns a new instance of Channel.



41
42
43
44
45
46
47
48
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/bisect/utilities.rb', line 41

def initialize
  @read_io, @write_io = IO.pipe

  if defined?(MARSHAL_DUMP_ENCODING) && IO.method_defined?(:set_encoding)
    # Ensure the pipe can send any content produced by Marshal.dump
    @write_io.set_encoding MARSHAL_DUMP_ENCODING
  end
end

Instance Method Details

#closeObject

rubocop:enable Security/MarshalLoad



62
63
64
65
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/bisect/utilities.rb', line 62

def close
  @read_io.close
  @write_io.close
end

#receiveObject

rubocop:disable Security/MarshalLoad



56
57
58
59
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/bisect/utilities.rb', line 56

def receive
  packet_size = Integer(@read_io.gets)
  Marshal.load(@read_io.read(packet_size))
end

#send(message) ⇒ Object



50
51
52
53
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/bisect/utilities.rb', line 50

def send(message)
  packet = Marshal.dump(message)
  @write_io.write("#{packet.bytesize}\n#{packet}")
end