oicana 0.10.0-aarch64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2548 @@
1
+ # This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ # Trust me, you don't want to mess with it!
3
+
4
+ # Common helper code.
5
+ #
6
+ # Ideally this would live in a separate .rb file where it can be unittested etc
7
+ # in isolation, and perhaps even published as a re-useable package.
8
+ #
9
+ # However, it's important that the details of how this helper code works (e.g. the
10
+ # way that different builtin types are passed across the FFI) exactly match what's
11
+ # expected by the rust code on the other side of the interface. In practice right
12
+ # now that means coming from the exact some version of `uniffi` that was used to
13
+ # compile the rust component. The easiest way to ensure this is to bundle the Ruby
14
+ # helpers directly inline like we're doing here.
15
+
16
+ require 'ffi'
17
+
18
+
19
+ module OicanaUniffi
20
+ def self.uniffi_in_range(i, type_name, min, max)
21
+ raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
22
+ i = i.to_int
23
+ raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
24
+ i
25
+ end
26
+
27
+ def self.uniffi_utf8(v)
28
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
29
+ v = v.to_str.encode(Encoding::UTF_8)
30
+ raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
31
+ v
32
+ end
33
+
34
+ def self.uniffi_bytes(v)
35
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
36
+ v.to_str
37
+ end
38
+
39
+ class RustBuffer < FFI::Struct
40
+ layout :capacity, :uint64,
41
+ :len, :uint64,
42
+ :data, :pointer
43
+
44
+ def self.alloc(size)
45
+ return OicanaUniffi.rust_call(:ffi_oicana_uniffi_rustbuffer_alloc, size)
46
+ end
47
+
48
+ def self.reserve(rbuf, additional)
49
+ return OicanaUniffi.rust_call(:ffi_oicana_uniffi_rustbuffer_reserve, rbuf, additional)
50
+ end
51
+
52
+ def free
53
+ OicanaUniffi.rust_call(:ffi_oicana_uniffi_rustbuffer_free, self)
54
+ end
55
+
56
+ def capacity
57
+ self[:capacity]
58
+ end
59
+
60
+ def len
61
+ self[:len]
62
+ end
63
+
64
+ def len=(value)
65
+ self[:len] = value
66
+ end
67
+
68
+ def data
69
+ self[:data]
70
+ end
71
+
72
+ def to_s
73
+ "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
74
+ end
75
+
76
+ # The allocated buffer will be automatically freed if an error occurs, ensuring that
77
+ # we don't accidentally leak it.
78
+ def self.allocWithBuilder
79
+ builder = RustBufferBuilder.new
80
+
81
+ begin
82
+ yield builder
83
+ rescue => e
84
+ builder.discard
85
+ raise e
86
+ end
87
+ end
88
+
89
+ # The RustBuffer will be freed once the context-manager exits, ensuring that we don't
90
+ # leak it even if an error occurs.
91
+ def consumeWithStream
92
+ stream = RustBufferStream.new self
93
+
94
+ yield stream
95
+
96
+ raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
97
+ ensure
98
+ free
99
+ end# The primitive String type.
100
+
101
+ def self.allocFromString(value)
102
+ RustBuffer.allocWithBuilder do |builder|
103
+ builder.write value.encode('utf-8')
104
+ return builder.finalize
105
+ end
106
+ end
107
+
108
+ def consumeIntoString
109
+ consumeWithStream do |stream|
110
+ return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
111
+ end
112
+ end
113
+
114
+ # The primitive Bytes type.
115
+
116
+ def self.allocFromBytes(value)
117
+ RustBuffer.allocWithBuilder do |builder|
118
+ builder.write_Bytes(value)
119
+ return builder.finalize
120
+ end
121
+ end
122
+
123
+ def consumeIntoBytes
124
+ consumeWithStream do |stream|
125
+ return stream.readBytes
126
+ end
127
+ end
128
+
129
+ # The Record type BlobInput.
130
+
131
+ def self.check_lower_TypeBlobInput(v)
132
+
133
+
134
+ end
135
+
136
+ def self.alloc_from_TypeBlobInput(v)
137
+ RustBuffer.allocWithBuilder do |builder|
138
+ builder.write_TypeBlobInput(v)
139
+ return builder.finalize
140
+ end
141
+ end
142
+
143
+ def consumeIntoTypeBlobInput
144
+ consumeWithStream do |stream|
145
+ return stream.readTypeBlobInput
146
+ end
147
+ end
148
+
149
+ # The Record type Diagnostic.
150
+
151
+ def self.check_lower_TypeDiagnostic(v)
152
+ RustBuffer.check_lower_TypeDiagnosticSeverity(v.severity)
153
+
154
+ RustBuffer.check_lower_OptionalTypeSourceLocation(v.location)
155
+ RustBuffer.check_lower_Sequencestring(v.hints)
156
+ RustBuffer.check_lower_SequenceTypeTracePoint(v.trace)
157
+
158
+ end
159
+
160
+ def self.alloc_from_TypeDiagnostic(v)
161
+ RustBuffer.allocWithBuilder do |builder|
162
+ builder.write_TypeDiagnostic(v)
163
+ return builder.finalize
164
+ end
165
+ end
166
+
167
+ def consumeIntoTypeDiagnostic
168
+ consumeWithStream do |stream|
169
+ return stream.readTypeDiagnostic
170
+ end
171
+ end
172
+
173
+ # The Record type ExportOnceResult.
174
+
175
+ def self.check_lower_TypeExportOnceResult(v)
176
+
177
+ RustBuffer.check_lower_SequenceTypeDiagnostic(v.warnings)
178
+ end
179
+
180
+ def self.alloc_from_TypeExportOnceResult(v)
181
+ RustBuffer.allocWithBuilder do |builder|
182
+ builder.write_TypeExportOnceResult(v)
183
+ return builder.finalize
184
+ end
185
+ end
186
+
187
+ def consumeIntoTypeExportOnceResult
188
+ consumeWithStream do |stream|
189
+ return stream.readTypeExportOnceResult
190
+ end
191
+ end
192
+
193
+ # The Record type PageRange.
194
+
195
+ def self.check_lower_TypePageRange(v)
196
+ RustBuffer.check_lower_Optionalu64(v.start)
197
+ RustBuffer.check_lower_Optionalu64(v._end)
198
+ end
199
+
200
+ def self.alloc_from_TypePageRange(v)
201
+ RustBuffer.allocWithBuilder do |builder|
202
+ builder.write_TypePageRange(v)
203
+ return builder.finalize
204
+ end
205
+ end
206
+
207
+ def consumeIntoTypePageRange
208
+ consumeWithStream do |stream|
209
+ return stream.readTypePageRange
210
+ end
211
+ end
212
+
213
+ # The Record type PageSize.
214
+
215
+ def self.check_lower_TypePageSize(v)
216
+
217
+
218
+ end
219
+
220
+ def self.alloc_from_TypePageSize(v)
221
+ RustBuffer.allocWithBuilder do |builder|
222
+ builder.write_TypePageSize(v)
223
+ return builder.finalize
224
+ end
225
+ end
226
+
227
+ def consumeIntoTypePageSize
228
+ consumeWithStream do |stream|
229
+ return stream.readTypePageSize
230
+ end
231
+ end
232
+
233
+ # The Record type RegisteredFont.
234
+
235
+ def self.check_lower_TypeRegisteredFont(v)
236
+
237
+ RustBuffer.check_lower_Optionalstring(v.path)
238
+ end
239
+
240
+ def self.alloc_from_TypeRegisteredFont(v)
241
+ RustBuffer.allocWithBuilder do |builder|
242
+ builder.write_TypeRegisteredFont(v)
243
+ return builder.finalize
244
+ end
245
+ end
246
+
247
+ def consumeIntoTypeRegisteredFont
248
+ consumeWithStream do |stream|
249
+ return stream.readTypeRegisteredFont
250
+ end
251
+ end
252
+
253
+ # The Record type SourceLocation.
254
+
255
+ def self.check_lower_TypeSourceLocation(v)
256
+
257
+
258
+
259
+
260
+
261
+ end
262
+
263
+ def self.alloc_from_TypeSourceLocation(v)
264
+ RustBuffer.allocWithBuilder do |builder|
265
+ builder.write_TypeSourceLocation(v)
266
+ return builder.finalize
267
+ end
268
+ end
269
+
270
+ def consumeIntoTypeSourceLocation
271
+ consumeWithStream do |stream|
272
+ return stream.readTypeSourceLocation
273
+ end
274
+ end
275
+
276
+ # The Record type TracePoint.
277
+
278
+ def self.check_lower_TypeTracePoint(v)
279
+
280
+ RustBuffer.check_lower_OptionalTypeSourceLocation(v.location)
281
+ end
282
+
283
+ def self.alloc_from_TypeTracePoint(v)
284
+ RustBuffer.allocWithBuilder do |builder|
285
+ builder.write_TypeTracePoint(v)
286
+ return builder.finalize
287
+ end
288
+ end
289
+
290
+ def consumeIntoTypeTracePoint
291
+ consumeWithStream do |stream|
292
+ return stream.readTypeTracePoint
293
+ end
294
+ end
295
+
296
+ # The Record type ZipLimits.
297
+
298
+ def self.check_lower_TypeZipLimits(v)
299
+ RustBuffer.check_lower_Optionalu64(v.max_entries)
300
+ RustBuffer.check_lower_Optionalu64(v.max_total_decompressed_bytes)
301
+ end
302
+
303
+ def self.alloc_from_TypeZipLimits(v)
304
+ RustBuffer.allocWithBuilder do |builder|
305
+ builder.write_TypeZipLimits(v)
306
+ return builder.finalize
307
+ end
308
+ end
309
+
310
+ def consumeIntoTypeZipLimits
311
+ consumeWithStream do |stream|
312
+ return stream.readTypeZipLimits
313
+ end
314
+ end
315
+
316
+ # The Enum type CompilationMode.
317
+
318
+ def self.check_lower_TypeCompilationMode(v)
319
+ end
320
+
321
+ def self.alloc_from_TypeCompilationMode(v)
322
+ RustBuffer.allocWithBuilder do |builder|
323
+ builder.write_TypeCompilationMode(v)
324
+ return builder.finalize
325
+ end
326
+ end
327
+
328
+ def consumeIntoTypeCompilationMode
329
+ consumeWithStream do |stream|
330
+ return stream.readTypeCompilationMode
331
+ end
332
+ end
333
+
334
+
335
+ # The Enum type DiagnosticColor.
336
+
337
+ def self.check_lower_TypeDiagnosticColor(v)
338
+ end
339
+
340
+ def self.alloc_from_TypeDiagnosticColor(v)
341
+ RustBuffer.allocWithBuilder do |builder|
342
+ builder.write_TypeDiagnosticColor(v)
343
+ return builder.finalize
344
+ end
345
+ end
346
+
347
+ def consumeIntoTypeDiagnosticColor
348
+ consumeWithStream do |stream|
349
+ return stream.readTypeDiagnosticColor
350
+ end
351
+ end
352
+
353
+
354
+ # The Enum type DiagnosticSeverity.
355
+
356
+ def self.check_lower_TypeDiagnosticSeverity(v)
357
+ end
358
+
359
+ def self.alloc_from_TypeDiagnosticSeverity(v)
360
+ RustBuffer.allocWithBuilder do |builder|
361
+ builder.write_TypeDiagnosticSeverity(v)
362
+ return builder.finalize
363
+ end
364
+ end
365
+
366
+ def consumeIntoTypeDiagnosticSeverity
367
+ consumeWithStream do |stream|
368
+ return stream.readTypeDiagnosticSeverity
369
+ end
370
+ end
371
+
372
+
373
+ # The Enum type ExportFormat.
374
+
375
+ def self.check_lower_TypeExportFormat(v)
376
+ if v.pdf?
377
+ return
378
+ end
379
+ if v.png?
380
+
381
+ return
382
+ end
383
+ if v.svg?
384
+ return
385
+ end
386
+ end
387
+
388
+ def self.alloc_from_TypeExportFormat(v)
389
+ RustBuffer.allocWithBuilder do |builder|
390
+ builder.write_TypeExportFormat(v)
391
+ return builder.finalize
392
+ end
393
+ end
394
+
395
+ def consumeIntoTypeExportFormat
396
+ consumeWithStream do |stream|
397
+ return stream.readTypeExportFormat
398
+ end
399
+ end
400
+
401
+
402
+
403
+
404
+ # The Optional<T> type for u64.
405
+
406
+ def self.check_lower_Optionalu64(v)
407
+ if not v.nil?
408
+
409
+ end
410
+ end
411
+
412
+ def self.alloc_from_Optionalu64(v)
413
+ RustBuffer.allocWithBuilder do |builder|
414
+ builder.write_Optionalu64(v)
415
+ return builder.finalize()
416
+ end
417
+ end
418
+
419
+ def consumeIntoOptionalu64
420
+ consumeWithStream do |stream|
421
+ return stream.readOptionalu64
422
+ end
423
+ end
424
+
425
+ # The Optional<T> type for string.
426
+
427
+ def self.check_lower_Optionalstring(v)
428
+ if not v.nil?
429
+
430
+ end
431
+ end
432
+
433
+ def self.alloc_from_Optionalstring(v)
434
+ RustBuffer.allocWithBuilder do |builder|
435
+ builder.write_Optionalstring(v)
436
+ return builder.finalize()
437
+ end
438
+ end
439
+
440
+ def consumeIntoOptionalstring
441
+ consumeWithStream do |stream|
442
+ return stream.readOptionalstring
443
+ end
444
+ end
445
+
446
+ # The Optional<T> type for TypePageRange.
447
+
448
+ def self.check_lower_OptionalTypePageRange(v)
449
+ if not v.nil?
450
+ RustBuffer.check_lower_TypePageRange(v)
451
+ end
452
+ end
453
+
454
+ def self.alloc_from_OptionalTypePageRange(v)
455
+ RustBuffer.allocWithBuilder do |builder|
456
+ builder.write_OptionalTypePageRange(v)
457
+ return builder.finalize()
458
+ end
459
+ end
460
+
461
+ def consumeIntoOptionalTypePageRange
462
+ consumeWithStream do |stream|
463
+ return stream.readOptionalTypePageRange
464
+ end
465
+ end
466
+
467
+ # The Optional<T> type for TypeSourceLocation.
468
+
469
+ def self.check_lower_OptionalTypeSourceLocation(v)
470
+ if not v.nil?
471
+ RustBuffer.check_lower_TypeSourceLocation(v)
472
+ end
473
+ end
474
+
475
+ def self.alloc_from_OptionalTypeSourceLocation(v)
476
+ RustBuffer.allocWithBuilder do |builder|
477
+ builder.write_OptionalTypeSourceLocation(v)
478
+ return builder.finalize()
479
+ end
480
+ end
481
+
482
+ def consumeIntoOptionalTypeSourceLocation
483
+ consumeWithStream do |stream|
484
+ return stream.readOptionalTypeSourceLocation
485
+ end
486
+ end
487
+
488
+ # The Optional<T> type for TypeZipLimits.
489
+
490
+ def self.check_lower_OptionalTypeZipLimits(v)
491
+ if not v.nil?
492
+ RustBuffer.check_lower_TypeZipLimits(v)
493
+ end
494
+ end
495
+
496
+ def self.alloc_from_OptionalTypeZipLimits(v)
497
+ RustBuffer.allocWithBuilder do |builder|
498
+ builder.write_OptionalTypeZipLimits(v)
499
+ return builder.finalize()
500
+ end
501
+ end
502
+
503
+ def consumeIntoOptionalTypeZipLimits
504
+ consumeWithStream do |stream|
505
+ return stream.readOptionalTypeZipLimits
506
+ end
507
+ end
508
+
509
+ # The Sequence<T> type for string.
510
+
511
+ def self.check_lower_Sequencestring(v)
512
+ v.each do |item|
513
+
514
+ end
515
+ end
516
+
517
+ def self.alloc_from_Sequencestring(v)
518
+ RustBuffer.allocWithBuilder do |builder|
519
+ builder.write_Sequencestring(v)
520
+ return builder.finalize()
521
+ end
522
+ end
523
+
524
+ def consumeIntoSequencestring
525
+ consumeWithStream do |stream|
526
+ return stream.readSequencestring
527
+ end
528
+ end
529
+
530
+ # The Sequence<T> type for bytes.
531
+
532
+ def self.check_lower_Sequencebytes(v)
533
+ v.each do |item|
534
+
535
+ end
536
+ end
537
+
538
+ def self.alloc_from_Sequencebytes(v)
539
+ RustBuffer.allocWithBuilder do |builder|
540
+ builder.write_Sequencebytes(v)
541
+ return builder.finalize()
542
+ end
543
+ end
544
+
545
+ def consumeIntoSequencebytes
546
+ consumeWithStream do |stream|
547
+ return stream.readSequencebytes
548
+ end
549
+ end
550
+
551
+ # The Sequence<T> type for TypeDiagnostic.
552
+
553
+ def self.check_lower_SequenceTypeDiagnostic(v)
554
+ v.each do |item|
555
+ RustBuffer.check_lower_TypeDiagnostic(item)
556
+ end
557
+ end
558
+
559
+ def self.alloc_from_SequenceTypeDiagnostic(v)
560
+ RustBuffer.allocWithBuilder do |builder|
561
+ builder.write_SequenceTypeDiagnostic(v)
562
+ return builder.finalize()
563
+ end
564
+ end
565
+
566
+ def consumeIntoSequenceTypeDiagnostic
567
+ consumeWithStream do |stream|
568
+ return stream.readSequenceTypeDiagnostic
569
+ end
570
+ end
571
+
572
+ # The Sequence<T> type for TypePageSize.
573
+
574
+ def self.check_lower_SequenceTypePageSize(v)
575
+ v.each do |item|
576
+ RustBuffer.check_lower_TypePageSize(item)
577
+ end
578
+ end
579
+
580
+ def self.alloc_from_SequenceTypePageSize(v)
581
+ RustBuffer.allocWithBuilder do |builder|
582
+ builder.write_SequenceTypePageSize(v)
583
+ return builder.finalize()
584
+ end
585
+ end
586
+
587
+ def consumeIntoSequenceTypePageSize
588
+ consumeWithStream do |stream|
589
+ return stream.readSequenceTypePageSize
590
+ end
591
+ end
592
+
593
+ # The Sequence<T> type for TypeRegisteredFont.
594
+
595
+ def self.check_lower_SequenceTypeRegisteredFont(v)
596
+ v.each do |item|
597
+ RustBuffer.check_lower_TypeRegisteredFont(item)
598
+ end
599
+ end
600
+
601
+ def self.alloc_from_SequenceTypeRegisteredFont(v)
602
+ RustBuffer.allocWithBuilder do |builder|
603
+ builder.write_SequenceTypeRegisteredFont(v)
604
+ return builder.finalize()
605
+ end
606
+ end
607
+
608
+ def consumeIntoSequenceTypeRegisteredFont
609
+ consumeWithStream do |stream|
610
+ return stream.readSequenceTypeRegisteredFont
611
+ end
612
+ end
613
+
614
+ # The Sequence<T> type for TypeTracePoint.
615
+
616
+ def self.check_lower_SequenceTypeTracePoint(v)
617
+ v.each do |item|
618
+ RustBuffer.check_lower_TypeTracePoint(item)
619
+ end
620
+ end
621
+
622
+ def self.alloc_from_SequenceTypeTracePoint(v)
623
+ RustBuffer.allocWithBuilder do |builder|
624
+ builder.write_SequenceTypeTracePoint(v)
625
+ return builder.finalize()
626
+ end
627
+ end
628
+
629
+ def consumeIntoSequenceTypeTracePoint
630
+ consumeWithStream do |stream|
631
+ return stream.readSequenceTypeTracePoint
632
+ end
633
+ end
634
+
635
+ # The Map<T> type for string.
636
+
637
+ def self.check_lower_MapStringString(v)
638
+ v.each do |k, v|
639
+
640
+
641
+ end
642
+ end
643
+
644
+ def self.alloc_from_MapStringString(v)
645
+ RustBuffer.allocWithBuilder do |builder|
646
+ builder.write_MapStringString(v)
647
+ return builder.finalize
648
+ end
649
+ end
650
+
651
+ def consumeIntoMapStringString
652
+ consumeWithStream do |stream|
653
+ return stream.readMapStringString
654
+ end
655
+ end# The Map<T> type for TypeBlobInput.
656
+
657
+ def self.check_lower_MapStringTypeBlobInput(v)
658
+ v.each do |k, v|
659
+
660
+ RustBuffer.check_lower_TypeBlobInput(v)
661
+ end
662
+ end
663
+
664
+ def self.alloc_from_MapStringTypeBlobInput(v)
665
+ RustBuffer.allocWithBuilder do |builder|
666
+ builder.write_MapStringTypeBlobInput(v)
667
+ return builder.finalize
668
+ end
669
+ end
670
+
671
+ def consumeIntoMapStringTypeBlobInput
672
+ consumeWithStream do |stream|
673
+ return stream.readMapStringTypeBlobInput
674
+ end
675
+ end
676
+ end
677
+
678
+ module UniFFILib
679
+ class ForeignBytes < FFI::Struct
680
+ layout :len, :int32,
681
+ :data, :pointer
682
+
683
+ def len
684
+ self[:len]
685
+ end
686
+
687
+ def data
688
+ self[:data]
689
+ end
690
+
691
+ def to_s
692
+ "ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
693
+ end
694
+ end
695
+ end
696
+
697
+ private_constant :UniFFILib
698
+
699
+ # Helper for structured reading of values from a RustBuffer.
700
+ class RustBufferStream
701
+
702
+ def initialize(rbuf)
703
+ @rbuf = rbuf
704
+ @offset = 0
705
+ end
706
+
707
+ def remaining
708
+ @rbuf.len - @offset
709
+ end
710
+
711
+ def read(size)
712
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
713
+
714
+ data = @rbuf.data.get_bytes @offset, size
715
+
716
+ @offset += size
717
+
718
+ data
719
+ end
720
+
721
+ def readU32
722
+ unpack_from 4, 'L>'
723
+ end
724
+
725
+ def readU64
726
+ unpack_from 8, 'Q>'
727
+ end
728
+
729
+ def readF32
730
+ unpack_from 4, 'g'
731
+ end
732
+
733
+ def readF64
734
+ unpack_from 8, 'G'
735
+ end
736
+
737
+ def readBool
738
+ v = unpack_from 1, 'c'
739
+
740
+ return false if v == 0
741
+ return true if v == 1
742
+
743
+ raise InternalError, 'Unexpected byte for Boolean type'
744
+ end
745
+
746
+ def readString
747
+ size = unpack_from 4, 'l>'
748
+
749
+ raise InternalError, 'Unexpected negative string length' if size.negative?
750
+
751
+ read(size).force_encoding(Encoding::UTF_8)
752
+ end
753
+
754
+ def readBytes
755
+ size = unpack_from 4, 'l>'
756
+
757
+ raise InternalError, 'Unexpected negative byte string length' if size.negative?
758
+
759
+ read(size).force_encoding(Encoding::BINARY)
760
+ end
761
+
762
+ # The Object type CompiledDocument.
763
+
764
+ def readTypeCompiledDocument
765
+ handle = unpack_from 8, 'Q>'
766
+ return CompiledDocument.uniffi_allocate(handle)
767
+ end
768
+
769
+ # The Object type Template.
770
+
771
+ def readTypeTemplate
772
+ handle = unpack_from 8, 'Q>'
773
+ return Template.uniffi_allocate(handle)
774
+ end
775
+
776
+ # The Record type BlobInput.
777
+
778
+ def readTypeBlobInput
779
+ BlobInput.new(
780
+ data: readBytes,
781
+ metadata: readString
782
+ )
783
+ end
784
+
785
+ # The Record type Diagnostic.
786
+
787
+ def readTypeDiagnostic
788
+ Diagnostic.new(
789
+ severity: readTypeDiagnosticSeverity,
790
+ message: readString,
791
+ location: readOptionalTypeSourceLocation,
792
+ hints: readSequencestring,
793
+ trace: readSequenceTypeTracePoint,
794
+ formatted: readString
795
+ )
796
+ end
797
+
798
+ # The Record type ExportOnceResult.
799
+
800
+ def readTypeExportOnceResult
801
+ ExportOnceResult.new(
802
+ bytes: readBytes,
803
+ warnings: readSequenceTypeDiagnostic
804
+ )
805
+ end
806
+
807
+ # The Record type PageRange.
808
+
809
+ def readTypePageRange
810
+ PageRange.new(
811
+ start: readOptionalu64,
812
+ _end: readOptionalu64
813
+ )
814
+ end
815
+
816
+ # The Record type PageSize.
817
+
818
+ def readTypePageSize
819
+ PageSize.new(
820
+ width: readF64,
821
+ height: readF64
822
+ )
823
+ end
824
+
825
+ # The Record type RegisteredFont.
826
+
827
+ def readTypeRegisteredFont
828
+ RegisteredFont.new(
829
+ family: readString,
830
+ path: readOptionalstring
831
+ )
832
+ end
833
+
834
+ # The Record type SourceLocation.
835
+
836
+ def readTypeSourceLocation
837
+ SourceLocation.new(
838
+ file: readString,
839
+ line: readU32,
840
+ column: readU32,
841
+ end_line: readU32,
842
+ end_column: readU32
843
+ )
844
+ end
845
+
846
+ # The Record type TracePoint.
847
+
848
+ def readTypeTracePoint
849
+ TracePoint.new(
850
+ message: readString,
851
+ location: readOptionalTypeSourceLocation
852
+ )
853
+ end
854
+
855
+ # The Record type ZipLimits.
856
+
857
+ def readTypeZipLimits
858
+ ZipLimits.new(
859
+ max_entries: readOptionalu64,
860
+ max_total_decompressed_bytes: readOptionalu64
861
+ )
862
+ end
863
+
864
+
865
+
866
+ # The Enum type CompilationMode.
867
+
868
+ def readTypeCompilationMode
869
+ variant = unpack_from 4, 'l>'
870
+
871
+ if variant == 1
872
+ return CompilationMode::DEVELOPMENT
873
+ end
874
+ if variant == 2
875
+ return CompilationMode::PRODUCTION
876
+ end
877
+
878
+ raise InternalError, 'Unexpected variant tag for TypeCompilationMode'
879
+ end
880
+
881
+
882
+
883
+
884
+
885
+ # The Enum type DiagnosticColor.
886
+
887
+ def readTypeDiagnosticColor
888
+ variant = unpack_from 4, 'l>'
889
+
890
+ if variant == 1
891
+ return DiagnosticColor::NONE
892
+ end
893
+ if variant == 2
894
+ return DiagnosticColor::ANSI
895
+ end
896
+
897
+ raise InternalError, 'Unexpected variant tag for TypeDiagnosticColor'
898
+ end
899
+
900
+
901
+
902
+
903
+
904
+ # The Enum type DiagnosticSeverity.
905
+
906
+ def readTypeDiagnosticSeverity
907
+ variant = unpack_from 4, 'l>'
908
+
909
+ if variant == 1
910
+ return DiagnosticSeverity::ERROR
911
+ end
912
+ if variant == 2
913
+ return DiagnosticSeverity::WARNING
914
+ end
915
+
916
+ raise InternalError, 'Unexpected variant tag for TypeDiagnosticSeverity'
917
+ end
918
+
919
+
920
+
921
+
922
+
923
+ # The Enum type ExportFormat.
924
+
925
+ def readTypeExportFormat
926
+ variant = unpack_from 4, 'l>'
927
+
928
+ if variant == 1
929
+ return ExportFormat::PDF.new
930
+
931
+ end
932
+ if variant == 2
933
+ return ExportFormat::PNG.new(
934
+ self.readF32()
935
+ )
936
+ end
937
+ if variant == 3
938
+ return ExportFormat::SVG.new
939
+
940
+ end
941
+ raise InternalError, 'Unexpected variant tag for TypeExportFormat'
942
+ end
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+ # The Error type OicanaError
951
+
952
+ def readTypeOicanaError
953
+ variant = unpack_from 4, 'l>'
954
+
955
+ if variant == 1
956
+ return OicanaError::InvalidTemplate.new(
957
+ readString()
958
+ )
959
+ end
960
+ if variant == 2
961
+ return OicanaError::InvalidInput.new(
962
+ readString()
963
+ )
964
+ end
965
+ if variant == 3
966
+ return OicanaError::Compilation.new(
967
+ readString()
968
+ )
969
+ end
970
+ if variant == 4
971
+ return OicanaError::FileNotFound.new(
972
+ readString()
973
+ )
974
+ end
975
+ if variant == 5
976
+ return OicanaError::Export.new(
977
+ readString()
978
+ )
979
+ end
980
+ if variant == 6
981
+ return OicanaError::NotFound.new(
982
+ readString()
983
+ )
984
+ end
985
+ if variant == 7
986
+ return OicanaError::Internal.new(
987
+ readString()
988
+ )
989
+ end
990
+
991
+ raise InternalError, 'Unexpected variant tag for TypeOicanaError'
992
+ end
993
+
994
+
995
+ # The Optional<T> type for u64.
996
+
997
+ def readOptionalu64
998
+ flag = unpack_from 1, 'c'
999
+
1000
+ if flag == 0
1001
+ return nil
1002
+ elsif flag == 1
1003
+ return readU64
1004
+ else
1005
+ raise InternalError, 'Unexpected flag byte for Optionalu64'
1006
+ end
1007
+ end
1008
+
1009
+ # The Optional<T> type for string.
1010
+
1011
+ def readOptionalstring
1012
+ flag = unpack_from 1, 'c'
1013
+
1014
+ if flag == 0
1015
+ return nil
1016
+ elsif flag == 1
1017
+ return readString
1018
+ else
1019
+ raise InternalError, 'Unexpected flag byte for Optionalstring'
1020
+ end
1021
+ end
1022
+
1023
+ # The Optional<T> type for TypePageRange.
1024
+
1025
+ def readOptionalTypePageRange
1026
+ flag = unpack_from 1, 'c'
1027
+
1028
+ if flag == 0
1029
+ return nil
1030
+ elsif flag == 1
1031
+ return readTypePageRange
1032
+ else
1033
+ raise InternalError, 'Unexpected flag byte for OptionalTypePageRange'
1034
+ end
1035
+ end
1036
+
1037
+ # The Optional<T> type for TypeSourceLocation.
1038
+
1039
+ def readOptionalTypeSourceLocation
1040
+ flag = unpack_from 1, 'c'
1041
+
1042
+ if flag == 0
1043
+ return nil
1044
+ elsif flag == 1
1045
+ return readTypeSourceLocation
1046
+ else
1047
+ raise InternalError, 'Unexpected flag byte for OptionalTypeSourceLocation'
1048
+ end
1049
+ end
1050
+
1051
+ # The Optional<T> type for TypeZipLimits.
1052
+
1053
+ def readOptionalTypeZipLimits
1054
+ flag = unpack_from 1, 'c'
1055
+
1056
+ if flag == 0
1057
+ return nil
1058
+ elsif flag == 1
1059
+ return readTypeZipLimits
1060
+ else
1061
+ raise InternalError, 'Unexpected flag byte for OptionalTypeZipLimits'
1062
+ end
1063
+ end
1064
+
1065
+ # The Sequence<T> type for string.
1066
+
1067
+ def readSequencestring
1068
+ count = unpack_from 4, 'l>'
1069
+
1070
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1071
+
1072
+ items = []
1073
+
1074
+ count.times do
1075
+ items.append readString
1076
+ end
1077
+
1078
+ items
1079
+ end
1080
+
1081
+ # The Sequence<T> type for bytes.
1082
+
1083
+ def readSequencebytes
1084
+ count = unpack_from 4, 'l>'
1085
+
1086
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1087
+
1088
+ items = []
1089
+
1090
+ count.times do
1091
+ items.append readBytes
1092
+ end
1093
+
1094
+ items
1095
+ end
1096
+
1097
+ # The Sequence<T> type for TypeDiagnostic.
1098
+
1099
+ def readSequenceTypeDiagnostic
1100
+ count = unpack_from 4, 'l>'
1101
+
1102
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1103
+
1104
+ items = []
1105
+
1106
+ count.times do
1107
+ items.append readTypeDiagnostic
1108
+ end
1109
+
1110
+ items
1111
+ end
1112
+
1113
+ # The Sequence<T> type for TypePageSize.
1114
+
1115
+ def readSequenceTypePageSize
1116
+ count = unpack_from 4, 'l>'
1117
+
1118
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1119
+
1120
+ items = []
1121
+
1122
+ count.times do
1123
+ items.append readTypePageSize
1124
+ end
1125
+
1126
+ items
1127
+ end
1128
+
1129
+ # The Sequence<T> type for TypeRegisteredFont.
1130
+
1131
+ def readSequenceTypeRegisteredFont
1132
+ count = unpack_from 4, 'l>'
1133
+
1134
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1135
+
1136
+ items = []
1137
+
1138
+ count.times do
1139
+ items.append readTypeRegisteredFont
1140
+ end
1141
+
1142
+ items
1143
+ end
1144
+
1145
+ # The Sequence<T> type for TypeTracePoint.
1146
+
1147
+ def readSequenceTypeTracePoint
1148
+ count = unpack_from 4, 'l>'
1149
+
1150
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1151
+
1152
+ items = []
1153
+
1154
+ count.times do
1155
+ items.append readTypeTracePoint
1156
+ end
1157
+
1158
+ items
1159
+ end
1160
+
1161
+ # The Map<T> type for string.
1162
+
1163
+ def readMapStringString
1164
+ count = unpack_from 4, 'l>'
1165
+ raise InternalError, 'Unexpected negative map size' if count.negative?
1166
+
1167
+ items = {}
1168
+ count.times do
1169
+ key = readString
1170
+ items[key] = readString
1171
+ end
1172
+
1173
+ items
1174
+ end# The Map<T> type for TypeBlobInput.
1175
+
1176
+ def readMapStringTypeBlobInput
1177
+ count = unpack_from 4, 'l>'
1178
+ raise InternalError, 'Unexpected negative map size' if count.negative?
1179
+
1180
+ items = {}
1181
+ count.times do
1182
+ key = readString
1183
+ items[key] = readTypeBlobInput
1184
+ end
1185
+
1186
+ items
1187
+ end
1188
+
1189
+ def unpack_from(size, format)
1190
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
1191
+
1192
+ value = @rbuf.data.get_bytes(@offset, size).unpack format
1193
+
1194
+ @offset += size
1195
+
1196
+ # TODO: verify this
1197
+ raise 'more than one element!!!' if value.size > 1
1198
+
1199
+ value[0]
1200
+ end
1201
+ end
1202
+
1203
+ private_constant :RustBufferStream
1204
+
1205
+ # Helper for structured writing of values into a RustBuffer.
1206
+ class RustBufferBuilder
1207
+ def initialize
1208
+ @rust_buf = RustBuffer.alloc 16
1209
+ @rust_buf.len = 0
1210
+ end
1211
+
1212
+ def finalize
1213
+ rbuf = @rust_buf
1214
+
1215
+ @rust_buf = nil
1216
+
1217
+ rbuf
1218
+ end
1219
+
1220
+ def discard
1221
+ return if @rust_buf.nil?
1222
+
1223
+ rbuf = finalize
1224
+ rbuf.free
1225
+ end
1226
+
1227
+ def write(value)
1228
+ reserve(value.bytes.size) do
1229
+ @rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
1230
+ end
1231
+ end
1232
+
1233
+ def write_U32(v)
1234
+ v = OicanaUniffi::uniffi_in_range(v, "u32", 0, 2**32)
1235
+ pack_into(4, 'L>', v)
1236
+ end
1237
+
1238
+ def write_U64(v)
1239
+ v = OicanaUniffi::uniffi_in_range(v, "u64", 0, 2**64)
1240
+ pack_into(8, 'Q>', v)
1241
+ end
1242
+
1243
+ def write_F32(v)
1244
+ pack_into(4, 'g', v)
1245
+ end
1246
+
1247
+ def write_F64(v)
1248
+ pack_into(8, 'G', v)
1249
+ end
1250
+
1251
+ def write_Bool(v)
1252
+ pack_into(1, 'c', v ? 1 : 0)
1253
+ end
1254
+
1255
+ def write_String(v)
1256
+ v = OicanaUniffi::uniffi_utf8(v)
1257
+ pack_into 4, 'l>', v.bytes.size
1258
+ write v
1259
+ end
1260
+
1261
+ def write_Bytes(v)
1262
+ v = OicanaUniffi::uniffi_bytes(v)
1263
+ pack_into 4, 'l>', v.bytes.size
1264
+ write v
1265
+ end
1266
+
1267
+ # The Object type CompiledDocument.
1268
+
1269
+ def write_TypeCompiledDocument(obj)
1270
+ handle = CompiledDocument.uniffi_lower obj
1271
+ pack_into(8, 'Q>', handle)
1272
+ end
1273
+
1274
+ # The Object type Template.
1275
+
1276
+ def write_TypeTemplate(obj)
1277
+ handle = Template.uniffi_lower obj
1278
+ pack_into(8, 'Q>', handle)
1279
+ end
1280
+
1281
+ # The Record type BlobInput.
1282
+
1283
+ def write_TypeBlobInput(v)
1284
+ self.write_Bytes(v.data)
1285
+ self.write_String(v.metadata)
1286
+ end
1287
+
1288
+ # The Record type Diagnostic.
1289
+
1290
+ def write_TypeDiagnostic(v)
1291
+ self.write_TypeDiagnosticSeverity(v.severity)
1292
+ self.write_String(v.message)
1293
+ self.write_OptionalTypeSourceLocation(v.location)
1294
+ self.write_Sequencestring(v.hints)
1295
+ self.write_SequenceTypeTracePoint(v.trace)
1296
+ self.write_String(v.formatted)
1297
+ end
1298
+
1299
+ # The Record type ExportOnceResult.
1300
+
1301
+ def write_TypeExportOnceResult(v)
1302
+ self.write_Bytes(v.bytes)
1303
+ self.write_SequenceTypeDiagnostic(v.warnings)
1304
+ end
1305
+
1306
+ # The Record type PageRange.
1307
+
1308
+ def write_TypePageRange(v)
1309
+ self.write_Optionalu64(v.start)
1310
+ self.write_Optionalu64(v._end)
1311
+ end
1312
+
1313
+ # The Record type PageSize.
1314
+
1315
+ def write_TypePageSize(v)
1316
+ self.write_F64(v.width)
1317
+ self.write_F64(v.height)
1318
+ end
1319
+
1320
+ # The Record type RegisteredFont.
1321
+
1322
+ def write_TypeRegisteredFont(v)
1323
+ self.write_String(v.family)
1324
+ self.write_Optionalstring(v.path)
1325
+ end
1326
+
1327
+ # The Record type SourceLocation.
1328
+
1329
+ def write_TypeSourceLocation(v)
1330
+ self.write_String(v.file)
1331
+ self.write_U32(v.line)
1332
+ self.write_U32(v.column)
1333
+ self.write_U32(v.end_line)
1334
+ self.write_U32(v.end_column)
1335
+ end
1336
+
1337
+ # The Record type TracePoint.
1338
+
1339
+ def write_TypeTracePoint(v)
1340
+ self.write_String(v.message)
1341
+ self.write_OptionalTypeSourceLocation(v.location)
1342
+ end
1343
+
1344
+ # The Record type ZipLimits.
1345
+
1346
+ def write_TypeZipLimits(v)
1347
+ self.write_Optionalu64(v.max_entries)
1348
+ self.write_Optionalu64(v.max_total_decompressed_bytes)
1349
+ end
1350
+
1351
+ # The Enum type CompilationMode.
1352
+
1353
+ def write_TypeCompilationMode(v)
1354
+ pack_into(4, 'l>', v)
1355
+ end
1356
+
1357
+
1358
+ # The Enum type DiagnosticColor.
1359
+
1360
+ def write_TypeDiagnosticColor(v)
1361
+ pack_into(4, 'l>', v)
1362
+ end
1363
+
1364
+
1365
+ # The Enum type DiagnosticSeverity.
1366
+
1367
+ def write_TypeDiagnosticSeverity(v)
1368
+ pack_into(4, 'l>', v)
1369
+ end
1370
+
1371
+
1372
+ # The Enum type ExportFormat.
1373
+
1374
+ def write_TypeExportFormat(v)
1375
+ if v.pdf?
1376
+ pack_into(4, 'l>', 1)
1377
+ end
1378
+ if v.png?
1379
+ pack_into(4, 'l>', 2)
1380
+ self.write_F32(v.pixels_per_pt)
1381
+ end
1382
+ if v.svg?
1383
+ pack_into(4, 'l>', 3)
1384
+ end
1385
+ end
1386
+
1387
+
1388
+
1389
+
1390
+ # The Optional<T> type for u64.
1391
+
1392
+ def write_Optionalu64(v)
1393
+ if v.nil?
1394
+ pack_into(1, 'c', 0)
1395
+ else
1396
+ pack_into(1, 'c', 1)
1397
+ self.write_U64(v)
1398
+ end
1399
+ end
1400
+
1401
+ # The Optional<T> type for string.
1402
+
1403
+ def write_Optionalstring(v)
1404
+ if v.nil?
1405
+ pack_into(1, 'c', 0)
1406
+ else
1407
+ pack_into(1, 'c', 1)
1408
+ self.write_String(v)
1409
+ end
1410
+ end
1411
+
1412
+ # The Optional<T> type for TypePageRange.
1413
+
1414
+ def write_OptionalTypePageRange(v)
1415
+ if v.nil?
1416
+ pack_into(1, 'c', 0)
1417
+ else
1418
+ pack_into(1, 'c', 1)
1419
+ self.write_TypePageRange(v)
1420
+ end
1421
+ end
1422
+
1423
+ # The Optional<T> type for TypeSourceLocation.
1424
+
1425
+ def write_OptionalTypeSourceLocation(v)
1426
+ if v.nil?
1427
+ pack_into(1, 'c', 0)
1428
+ else
1429
+ pack_into(1, 'c', 1)
1430
+ self.write_TypeSourceLocation(v)
1431
+ end
1432
+ end
1433
+
1434
+ # The Optional<T> type for TypeZipLimits.
1435
+
1436
+ def write_OptionalTypeZipLimits(v)
1437
+ if v.nil?
1438
+ pack_into(1, 'c', 0)
1439
+ else
1440
+ pack_into(1, 'c', 1)
1441
+ self.write_TypeZipLimits(v)
1442
+ end
1443
+ end
1444
+
1445
+ # The Sequence<T> type for string.
1446
+
1447
+ def write_Sequencestring(items)
1448
+ pack_into(4, 'l>', items.size)
1449
+
1450
+ items.each do |item|
1451
+ self.write_String(item)
1452
+ end
1453
+ end
1454
+
1455
+ # The Sequence<T> type for bytes.
1456
+
1457
+ def write_Sequencebytes(items)
1458
+ pack_into(4, 'l>', items.size)
1459
+
1460
+ items.each do |item|
1461
+ self.write_Bytes(item)
1462
+ end
1463
+ end
1464
+
1465
+ # The Sequence<T> type for TypeDiagnostic.
1466
+
1467
+ def write_SequenceTypeDiagnostic(items)
1468
+ pack_into(4, 'l>', items.size)
1469
+
1470
+ items.each do |item|
1471
+ self.write_TypeDiagnostic(item)
1472
+ end
1473
+ end
1474
+
1475
+ # The Sequence<T> type for TypePageSize.
1476
+
1477
+ def write_SequenceTypePageSize(items)
1478
+ pack_into(4, 'l>', items.size)
1479
+
1480
+ items.each do |item|
1481
+ self.write_TypePageSize(item)
1482
+ end
1483
+ end
1484
+
1485
+ # The Sequence<T> type for TypeRegisteredFont.
1486
+
1487
+ def write_SequenceTypeRegisteredFont(items)
1488
+ pack_into(4, 'l>', items.size)
1489
+
1490
+ items.each do |item|
1491
+ self.write_TypeRegisteredFont(item)
1492
+ end
1493
+ end
1494
+
1495
+ # The Sequence<T> type for TypeTracePoint.
1496
+
1497
+ def write_SequenceTypeTracePoint(items)
1498
+ pack_into(4, 'l>', items.size)
1499
+
1500
+ items.each do |item|
1501
+ self.write_TypeTracePoint(item)
1502
+ end
1503
+ end
1504
+
1505
+ # The Map<T> type for string.
1506
+
1507
+ def write_MapStringString(items)
1508
+ pack_into(4, 'l>', items.size)
1509
+
1510
+ items.each do |k, v|
1511
+ write_String(k)
1512
+ self.write_String(v)
1513
+ end
1514
+ end# The Map<T> type for TypeBlobInput.
1515
+
1516
+ def write_MapStringTypeBlobInput(items)
1517
+ pack_into(4, 'l>', items.size)
1518
+
1519
+ items.each do |k, v|
1520
+ write_String(k)
1521
+ self.write_TypeBlobInput(v)
1522
+ end
1523
+ end
1524
+
1525
+ private
1526
+
1527
+ def reserve(num_bytes)
1528
+ if @rust_buf.len + num_bytes > @rust_buf.capacity
1529
+ @rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
1530
+ end
1531
+
1532
+ yield
1533
+
1534
+ @rust_buf.len += num_bytes
1535
+ end
1536
+
1537
+ def pack_into(size, format, value)
1538
+ reserve(size) do
1539
+ @rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
1540
+ end
1541
+ end
1542
+ end
1543
+
1544
+ private_constant :RustBufferBuilder
1545
+
1546
+ # Error definitions
1547
+ class RustCallStatus < FFI::Struct
1548
+ layout :code, :int8,
1549
+ :error_buf, RustBuffer
1550
+
1551
+ def code
1552
+ self[:code]
1553
+ end
1554
+
1555
+ def error_buf
1556
+ self[:error_buf]
1557
+ end
1558
+
1559
+ def to_s
1560
+ "RustCallStatus(code=#{self[:code]})"
1561
+ end
1562
+ end
1563
+
1564
+ # These match the values from the uniffi::rustcalls module
1565
+ CALL_SUCCESS = 0
1566
+ CALL_ERROR = 1
1567
+ CALL_PANIC = 2
1568
+
1569
+
1570
+ module OicanaError
1571
+ class InvalidTemplate < StandardError
1572
+ def initialize(message)
1573
+ @message = message
1574
+ super()
1575
+ end
1576
+
1577
+ attr_reader :message
1578
+
1579
+
1580
+ def to_s
1581
+ "#{self.class.name}(message=#{@message.inspect})"
1582
+ end
1583
+ end
1584
+ class InvalidInput < StandardError
1585
+ def initialize(message)
1586
+ @message = message
1587
+ super()
1588
+ end
1589
+
1590
+ attr_reader :message
1591
+
1592
+
1593
+ def to_s
1594
+ "#{self.class.name}(message=#{@message.inspect})"
1595
+ end
1596
+ end
1597
+ class Compilation < StandardError
1598
+ def initialize(message)
1599
+ @message = message
1600
+ super()
1601
+ end
1602
+
1603
+ attr_reader :message
1604
+
1605
+
1606
+ def to_s
1607
+ "#{self.class.name}(message=#{@message.inspect})"
1608
+ end
1609
+ end
1610
+ class FileNotFound < StandardError
1611
+ def initialize(message)
1612
+ @message = message
1613
+ super()
1614
+ end
1615
+
1616
+ attr_reader :message
1617
+
1618
+
1619
+ def to_s
1620
+ "#{self.class.name}(message=#{@message.inspect})"
1621
+ end
1622
+ end
1623
+ class Export < StandardError
1624
+ def initialize(message)
1625
+ @message = message
1626
+ super()
1627
+ end
1628
+
1629
+ attr_reader :message
1630
+
1631
+
1632
+ def to_s
1633
+ "#{self.class.name}(message=#{@message.inspect})"
1634
+ end
1635
+ end
1636
+ class NotFound < StandardError
1637
+ def initialize(message)
1638
+ @message = message
1639
+ super()
1640
+ end
1641
+
1642
+ attr_reader :message
1643
+
1644
+
1645
+ def to_s
1646
+ "#{self.class.name}(message=#{@message.inspect})"
1647
+ end
1648
+ end
1649
+ class Internal < StandardError
1650
+ def initialize(message)
1651
+ @message = message
1652
+ super()
1653
+ end
1654
+
1655
+ attr_reader :message
1656
+
1657
+
1658
+ def to_s
1659
+ "#{self.class.name}(message=#{@message.inspect})"
1660
+ end
1661
+ end
1662
+
1663
+ end
1664
+
1665
+
1666
+
1667
+
1668
+
1669
+
1670
+ # Map error modules to the RustBuffer method name that reads them
1671
+ ERROR_MODULE_TO_READER_METHOD = {
1672
+
1673
+ OicanaError => :readTypeOicanaError,
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+ }
1680
+
1681
+ private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
1682
+ :RustCallStatus
1683
+
1684
+ def self.consume_buffer_into_error(error_module, rust_buffer)
1685
+ rust_buffer.consumeWithStream do |stream|
1686
+ reader_method = ERROR_MODULE_TO_READER_METHOD[error_module]
1687
+ return stream.send(reader_method)
1688
+ end
1689
+ end
1690
+
1691
+ class InternalError < StandardError
1692
+ end
1693
+
1694
+ def self.rust_call(fn_name, *args)
1695
+ # Call a rust function
1696
+ rust_call_with_error(nil, fn_name, *args)
1697
+ end
1698
+
1699
+ def self.rust_call_with_error(error_module, fn_name, *args)
1700
+ # Call a rust function and handle errors
1701
+ #
1702
+ # Use this when the rust function returns a Result<>. error_module must be the error_module that corresponds to that Result.
1703
+
1704
+
1705
+ # Note: RustCallStatus.new zeroes out the struct, which is exactly what we
1706
+ # want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
1707
+ # data=NULL))
1708
+ status = RustCallStatus.new
1709
+ args << status
1710
+
1711
+ result = UniFFILib.public_send(fn_name, *args)
1712
+
1713
+ case status.code
1714
+ when CALL_SUCCESS
1715
+ result
1716
+ when CALL_ERROR
1717
+ if error_module.nil?
1718
+ status.error_buf.free
1719
+ raise InternalError, "CALL_ERROR with no error_module set"
1720
+ else
1721
+ raise consume_buffer_into_error(error_module, status.error_buf)
1722
+ end
1723
+ when CALL_PANIC
1724
+ # When the rust code sees a panic, it tries to construct a RustBuffer
1725
+ # with the message. But if that code panics, then it just sends back
1726
+ # an empty buffer.
1727
+ if status.error_buf.len > 0
1728
+ raise InternalError, status.error_buf.consumeIntoString()
1729
+ else
1730
+ raise InternalError, "Rust panic"
1731
+ end
1732
+ else
1733
+ raise InternalError, "Unknown call status: #{status.code}"
1734
+ end
1735
+ end
1736
+
1737
+ private_class_method :consume_buffer_into_error
1738
+
1739
+ # This is how we find and load the dynamic library provided by the component.
1740
+ # For now we just look it up by name.
1741
+ module UniFFILib
1742
+ extend FFI::Library
1743
+
1744
+
1745
+ ffi_lib ::Oicana::Native.prepare(self)
1746
+
1747
+
1748
+ attach_function :uniffi_oicana_uniffi_fn_clone_compileddocument,
1749
+ [:uint64, RustCallStatus.by_ref],
1750
+ :uint64
1751
+ attach_function :uniffi_oicana_uniffi_fn_free_compileddocument,
1752
+ [:uint64, RustCallStatus.by_ref],
1753
+ :void
1754
+ attach_function :uniffi_oicana_uniffi_fn_method_compileddocument_export,
1755
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1756
+ RustBuffer.by_value
1757
+ attach_function :uniffi_oicana_uniffi_fn_method_compileddocument_pages,
1758
+ [:uint64, RustCallStatus.by_ref],
1759
+ RustBuffer.by_value
1760
+ attach_function :uniffi_oicana_uniffi_fn_method_compileddocument_warnings,
1761
+ [:uint64, RustCallStatus.by_ref],
1762
+ RustBuffer.by_value
1763
+ attach_function :uniffi_oicana_uniffi_fn_clone_template,
1764
+ [:uint64, RustCallStatus.by_ref],
1765
+ :uint64
1766
+ attach_function :uniffi_oicana_uniffi_fn_free_template,
1767
+ [:uint64, RustCallStatus.by_ref],
1768
+ :void
1769
+ attach_function :uniffi_oicana_uniffi_fn_constructor_template_new,
1770
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1771
+ :uint64
1772
+ attach_function :uniffi_oicana_uniffi_fn_method_template_compile,
1773
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1774
+ :uint64
1775
+ attach_function :uniffi_oicana_uniffi_fn_method_template_file,
1776
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1777
+ RustBuffer.by_value
1778
+ attach_function :uniffi_oicana_uniffi_fn_method_template_manifest,
1779
+ [:uint64, RustCallStatus.by_ref],
1780
+ RustBuffer.by_value
1781
+ attach_function :uniffi_oicana_uniffi_fn_method_template_set_validate_inputs,
1782
+ [:uint64, :int8, RustCallStatus.by_ref],
1783
+ :void
1784
+ attach_function :uniffi_oicana_uniffi_fn_method_template_source,
1785
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1786
+ RustBuffer.by_value
1787
+ attach_function :uniffi_oicana_uniffi_fn_method_template_warnings,
1788
+ [:uint64, RustCallStatus.by_ref],
1789
+ RustBuffer.by_value
1790
+ attach_function :uniffi_oicana_uniffi_fn_func_clear_fonts,
1791
+ [RustCallStatus.by_ref],
1792
+ :void
1793
+ attach_function :uniffi_oicana_uniffi_fn_func_configure_automatic_cache_eviction,
1794
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1795
+ :void
1796
+ attach_function :uniffi_oicana_uniffi_fn_func_configure_diagnostic_color,
1797
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1798
+ :void
1799
+ attach_function :uniffi_oicana_uniffi_fn_func_evict_cache,
1800
+ [:uint64, RustCallStatus.by_ref],
1801
+ :void
1802
+ attach_function :uniffi_oicana_uniffi_fn_func_export_once,
1803
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1804
+ RustBuffer.by_value
1805
+ attach_function :uniffi_oicana_uniffi_fn_func_register_font_paths,
1806
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1807
+ :uint64
1808
+ attach_function :uniffi_oicana_uniffi_fn_func_register_fonts,
1809
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1810
+ :uint64
1811
+ attach_function :uniffi_oicana_uniffi_fn_func_registered_fonts,
1812
+ [RustCallStatus.by_ref],
1813
+ RustBuffer.by_value
1814
+ attach_function :uniffi_oicana_uniffi_fn_func_version,
1815
+ [RustCallStatus.by_ref],
1816
+ RustBuffer.by_value
1817
+ attach_function :ffi_oicana_uniffi_rustbuffer_alloc,
1818
+ [:uint64, RustCallStatus.by_ref],
1819
+ RustBuffer.by_value
1820
+ attach_function :ffi_oicana_uniffi_rustbuffer_from_bytes,
1821
+ [ForeignBytes, RustCallStatus.by_ref],
1822
+ RustBuffer.by_value
1823
+ attach_function :ffi_oicana_uniffi_rustbuffer_free,
1824
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1825
+ :void
1826
+ attach_function :ffi_oicana_uniffi_rustbuffer_reserve,
1827
+ [RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
1828
+ RustBuffer.by_value
1829
+ attach_function :uniffi_oicana_uniffi_checksum_func_clear_fonts,
1830
+ [RustCallStatus.by_ref],
1831
+ :uint16
1832
+ attach_function :uniffi_oicana_uniffi_checksum_func_configure_automatic_cache_eviction,
1833
+ [RustCallStatus.by_ref],
1834
+ :uint16
1835
+ attach_function :uniffi_oicana_uniffi_checksum_func_configure_diagnostic_color,
1836
+ [RustCallStatus.by_ref],
1837
+ :uint16
1838
+ attach_function :uniffi_oicana_uniffi_checksum_func_evict_cache,
1839
+ [RustCallStatus.by_ref],
1840
+ :uint16
1841
+ attach_function :uniffi_oicana_uniffi_checksum_func_export_once,
1842
+ [RustCallStatus.by_ref],
1843
+ :uint16
1844
+ attach_function :uniffi_oicana_uniffi_checksum_func_register_font_paths,
1845
+ [RustCallStatus.by_ref],
1846
+ :uint16
1847
+ attach_function :uniffi_oicana_uniffi_checksum_func_register_fonts,
1848
+ [RustCallStatus.by_ref],
1849
+ :uint16
1850
+ attach_function :uniffi_oicana_uniffi_checksum_func_registered_fonts,
1851
+ [RustCallStatus.by_ref],
1852
+ :uint16
1853
+ attach_function :uniffi_oicana_uniffi_checksum_func_version,
1854
+ [RustCallStatus.by_ref],
1855
+ :uint16
1856
+ attach_function :uniffi_oicana_uniffi_checksum_method_compileddocument_export,
1857
+ [RustCallStatus.by_ref],
1858
+ :uint16
1859
+ attach_function :uniffi_oicana_uniffi_checksum_method_compileddocument_pages,
1860
+ [RustCallStatus.by_ref],
1861
+ :uint16
1862
+ attach_function :uniffi_oicana_uniffi_checksum_method_compileddocument_warnings,
1863
+ [RustCallStatus.by_ref],
1864
+ :uint16
1865
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_compile,
1866
+ [RustCallStatus.by_ref],
1867
+ :uint16
1868
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_file,
1869
+ [RustCallStatus.by_ref],
1870
+ :uint16
1871
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_manifest,
1872
+ [RustCallStatus.by_ref],
1873
+ :uint16
1874
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_set_validate_inputs,
1875
+ [RustCallStatus.by_ref],
1876
+ :uint16
1877
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_source,
1878
+ [RustCallStatus.by_ref],
1879
+ :uint16
1880
+ attach_function :uniffi_oicana_uniffi_checksum_method_template_warnings,
1881
+ [RustCallStatus.by_ref],
1882
+ :uint16
1883
+ attach_function :uniffi_oicana_uniffi_checksum_constructor_template_new,
1884
+ [RustCallStatus.by_ref],
1885
+ :uint16
1886
+ attach_function :ffi_oicana_uniffi_uniffi_contract_version,
1887
+ [RustCallStatus.by_ref],
1888
+ :uint32
1889
+
1890
+ end
1891
+
1892
+ # Public interface members begin here.
1893
+
1894
+
1895
+
1896
+
1897
+
1898
+
1899
+ class CompilationMode
1900
+ DEVELOPMENT = 1
1901
+ PRODUCTION = 2
1902
+
1903
+ end
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1910
+ class DiagnosticColor
1911
+ NONE = 1
1912
+ ANSI = 2
1913
+
1914
+ end
1915
+
1916
+
1917
+
1918
+
1919
+
1920
+
1921
+ class DiagnosticSeverity
1922
+ ERROR = 1
1923
+ WARNING = 2
1924
+
1925
+ end
1926
+
1927
+
1928
+
1929
+
1930
+
1931
+
1932
+ class ExportFormat
1933
+ def initialize
1934
+ raise RuntimeError, 'ExportFormat cannot be instantiated directly'
1935
+ end
1936
+
1937
+ # Each enum variant is a nested class of the enum itself.
1938
+ class PDF
1939
+
1940
+ def initialize()
1941
+
1942
+
1943
+ end
1944
+
1945
+ def to_s
1946
+ "ExportFormat::PDF()"
1947
+ end
1948
+
1949
+ def ==(other)
1950
+ if !other.pdf?
1951
+ return false
1952
+ end
1953
+
1954
+ true
1955
+ end
1956
+
1957
+ # For each variant, we have an `NAME?` method for easily checking
1958
+ # whether an instance is that variant.
1959
+
1960
+ def pdf?
1961
+ instance_of? ExportFormat::PDF
1962
+ end
1963
+
1964
+ def png?
1965
+ instance_of? ExportFormat::PNG
1966
+ end
1967
+
1968
+ def svg?
1969
+ instance_of? ExportFormat::SVG
1970
+ end
1971
+
1972
+ end
1973
+ class PNG
1974
+
1975
+ attr_reader :pixels_per_pt
1976
+
1977
+ def initialize(pixels_per_pt)
1978
+
1979
+ @pixels_per_pt = pixels_per_pt
1980
+
1981
+ end
1982
+
1983
+ def to_s
1984
+ "ExportFormat::PNG(pixels_per_pt=#{@pixels_per_pt})"
1985
+ end
1986
+
1987
+ def ==(other)
1988
+ if !other.png?
1989
+ return false
1990
+ end
1991
+ if @pixels_per_pt != other.pixels_per_pt
1992
+ return false
1993
+ end
1994
+
1995
+ true
1996
+ end
1997
+
1998
+ # For each variant, we have an `NAME?` method for easily checking
1999
+ # whether an instance is that variant.
2000
+
2001
+ def pdf?
2002
+ instance_of? ExportFormat::PDF
2003
+ end
2004
+
2005
+ def png?
2006
+ instance_of? ExportFormat::PNG
2007
+ end
2008
+
2009
+ def svg?
2010
+ instance_of? ExportFormat::SVG
2011
+ end
2012
+
2013
+ end
2014
+ class SVG
2015
+
2016
+ def initialize()
2017
+
2018
+
2019
+ end
2020
+
2021
+ def to_s
2022
+ "ExportFormat::SVG()"
2023
+ end
2024
+
2025
+ def ==(other)
2026
+ if !other.svg?
2027
+ return false
2028
+ end
2029
+
2030
+ true
2031
+ end
2032
+
2033
+ # For each variant, we have an `NAME?` method for easily checking
2034
+ # whether an instance is that variant.
2035
+
2036
+ def pdf?
2037
+ instance_of? ExportFormat::PDF
2038
+ end
2039
+
2040
+ def png?
2041
+ instance_of? ExportFormat::PNG
2042
+ end
2043
+
2044
+ def svg?
2045
+ instance_of? ExportFormat::SVG
2046
+ end
2047
+
2048
+ end
2049
+
2050
+ end
2051
+
2052
+
2053
+
2054
+ # Record type BlobInput
2055
+ class BlobInput
2056
+ attr_reader :data, :metadata
2057
+
2058
+ def initialize(data:, metadata: "{}")
2059
+ @data = data
2060
+ @metadata = metadata
2061
+ end
2062
+
2063
+ def ==(other)
2064
+ if @data != other.data
2065
+ return false
2066
+ end
2067
+ if @metadata != other.metadata
2068
+ return false
2069
+ end
2070
+
2071
+ true
2072
+ end
2073
+ end
2074
+
2075
+ # Record type Diagnostic
2076
+ class Diagnostic
2077
+ attr_reader :severity, :message, :location, :hints, :trace, :formatted
2078
+
2079
+ def initialize(severity:, message:, location:, hints:, trace:, formatted:)
2080
+ @severity = severity
2081
+ @message = message
2082
+ @location = location
2083
+ @hints = hints
2084
+ @trace = trace
2085
+ @formatted = formatted
2086
+ end
2087
+
2088
+ def ==(other)
2089
+ if @severity != other.severity
2090
+ return false
2091
+ end
2092
+ if @message != other.message
2093
+ return false
2094
+ end
2095
+ if @location != other.location
2096
+ return false
2097
+ end
2098
+ if @hints != other.hints
2099
+ return false
2100
+ end
2101
+ if @trace != other.trace
2102
+ return false
2103
+ end
2104
+ if @formatted != other.formatted
2105
+ return false
2106
+ end
2107
+
2108
+ true
2109
+ end
2110
+ end
2111
+
2112
+ # Record type ExportOnceResult
2113
+ class ExportOnceResult
2114
+ attr_reader :bytes, :warnings
2115
+
2116
+ def initialize(bytes:, warnings:)
2117
+ @bytes = bytes
2118
+ @warnings = warnings
2119
+ end
2120
+
2121
+ def ==(other)
2122
+ if @bytes != other.bytes
2123
+ return false
2124
+ end
2125
+ if @warnings != other.warnings
2126
+ return false
2127
+ end
2128
+
2129
+ true
2130
+ end
2131
+ end
2132
+
2133
+ # Record type PageRange
2134
+ class PageRange
2135
+ attr_reader :start, :_end
2136
+
2137
+ def initialize(start: nil, _end: nil)
2138
+ @start = start
2139
+ @_end = _end
2140
+ end
2141
+
2142
+ def ==(other)
2143
+ if @start != other.start
2144
+ return false
2145
+ end
2146
+ if @_end != other._end
2147
+ return false
2148
+ end
2149
+
2150
+ true
2151
+ end
2152
+ end
2153
+
2154
+ # Record type PageSize
2155
+ class PageSize
2156
+ attr_reader :width, :height
2157
+
2158
+ def initialize(width:, height:)
2159
+ @width = width
2160
+ @height = height
2161
+ end
2162
+
2163
+ def ==(other)
2164
+ if @width != other.width
2165
+ return false
2166
+ end
2167
+ if @height != other.height
2168
+ return false
2169
+ end
2170
+
2171
+ true
2172
+ end
2173
+ end
2174
+
2175
+ # Record type RegisteredFont
2176
+ class RegisteredFont
2177
+ attr_reader :family, :path
2178
+
2179
+ def initialize(family:, path:)
2180
+ @family = family
2181
+ @path = path
2182
+ end
2183
+
2184
+ def ==(other)
2185
+ if @family != other.family
2186
+ return false
2187
+ end
2188
+ if @path != other.path
2189
+ return false
2190
+ end
2191
+
2192
+ true
2193
+ end
2194
+ end
2195
+
2196
+ # Record type SourceLocation
2197
+ class SourceLocation
2198
+ attr_reader :file, :line, :column, :end_line, :end_column
2199
+
2200
+ def initialize(file:, line:, column:, end_line:, end_column:)
2201
+ @file = file
2202
+ @line = line
2203
+ @column = column
2204
+ @end_line = end_line
2205
+ @end_column = end_column
2206
+ end
2207
+
2208
+ def ==(other)
2209
+ if @file != other.file
2210
+ return false
2211
+ end
2212
+ if @line != other.line
2213
+ return false
2214
+ end
2215
+ if @column != other.column
2216
+ return false
2217
+ end
2218
+ if @end_line != other.end_line
2219
+ return false
2220
+ end
2221
+ if @end_column != other.end_column
2222
+ return false
2223
+ end
2224
+
2225
+ true
2226
+ end
2227
+ end
2228
+
2229
+ # Record type TracePoint
2230
+ class TracePoint
2231
+ attr_reader :message, :location
2232
+
2233
+ def initialize(message:, location:)
2234
+ @message = message
2235
+ @location = location
2236
+ end
2237
+
2238
+ def ==(other)
2239
+ if @message != other.message
2240
+ return false
2241
+ end
2242
+ if @location != other.location
2243
+ return false
2244
+ end
2245
+
2246
+ true
2247
+ end
2248
+ end
2249
+
2250
+ # Record type ZipLimits
2251
+ class ZipLimits
2252
+ attr_reader :max_entries, :max_total_decompressed_bytes
2253
+
2254
+ def initialize(max_entries: nil, max_total_decompressed_bytes: nil)
2255
+ @max_entries = max_entries
2256
+ @max_total_decompressed_bytes = max_total_decompressed_bytes
2257
+ end
2258
+
2259
+ def ==(other)
2260
+ if @max_entries != other.max_entries
2261
+ return false
2262
+ end
2263
+ if @max_total_decompressed_bytes != other.max_total_decompressed_bytes
2264
+ return false
2265
+ end
2266
+
2267
+ true
2268
+ end
2269
+ end
2270
+
2271
+
2272
+
2273
+
2274
+
2275
+ def self.clear_fonts()
2276
+ OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_clear_fonts,)
2277
+ end
2278
+
2279
+
2280
+
2281
+
2282
+ def self.configure_automatic_cache_eviction(max_age)
2283
+ max_age = (max_age ? OicanaUniffi::uniffi_in_range(max_age, "u64", 0, 2**64) : nil)
2284
+ RustBuffer.check_lower_Optionalu64(max_age)
2285
+
2286
+ OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_configure_automatic_cache_eviction,RustBuffer.alloc_from_Optionalu64(max_age))
2287
+ end
2288
+
2289
+
2290
+
2291
+
2292
+ def self.configure_diagnostic_color(color)
2293
+ color = color
2294
+ RustBuffer.check_lower_TypeDiagnosticColor(color)
2295
+
2296
+ OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_configure_diagnostic_color,RustBuffer.alloc_from_TypeDiagnosticColor(color))
2297
+ end
2298
+
2299
+
2300
+
2301
+
2302
+ def self.evict_cache(max_age)
2303
+ max_age = OicanaUniffi::uniffi_in_range(max_age, "u64", 0, 2**64)
2304
+
2305
+
2306
+ OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_evict_cache,max_age)
2307
+ end
2308
+
2309
+
2310
+
2311
+
2312
+ def self.export_once(files, json_inputs, blob_inputs, mode, format, pages = nil, limits = nil)
2313
+ files = OicanaUniffi::uniffi_bytes(files)
2314
+
2315
+
2316
+ json_inputs = json_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = OicanaUniffi::uniffi_utf8(v) }
2317
+ RustBuffer.check_lower_MapStringString(json_inputs)
2318
+
2319
+ blob_inputs = blob_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = v }
2320
+ RustBuffer.check_lower_MapStringTypeBlobInput(blob_inputs)
2321
+
2322
+ mode = mode
2323
+ RustBuffer.check_lower_TypeCompilationMode(mode)
2324
+
2325
+ format = format
2326
+ RustBuffer.check_lower_TypeExportFormat(format)
2327
+
2328
+ pages = (pages ? pages : nil)
2329
+ RustBuffer.check_lower_OptionalTypePageRange(pages)
2330
+
2331
+ limits = (limits ? limits : nil)
2332
+ RustBuffer.check_lower_OptionalTypeZipLimits(limits)
2333
+
2334
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_func_export_once,RustBuffer.allocFromBytes(files),RustBuffer.alloc_from_MapStringString(json_inputs),RustBuffer.alloc_from_MapStringTypeBlobInput(blob_inputs),RustBuffer.alloc_from_TypeCompilationMode(mode),RustBuffer.alloc_from_TypeExportFormat(format),RustBuffer.alloc_from_OptionalTypePageRange(pages),RustBuffer.alloc_from_OptionalTypeZipLimits(limits))
2335
+ return result.consumeIntoTypeExportOnceResult
2336
+ end
2337
+
2338
+
2339
+
2340
+
2341
+
2342
+ def self.register_font_paths(paths)
2343
+ paths = paths.map { |v| OicanaUniffi::uniffi_utf8(v) }
2344
+ RustBuffer.check_lower_Sequencestring(paths)
2345
+
2346
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_register_font_paths,RustBuffer.alloc_from_Sequencestring(paths))
2347
+ return result.to_i
2348
+ end
2349
+
2350
+
2351
+
2352
+
2353
+
2354
+ def self.register_fonts(fonts)
2355
+ fonts = fonts.map { |v| OicanaUniffi::uniffi_bytes(v) }
2356
+ RustBuffer.check_lower_Sequencebytes(fonts)
2357
+
2358
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_register_fonts,RustBuffer.alloc_from_Sequencebytes(fonts))
2359
+ return result.to_i
2360
+ end
2361
+
2362
+
2363
+
2364
+
2365
+
2366
+ def self.registered_fonts()
2367
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_registered_fonts,)
2368
+ return result.consumeIntoSequenceTypeRegisteredFont
2369
+ end
2370
+
2371
+
2372
+
2373
+
2374
+
2375
+ def self.version()
2376
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_func_version,)
2377
+ return result.consumeIntoString
2378
+ end
2379
+
2380
+
2381
+
2382
+
2383
+
2384
+ class CompiledDocument
2385
+
2386
+ # A private helper for initializing instances of the class from a raw handle,
2387
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2388
+ def self.uniffi_allocate(handle)
2389
+ inst = allocate
2390
+ inst.instance_variable_set :@handle, handle
2391
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2392
+ return inst
2393
+ end
2394
+
2395
+ # A private helper for registering an object finalizer.
2396
+ # N.B. it's important that this does not capture a reference
2397
+ # to the actual instance, only its underlying handle.
2398
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2399
+ Proc.new do |_id|
2400
+ OicanaUniffi.rust_call(
2401
+ :uniffi_oicana_uniffi_fn_free_compileddocument,
2402
+ handle
2403
+ )
2404
+ end
2405
+ end
2406
+
2407
+ # A private helper for lowering instances into a raw handle.
2408
+ # This does an explicit typecheck, because accidentally lowering a different type of
2409
+ # object in a place where this type is expected, could lead to memory unsafety.
2410
+ def self.uniffi_check_lower(inst)
2411
+ if not inst.is_a? self
2412
+ raise TypeError.new "Expected a CompiledDocument instance, got #{inst}"
2413
+ end
2414
+ end
2415
+
2416
+ def uniffi_clone_handle()
2417
+ return OicanaUniffi.rust_call(
2418
+ :uniffi_oicana_uniffi_fn_clone_compileddocument,
2419
+ @handle
2420
+ )
2421
+ end
2422
+
2423
+ def self.uniffi_lower(inst)
2424
+ return inst.uniffi_clone_handle()
2425
+ end
2426
+
2427
+
2428
+
2429
+ def export(format, pages = nil)
2430
+ format = format
2431
+ RustBuffer.check_lower_TypeExportFormat(format)
2432
+ pages = (pages ? pages : nil)
2433
+ RustBuffer.check_lower_OptionalTypePageRange(pages)
2434
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_compileddocument_export,uniffi_clone_handle(),RustBuffer.alloc_from_TypeExportFormat(format),RustBuffer.alloc_from_OptionalTypePageRange(pages))
2435
+ return result.consumeIntoBytes
2436
+ end
2437
+ def pages()
2438
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_method_compileddocument_pages,uniffi_clone_handle(),)
2439
+ return result.consumeIntoSequenceTypePageSize
2440
+ end
2441
+ def warnings()
2442
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_method_compileddocument_warnings,uniffi_clone_handle(),)
2443
+ return result.consumeIntoSequenceTypeDiagnostic
2444
+ end
2445
+
2446
+ end
2447
+
2448
+ class Template
2449
+
2450
+ # A private helper for initializing instances of the class from a raw handle,
2451
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2452
+ def self.uniffi_allocate(handle)
2453
+ inst = allocate
2454
+ inst.instance_variable_set :@handle, handle
2455
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2456
+ return inst
2457
+ end
2458
+
2459
+ # A private helper for registering an object finalizer.
2460
+ # N.B. it's important that this does not capture a reference
2461
+ # to the actual instance, only its underlying handle.
2462
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2463
+ Proc.new do |_id|
2464
+ OicanaUniffi.rust_call(
2465
+ :uniffi_oicana_uniffi_fn_free_template,
2466
+ handle
2467
+ )
2468
+ end
2469
+ end
2470
+
2471
+ # A private helper for lowering instances into a raw handle.
2472
+ # This does an explicit typecheck, because accidentally lowering a different type of
2473
+ # object in a place where this type is expected, could lead to memory unsafety.
2474
+ def self.uniffi_check_lower(inst)
2475
+ if not inst.is_a? self
2476
+ raise TypeError.new "Expected a Template instance, got #{inst}"
2477
+ end
2478
+ end
2479
+
2480
+ def uniffi_clone_handle()
2481
+ return OicanaUniffi.rust_call(
2482
+ :uniffi_oicana_uniffi_fn_clone_template,
2483
+ @handle
2484
+ )
2485
+ end
2486
+
2487
+ def self.uniffi_lower(inst)
2488
+ return inst.uniffi_clone_handle()
2489
+ end
2490
+ def initialize(files, json_inputs, blob_inputs, mode, limits = nil)
2491
+ files = OicanaUniffi::uniffi_bytes(files)
2492
+
2493
+ json_inputs = json_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = OicanaUniffi::uniffi_utf8(v) }
2494
+ RustBuffer.check_lower_MapStringString(json_inputs)
2495
+ blob_inputs = blob_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = v }
2496
+ RustBuffer.check_lower_MapStringTypeBlobInput(blob_inputs)
2497
+ mode = mode
2498
+ RustBuffer.check_lower_TypeCompilationMode(mode)
2499
+ limits = (limits ? limits : nil)
2500
+ RustBuffer.check_lower_OptionalTypeZipLimits(limits)
2501
+ handle = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_constructor_template_new,RustBuffer.allocFromBytes(files),RustBuffer.alloc_from_MapStringString(json_inputs),RustBuffer.alloc_from_MapStringTypeBlobInput(blob_inputs),RustBuffer.alloc_from_TypeCompilationMode(mode),RustBuffer.alloc_from_OptionalTypeZipLimits(limits))
2502
+ @handle = handle
2503
+ ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_handle(handle, self.object_id))
2504
+ end
2505
+
2506
+
2507
+
2508
+ def compile(json_inputs, blob_inputs, mode)
2509
+ json_inputs = json_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = OicanaUniffi::uniffi_utf8(v) }
2510
+ RustBuffer.check_lower_MapStringString(json_inputs)
2511
+ blob_inputs = blob_inputs.each.with_object({}) { |(k, v), res| res[OicanaUniffi::uniffi_utf8(k)] = v }
2512
+ RustBuffer.check_lower_MapStringTypeBlobInput(blob_inputs)
2513
+ mode = mode
2514
+ RustBuffer.check_lower_TypeCompilationMode(mode)
2515
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_template_compile,uniffi_clone_handle(),RustBuffer.alloc_from_MapStringString(json_inputs),RustBuffer.alloc_from_MapStringTypeBlobInput(blob_inputs),RustBuffer.alloc_from_TypeCompilationMode(mode))
2516
+ return CompiledDocument.uniffi_allocate(result)
2517
+ end
2518
+ def file(path)
2519
+ path = OicanaUniffi::uniffi_utf8(path)
2520
+
2521
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_template_file,uniffi_clone_handle(),RustBuffer.allocFromString(path))
2522
+ return result.consumeIntoBytes
2523
+ end
2524
+ def manifest()
2525
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_template_manifest,uniffi_clone_handle(),)
2526
+ return result.consumeIntoString
2527
+ end
2528
+ def set_validate_inputs(validate)
2529
+ validate = validate ? true : false
2530
+
2531
+ OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_template_set_validate_inputs,uniffi_clone_handle(),(validate ? 1 : 0))
2532
+ end
2533
+
2534
+ def source(path)
2535
+ path = OicanaUniffi::uniffi_utf8(path)
2536
+
2537
+ result = OicanaUniffi.rust_call_with_error(OicanaError,:uniffi_oicana_uniffi_fn_method_template_source,uniffi_clone_handle(),RustBuffer.allocFromString(path))
2538
+ return result.consumeIntoString
2539
+ end
2540
+ def warnings()
2541
+ result = OicanaUniffi.rust_call(:uniffi_oicana_uniffi_fn_method_template_warnings,uniffi_clone_handle(),)
2542
+ return result.consumeIntoSequenceTypeDiagnostic
2543
+ end
2544
+
2545
+ end
2546
+
2547
+ end
2548
+