Class: Chordsketch::RustBuffer
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Chordsketch::RustBuffer
- Defined in:
- lib/chordsketch_uniffi.rb
Class Method Summary collapse
- .alloc(size) ⇒ Object
- .alloc_from_Optionali8(v) ⇒ Object
- .alloc_from_Optionalstring(v) ⇒ Object
- .alloc_from_Sequencestring(v) ⇒ Object
-
.allocFromBytes(value) ⇒ Object
The primitive Bytes type.
-
.allocFromString(value) ⇒ Object
The primitive String type.
-
.allocWithBuilder ⇒ Object
The allocated buffer will be automatically freed if an error occurs, ensuring that we don’t accidentally leak it.
-
.check_lower_Optionali8(v) ⇒ Object
The Optional<T> type for i8.
-
.check_lower_Optionalstring(v) ⇒ Object
The Optional<T> type for string.
-
.check_lower_Sequencestring(v) ⇒ Object
The Sequence<T> type for string.
- .reserve(rbuf, additional) ⇒ Object
Instance Method Summary collapse
- #capacity ⇒ Object
- #consumeIntoBytes ⇒ Object
- #consumeIntoOptionali8 ⇒ Object
- #consumeIntoOptionalstring ⇒ Object
- #consumeIntoSequencestring ⇒ Object
- #consumeIntoString ⇒ Object
-
#consumeWithStream ⇒ Object
The RustBuffer will be freed once the context-manager exits, ensuring that we don’t leak it even if an error occurs.
- #data ⇒ Object
- #free ⇒ Object
- #len ⇒ Object
- #len=(value) ⇒ Object
- #to_s ⇒ Object
Class Method Details
.alloc(size) ⇒ Object
44 45 46 |
# File 'lib/chordsketch_uniffi.rb', line 44 def self.alloc(size) return Chordsketch.rust_call(:ffi_chordsketch_ffi_rustbuffer_alloc, size) end |
.alloc_from_Optionali8(v) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/chordsketch_uniffi.rb', line 139 def self.alloc_from_Optionali8(v) RustBuffer.allocWithBuilder do |builder| builder.write_Optionali8(v) return builder.finalize() end end |
.alloc_from_Optionalstring(v) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/chordsketch_uniffi.rb', line 160 def self.alloc_from_Optionalstring(v) RustBuffer.allocWithBuilder do |builder| builder.write_Optionalstring(v) return builder.finalize() end end |
.alloc_from_Sequencestring(v) ⇒ Object
181 182 183 184 185 186 |
# File 'lib/chordsketch_uniffi.rb', line 181 def self.alloc_from_Sequencestring(v) RustBuffer.allocWithBuilder do |builder| builder.write_Sequencestring(v) return builder.finalize() end end |
.allocFromBytes(value) ⇒ Object
The primitive Bytes type.
116 117 118 119 120 121 |
# File 'lib/chordsketch_uniffi.rb', line 116 def self.allocFromBytes(value) RustBuffer.allocWithBuilder do |builder| builder.write_Bytes(value) return builder.finalize end end |
.allocFromString(value) ⇒ Object
The primitive String type.
101 102 103 104 105 106 |
# File 'lib/chordsketch_uniffi.rb', line 101 def self.allocFromString(value) RustBuffer.allocWithBuilder do |builder| builder.write value.encode('utf-8') return builder.finalize end end |
.allocWithBuilder ⇒ Object
The allocated buffer will be automatically freed if an error occurs, ensuring that we don’t accidentally leak it.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chordsketch_uniffi.rb', line 78 def self.allocWithBuilder builder = RustBufferBuilder.new begin yield builder rescue => e builder.discard raise e end end |
.check_lower_Optionali8(v) ⇒ Object
The Optional<T> type for i8.
133 134 135 136 137 |
# File 'lib/chordsketch_uniffi.rb', line 133 def self.check_lower_Optionali8(v) if not v.nil? end end |
.check_lower_Optionalstring(v) ⇒ Object
The Optional<T> type for string.
154 155 156 157 158 |
# File 'lib/chordsketch_uniffi.rb', line 154 def self.check_lower_Optionalstring(v) if not v.nil? end end |
.check_lower_Sequencestring(v) ⇒ Object
The Sequence<T> type for string.
175 176 177 178 179 |
# File 'lib/chordsketch_uniffi.rb', line 175 def self.check_lower_Sequencestring(v) v.each do |item| end end |
.reserve(rbuf, additional) ⇒ Object
48 49 50 |
# File 'lib/chordsketch_uniffi.rb', line 48 def self.reserve(rbuf, additional) return Chordsketch.rust_call(:ffi_chordsketch_ffi_rustbuffer_reserve, rbuf, additional) end |
Instance Method Details
#capacity ⇒ Object
56 57 58 |
# File 'lib/chordsketch_uniffi.rb', line 56 def capacity self[:capacity] end |
#consumeIntoBytes ⇒ Object
123 124 125 126 127 |
# File 'lib/chordsketch_uniffi.rb', line 123 def consumeIntoBytes consumeWithStream do |stream| return stream.readBytes end end |
#consumeIntoOptionali8 ⇒ Object
146 147 148 149 150 |
# File 'lib/chordsketch_uniffi.rb', line 146 def consumeIntoOptionali8 consumeWithStream do |stream| return stream.readOptionali8 end end |
#consumeIntoOptionalstring ⇒ Object
167 168 169 170 171 |
# File 'lib/chordsketch_uniffi.rb', line 167 def consumeIntoOptionalstring consumeWithStream do |stream| return stream.readOptionalstring end end |
#consumeIntoSequencestring ⇒ Object
188 189 190 191 192 |
# File 'lib/chordsketch_uniffi.rb', line 188 def consumeIntoSequencestring consumeWithStream do |stream| return stream.readSequencestring end end |
#consumeIntoString ⇒ Object
108 109 110 111 112 |
# File 'lib/chordsketch_uniffi.rb', line 108 def consumeIntoString consumeWithStream do |stream| return stream.read(stream.remaining).force_encoding(Encoding::UTF_8) end end |
#consumeWithStream ⇒ Object
The RustBuffer will be freed once the context-manager exits, ensuring that we don’t leak it even if an error occurs.
91 92 93 94 95 96 97 98 99 |
# File 'lib/chordsketch_uniffi.rb', line 91 def consumeWithStream stream = RustBufferStream.new self yield stream raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0 ensure free end |
#data ⇒ Object
68 69 70 |
# File 'lib/chordsketch_uniffi.rb', line 68 def data self[:data] end |
#free ⇒ Object
52 53 54 |
# File 'lib/chordsketch_uniffi.rb', line 52 def free Chordsketch.rust_call(:ffi_chordsketch_ffi_rustbuffer_free, self) end |
#len ⇒ Object
60 61 62 |
# File 'lib/chordsketch_uniffi.rb', line 60 def len self[:len] end |
#len=(value) ⇒ Object
64 65 66 |
# File 'lib/chordsketch_uniffi.rb', line 64 def len=(value) self[:len] = value end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/chordsketch_uniffi.rb', line 72 def to_s "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})" end |