Module: Spotify::ByteString

Extended by:
FFI::DataConverter
Defined in:
lib/spotify/data_converters/byte_string.rb

Overview

ByteStrings are for strings that store any binary data, not just regular NULL-terminated strings. It is used for the Spotify application key.

Class Method Summary collapse

Class Method Details

.reference_required?Boolean

Returns:

  • (Boolean)

See Also:

  • NulString.reference_required?


26
27
28
# File 'lib/spotify/data_converters/byte_string.rb', line 26

def reference_required?
  true
end

.to_native(value, ctx) ⇒ FFI::Pointer

Given either a String or nil, make an actual FFI::Pointer of that value, without an ending NULL-byte.

Parameters:

  • value (#to_str, nil)
  • ctx

Returns:

  • (FFI::Pointer)


16
17
18
19
20
21
22
23
# File 'lib/spotify/data_converters/byte_string.rb', line 16

def to_native(value, ctx)
  value && begin
    value = value.to_str

    pointer = FFI::MemoryPointer.new(:char, value.bytesize)
    pointer.write_string(value)
  end
end