Class: YARP::LibRubyParser::YPBuffer
- Inherits:
-
Object
- Object
- YARP::LibRubyParser::YPBuffer
- Defined in:
- lib/yarp/ffi.rb
Overview
This object represents a yp_buffer_t. We only use it as an opaque pointer, so it doesn’t need to know the fields of yp_buffer_t.
Constant Summary collapse
- SIZEOF =
LibRubyParser.yp_buffer_sizeof
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Class Method Summary collapse
-
.with(&block) ⇒ Object
Initialize a new buffer and yield it to the block.
Instance Method Summary collapse
-
#initialize(pointer) ⇒ YPBuffer
constructor
A new instance of YPBuffer.
- #length ⇒ Object
- #read ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(pointer) ⇒ YPBuffer
Returns a new instance of YPBuffer.
102 103 104 |
# File 'lib/yarp/ffi.rb', line 102 def initialize(pointer) @pointer = pointer end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
100 101 102 |
# File 'lib/yarp/ffi.rb', line 100 def pointer @pointer end |
Class Method Details
.with(&block) ⇒ Object
Initialize a new buffer and yield it to the block. The buffer will be automatically freed when the block returns.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/yarp/ffi.rb', line 120 def self.with(&block) pointer = FFI::MemoryPointer.new(SIZEOF) begin raise unless LibRubyParser.yp_buffer_init(pointer) yield new(pointer) ensure LibRubyParser.yp_buffer_free(pointer) pointer.free end end |
Instance Method Details
#length ⇒ Object
110 111 112 |
# File 'lib/yarp/ffi.rb', line 110 def length LibRubyParser.yp_buffer_length(pointer) end |
#read ⇒ Object
114 115 116 |
# File 'lib/yarp/ffi.rb', line 114 def read value.read_string(length) end |
#value ⇒ Object
106 107 108 |
# File 'lib/yarp/ffi.rb', line 106 def value LibRubyParser.yp_buffer_value(pointer) end |