class Rnp::Input
Class used to feed data into RNP.
@note When dealing with very large data sources, prefer {from_path} which
should be the most efficient. {from_io} is likely to have more overhead.
@example input from a string
Rnp::Input.from_string('my data')
@example input from a file
Rnp::Input.from_path('/path/to/my/file')
@example input from a Ruby IO object
Rnp::Input.from_io(File.open('/path/to/file', 'rb'))
Constants
- READER
@api private
Attributes
ptr[R]
@api private
Public Class Methods
destroy(ptr)
click to toggle source
@api private
# File lib/rnp/input.rb, line 39 def self.destroy(ptr) LibRnp.rnp_input_destroy(ptr) end
from_callback(reader)
click to toggle source
@api private
# File lib/rnp/input.rb, line 91 def self.from_callback(reader) pptr = FFI::MemoryPointer.new(:pointer) readercb = READER.curry[reader] Rnp.call_ffi(:rnp_input_from_callback, pptr, readercb, nil, nil) Input.new(pptr.read_pointer, readercb) end
from_io(io)
click to toggle source
Create an Input
to read from an IO object.
@param io [IO, read] the IO object @return [Input]
# File lib/rnp/input.rb, line 72 def self.from_io(io) from_callback(io.method(:read)) end
from_path(path)
click to toggle source
Create an Input
to read from a path.
@param path [String] the path @return [Input]
# File lib/rnp/input.rb, line 62 def self.from_path(path) pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_input_from_path, pptr, path) Input.new(pptr.read_pointer) end
from_string(data)
click to toggle source
Create an Input
to read from a string.
@param data [String] the string data @return [Input]
# File lib/rnp/input.rb, line 51 def self.from_string(data) pptr = FFI::MemoryPointer.new(:pointer) buf = FFI::MemoryPointer.from_data(data) Rnp.call_ffi(:rnp_input_from_memory, pptr, buf, buf.size, true) Input.new(pptr.read_pointer) end
new(ptr, reader = nil)
click to toggle source
@api private
# File lib/rnp/input.rb, line 32 def initialize(ptr, reader = nil) raise Rnp::Error, 'NULL pointer' if ptr.null? @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) @reader = reader end
Public Instance Methods
inspect()
click to toggle source
# File lib/rnp/input.rb, line 43 def inspect Rnp.inspect_ptr(self) end