Module: Spotify::BestEffortString

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

Overview

A regular string type, ending at the first NULL byte.

Regular FFI :string raises errors when it encounters NULLs.

Class Method Summary collapse

Class Method Details

.to_native(value, ctx) ⇒ String

Extracts all of the string up until the first NULL byte.

Parameters:

  • value (String, nil)
  • ctx

Returns:

  • (String)

    value, up until the first NULL byte



16
17
18
# File 'lib/spotify/data_converters/best_effort_string.rb', line 16

def to_native(value, ctx)
  value && value.dup.force_encoding(Encoding::BINARY)[/[^\x00]*/n]
end