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



220
221
222
223
224
225
# File 'lib/chordsketch_uniffi.rb', line 220

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

.alloc_from_Optionalstring(v) ⇒ Object



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

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

.alloc_from_Sequencestring(v) ⇒ Object



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

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

.alloc_from_SequenceTypeValidationError(v) ⇒ Object



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

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

.alloc_from_TypeConversionWithWarnings(v) ⇒ Object



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

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

.alloc_from_TypePdfRenderWithWarnings(v) ⇒ Object



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

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

.alloc_from_TypeTextRenderWithWarnings(v) ⇒ Object



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

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

.alloc_from_TypeValidationError(v) ⇒ Object



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

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.



214
215
216
217
218
# File 'lib/chordsketch_uniffi.rb', line 214

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

.check_lower_Optionalstring(v) ⇒ Object

The Optional<T> type for string.



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

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

.check_lower_Sequencestring(v) ⇒ Object

The Sequence<T> type for string.



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

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

.check_lower_SequenceTypeValidationError(v) ⇒ Object

The Sequence<T> type for TypeValidationError.



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

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

.check_lower_TypeConversionWithWarnings(v) ⇒ Object

The Record type ConversionWithWarnings.



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

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

.check_lower_TypePdfRenderWithWarnings(v) ⇒ Object

The Record type PdfRenderWithWarnings.



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

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

.check_lower_TypeTextRenderWithWarnings(v) ⇒ Object

The Record type TextRenderWithWarnings.



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

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

.check_lower_TypeValidationError(v) ⇒ Object

The Record type ValidationError.



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

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



227
228
229
230
231
# File 'lib/chordsketch_uniffi.rb', line 227

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

#consumeIntoOptionalstringObject



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

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

#consumeIntoSequencestringObject



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

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

#consumeIntoSequenceTypeValidationErrorObject



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

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

#consumeIntoTypeConversionWithWarningsObject



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

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

#consumeIntoTypePdfRenderWithWarningsObject



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

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

#consumeIntoTypeTextRenderWithWarningsObject



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

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

#consumeIntoTypeValidationErrorObject



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

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