Class: Chordsketch::RustBuffer

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/chordsketch_uniffi.rb

Class Method Summary collapse

Instance Method Summary collapse

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



240
241
242
243
244
245
# File 'lib/chordsketch_uniffi.rb', line 240

def self.alloc_from_Optionali8(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_Optionali8(v)
    return builder.finalize()
  end
end

.alloc_from_Optionalstring(v) ⇒ Object



261
262
263
264
265
266
# File 'lib/chordsketch_uniffi.rb', line 261

def self.alloc_from_Optionalstring(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_Optionalstring(v)
    return builder.finalize()
  end
end

.alloc_from_Sequencestring(v) ⇒ Object



282
283
284
285
286
287
# File 'lib/chordsketch_uniffi.rb', line 282

def self.alloc_from_Sequencestring(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_Sequencestring(v)
    return builder.finalize()
  end
end

.alloc_from_SequenceTypeChordDefine(v) ⇒ Object



303
304
305
306
307
308
# File 'lib/chordsketch_uniffi.rb', line 303

def self.alloc_from_SequenceTypeChordDefine(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_SequenceTypeChordDefine(v)
    return builder.finalize()
  end
end

.alloc_from_SequenceTypeValidationError(v) ⇒ Object



324
325
326
327
328
329
# File 'lib/chordsketch_uniffi.rb', line 324

def self.alloc_from_SequenceTypeValidationError(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_SequenceTypeValidationError(v)
    return builder.finalize()
  end
end

.alloc_from_TypeChordDefine(v) ⇒ Object



136
137
138
139
140
141
# File 'lib/chordsketch_uniffi.rb', line 136

def self.alloc_from_TypeChordDefine(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_TypeChordDefine(v)
    return builder.finalize
  end
end

.alloc_from_TypeConversionWithWarnings(v) ⇒ Object



156
157
158
159
160
161
# File 'lib/chordsketch_uniffi.rb', line 156

def self.alloc_from_TypeConversionWithWarnings(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_TypeConversionWithWarnings(v)
    return builder.finalize
  end
end

.alloc_from_TypePdfRenderWithWarnings(v) ⇒ Object



176
177
178
179
180
181
# File 'lib/chordsketch_uniffi.rb', line 176

def self.alloc_from_TypePdfRenderWithWarnings(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_TypePdfRenderWithWarnings(v)
    return builder.finalize
  end
end

.alloc_from_TypeTextRenderWithWarnings(v) ⇒ Object



196
197
198
199
200
201
# File 'lib/chordsketch_uniffi.rb', line 196

def self.alloc_from_TypeTextRenderWithWarnings(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_TypeTextRenderWithWarnings(v)
    return builder.finalize
  end
end

.alloc_from_TypeValidationError(v) ⇒ Object



217
218
219
220
221
222
# File 'lib/chordsketch_uniffi.rb', line 217

def self.alloc_from_TypeValidationError(v)
  RustBuffer.allocWithBuilder do |builder|
    builder.write_TypeValidationError(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

.allocWithBuilderObject

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.



234
235
236
237
238
# File 'lib/chordsketch_uniffi.rb', line 234

def self.check_lower_Optionali8(v)
  if not v.nil?
    
  end
end

.check_lower_Optionalstring(v) ⇒ Object

The Optional<T> type for string.



255
256
257
258
259
# File 'lib/chordsketch_uniffi.rb', line 255

def self.check_lower_Optionalstring(v)
  if not v.nil?
    
  end
end

.check_lower_Sequencestring(v) ⇒ Object

The Sequence<T> type for string.



276
277
278
279
280
# File 'lib/chordsketch_uniffi.rb', line 276

def self.check_lower_Sequencestring(v)
  v.each do |item|
    
  end
end

.check_lower_SequenceTypeChordDefine(v) ⇒ Object

The Sequence<T> type for TypeChordDefine.



297
298
299
300
301
# File 'lib/chordsketch_uniffi.rb', line 297

def self.check_lower_SequenceTypeChordDefine(v)
  v.each do |item|
    RustBuffer.check_lower_TypeChordDefine(item)
  end
end

.check_lower_SequenceTypeValidationError(v) ⇒ Object

The Sequence<T> type for TypeValidationError.



318
319
320
321
322
# File 'lib/chordsketch_uniffi.rb', line 318

def self.check_lower_SequenceTypeValidationError(v)
  v.each do |item|
    RustBuffer.check_lower_TypeValidationError(item)
  end
end

.check_lower_TypeChordDefine(v) ⇒ Object

The Record type ChordDefine.



131
132
133
134
# File 'lib/chordsketch_uniffi.rb', line 131

def self.check_lower_TypeChordDefine(v)
  
  
end

.check_lower_TypeConversionWithWarnings(v) ⇒ Object

The Record type ConversionWithWarnings.



151
152
153
154
# File 'lib/chordsketch_uniffi.rb', line 151

def self.check_lower_TypeConversionWithWarnings(v)
  
  RustBuffer.check_lower_Sequencestring(v.warnings)
end

.check_lower_TypePdfRenderWithWarnings(v) ⇒ Object

The Record type PdfRenderWithWarnings.



171
172
173
174
# File 'lib/chordsketch_uniffi.rb', line 171

def self.check_lower_TypePdfRenderWithWarnings(v)
  
  RustBuffer.check_lower_Sequencestring(v.warnings)
end

.check_lower_TypeTextRenderWithWarnings(v) ⇒ Object

The Record type TextRenderWithWarnings.



191
192
193
194
# File 'lib/chordsketch_uniffi.rb', line 191

def self.check_lower_TypeTextRenderWithWarnings(v)
  
  RustBuffer.check_lower_Sequencestring(v.warnings)
end

.check_lower_TypeValidationError(v) ⇒ Object

The Record type ValidationError.



211
212
213
214
215
# File 'lib/chordsketch_uniffi.rb', line 211

def self.check_lower_TypeValidationError(v)
  
  
  
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

#capacityObject



56
57
58
# File 'lib/chordsketch_uniffi.rb', line 56

def capacity
  self[:capacity]
end

#consumeIntoBytesObject



123
124
125
126
127
# File 'lib/chordsketch_uniffi.rb', line 123

def consumeIntoBytes
  consumeWithStream do |stream|
    return stream.readBytes
  end
end

#consumeIntoOptionali8Object



247
248
249
250
251
# File 'lib/chordsketch_uniffi.rb', line 247

def consumeIntoOptionali8
  consumeWithStream do |stream|
    return stream.readOptionali8
  end
end

#consumeIntoOptionalstringObject



268
269
270
271
272
# File 'lib/chordsketch_uniffi.rb', line 268

def consumeIntoOptionalstring
  consumeWithStream do |stream|
    return stream.readOptionalstring
  end
end

#consumeIntoSequencestringObject



289
290
291
292
293
# File 'lib/chordsketch_uniffi.rb', line 289

def consumeIntoSequencestring
  consumeWithStream do |stream|
    return stream.readSequencestring
  end
end

#consumeIntoSequenceTypeChordDefineObject



310
311
312
313
314
# File 'lib/chordsketch_uniffi.rb', line 310

def consumeIntoSequenceTypeChordDefine
  consumeWithStream do |stream|
    return stream.readSequenceTypeChordDefine
  end
end

#consumeIntoSequenceTypeValidationErrorObject



331
332
333
334
335
# File 'lib/chordsketch_uniffi.rb', line 331

def consumeIntoSequenceTypeValidationError
  consumeWithStream do |stream|
    return stream.readSequenceTypeValidationError
  end
end

#consumeIntoStringObject



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

#consumeIntoTypeChordDefineObject



143
144
145
146
147
# File 'lib/chordsketch_uniffi.rb', line 143

def consumeIntoTypeChordDefine
  consumeWithStream do |stream|
    return stream.readTypeChordDefine
  end
end

#consumeIntoTypeConversionWithWarningsObject



163
164
165
166
167
# File 'lib/chordsketch_uniffi.rb', line 163

def consumeIntoTypeConversionWithWarnings
  consumeWithStream do |stream|
    return stream.readTypeConversionWithWarnings
  end
end

#consumeIntoTypePdfRenderWithWarningsObject



183
184
185
186
187
# File 'lib/chordsketch_uniffi.rb', line 183

def consumeIntoTypePdfRenderWithWarnings
  consumeWithStream do |stream|
    return stream.readTypePdfRenderWithWarnings
  end
end

#consumeIntoTypeTextRenderWithWarningsObject



203
204
205
206
207
# File 'lib/chordsketch_uniffi.rb', line 203

def consumeIntoTypeTextRenderWithWarnings
  consumeWithStream do |stream|
    return stream.readTypeTextRenderWithWarnings
  end
end

#consumeIntoTypeValidationErrorObject



224
225
226
227
228
# File 'lib/chordsketch_uniffi.rb', line 224

def consumeIntoTypeValidationError
  consumeWithStream do |stream|
    return stream.readTypeValidationError
  end
end

#consumeWithStreamObject

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

#dataObject



68
69
70
# File 'lib/chordsketch_uniffi.rb', line 68

def data
  self[:data]
end

#freeObject



52
53
54
# File 'lib/chordsketch_uniffi.rb', line 52

def free
  Chordsketch.rust_call(:ffi_chordsketch_ffi_rustbuffer_free, self)
end

#lenObject



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_sObject



72
73
74
# File 'lib/chordsketch_uniffi.rb', line 72

def to_s
  "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
end