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



200
201
202
203
204
205
# File 'lib/chordsketch_uniffi.rb', line 200

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

.alloc_from_Optionalstring(v) ⇒ Object



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

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

.alloc_from_Sequencestring(v) ⇒ Object



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

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

.alloc_from_SequenceTypeValidationError(v) ⇒ Object



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

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

.alloc_from_TypePdfRenderWithWarnings(v) ⇒ Object



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

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

.alloc_from_TypeTextRenderWithWarnings(v) ⇒ Object



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

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

.alloc_from_TypeValidationError(v) ⇒ Object



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

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.



194
195
196
197
198
# File 'lib/chordsketch_uniffi.rb', line 194

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

.check_lower_Optionalstring(v) ⇒ Object

The Optional<T> type for string.



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

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

.check_lower_Sequencestring(v) ⇒ Object

The Sequence<T> type for string.



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

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

.check_lower_SequenceTypeValidationError(v) ⇒ Object

The Sequence<T> type for TypeValidationError.



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

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

.check_lower_TypePdfRenderWithWarnings(v) ⇒ Object

The Record type PdfRenderWithWarnings.



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

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

.check_lower_TypeTextRenderWithWarnings(v) ⇒ Object

The Record type TextRenderWithWarnings.



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

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

.check_lower_TypeValidationError(v) ⇒ Object

The Record type ValidationError.



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

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



207
208
209
210
211
# File 'lib/chordsketch_uniffi.rb', line 207

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

#consumeIntoOptionalstringObject



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

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

#consumeIntoSequencestringObject



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

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

#consumeIntoSequenceTypeValidationErrorObject



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

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

#consumeIntoTypePdfRenderWithWarningsObject



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

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

#consumeIntoTypeTextRenderWithWarningsObject



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

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

#consumeIntoTypeValidationErrorObject



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

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