Module: Chordsketch
- Defined in:
- lib/chordsketch.rb,
lib/chordsketch_uniffi.rb
Overview
Detect the platform and pre-load the correct native library before requiring the UniFFI-generated bindings.
Defined Under Namespace
Modules: ChordSketchError, NativeLoader
Classes: InternalError, RustBuffer
Class Method Summary
collapse
-
.parse_and_render_html(input, config_json, transpose) ⇒ Object
-
.parse_and_render_pdf(input, config_json, transpose) ⇒ Object
-
.parse_and_render_text(input, config_json, transpose) ⇒ Object
-
.rust_call(fn_name, *args) ⇒ Object
-
.rust_call_with_error(error_module, fn_name, *args) ⇒ Object
-
.uniffi_bytes(v) ⇒ Object
-
.uniffi_in_range(i, type_name, min, max) ⇒ Object
-
.uniffi_utf8(v) ⇒ Object
-
.validate(input) ⇒ Object
-
.version ⇒ Object
Class Method Details
.parse_and_render_html(input, config_json, transpose) ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
|
# File 'lib/chordsketch_uniffi.rb', line 627
def self.parse_and_render_html(input, config_json, transpose)
input = Chordsketch::uniffi_utf8(input)
config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
RustBuffer.check_lower_Optionalstring(config_json)
transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
RustBuffer.check_lower_Optionali8(transpose)
result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_html,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
return result.consumeIntoString
end
|
.parse_and_render_pdf(input, config_json, transpose) ⇒ Object
645
646
647
648
649
650
651
652
653
654
655
656
657
|
# File 'lib/chordsketch_uniffi.rb', line 645
def self.parse_and_render_pdf(input, config_json, transpose)
input = Chordsketch::uniffi_utf8(input)
config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
RustBuffer.check_lower_Optionalstring(config_json)
transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
RustBuffer.check_lower_Optionali8(transpose)
result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_pdf,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
return result.consumeIntoBytes
end
|
.parse_and_render_text(input, config_json, transpose) ⇒ Object
663
664
665
666
667
668
669
670
671
672
673
674
675
|
# File 'lib/chordsketch_uniffi.rb', line 663
def self.parse_and_render_text(input, config_json, transpose)
input = Chordsketch::uniffi_utf8(input)
config_json = (config_json ? Chordsketch::uniffi_utf8(config_json) : nil)
RustBuffer.check_lower_Optionalstring(config_json)
transpose = (transpose ? Chordsketch::uniffi_in_range(transpose, "i8", -2**7, 2**7) : nil)
RustBuffer.check_lower_Optionali8(transpose)
result = Chordsketch.rust_call_with_error(ChordSketchError,:uniffi_chordsketch_ffi_fn_func_parse_and_render_text,RustBuffer.allocFromString(input),RustBuffer.alloc_from_Optionalstring(config_json),RustBuffer.alloc_from_Optionali8(transpose))
return result.consumeIntoString
end
|
.rust_call(fn_name, *args) ⇒ Object
517
518
519
520
|
# File 'lib/chordsketch_uniffi.rb', line 517
def self.rust_call(fn_name, *args)
rust_call_with_error(nil, fn_name, *args)
end
|
.rust_call_with_error(error_module, fn_name, *args) ⇒ Object
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
# File 'lib/chordsketch_uniffi.rb', line 522
def self.rust_call_with_error(error_module, fn_name, *args)
status = RustCallStatus.new
args << status
result = UniFFILib.public_send(fn_name, *args)
case status.code
when CALL_SUCCESS
result
when CALL_ERROR
if error_module.nil?
status.error_buf.free
raise InternalError, "CALL_ERROR with no error_module set"
else
raise consume_buffer_into_error(error_module, status.error_buf)
end
when CALL_PANIC
if status.error_buf.len > 0
raise InternalError, status.error_buf.consumeIntoString()
else
raise InternalError, "Rust panic"
end
else
raise InternalError, "Unknown call status: #{status.code}"
end
end
|
.uniffi_bytes(v) ⇒ Object
34
35
36
37
|
# File 'lib/chordsketch_uniffi.rb', line 34
def self.uniffi_bytes(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v.to_str
end
|
.uniffi_in_range(i, type_name, min, max) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/chordsketch_uniffi.rb', line 20
def self.uniffi_in_range(i, type_name, min, max)
raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
i = i.to_int
raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
i
end
|
.uniffi_utf8(v) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/chordsketch_uniffi.rb', line 27
def self.uniffi_utf8(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v = v.to_str.encode(Encoding::UTF_8)
raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
v
end
|
.validate(input) ⇒ Object
.version ⇒ Object
693
694
695
696
|
# File 'lib/chordsketch_uniffi.rb', line 693
def self.version()
result = Chordsketch.rust_call(:uniffi_chordsketch_ffi_fn_func_version,)
return result.consumeIntoString
end
|