Class: Rnp::Input
- Inherits:
-
Object
- Object
- Rnp::Input
- Defined in:
- lib/rnp/input.rb
Overview
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 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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
Instance Attribute Summary collapse
- #ptr ⇒ Object readonly private
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
- .from_callback(reader) ⇒ Object private
-
.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
-
#initialize(ptr, reader = nil) ⇒ Input
constructor
private
A new instance of Input.
- #inspect ⇒ Object
Constructor Details
#initialize(ptr, reader = nil) ⇒ Input
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.
Returns a new instance of Input.
32 33 34 35 36 |
# 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 |
Instance Attribute Details
#ptr ⇒ Object (readonly)
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.
29 30 31 |
# File 'lib/rnp/input.rb', line 29 def ptr @ptr end |
Class Method Details
.destroy(ptr) ⇒ 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.
39 40 41 |
# File 'lib/rnp/input.rb', line 39 def self.destroy(ptr) LibRnp.rnp_input_destroy(ptr) end |
.from_callback(reader) ⇒ 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.
91 92 93 94 95 96 |
# 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) ⇒ Input
Create an Input to read from an IO object.
72 73 74 |
# File 'lib/rnp/input.rb', line 72 def self.from_io(io) from_callback(io.method(:read)) end |
.from_path(path) ⇒ Input
Create an Input to read from a path.
62 63 64 65 66 |
# 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) ⇒ Input
Create an Input to read from a string.
51 52 53 54 55 56 |
# 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 |
Instance Method Details
#inspect ⇒ Object
43 44 45 |
# File 'lib/rnp/input.rb', line 43 def inspect Rnp.inspect_ptr(self) end |