Class: ADSP::Test::Mock::Stream::Raw::NativeDecompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/adsp/test/mock/stream/raw/native_decompressor.rb

Overview

ADSP::Test::Mock::Stream::Raw::NativeDecompressor class.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ NativeDecompressor

Returns a new instance of NativeDecompressor.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/adsp/test/mock/stream/raw/native_decompressor.rb', line 16

def initialize(options)
  ADSP::Validation.validate_hash options

  destination_buffer_length = options[:destination_buffer_length]
  ADSP::Validation.validate_not_negative_integer destination_buffer_length

  destination_buffer_length = Common::DEFAULT_DESTINATION_BUFFER_LENGTH \
    if destination_buffer_length.zero?

  @destination_buffer        = "".b
  @destination_buffer_length = destination_buffer_length

  @is_closed = false
end

Instance Method Details

#closeObject



55
56
57
58
59
60
61
# File 'lib/adsp/test/mock/stream/raw/native_decompressor.rb', line 55

def close
  do_not_use_after_close

  @is_closed = true

  nil
end

#read(source) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/adsp/test/mock/stream/raw/native_decompressor.rb', line 31

def read(source)
  ADSP::Validation.validate_string source

  do_not_use_after_close

  remaining_destination_buffer_length = @destination_buffer_length - @destination_buffer.bytesize
  return [0, true] if remaining_destination_buffer_length.zero?

  data, bytes_read = Common.native_decompress source, remaining_destination_buffer_length
  needs_more_destination = bytes_read < source.bytesize
  @destination_buffer << data

  [bytes_read, needs_more_destination]
end

#read_resultObject



46
47
48
49
50
51
52
53
# File 'lib/adsp/test/mock/stream/raw/native_decompressor.rb', line 46

def read_result
  do_not_use_after_close

  result = @destination_buffer
  @destination_buffer = "".b

  result
end