Module: ADSP::Test::Mock::Common

Defined in:
lib/adsp/test/mock/common.rb

Overview

ADSP::Test::Mock::Common module.

Constant Summary collapse

DEFAULT_DESTINATION_BUFFER_LENGTH =

256 KB

1 << 18

Class Method Summary collapse

Class Method Details

.native_compress(source, destination_buffer_length) ⇒ Object

Flipping bytes and packing them as 16-bit values in network byte order. This method will make compressed data bytesize more than original bytesize. It will help to improve testing coverage.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/adsp/test/mock/common.rb', line 18

def self.native_compress(source, destination_buffer_length)
  source_length             = source.bytesize
  destination_buffer_length = DEFAULT_DESTINATION_BUFFER_LENGTH if destination_buffer_length.zero?

  bytes_read =
    if destination_buffer_length.nil?
      source_length
    else
      [source_length, destination_buffer_length / 2].min
    end

  result = source
    .byteslice(0, bytes_read)
    .unpack("C*")
    .map { |byte| byte ^ 0xFF }
    .pack "n*"
  [result, bytes_read]
end

.native_decompress(source, destination_buffer_length) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/adsp/test/mock/common.rb', line 37

def self.native_decompress(source, destination_buffer_length)
  source_length             = source.bytesize / 2 * 2
  destination_buffer_length = DEFAULT_DESTINATION_BUFFER_LENGTH if destination_buffer_length.zero?

  bytes_read =
    if destination_buffer_length.nil?
      source_length
    else
      [source_length, destination_buffer_length * 2].min
    end

  result = source
    .byteslice(0, bytes_read)
    .unpack("n*")
    .map { |byte| byte ^ 0xFF }
    .pack "C*"
  [result, bytes_read]
end