Sha256: ad5b98b1c8857a9f9882d1ad3a9cff0b8f4f4d0e40062047513852e933534ae6

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

# (c) 2018 Ribose Inc.

require 'ffi'

require 'rnp/error'
require 'rnp/ffi/librnp'

class Rnp
  # @api private
  #
  # Calls the LibRnp FFI function indicated.
  # If the return code is <0, an error will be raised.
  #
  # @param fn [Symbol] the name of the function to call
  # @param args the arguments to pass to the FFI function
  # @return [void]
  def self.call_ffi(fn, *args)
    rc = LibRnp.method(fn).call(*args)
    Rnp.raise_error("#{fn} failed", rc) unless rc.zero?
    nil
  end

  # @api private
  def self.inspect_ptr(myself)
    ptr_format = "0x%0#{FFI::Pointer.size * 2}x"
    ptr_s = format(ptr_format, myself.instance_variable_get(:@ptr).address)
    class_name = myself.class.to_s
    "#<#{class_name}:#{ptr_s}>"
  end

  unless FFI::MemoryPointer.respond_to?(:from_data)
    # @api private
    class << FFI::MemoryPointer
      def from_data(data)
        buf = FFI::MemoryPointer.new(:uint8, data.bytesize)
        buf.write_bytes(data)
        buf
      end
    end
  end
end # class

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rnp-1.0.5 lib/rnp/utils.rb
rnp-1.0.4 lib/rnp/utils.rb
rnp-1.0.3 lib/rnp/utils.rb
rnp-1.0.2 lib/rnp/utils.rb
rnp-1.0.1 lib/rnp/utils.rb
rnp-1.0.0 lib/rnp/utils.rb