Class: Rnp::Input
- Inherits:
-
Object
- Object
- Rnp::Input
- Defined in:
- lib/rnp/input.rb
Overview
Note:
When dealing with very large data sources, prefer Input.from_path which should be the most efficient. Input.from_io is likely to have more overhead.
Class used to feed data into RNP.
Constant Summary collapse
- READER =
lambda do |reader, _ctx, buf, buf_len| begin data = reader.call(buf_len) return 0 unless data raise Rnp::Error, 'Read exceeded buffer size' if data.size > buf_len buf.write_bytes(data) return data.size rescue puts $ERROR_INFO return -1 end end
Class Method Summary collapse
-
.from_io(io) ⇒ Input
Create an Input to read from an IO object.
-
.from_path(path) ⇒ Input
Create an Input to read from a path.
-
.from_string(data) ⇒ Input
Create an Input to read from a string.
Instance Method Summary collapse
Class Method Details
.from_io(io) ⇒ Input
Create an Input to read from an IO object.
73 74 75 |
# File 'lib/rnp/input.rb', line 73 def self.from_io(io) from_callback(io.method(:read)) end |
.from_path(path) ⇒ Input
Create an Input to read from a path.
63 64 65 66 67 |
# File 'lib/rnp/input.rb', line 63 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) ⇒ Input
Create an Input to read from a string.
52 53 54 55 56 57 |
# File 'lib/rnp/input.rb', line 52 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 |
Instance Method Details
#inspect ⇒ Object
44 45 46 |
# File 'lib/rnp/input.rb', line 44 def inspect Rnp.inspect_ptr(self) end |