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



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

.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.



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

#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



146
147
148
149
150
# File 'lib/chordsketch_uniffi.rb', line 146

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

#consumeIntoOptionalstringObject



167
168
169
170
171
# File 'lib/chordsketch_uniffi.rb', line 167

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

#consumeIntoSequencestringObject



188
189
190
191
192
# File 'lib/chordsketch_uniffi.rb', line 188

def consumeIntoSequencestring
  consumeWithStream do |stream|
    return stream.readSequencestring
  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

#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