Module: Appsignal::Extension::Jruby::StringHelpers Private

Included in:
Appsignal::Extension::Jruby, Data, Transaction
Defined in:
lib/appsignal/extension/jruby.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

JRuby extension String helpers.

Based on the make_appsignal_string and make_ruby_string helpers from the AppSignal C-extension in ext/appsignal_extension.c.

Defined Under Namespace

Classes: AppsignalString

Instance Method Summary collapse

Instance Method Details

#make_appsignal_string(ruby_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
33
34
# File 'lib/appsignal/extension/jruby.rb', line 25

def make_appsignal_string(ruby_string)
  unless ruby_string.is_a?(String)
    raise ArgumentError, "argument is not a string"
  end

  AppsignalString.new.tap do |appsignal_string|
    appsignal_string[:len] = ruby_string.bytesize
    appsignal_string[:buf] = FFI::MemoryPointer.from_string(ruby_string)
  end
end

#make_ruby_string(appsignal_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
# File 'lib/appsignal/extension/jruby.rb', line 36

def make_ruby_string(appsignal_string)
  appsignal_string[:buf].read_string(appsignal_string[:len]).tap do |ruby_string|
    ruby_string.force_encoding(Encoding::UTF_8)
  end
end