Class: HnApi::RustBuffer
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- HnApi::RustBuffer
- Defined in:
- lib/hn_api.rb
Class Method Summary collapse
- .alloc(size) ⇒ Object
-
.alloc_from_OptionalSequenceu32(v) ⇒ Object
The Optional<T> type for Sequenceu32.
-
.alloc_from_Optionalstring(v) ⇒ Object
The Optional<T> type for string.
-
.alloc_from_OptionalTypeStory(v) ⇒ Object
The Optional<T> type for TypeStory.
-
.alloc_from_OptionalTypeUser(v) ⇒ Object
The Optional<T> type for TypeUser.
-
.alloc_from_Optionalu32(v) ⇒ Object
The Optional<T> type for u32.
-
.alloc_from_Sequenceu32(v) ⇒ Object
The Sequence<T> type for u32.
-
.alloc_from_TypeStory(v) ⇒ Object
The Record type Story.
-
.alloc_from_TypeUser(v) ⇒ Object
The Record type User.
-
.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.
- .reserve(rbuf, additional) ⇒ Object
Instance Method Summary collapse
- #capacity ⇒ Object
- #consumeIntoOptionalSequenceu32 ⇒ Object
- #consumeIntoOptionalstring ⇒ Object
- #consumeIntoOptionalTypeStory ⇒ Object
- #consumeIntoOptionalTypeUser ⇒ Object
- #consumeIntoOptionalu32 ⇒ Object
- #consumeIntoSequenceu32 ⇒ Object
- #consumeIntoString ⇒ Object
- #consumeIntoTypeStory ⇒ Object
- #consumeIntoTypeUser ⇒ 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
24 25 26 |
# File 'lib/hn_api.rb', line 24 def self.alloc(size) return HnApi.rust_call(:ffi_hn_api_d6e5_rustbuffer_alloc, size) end |
.alloc_from_OptionalSequenceu32(v) ⇒ Object
The Optional<T> type for Sequenceu32.
186 187 188 189 190 191 |
# File 'lib/hn_api.rb', line 186 def self.alloc_from_OptionalSequenceu32(v) RustBuffer.allocWithBuilder do |builder| builder.write_OptionalSequenceu32(v) return builder.finalize() end end |
.alloc_from_Optionalstring(v) ⇒ Object
The Optional<T> type for string.
141 142 143 144 145 146 |
# File 'lib/hn_api.rb', line 141 def self.alloc_from_Optionalstring(v) RustBuffer.allocWithBuilder do |builder| builder.write_Optionalstring(v) return builder.finalize() end end |
.alloc_from_OptionalTypeStory(v) ⇒ Object
The Optional<T> type for TypeStory.
156 157 158 159 160 161 |
# File 'lib/hn_api.rb', line 156 def self.alloc_from_OptionalTypeStory(v) RustBuffer.allocWithBuilder do |builder| builder.write_OptionalTypeStory(v) return builder.finalize() end end |
.alloc_from_OptionalTypeUser(v) ⇒ Object
The Optional<T> type for TypeUser.
171 172 173 174 175 176 |
# File 'lib/hn_api.rb', line 171 def self.alloc_from_OptionalTypeUser(v) RustBuffer.allocWithBuilder do |builder| builder.write_OptionalTypeUser(v) return builder.finalize() end end |
.alloc_from_Optionalu32(v) ⇒ Object
The Optional<T> type for u32.
126 127 128 129 130 131 |
# File 'lib/hn_api.rb', line 126 def self.alloc_from_Optionalu32(v) RustBuffer.allocWithBuilder do |builder| builder.write_Optionalu32(v) return builder.finalize() end end |
.alloc_from_Sequenceu32(v) ⇒ Object
The Sequence<T> type for u32.
201 202 203 204 205 206 |
# File 'lib/hn_api.rb', line 201 def self.alloc_from_Sequenceu32(v) RustBuffer.allocWithBuilder do |builder| builder.write_Sequenceu32(v) return builder.finalize() end end |
.alloc_from_TypeStory(v) ⇒ Object
The Record type Story.
96 97 98 99 100 101 |
# File 'lib/hn_api.rb', line 96 def self.alloc_from_TypeStory(v) RustBuffer.allocWithBuilder do |builder| builder.write_TypeStory(v) return builder.finalize end end |
.alloc_from_TypeUser(v) ⇒ Object
The Record type User.
111 112 113 114 115 116 |
# File 'lib/hn_api.rb', line 111 def self.alloc_from_TypeUser(v) RustBuffer.allocWithBuilder do |builder| builder.write_TypeUser(v) return builder.finalize end end |
.allocFromString(value) ⇒ Object
The primitive String type.
81 82 83 84 85 86 |
# File 'lib/hn_api.rb', line 81 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.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hn_api.rb', line 58 def self.allocWithBuilder builder = RustBufferBuilder.new begin yield builder rescue => e builder.discard raise e end end |
.reserve(rbuf, additional) ⇒ Object
28 29 30 |
# File 'lib/hn_api.rb', line 28 def self.reserve(rbuf, additional) return HnApi.rust_call(:ffi_hn_api_d6e5_rustbuffer_reserve, rbuf, additional) end |
Instance Method Details
#capacity ⇒ Object
36 37 38 |
# File 'lib/hn_api.rb', line 36 def capacity self[:capacity] end |
#consumeIntoOptionalSequenceu32 ⇒ Object
193 194 195 196 197 |
# File 'lib/hn_api.rb', line 193 def consumeIntoOptionalSequenceu32 consumeWithStream do |stream| return stream.readOptionalSequenceu32 end end |
#consumeIntoOptionalstring ⇒ Object
148 149 150 151 152 |
# File 'lib/hn_api.rb', line 148 def consumeIntoOptionalstring consumeWithStream do |stream| return stream.readOptionalstring end end |
#consumeIntoOptionalTypeStory ⇒ Object
163 164 165 166 167 |
# File 'lib/hn_api.rb', line 163 def consumeIntoOptionalTypeStory consumeWithStream do |stream| return stream.readOptionalTypeStory end end |
#consumeIntoOptionalTypeUser ⇒ Object
178 179 180 181 182 |
# File 'lib/hn_api.rb', line 178 def consumeIntoOptionalTypeUser consumeWithStream do |stream| return stream.readOptionalTypeUser end end |
#consumeIntoOptionalu32 ⇒ Object
133 134 135 136 137 |
# File 'lib/hn_api.rb', line 133 def consumeIntoOptionalu32 consumeWithStream do |stream| return stream.readOptionalu32 end end |
#consumeIntoSequenceu32 ⇒ Object
208 209 210 211 212 |
# File 'lib/hn_api.rb', line 208 def consumeIntoSequenceu32 consumeWithStream do |stream| return stream.readSequenceu32 end end |
#consumeIntoString ⇒ Object
88 89 90 91 92 |
# File 'lib/hn_api.rb', line 88 def consumeIntoString consumeWithStream do |stream| return stream.read(stream.remaining).force_encoding(Encoding::UTF_8) end end |
#consumeIntoTypeStory ⇒ Object
103 104 105 106 107 |
# File 'lib/hn_api.rb', line 103 def consumeIntoTypeStory consumeWithStream do |stream| return stream.readTypeStory end end |
#consumeIntoTypeUser ⇒ Object
118 119 120 121 122 |
# File 'lib/hn_api.rb', line 118 def consumeIntoTypeUser consumeWithStream do |stream| return stream.readTypeUser 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.
71 72 73 74 75 76 77 78 79 |
# File 'lib/hn_api.rb', line 71 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
48 49 50 |
# File 'lib/hn_api.rb', line 48 def data self[:data] end |
#free ⇒ Object
32 33 34 |
# File 'lib/hn_api.rb', line 32 def free HnApi.rust_call(:ffi_hn_api_d6e5_rustbuffer_free, self) end |
#len ⇒ Object
40 41 42 |
# File 'lib/hn_api.rb', line 40 def len self[:len] end |
#len=(value) ⇒ Object
44 45 46 |
# File 'lib/hn_api.rb', line 44 def len=(value) self[:len] = value end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/hn_api.rb', line 52 def to_s "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})" end |