class ADSP::Stream::Raw::Abstract

ADSP::Stream::Raw::Abstract class.

Public Class Methods

new(native_stream) click to toggle source

Initializes raw stream using native_stream.

# File lib/adsp/stream/raw/abstract.rb, line 13
def initialize(native_stream)
  @native_stream = native_stream
  @is_closed     = false
end

Public Instance Methods

close(&writer) click to toggle source

Writes next result using writer proc and closes raw stream.

# File lib/adsp/stream/raw/abstract.rb, line 53
def close(&writer)
  write_result(&writer)

  @native_stream.close
  @is_closed = true

  nil
end
closed?() click to toggle source

Returns whether raw stream is closed.

# File lib/adsp/stream/raw/abstract.rb, line 63
def closed?
  @is_closed
end
flush(&writer) click to toggle source

Flushes raw stream and writes next result using writer proc.

# File lib/adsp/stream/raw/abstract.rb, line 21
def flush(&writer)
  do_not_use_after_close

  Validation.validate_proc writer

  write_result(&writer)

  nil
end

Protected Instance Methods

do_not_use_after_close() click to toggle source

Raises error when raw stream is closed.

# File lib/adsp/stream/raw/abstract.rb, line 48
          def do_not_use_after_close
  raise UsedAfterCloseError, "used after close" if closed?
end
more_destination(&writer) click to toggle source

Writes next result using writer proc and frees destination buffer.

# File lib/adsp/stream/raw/abstract.rb, line 32
          def more_destination(&writer)
  result_bytesize = write_result(&writer)
  raise NotEnoughDestinationError, "not enough destination" if result_bytesize.zero?
end
write_result() { |result| ... } click to toggle source

Writes next result using block.

# File lib/adsp/stream/raw/abstract.rb, line 38
          def write_result(&_writer)
  result = @native_stream.read_result
  yield result

  result.bytesize
end