rusto 0.3.2__py3-none-any.whl

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,2767 @@
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 .py 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 Python
14
+ # helpers directly inline like we're doing here.
15
+
16
+ from __future__ import annotations
17
+ import os
18
+ import sys
19
+ import ctypes
20
+ from dataclasses import dataclass
21
+ import enum
22
+ import struct
23
+ import contextlib
24
+ import datetime
25
+ import threading
26
+ import itertools
27
+ import traceback
28
+ import typing
29
+ import platform
30
+
31
+
32
+ # Used for default argument values
33
+ _DEFAULT = object() # type: typing.Any
34
+
35
+
36
+ class _UniffiRustBuffer(ctypes.Structure):
37
+ _fields_ = [
38
+ ("capacity", ctypes.c_uint64),
39
+ ("len", ctypes.c_uint64),
40
+ ("data", ctypes.POINTER(ctypes.c_char)),
41
+ ]
42
+
43
+ @staticmethod
44
+ def default():
45
+ return _UniffiRustBuffer(0, 0, None)
46
+
47
+ @staticmethod
48
+ def alloc(size):
49
+ return _uniffi_rust_call(_UniffiLib.ffi_rusto_rustbuffer_alloc, size)
50
+
51
+ @staticmethod
52
+ def reserve(rbuf, additional):
53
+ return _uniffi_rust_call(_UniffiLib.ffi_rusto_rustbuffer_reserve, rbuf, additional)
54
+
55
+ def free(self):
56
+ return _uniffi_rust_call(_UniffiLib.ffi_rusto_rustbuffer_free, self)
57
+
58
+ def __str__(self):
59
+ return "_UniffiRustBuffer(capacity={}, len={}, data={})".format(
60
+ self.capacity,
61
+ self.len,
62
+ self.data[0:self.len]
63
+ )
64
+
65
+ @contextlib.contextmanager
66
+ def alloc_with_builder(*args):
67
+ """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder.
68
+
69
+ The allocated buffer will be automatically freed if an error occurs, ensuring that
70
+ we don't accidentally leak it.
71
+ """
72
+ builder = _UniffiRustBufferBuilder()
73
+ try:
74
+ yield builder
75
+ except:
76
+ builder.discard()
77
+ raise
78
+
79
+ @contextlib.contextmanager
80
+ def consume_with_stream(self):
81
+ """Context-manager to consume a buffer using a _UniffiRustBufferStream.
82
+
83
+ The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't
84
+ leak it even if an error occurs.
85
+ """
86
+ try:
87
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
88
+ yield s
89
+ if s.remaining() != 0:
90
+ raise RuntimeError(f"junk data left in buffer at end of consume_with_stream {s.remaining()}")
91
+ finally:
92
+ self.free()
93
+
94
+ @contextlib.contextmanager
95
+ def read_with_stream(self):
96
+ """Context-manager to read a buffer using a _UniffiRustBufferStream.
97
+
98
+ This is like consume_with_stream, but doesn't free the buffer afterwards.
99
+ It should only be used with borrowed `_UniffiRustBuffer` data.
100
+ """
101
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
102
+ yield s
103
+ if s.remaining() != 0:
104
+ raise RuntimeError(f"junk data left in buffer at end of read_with_stream {s.remaining()}")
105
+
106
+ class _UniffiForeignBytes(ctypes.Structure):
107
+ _fields_ = [
108
+ ("len", ctypes.c_int32),
109
+ ("data", ctypes.POINTER(ctypes.c_char)),
110
+ ]
111
+
112
+ def __str__(self):
113
+ return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len])
114
+
115
+
116
+ class _UniffiRustBufferStream:
117
+ """
118
+ Helper for structured reading of bytes from a _UniffiRustBuffer
119
+ """
120
+
121
+ def __init__(self, data, len):
122
+ self.data = data
123
+ self.len = len
124
+ self.offset = 0
125
+
126
+ @classmethod
127
+ def from_rust_buffer(cls, buf):
128
+ return cls(buf.data, buf.len)
129
+
130
+ def remaining(self):
131
+ return self.len - self.offset
132
+
133
+ def _unpack_from(self, size, format):
134
+ if self.offset + size > self.len:
135
+ raise InternalError("read past end of rust buffer")
136
+ value = struct.unpack(format, self.data[self.offset:self.offset+size])[0]
137
+ self.offset += size
138
+ return value
139
+
140
+ def read(self, size):
141
+ if self.offset + size > self.len:
142
+ raise InternalError("read past end of rust buffer")
143
+ data = self.data[self.offset:self.offset+size]
144
+ self.offset += size
145
+ return data
146
+
147
+ def read_i8(self):
148
+ return self._unpack_from(1, ">b")
149
+
150
+ def read_u8(self):
151
+ return self._unpack_from(1, ">B")
152
+
153
+ def read_i16(self):
154
+ return self._unpack_from(2, ">h")
155
+
156
+ def read_u16(self):
157
+ return self._unpack_from(2, ">H")
158
+
159
+ def read_i32(self):
160
+ return self._unpack_from(4, ">i")
161
+
162
+ def read_u32(self):
163
+ return self._unpack_from(4, ">I")
164
+
165
+ def read_i64(self):
166
+ return self._unpack_from(8, ">q")
167
+
168
+ def read_u64(self):
169
+ return self._unpack_from(8, ">Q")
170
+
171
+ def read_float(self):
172
+ v = self._unpack_from(4, ">f")
173
+ return v
174
+
175
+ def read_double(self):
176
+ return self._unpack_from(8, ">d")
177
+
178
+ class _UniffiRustBufferBuilder:
179
+ """
180
+ Helper for structured writing of bytes into a _UniffiRustBuffer.
181
+ """
182
+
183
+ def __init__(self):
184
+ self.rbuf = _UniffiRustBuffer.alloc(16)
185
+ self.rbuf.len = 0
186
+
187
+ def finalize(self):
188
+ rbuf = self.rbuf
189
+ self.rbuf = None
190
+ return rbuf
191
+
192
+ def discard(self):
193
+ if self.rbuf is not None:
194
+ rbuf = self.finalize()
195
+ rbuf.free()
196
+
197
+ @contextlib.contextmanager
198
+ def _reserve(self, num_bytes):
199
+ if self.rbuf.len + num_bytes > self.rbuf.capacity:
200
+ self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes)
201
+ yield None
202
+ self.rbuf.len += num_bytes
203
+
204
+ def _pack_into(self, size, format, value):
205
+ with self._reserve(size):
206
+ # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out.
207
+ for i, byte in enumerate(struct.pack(format, value)):
208
+ self.rbuf.data[self.rbuf.len + i] = byte
209
+
210
+ def write(self, value):
211
+ with self._reserve(len(value)):
212
+ for i, byte in enumerate(value):
213
+ self.rbuf.data[self.rbuf.len + i] = byte
214
+
215
+ def write_i8(self, v):
216
+ self._pack_into(1, ">b", v)
217
+
218
+ def write_u8(self, v):
219
+ self._pack_into(1, ">B", v)
220
+
221
+ def write_i16(self, v):
222
+ self._pack_into(2, ">h", v)
223
+
224
+ def write_u16(self, v):
225
+ self._pack_into(2, ">H", v)
226
+
227
+ def write_i32(self, v):
228
+ self._pack_into(4, ">i", v)
229
+
230
+ def write_u32(self, v):
231
+ self._pack_into(4, ">I", v)
232
+
233
+ def write_i64(self, v):
234
+ self._pack_into(8, ">q", v)
235
+
236
+ def write_u64(self, v):
237
+ self._pack_into(8, ">Q", v)
238
+
239
+ def write_float(self, v):
240
+ self._pack_into(4, ">f", v)
241
+
242
+ def write_double(self, v):
243
+ self._pack_into(8, ">d", v)
244
+
245
+ def write_c_size_t(self, v):
246
+ self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v)
247
+ # A handful of classes and functions to support the generated data structures.
248
+ # This would be a good candidate for isolating in its own ffi-support lib.
249
+
250
+ class InternalError(Exception):
251
+ pass
252
+
253
+ class _UniffiRustCallStatus(ctypes.Structure):
254
+ """
255
+ Error runtime.
256
+ """
257
+ _fields_ = [
258
+ ("code", ctypes.c_int8),
259
+ ("error_buf", _UniffiRustBuffer),
260
+ ]
261
+
262
+ # These match the values from the uniffi::rustcalls module
263
+ CALL_SUCCESS = 0
264
+ CALL_ERROR = 1
265
+ CALL_UNEXPECTED_ERROR = 2
266
+
267
+ @staticmethod
268
+ def default():
269
+ return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default())
270
+
271
+ def __str__(self):
272
+ if self.code == _UniffiRustCallStatus.CALL_SUCCESS:
273
+ return "_UniffiRustCallStatus(CALL_SUCCESS)"
274
+ elif self.code == _UniffiRustCallStatus.CALL_ERROR:
275
+ return "_UniffiRustCallStatus(CALL_ERROR)"
276
+ elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
277
+ return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)"
278
+ else:
279
+ return "_UniffiRustCallStatus(<invalid code>)"
280
+
281
+ def _uniffi_rust_call(fn, *args):
282
+ # Call a rust function
283
+ return _uniffi_rust_call_with_error(None, fn, *args)
284
+
285
+ def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args):
286
+ # Call a rust function and handle any errors
287
+ #
288
+ # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code.
289
+ # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result.
290
+ call_status = _UniffiRustCallStatus.default()
291
+
292
+ args_with_error = args + (ctypes.byref(call_status),)
293
+ result = fn(*args_with_error)
294
+ _uniffi_check_call_status(error_ffi_converter, call_status)
295
+ return result
296
+
297
+ def _uniffi_check_call_status(error_ffi_converter, call_status):
298
+ if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS:
299
+ pass
300
+ elif call_status.code == _UniffiRustCallStatus.CALL_ERROR:
301
+ if error_ffi_converter is None:
302
+ call_status.error_buf.free()
303
+ raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None")
304
+ else:
305
+ raise error_ffi_converter.lift(call_status.error_buf)
306
+ elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
307
+ # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer
308
+ # with the message. But if that code panics, then it just sends back
309
+ # an empty buffer.
310
+ if call_status.error_buf.len > 0:
311
+ msg = _UniffiFfiConverterString.lift(call_status.error_buf)
312
+ else:
313
+ msg = "Unknown rust panic"
314
+ raise InternalError(msg)
315
+ else:
316
+ raise InternalError("Invalid _UniffiRustCallStatus code: {}".format(
317
+ call_status.code))
318
+
319
+ def _uniffi_trait_interface_call(call_status, make_call, write_return_value):
320
+ try:
321
+ return write_return_value(make_call())
322
+ except Exception as e:
323
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
324
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
325
+
326
+ def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error):
327
+ try:
328
+ try:
329
+ return write_return_value(make_call())
330
+ except error_type as e:
331
+ call_status.code = _UniffiRustCallStatus.CALL_ERROR
332
+ call_status.error_buf = lower_error(e)
333
+ except Exception as e:
334
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
335
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
336
+ # Initial value and increment amount for handles.
337
+ # These ensure that Python-generated handles always have the lowest bit set
338
+ _UNIFFI_HANDLEMAP_INITIAL = 1
339
+ _UNIFFI_HANDLEMAP_DELTA = 2
340
+
341
+ class _UniffiHandleMap:
342
+ """
343
+ A map where inserting, getting and removing data is synchronized with a lock.
344
+ """
345
+
346
+ def __init__(self):
347
+ # type Handle = int
348
+ self._map = {} # type: Dict[Handle, Any]
349
+ self._lock = threading.Lock()
350
+ self._counter = _UNIFFI_HANDLEMAP_INITIAL
351
+
352
+ def insert(self, obj):
353
+ with self._lock:
354
+ return self._insert(obj)
355
+
356
+ """Low-level insert, this assumes `self._lock` is held."""
357
+ def _insert(self, obj):
358
+ handle = self._counter
359
+ self._counter += _UNIFFI_HANDLEMAP_DELTA
360
+ self._map[handle] = obj
361
+ return handle
362
+
363
+ def get(self, handle):
364
+ try:
365
+ with self._lock:
366
+ return self._map[handle]
367
+ except KeyError:
368
+ raise InternalError(f"_UniffiHandleMap.get: Invalid handle {handle}")
369
+
370
+ def clone(self, handle):
371
+ try:
372
+ with self._lock:
373
+ obj = self._map[handle]
374
+ return self._insert(obj)
375
+ except KeyError:
376
+ raise InternalError(f"_UniffiHandleMap.clone: Invalid handle {handle}")
377
+
378
+ def remove(self, handle):
379
+ try:
380
+ with self._lock:
381
+ return self._map.pop(handle)
382
+ except KeyError:
383
+ raise InternalError(f"_UniffiHandleMap.remove: Invalid handle: {handle}")
384
+
385
+ def __len__(self):
386
+ return len(self._map)
387
+ # Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI.
388
+ class _UniffiConverterPrimitive:
389
+ @classmethod
390
+ def lift(cls, value):
391
+ return value
392
+
393
+ @classmethod
394
+ def lower(cls, value):
395
+ return value
396
+
397
+ class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive):
398
+ @classmethod
399
+ def check_lower(cls, value):
400
+ try:
401
+ value = value.__index__()
402
+ except Exception:
403
+ raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__))
404
+ if not isinstance(value, int):
405
+ raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__))
406
+ if not cls.VALUE_MIN <= value < cls.VALUE_MAX:
407
+ raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX))
408
+
409
+ class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive):
410
+ @classmethod
411
+ def check_lower(cls, value):
412
+ try:
413
+ value = value.__float__()
414
+ except Exception:
415
+ raise TypeError("must be real number, not {}".format(type(value).__name__))
416
+ if not isinstance(value, float):
417
+ raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__))
418
+
419
+ # Helper class for wrapper types that will always go through a _UniffiRustBuffer.
420
+ # Classes should inherit from this and implement the `read` and `write` static methods.
421
+ class _UniffiConverterRustBuffer:
422
+ @classmethod
423
+ def lift(cls, rbuf):
424
+ with rbuf.consume_with_stream() as stream:
425
+ return cls.read(stream)
426
+
427
+ @classmethod
428
+ def lower(cls, value):
429
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
430
+ cls.write(value, builder)
431
+ return builder.finalize()
432
+
433
+ # Contains loading, initialization code, and the FFI Function declarations.
434
+ # Define some ctypes FFI types that we use in the library
435
+
436
+ """
437
+ Function pointer for a Rust task, which a callback function that takes a opaque pointer
438
+ """
439
+ _UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
440
+
441
+ def _uniffi_future_callback_t(return_type):
442
+ """
443
+ Factory function to create callback function types for async functions
444
+ """
445
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
446
+
447
+ def _uniffi_load_indirect():
448
+ """
449
+ This is how we find and load the dynamic library provided by the component.
450
+ For now we just look it up by name.
451
+ """
452
+ if sys.platform == "darwin":
453
+ libname = "lib{}.dylib"
454
+ elif sys.platform.startswith("win"):
455
+ # As of python3.8, ctypes does not seem to search $PATH when loading DLLs.
456
+ # We could use `os.add_dll_directory` to configure the search path, but
457
+ # it doesn't feel right to mess with application-wide settings. Let's
458
+ # assume that the `.dll` is next to the `.py` file and load by full path.
459
+ libname = os.path.join(
460
+ os.path.dirname(__file__),
461
+ "{}.dll",
462
+ )
463
+ else:
464
+ # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos
465
+ libname = "lib{}.so"
466
+
467
+ libname = libname.format("rusto")
468
+ candidates = [
469
+ os.path.join(os.path.dirname(__file__), libname),
470
+ os.path.join(os.path.dirname(__file__), "..", libname),
471
+ os.path.join(os.path.dirname(__file__), "../../../../target/release", libname),
472
+ os.path.join(os.path.dirname(__file__), "../../../../target/debug", libname),
473
+ ]
474
+ env_path = os.environ.get("RUSTO_LIB_PATH")
475
+ if env_path:
476
+ candidates.insert(0, env_path)
477
+
478
+ for p in candidates:
479
+ if os.path.exists(p):
480
+ try:
481
+ return ctypes.cdll.LoadLibrary(p)
482
+ except Exception:
483
+ pass
484
+
485
+ try:
486
+ return ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), libname))
487
+ except Exception:
488
+ return ctypes.cdll.LoadLibrary(libname)
489
+
490
+ def _uniffi_check_contract_api_version(lib):
491
+ # Get the bindings contract version from our ComponentInterface
492
+ bindings_contract_version = 30
493
+ # Get the scaffolding contract version by calling the into the dylib
494
+ scaffolding_contract_version = lib.ffi_rusto_uniffi_contract_version()
495
+ if bindings_contract_version != scaffolding_contract_version:
496
+ raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
497
+
498
+ def _uniffi_check_api_checksums(lib):
499
+ if lib.uniffi_rusto_checksum_func_create_initialize_config_ppv6() != 12132:
500
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
501
+ if lib.uniffi_rusto_checksum_func_default_ocr_run_options() != 50314:
502
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
503
+ if lib.uniffi_rusto_checksum_func_rusto_version() != 48676:
504
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
505
+ if lib.uniffi_rusto_checksum_constructor_rusto_initialize() != 334:
506
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
507
+ if lib.uniffi_rusto_checksum_constructor_rusto_initialize_from_json() != 23041:
508
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
509
+ if lib.uniffi_rusto_checksum_method_rusto_detect_text() != 7671:
510
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
511
+ if lib.uniffi_rusto_checksum_method_rusto_detect_text_rgb() != 14239:
512
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
513
+ if lib.uniffi_rusto_checksum_method_rusto_version() != 27087:
514
+ raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
515
+
516
+ # A ctypes library to expose the extern-C FFI definitions.
517
+ # This is an implementation detail which will be called internally by the public API.
518
+
519
+ _UniffiLib = _uniffi_load_indirect()
520
+ _UniffiLib.ffi_rusto_rustbuffer_alloc.argtypes = (
521
+ ctypes.c_uint64,
522
+ ctypes.POINTER(_UniffiRustCallStatus),
523
+ )
524
+ _UniffiLib.ffi_rusto_rustbuffer_alloc.restype = _UniffiRustBuffer
525
+ _UniffiLib.ffi_rusto_rustbuffer_from_bytes.argtypes = (
526
+ _UniffiForeignBytes,
527
+ ctypes.POINTER(_UniffiRustCallStatus),
528
+ )
529
+ _UniffiLib.ffi_rusto_rustbuffer_from_bytes.restype = _UniffiRustBuffer
530
+ _UniffiLib.ffi_rusto_rustbuffer_free.argtypes = (
531
+ _UniffiRustBuffer,
532
+ ctypes.POINTER(_UniffiRustCallStatus),
533
+ )
534
+ _UniffiLib.ffi_rusto_rustbuffer_free.restype = None
535
+ _UniffiLib.ffi_rusto_rustbuffer_reserve.argtypes = (
536
+ _UniffiRustBuffer,
537
+ ctypes.c_uint64,
538
+ ctypes.POINTER(_UniffiRustCallStatus),
539
+ )
540
+ _UniffiLib.ffi_rusto_rustbuffer_reserve.restype = _UniffiRustBuffer
541
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8,
542
+ )
543
+ _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,
544
+ )
545
+ class _UniffiForeignFutureDroppedCallbackStruct(ctypes.Structure):
546
+ _fields_ = [
547
+ ("handle", ctypes.c_uint64),
548
+ ("free", _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK),
549
+ ]
550
+ _UniffiLib.ffi_rusto_rust_future_poll_u8.argtypes = (
551
+ ctypes.c_uint64,
552
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
553
+ ctypes.c_uint64,
554
+ )
555
+ _UniffiLib.ffi_rusto_rust_future_poll_u8.restype = None
556
+ _UniffiLib.ffi_rusto_rust_future_cancel_u8.argtypes = (
557
+ ctypes.c_uint64,
558
+ )
559
+ _UniffiLib.ffi_rusto_rust_future_cancel_u8.restype = None
560
+ _UniffiLib.ffi_rusto_rust_future_complete_u8.argtypes = (
561
+ ctypes.c_uint64,
562
+ ctypes.POINTER(_UniffiRustCallStatus),
563
+ )
564
+ _UniffiLib.ffi_rusto_rust_future_complete_u8.restype = ctypes.c_uint8
565
+ _UniffiLib.ffi_rusto_rust_future_free_u8.argtypes = (
566
+ ctypes.c_uint64,
567
+ )
568
+ _UniffiLib.ffi_rusto_rust_future_free_u8.restype = None
569
+ _UniffiLib.ffi_rusto_rust_future_poll_i8.argtypes = (
570
+ ctypes.c_uint64,
571
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
572
+ ctypes.c_uint64,
573
+ )
574
+ _UniffiLib.ffi_rusto_rust_future_poll_i8.restype = None
575
+ _UniffiLib.ffi_rusto_rust_future_cancel_i8.argtypes = (
576
+ ctypes.c_uint64,
577
+ )
578
+ _UniffiLib.ffi_rusto_rust_future_cancel_i8.restype = None
579
+ _UniffiLib.ffi_rusto_rust_future_complete_i8.argtypes = (
580
+ ctypes.c_uint64,
581
+ ctypes.POINTER(_UniffiRustCallStatus),
582
+ )
583
+ _UniffiLib.ffi_rusto_rust_future_complete_i8.restype = ctypes.c_int8
584
+ _UniffiLib.ffi_rusto_rust_future_free_i8.argtypes = (
585
+ ctypes.c_uint64,
586
+ )
587
+ _UniffiLib.ffi_rusto_rust_future_free_i8.restype = None
588
+ _UniffiLib.ffi_rusto_rust_future_poll_u16.argtypes = (
589
+ ctypes.c_uint64,
590
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
591
+ ctypes.c_uint64,
592
+ )
593
+ _UniffiLib.ffi_rusto_rust_future_poll_u16.restype = None
594
+ _UniffiLib.ffi_rusto_rust_future_cancel_u16.argtypes = (
595
+ ctypes.c_uint64,
596
+ )
597
+ _UniffiLib.ffi_rusto_rust_future_cancel_u16.restype = None
598
+ _UniffiLib.ffi_rusto_rust_future_complete_u16.argtypes = (
599
+ ctypes.c_uint64,
600
+ ctypes.POINTER(_UniffiRustCallStatus),
601
+ )
602
+ _UniffiLib.ffi_rusto_rust_future_complete_u16.restype = ctypes.c_uint16
603
+ _UniffiLib.ffi_rusto_rust_future_free_u16.argtypes = (
604
+ ctypes.c_uint64,
605
+ )
606
+ _UniffiLib.ffi_rusto_rust_future_free_u16.restype = None
607
+ _UniffiLib.ffi_rusto_rust_future_poll_i16.argtypes = (
608
+ ctypes.c_uint64,
609
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
610
+ ctypes.c_uint64,
611
+ )
612
+ _UniffiLib.ffi_rusto_rust_future_poll_i16.restype = None
613
+ _UniffiLib.ffi_rusto_rust_future_cancel_i16.argtypes = (
614
+ ctypes.c_uint64,
615
+ )
616
+ _UniffiLib.ffi_rusto_rust_future_cancel_i16.restype = None
617
+ _UniffiLib.ffi_rusto_rust_future_complete_i16.argtypes = (
618
+ ctypes.c_uint64,
619
+ ctypes.POINTER(_UniffiRustCallStatus),
620
+ )
621
+ _UniffiLib.ffi_rusto_rust_future_complete_i16.restype = ctypes.c_int16
622
+ _UniffiLib.ffi_rusto_rust_future_free_i16.argtypes = (
623
+ ctypes.c_uint64,
624
+ )
625
+ _UniffiLib.ffi_rusto_rust_future_free_i16.restype = None
626
+ _UniffiLib.ffi_rusto_rust_future_poll_u32.argtypes = (
627
+ ctypes.c_uint64,
628
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
629
+ ctypes.c_uint64,
630
+ )
631
+ _UniffiLib.ffi_rusto_rust_future_poll_u32.restype = None
632
+ _UniffiLib.ffi_rusto_rust_future_cancel_u32.argtypes = (
633
+ ctypes.c_uint64,
634
+ )
635
+ _UniffiLib.ffi_rusto_rust_future_cancel_u32.restype = None
636
+ _UniffiLib.ffi_rusto_rust_future_complete_u32.argtypes = (
637
+ ctypes.c_uint64,
638
+ ctypes.POINTER(_UniffiRustCallStatus),
639
+ )
640
+ _UniffiLib.ffi_rusto_rust_future_complete_u32.restype = ctypes.c_uint32
641
+ _UniffiLib.ffi_rusto_rust_future_free_u32.argtypes = (
642
+ ctypes.c_uint64,
643
+ )
644
+ _UniffiLib.ffi_rusto_rust_future_free_u32.restype = None
645
+ _UniffiLib.ffi_rusto_rust_future_poll_i32.argtypes = (
646
+ ctypes.c_uint64,
647
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
648
+ ctypes.c_uint64,
649
+ )
650
+ _UniffiLib.ffi_rusto_rust_future_poll_i32.restype = None
651
+ _UniffiLib.ffi_rusto_rust_future_cancel_i32.argtypes = (
652
+ ctypes.c_uint64,
653
+ )
654
+ _UniffiLib.ffi_rusto_rust_future_cancel_i32.restype = None
655
+ _UniffiLib.ffi_rusto_rust_future_complete_i32.argtypes = (
656
+ ctypes.c_uint64,
657
+ ctypes.POINTER(_UniffiRustCallStatus),
658
+ )
659
+ _UniffiLib.ffi_rusto_rust_future_complete_i32.restype = ctypes.c_int32
660
+ _UniffiLib.ffi_rusto_rust_future_free_i32.argtypes = (
661
+ ctypes.c_uint64,
662
+ )
663
+ _UniffiLib.ffi_rusto_rust_future_free_i32.restype = None
664
+ _UniffiLib.ffi_rusto_rust_future_poll_u64.argtypes = (
665
+ ctypes.c_uint64,
666
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
667
+ ctypes.c_uint64,
668
+ )
669
+ _UniffiLib.ffi_rusto_rust_future_poll_u64.restype = None
670
+ _UniffiLib.ffi_rusto_rust_future_cancel_u64.argtypes = (
671
+ ctypes.c_uint64,
672
+ )
673
+ _UniffiLib.ffi_rusto_rust_future_cancel_u64.restype = None
674
+ _UniffiLib.ffi_rusto_rust_future_complete_u64.argtypes = (
675
+ ctypes.c_uint64,
676
+ ctypes.POINTER(_UniffiRustCallStatus),
677
+ )
678
+ _UniffiLib.ffi_rusto_rust_future_complete_u64.restype = ctypes.c_uint64
679
+ _UniffiLib.ffi_rusto_rust_future_free_u64.argtypes = (
680
+ ctypes.c_uint64,
681
+ )
682
+ _UniffiLib.ffi_rusto_rust_future_free_u64.restype = None
683
+ _UniffiLib.ffi_rusto_rust_future_poll_i64.argtypes = (
684
+ ctypes.c_uint64,
685
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
686
+ ctypes.c_uint64,
687
+ )
688
+ _UniffiLib.ffi_rusto_rust_future_poll_i64.restype = None
689
+ _UniffiLib.ffi_rusto_rust_future_cancel_i64.argtypes = (
690
+ ctypes.c_uint64,
691
+ )
692
+ _UniffiLib.ffi_rusto_rust_future_cancel_i64.restype = None
693
+ _UniffiLib.ffi_rusto_rust_future_complete_i64.argtypes = (
694
+ ctypes.c_uint64,
695
+ ctypes.POINTER(_UniffiRustCallStatus),
696
+ )
697
+ _UniffiLib.ffi_rusto_rust_future_complete_i64.restype = ctypes.c_int64
698
+ _UniffiLib.ffi_rusto_rust_future_free_i64.argtypes = (
699
+ ctypes.c_uint64,
700
+ )
701
+ _UniffiLib.ffi_rusto_rust_future_free_i64.restype = None
702
+ _UniffiLib.ffi_rusto_rust_future_poll_f32.argtypes = (
703
+ ctypes.c_uint64,
704
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
705
+ ctypes.c_uint64,
706
+ )
707
+ _UniffiLib.ffi_rusto_rust_future_poll_f32.restype = None
708
+ _UniffiLib.ffi_rusto_rust_future_cancel_f32.argtypes = (
709
+ ctypes.c_uint64,
710
+ )
711
+ _UniffiLib.ffi_rusto_rust_future_cancel_f32.restype = None
712
+ _UniffiLib.ffi_rusto_rust_future_complete_f32.argtypes = (
713
+ ctypes.c_uint64,
714
+ ctypes.POINTER(_UniffiRustCallStatus),
715
+ )
716
+ _UniffiLib.ffi_rusto_rust_future_complete_f32.restype = ctypes.c_float
717
+ _UniffiLib.ffi_rusto_rust_future_free_f32.argtypes = (
718
+ ctypes.c_uint64,
719
+ )
720
+ _UniffiLib.ffi_rusto_rust_future_free_f32.restype = None
721
+ _UniffiLib.ffi_rusto_rust_future_poll_f64.argtypes = (
722
+ ctypes.c_uint64,
723
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
724
+ ctypes.c_uint64,
725
+ )
726
+ _UniffiLib.ffi_rusto_rust_future_poll_f64.restype = None
727
+ _UniffiLib.ffi_rusto_rust_future_cancel_f64.argtypes = (
728
+ ctypes.c_uint64,
729
+ )
730
+ _UniffiLib.ffi_rusto_rust_future_cancel_f64.restype = None
731
+ _UniffiLib.ffi_rusto_rust_future_complete_f64.argtypes = (
732
+ ctypes.c_uint64,
733
+ ctypes.POINTER(_UniffiRustCallStatus),
734
+ )
735
+ _UniffiLib.ffi_rusto_rust_future_complete_f64.restype = ctypes.c_double
736
+ _UniffiLib.ffi_rusto_rust_future_free_f64.argtypes = (
737
+ ctypes.c_uint64,
738
+ )
739
+ _UniffiLib.ffi_rusto_rust_future_free_f64.restype = None
740
+ _UniffiLib.ffi_rusto_rust_future_poll_rust_buffer.argtypes = (
741
+ ctypes.c_uint64,
742
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
743
+ ctypes.c_uint64,
744
+ )
745
+ _UniffiLib.ffi_rusto_rust_future_poll_rust_buffer.restype = None
746
+ _UniffiLib.ffi_rusto_rust_future_cancel_rust_buffer.argtypes = (
747
+ ctypes.c_uint64,
748
+ )
749
+ _UniffiLib.ffi_rusto_rust_future_cancel_rust_buffer.restype = None
750
+ _UniffiLib.ffi_rusto_rust_future_complete_rust_buffer.argtypes = (
751
+ ctypes.c_uint64,
752
+ ctypes.POINTER(_UniffiRustCallStatus),
753
+ )
754
+ _UniffiLib.ffi_rusto_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer
755
+ _UniffiLib.ffi_rusto_rust_future_free_rust_buffer.argtypes = (
756
+ ctypes.c_uint64,
757
+ )
758
+ _UniffiLib.ffi_rusto_rust_future_free_rust_buffer.restype = None
759
+ _UniffiLib.ffi_rusto_rust_future_poll_void.argtypes = (
760
+ ctypes.c_uint64,
761
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
762
+ ctypes.c_uint64,
763
+ )
764
+ _UniffiLib.ffi_rusto_rust_future_poll_void.restype = None
765
+ _UniffiLib.ffi_rusto_rust_future_cancel_void.argtypes = (
766
+ ctypes.c_uint64,
767
+ )
768
+ _UniffiLib.ffi_rusto_rust_future_cancel_void.restype = None
769
+ _UniffiLib.ffi_rusto_rust_future_complete_void.argtypes = (
770
+ ctypes.c_uint64,
771
+ ctypes.POINTER(_UniffiRustCallStatus),
772
+ )
773
+ _UniffiLib.ffi_rusto_rust_future_complete_void.restype = None
774
+ _UniffiLib.ffi_rusto_rust_future_free_void.argtypes = (
775
+ ctypes.c_uint64,
776
+ )
777
+ _UniffiLib.ffi_rusto_rust_future_free_void.restype = None
778
+ _UniffiLib.uniffi_rusto_fn_clone_rusto.argtypes = (
779
+ ctypes.c_uint64,
780
+ ctypes.POINTER(_UniffiRustCallStatus),
781
+ )
782
+ _UniffiLib.uniffi_rusto_fn_clone_rusto.restype = ctypes.c_uint64
783
+ _UniffiLib.uniffi_rusto_fn_free_rusto.argtypes = (
784
+ ctypes.c_uint64,
785
+ ctypes.POINTER(_UniffiRustCallStatus),
786
+ )
787
+ _UniffiLib.uniffi_rusto_fn_free_rusto.restype = None
788
+ _UniffiLib.uniffi_rusto_fn_func_create_initialize_config_ppv6.argtypes = (
789
+ _UniffiRustBuffer,
790
+ _UniffiRustBuffer,
791
+ _UniffiRustBuffer,
792
+ ctypes.POINTER(_UniffiRustCallStatus),
793
+ )
794
+ _UniffiLib.uniffi_rusto_fn_func_create_initialize_config_ppv6.restype = _UniffiRustBuffer
795
+ _UniffiLib.uniffi_rusto_fn_func_default_ocr_run_options.argtypes = (
796
+ ctypes.POINTER(_UniffiRustCallStatus),
797
+ )
798
+ _UniffiLib.uniffi_rusto_fn_func_default_ocr_run_options.restype = _UniffiRustBuffer
799
+ _UniffiLib.uniffi_rusto_fn_func_rusto_version.argtypes = (
800
+ ctypes.POINTER(_UniffiRustCallStatus),
801
+ )
802
+ _UniffiLib.uniffi_rusto_fn_func_rusto_version.restype = _UniffiRustBuffer
803
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize.argtypes = (
804
+ _UniffiRustBuffer,
805
+ ctypes.POINTER(_UniffiRustCallStatus),
806
+ )
807
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize.restype = ctypes.c_uint64
808
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize_from_json.argtypes = (
809
+ _UniffiRustBuffer,
810
+ ctypes.POINTER(_UniffiRustCallStatus),
811
+ )
812
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize_from_json.restype = ctypes.c_uint64
813
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text.argtypes = (
814
+ ctypes.c_uint64,
815
+ _UniffiRustBuffer,
816
+ _UniffiRustBuffer,
817
+ ctypes.POINTER(_UniffiRustCallStatus),
818
+ )
819
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text.restype = _UniffiRustBuffer
820
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text_rgb.argtypes = (
821
+ ctypes.c_uint64,
822
+ _UniffiRustBuffer,
823
+ ctypes.c_uint32,
824
+ ctypes.c_uint32,
825
+ ctypes.c_uint64,
826
+ _UniffiRustBuffer,
827
+ ctypes.POINTER(_UniffiRustCallStatus),
828
+ )
829
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text_rgb.restype = _UniffiRustBuffer
830
+ _UniffiLib.uniffi_rusto_fn_method_rusto_version.argtypes = (
831
+ ctypes.c_uint64,
832
+ ctypes.POINTER(_UniffiRustCallStatus),
833
+ )
834
+ _UniffiLib.uniffi_rusto_fn_method_rusto_version.restype = _UniffiRustBuffer
835
+ _UniffiLib.ffi_rusto_uniffi_contract_version.argtypes = (
836
+ )
837
+ _UniffiLib.ffi_rusto_uniffi_contract_version.restype = ctypes.c_uint32
838
+ _UniffiLib.uniffi_rusto_checksum_func_create_initialize_config_ppv6.argtypes = (
839
+ )
840
+ _UniffiLib.uniffi_rusto_checksum_func_create_initialize_config_ppv6.restype = ctypes.c_uint16
841
+ _UniffiLib.uniffi_rusto_checksum_func_default_ocr_run_options.argtypes = (
842
+ )
843
+ _UniffiLib.uniffi_rusto_checksum_func_default_ocr_run_options.restype = ctypes.c_uint16
844
+ _UniffiLib.uniffi_rusto_checksum_func_rusto_version.argtypes = (
845
+ )
846
+ _UniffiLib.uniffi_rusto_checksum_func_rusto_version.restype = ctypes.c_uint16
847
+ _UniffiLib.uniffi_rusto_checksum_constructor_rusto_initialize.argtypes = (
848
+ )
849
+ _UniffiLib.uniffi_rusto_checksum_constructor_rusto_initialize.restype = ctypes.c_uint16
850
+ _UniffiLib.uniffi_rusto_checksum_constructor_rusto_initialize_from_json.argtypes = (
851
+ )
852
+ _UniffiLib.uniffi_rusto_checksum_constructor_rusto_initialize_from_json.restype = ctypes.c_uint16
853
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_detect_text.argtypes = (
854
+ )
855
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_detect_text.restype = ctypes.c_uint16
856
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_detect_text_rgb.argtypes = (
857
+ )
858
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_detect_text_rgb.restype = ctypes.c_uint16
859
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_version.argtypes = (
860
+ )
861
+ _UniffiLib.uniffi_rusto_checksum_method_rusto_version.restype = ctypes.c_uint16
862
+
863
+ _uniffi_check_contract_api_version(_UniffiLib)
864
+ # _uniffi_check_api_checksums(_UniffiLib)
865
+
866
+
867
+
868
+ # Public interface members begin here.
869
+
870
+
871
+ class _UniffiFfiConverterFloat32(_UniffiConverterPrimitiveFloat):
872
+ @staticmethod
873
+ def read(buf):
874
+ return buf.read_float()
875
+
876
+ @staticmethod
877
+ def write(value, buf):
878
+ buf.write_float(value)
879
+
880
+ class _UniffiFfiConverterOptionalFloat32(_UniffiConverterRustBuffer):
881
+ @classmethod
882
+ def check_lower(cls, value):
883
+ if value is not None:
884
+ _UniffiFfiConverterFloat32.check_lower(value)
885
+
886
+ @classmethod
887
+ def write(cls, value, buf):
888
+ if value is None:
889
+ buf.write_u8(0)
890
+ return
891
+
892
+ buf.write_u8(1)
893
+ _UniffiFfiConverterFloat32.write(value, buf)
894
+
895
+ @classmethod
896
+ def read(cls, buf):
897
+ flag = buf.read_u8()
898
+ if flag == 0:
899
+ return None
900
+ elif flag == 1:
901
+ return _UniffiFfiConverterFloat32.read(buf)
902
+ else:
903
+ raise InternalError("Unexpected flag byte for optional type")
904
+
905
+ @dataclass
906
+ class CalibrationOptions:
907
+ def __init__(self, *, descreen_strength:typing.Optional[float]):
908
+ self.descreen_strength = descreen_strength
909
+
910
+
911
+
912
+
913
+ def __str__(self):
914
+ return "CalibrationOptions(descreen_strength={})".format(self.descreen_strength)
915
+ def __eq__(self, other):
916
+ if self.descreen_strength != other.descreen_strength:
917
+ return False
918
+ return True
919
+
920
+ class _UniffiFfiConverterTypeCalibrationOptions(_UniffiConverterRustBuffer):
921
+ @staticmethod
922
+ def read(buf):
923
+ return CalibrationOptions(
924
+ descreen_strength=_UniffiFfiConverterOptionalFloat32.read(buf),
925
+ )
926
+
927
+ @staticmethod
928
+ def check_lower(value):
929
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.descreen_strength)
930
+
931
+ @staticmethod
932
+ def write(value, buf):
933
+ _UniffiFfiConverterOptionalFloat32.write(value.descreen_strength, buf)
934
+
935
+ class _UniffiFfiConverterBoolean:
936
+ @classmethod
937
+ def check_lower(cls, value):
938
+ return not not value
939
+
940
+ @classmethod
941
+ def lower(cls, value):
942
+ return 1 if value else 0
943
+
944
+ @staticmethod
945
+ def lift(value):
946
+ return value != 0
947
+
948
+ @classmethod
949
+ def read(cls, buf):
950
+ return cls.lift(buf.read_u8())
951
+
952
+ @classmethod
953
+ def write(cls, value, buf):
954
+ buf.write_u8(value)
955
+
956
+ class _UniffiFfiConverterOptionalBoolean(_UniffiConverterRustBuffer):
957
+ @classmethod
958
+ def check_lower(cls, value):
959
+ if value is not None:
960
+ _UniffiFfiConverterBoolean.check_lower(value)
961
+
962
+ @classmethod
963
+ def write(cls, value, buf):
964
+ if value is None:
965
+ buf.write_u8(0)
966
+ return
967
+
968
+ buf.write_u8(1)
969
+ _UniffiFfiConverterBoolean.write(value, buf)
970
+
971
+ @classmethod
972
+ def read(cls, buf):
973
+ flag = buf.read_u8()
974
+ if flag == 0:
975
+ return None
976
+ elif flag == 1:
977
+ return _UniffiFfiConverterBoolean.read(buf)
978
+ else:
979
+ raise InternalError("Unexpected flag byte for optional type")
980
+
981
+ class _UniffiFfiConverterString:
982
+ @staticmethod
983
+ def check_lower(value):
984
+ if not isinstance(value, str):
985
+ raise TypeError("argument must be str, not {}".format(type(value).__name__))
986
+ return value
987
+
988
+ @staticmethod
989
+ def read(buf):
990
+ size = buf.read_i32()
991
+ if size < 0:
992
+ raise InternalError("Unexpected negative string length")
993
+ utf8_bytes = buf.read(size)
994
+ return utf8_bytes.decode("utf-8")
995
+
996
+ @staticmethod
997
+ def write(value, buf):
998
+ utf8_bytes = value.encode("utf-8")
999
+ buf.write_i32(len(utf8_bytes))
1000
+ buf.write(utf8_bytes)
1001
+
1002
+ @staticmethod
1003
+ def lift(buf):
1004
+ with buf.consume_with_stream() as stream:
1005
+ return stream.read(stream.remaining()).decode("utf-8")
1006
+
1007
+ @staticmethod
1008
+ def lower(value):
1009
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
1010
+ builder.write(value.encode("utf-8"))
1011
+ return builder.finalize()
1012
+
1013
+ class _UniffiFfiConverterOptionalString(_UniffiConverterRustBuffer):
1014
+ @classmethod
1015
+ def check_lower(cls, value):
1016
+ if value is not None:
1017
+ _UniffiFfiConverterString.check_lower(value)
1018
+
1019
+ @classmethod
1020
+ def write(cls, value, buf):
1021
+ if value is None:
1022
+ buf.write_u8(0)
1023
+ return
1024
+
1025
+ buf.write_u8(1)
1026
+ _UniffiFfiConverterString.write(value, buf)
1027
+
1028
+ @classmethod
1029
+ def read(cls, buf):
1030
+ flag = buf.read_u8()
1031
+ if flag == 0:
1032
+ return None
1033
+ elif flag == 1:
1034
+ return _UniffiFfiConverterString.read(buf)
1035
+ else:
1036
+ raise InternalError("Unexpected flag byte for optional type")
1037
+
1038
+ @dataclass
1039
+ class ClassificationConfig:
1040
+ def __init__(self, *, enabled:typing.Optional[bool], model_path:typing.Optional[str], thresh:typing.Optional[float]):
1041
+ self.enabled = enabled
1042
+ self.model_path = model_path
1043
+ self.thresh = thresh
1044
+
1045
+
1046
+
1047
+
1048
+ def __str__(self):
1049
+ return "ClassificationConfig(enabled={}, model_path={}, thresh={})".format(self.enabled, self.model_path, self.thresh)
1050
+ def __eq__(self, other):
1051
+ if self.enabled != other.enabled:
1052
+ return False
1053
+ if self.model_path != other.model_path:
1054
+ return False
1055
+ if self.thresh != other.thresh:
1056
+ return False
1057
+ return True
1058
+
1059
+ class _UniffiFfiConverterTypeClassificationConfig(_UniffiConverterRustBuffer):
1060
+ @staticmethod
1061
+ def read(buf):
1062
+ return ClassificationConfig(
1063
+ enabled=_UniffiFfiConverterOptionalBoolean.read(buf),
1064
+ model_path=_UniffiFfiConverterOptionalString.read(buf),
1065
+ thresh=_UniffiFfiConverterOptionalFloat32.read(buf),
1066
+ )
1067
+
1068
+ @staticmethod
1069
+ def check_lower(value):
1070
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.enabled)
1071
+ _UniffiFfiConverterOptionalString.check_lower(value.model_path)
1072
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.thresh)
1073
+
1074
+ @staticmethod
1075
+ def write(value, buf):
1076
+ _UniffiFfiConverterOptionalBoolean.write(value.enabled, buf)
1077
+ _UniffiFfiConverterOptionalString.write(value.model_path, buf)
1078
+ _UniffiFfiConverterOptionalFloat32.write(value.thresh, buf)
1079
+
1080
+ class _UniffiFfiConverterInt32(_UniffiConverterPrimitiveInt):
1081
+ CLASS_NAME = "i32"
1082
+ VALUE_MIN = -2**31
1083
+ VALUE_MAX = 2**31
1084
+
1085
+ @staticmethod
1086
+ def read(buf):
1087
+ return buf.read_i32()
1088
+
1089
+ @staticmethod
1090
+ def write(value, buf):
1091
+ buf.write_i32(value)
1092
+
1093
+ class _UniffiFfiConverterOptionalInt32(_UniffiConverterRustBuffer):
1094
+ @classmethod
1095
+ def check_lower(cls, value):
1096
+ if value is not None:
1097
+ _UniffiFfiConverterInt32.check_lower(value)
1098
+
1099
+ @classmethod
1100
+ def write(cls, value, buf):
1101
+ if value is None:
1102
+ buf.write_u8(0)
1103
+ return
1104
+
1105
+ buf.write_u8(1)
1106
+ _UniffiFfiConverterInt32.write(value, buf)
1107
+
1108
+ @classmethod
1109
+ def read(cls, buf):
1110
+ flag = buf.read_u8()
1111
+ if flag == 0:
1112
+ return None
1113
+ elif flag == 1:
1114
+ return _UniffiFfiConverterInt32.read(buf)
1115
+ else:
1116
+ raise InternalError("Unexpected flag byte for optional type")
1117
+
1118
+ @dataclass
1119
+ class DetectionConfig:
1120
+ def __init__(self, *, enabled:typing.Optional[bool], model_path:typing.Optional[str], thresh:typing.Optional[float], box_thresh:typing.Optional[float], unclip_ratio:typing.Optional[float], limit_side_len:typing.Optional[int], limit_type:typing.Optional[str], use_dilation:typing.Optional[bool]):
1121
+ self.enabled = enabled
1122
+ self.model_path = model_path
1123
+ self.thresh = thresh
1124
+ self.box_thresh = box_thresh
1125
+ self.unclip_ratio = unclip_ratio
1126
+ self.limit_side_len = limit_side_len
1127
+ self.limit_type = limit_type
1128
+ self.use_dilation = use_dilation
1129
+
1130
+
1131
+
1132
+
1133
+ def __str__(self):
1134
+ return "DetectionConfig(enabled={}, model_path={}, thresh={}, box_thresh={}, unclip_ratio={}, limit_side_len={}, limit_type={}, use_dilation={})".format(self.enabled, self.model_path, self.thresh, self.box_thresh, self.unclip_ratio, self.limit_side_len, self.limit_type, self.use_dilation)
1135
+ def __eq__(self, other):
1136
+ if self.enabled != other.enabled:
1137
+ return False
1138
+ if self.model_path != other.model_path:
1139
+ return False
1140
+ if self.thresh != other.thresh:
1141
+ return False
1142
+ if self.box_thresh != other.box_thresh:
1143
+ return False
1144
+ if self.unclip_ratio != other.unclip_ratio:
1145
+ return False
1146
+ if self.limit_side_len != other.limit_side_len:
1147
+ return False
1148
+ if self.limit_type != other.limit_type:
1149
+ return False
1150
+ if self.use_dilation != other.use_dilation:
1151
+ return False
1152
+ return True
1153
+
1154
+ class _UniffiFfiConverterTypeDetectionConfig(_UniffiConverterRustBuffer):
1155
+ @staticmethod
1156
+ def read(buf):
1157
+ return DetectionConfig(
1158
+ enabled=_UniffiFfiConverterOptionalBoolean.read(buf),
1159
+ model_path=_UniffiFfiConverterOptionalString.read(buf),
1160
+ thresh=_UniffiFfiConverterOptionalFloat32.read(buf),
1161
+ box_thresh=_UniffiFfiConverterOptionalFloat32.read(buf),
1162
+ unclip_ratio=_UniffiFfiConverterOptionalFloat32.read(buf),
1163
+ limit_side_len=_UniffiFfiConverterOptionalInt32.read(buf),
1164
+ limit_type=_UniffiFfiConverterOptionalString.read(buf),
1165
+ use_dilation=_UniffiFfiConverterOptionalBoolean.read(buf),
1166
+ )
1167
+
1168
+ @staticmethod
1169
+ def check_lower(value):
1170
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.enabled)
1171
+ _UniffiFfiConverterOptionalString.check_lower(value.model_path)
1172
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.thresh)
1173
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.box_thresh)
1174
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.unclip_ratio)
1175
+ _UniffiFfiConverterOptionalInt32.check_lower(value.limit_side_len)
1176
+ _UniffiFfiConverterOptionalString.check_lower(value.limit_type)
1177
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.use_dilation)
1178
+
1179
+ @staticmethod
1180
+ def write(value, buf):
1181
+ _UniffiFfiConverterOptionalBoolean.write(value.enabled, buf)
1182
+ _UniffiFfiConverterOptionalString.write(value.model_path, buf)
1183
+ _UniffiFfiConverterOptionalFloat32.write(value.thresh, buf)
1184
+ _UniffiFfiConverterOptionalFloat32.write(value.box_thresh, buf)
1185
+ _UniffiFfiConverterOptionalFloat32.write(value.unclip_ratio, buf)
1186
+ _UniffiFfiConverterOptionalInt32.write(value.limit_side_len, buf)
1187
+ _UniffiFfiConverterOptionalString.write(value.limit_type, buf)
1188
+ _UniffiFfiConverterOptionalBoolean.write(value.use_dilation, buf)
1189
+
1190
+ class _UniffiFfiConverterSequenceFloat32(_UniffiConverterRustBuffer):
1191
+ @classmethod
1192
+ def check_lower(cls, value):
1193
+ for item in value:
1194
+ _UniffiFfiConverterFloat32.check_lower(item)
1195
+
1196
+ @classmethod
1197
+ def write(cls, value, buf):
1198
+ items = len(value)
1199
+ buf.write_i32(items)
1200
+ for item in value:
1201
+ _UniffiFfiConverterFloat32.write(item, buf)
1202
+
1203
+ @classmethod
1204
+ def read(cls, buf):
1205
+ count = buf.read_i32()
1206
+ if count < 0:
1207
+ raise InternalError("Unexpected negative sequence length")
1208
+
1209
+ return [
1210
+ _UniffiFfiConverterFloat32.read(buf) for i in range(count)
1211
+ ]
1212
+
1213
+ class _UniffiFfiConverterOptionalSequenceFloat32(_UniffiConverterRustBuffer):
1214
+ @classmethod
1215
+ def check_lower(cls, value):
1216
+ if value is not None:
1217
+ _UniffiFfiConverterSequenceFloat32.check_lower(value)
1218
+
1219
+ @classmethod
1220
+ def write(cls, value, buf):
1221
+ if value is None:
1222
+ buf.write_u8(0)
1223
+ return
1224
+
1225
+ buf.write_u8(1)
1226
+ _UniffiFfiConverterSequenceFloat32.write(value, buf)
1227
+
1228
+ @classmethod
1229
+ def read(cls, buf):
1230
+ flag = buf.read_u8()
1231
+ if flag == 0:
1232
+ return None
1233
+ elif flag == 1:
1234
+ return _UniffiFfiConverterSequenceFloat32.read(buf)
1235
+ else:
1236
+ raise InternalError("Unexpected flag byte for optional type")
1237
+
1238
+ @dataclass
1239
+ class PostprocessRunOptions:
1240
+ def __init__(self, *, threshold:typing.Optional[float], box_threshold:typing.Optional[float], max_candidates:typing.Optional[int], unclip_ratio:typing.Optional[float], use_dilation:typing.Optional[bool]):
1241
+ self.threshold = threshold
1242
+ self.box_threshold = box_threshold
1243
+ self.max_candidates = max_candidates
1244
+ self.unclip_ratio = unclip_ratio
1245
+ self.use_dilation = use_dilation
1246
+
1247
+
1248
+
1249
+
1250
+ def __str__(self):
1251
+ return "PostprocessRunOptions(threshold={}, box_threshold={}, max_candidates={}, unclip_ratio={}, use_dilation={})".format(self.threshold, self.box_threshold, self.max_candidates, self.unclip_ratio, self.use_dilation)
1252
+ def __eq__(self, other):
1253
+ if self.threshold != other.threshold:
1254
+ return False
1255
+ if self.box_threshold != other.box_threshold:
1256
+ return False
1257
+ if self.max_candidates != other.max_candidates:
1258
+ return False
1259
+ if self.unclip_ratio != other.unclip_ratio:
1260
+ return False
1261
+ if self.use_dilation != other.use_dilation:
1262
+ return False
1263
+ return True
1264
+
1265
+ class _UniffiFfiConverterTypePostprocessRunOptions(_UniffiConverterRustBuffer):
1266
+ @staticmethod
1267
+ def read(buf):
1268
+ return PostprocessRunOptions(
1269
+ threshold=_UniffiFfiConverterOptionalFloat32.read(buf),
1270
+ box_threshold=_UniffiFfiConverterOptionalFloat32.read(buf),
1271
+ max_candidates=_UniffiFfiConverterOptionalInt32.read(buf),
1272
+ unclip_ratio=_UniffiFfiConverterOptionalFloat32.read(buf),
1273
+ use_dilation=_UniffiFfiConverterOptionalBoolean.read(buf),
1274
+ )
1275
+
1276
+ @staticmethod
1277
+ def check_lower(value):
1278
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.threshold)
1279
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.box_threshold)
1280
+ _UniffiFfiConverterOptionalInt32.check_lower(value.max_candidates)
1281
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.unclip_ratio)
1282
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.use_dilation)
1283
+
1284
+ @staticmethod
1285
+ def write(value, buf):
1286
+ _UniffiFfiConverterOptionalFloat32.write(value.threshold, buf)
1287
+ _UniffiFfiConverterOptionalFloat32.write(value.box_threshold, buf)
1288
+ _UniffiFfiConverterOptionalInt32.write(value.max_candidates, buf)
1289
+ _UniffiFfiConverterOptionalFloat32.write(value.unclip_ratio, buf)
1290
+ _UniffiFfiConverterOptionalBoolean.write(value.use_dilation, buf)
1291
+
1292
+ class _UniffiFfiConverterOptionalTypePostprocessRunOptions(_UniffiConverterRustBuffer):
1293
+ @classmethod
1294
+ def check_lower(cls, value):
1295
+ if value is not None:
1296
+ _UniffiFfiConverterTypePostprocessRunOptions.check_lower(value)
1297
+
1298
+ @classmethod
1299
+ def write(cls, value, buf):
1300
+ if value is None:
1301
+ buf.write_u8(0)
1302
+ return
1303
+
1304
+ buf.write_u8(1)
1305
+ _UniffiFfiConverterTypePostprocessRunOptions.write(value, buf)
1306
+
1307
+ @classmethod
1308
+ def read(cls, buf):
1309
+ flag = buf.read_u8()
1310
+ if flag == 0:
1311
+ return None
1312
+ elif flag == 1:
1313
+ return _UniffiFfiConverterTypePostprocessRunOptions.read(buf)
1314
+ else:
1315
+ raise InternalError("Unexpected flag byte for optional type")
1316
+
1317
+ @dataclass
1318
+ class DetectionRunOptions:
1319
+ def __init__(self, *, limit_side_len:typing.Optional[int], limit_type:typing.Optional[str], mean:typing.Optional[typing.List[float]], std:typing.Optional[typing.List[float]], postprocess:typing.Optional[PostprocessRunOptions]):
1320
+ self.limit_side_len = limit_side_len
1321
+ self.limit_type = limit_type
1322
+ self.mean = mean
1323
+ self.std = std
1324
+ self.postprocess = postprocess
1325
+
1326
+
1327
+
1328
+
1329
+ def __str__(self):
1330
+ return "DetectionRunOptions(limit_side_len={}, limit_type={}, mean={}, std={}, postprocess={})".format(self.limit_side_len, self.limit_type, self.mean, self.std, self.postprocess)
1331
+ def __eq__(self, other):
1332
+ if self.limit_side_len != other.limit_side_len:
1333
+ return False
1334
+ if self.limit_type != other.limit_type:
1335
+ return False
1336
+ if self.mean != other.mean:
1337
+ return False
1338
+ if self.std != other.std:
1339
+ return False
1340
+ if self.postprocess != other.postprocess:
1341
+ return False
1342
+ return True
1343
+
1344
+ class _UniffiFfiConverterTypeDetectionRunOptions(_UniffiConverterRustBuffer):
1345
+ @staticmethod
1346
+ def read(buf):
1347
+ return DetectionRunOptions(
1348
+ limit_side_len=_UniffiFfiConverterOptionalInt32.read(buf),
1349
+ limit_type=_UniffiFfiConverterOptionalString.read(buf),
1350
+ mean=_UniffiFfiConverterOptionalSequenceFloat32.read(buf),
1351
+ std=_UniffiFfiConverterOptionalSequenceFloat32.read(buf),
1352
+ postprocess=_UniffiFfiConverterOptionalTypePostprocessRunOptions.read(buf),
1353
+ )
1354
+
1355
+ @staticmethod
1356
+ def check_lower(value):
1357
+ _UniffiFfiConverterOptionalInt32.check_lower(value.limit_side_len)
1358
+ _UniffiFfiConverterOptionalString.check_lower(value.limit_type)
1359
+ _UniffiFfiConverterOptionalSequenceFloat32.check_lower(value.mean)
1360
+ _UniffiFfiConverterOptionalSequenceFloat32.check_lower(value.std)
1361
+ _UniffiFfiConverterOptionalTypePostprocessRunOptions.check_lower(value.postprocess)
1362
+
1363
+ @staticmethod
1364
+ def write(value, buf):
1365
+ _UniffiFfiConverterOptionalInt32.write(value.limit_side_len, buf)
1366
+ _UniffiFfiConverterOptionalString.write(value.limit_type, buf)
1367
+ _UniffiFfiConverterOptionalSequenceFloat32.write(value.mean, buf)
1368
+ _UniffiFfiConverterOptionalSequenceFloat32.write(value.std, buf)
1369
+ _UniffiFfiConverterOptionalTypePostprocessRunOptions.write(value.postprocess, buf)
1370
+
1371
+ @dataclass
1372
+ class Frame:
1373
+ def __init__(self, *, width:float, height:float, top:float, left:float):
1374
+ self.width = width
1375
+ self.height = height
1376
+ self.top = top
1377
+ self.left = left
1378
+
1379
+
1380
+
1381
+
1382
+ def __str__(self):
1383
+ return "Frame(width={}, height={}, top={}, left={})".format(self.width, self.height, self.top, self.left)
1384
+ def __eq__(self, other):
1385
+ if self.width != other.width:
1386
+ return False
1387
+ if self.height != other.height:
1388
+ return False
1389
+ if self.top != other.top:
1390
+ return False
1391
+ if self.left != other.left:
1392
+ return False
1393
+ return True
1394
+
1395
+ class _UniffiFfiConverterTypeFrame(_UniffiConverterRustBuffer):
1396
+ @staticmethod
1397
+ def read(buf):
1398
+ return Frame(
1399
+ width=_UniffiFfiConverterFloat32.read(buf),
1400
+ height=_UniffiFfiConverterFloat32.read(buf),
1401
+ top=_UniffiFfiConverterFloat32.read(buf),
1402
+ left=_UniffiFfiConverterFloat32.read(buf),
1403
+ )
1404
+
1405
+ @staticmethod
1406
+ def check_lower(value):
1407
+ _UniffiFfiConverterFloat32.check_lower(value.width)
1408
+ _UniffiFfiConverterFloat32.check_lower(value.height)
1409
+ _UniffiFfiConverterFloat32.check_lower(value.top)
1410
+ _UniffiFfiConverterFloat32.check_lower(value.left)
1411
+
1412
+ @staticmethod
1413
+ def write(value, buf):
1414
+ _UniffiFfiConverterFloat32.write(value.width, buf)
1415
+ _UniffiFfiConverterFloat32.write(value.height, buf)
1416
+ _UniffiFfiConverterFloat32.write(value.top, buf)
1417
+ _UniffiFfiConverterFloat32.write(value.left, buf)
1418
+
1419
+ class _UniffiFfiConverterOptionalTypeDetectionConfig(_UniffiConverterRustBuffer):
1420
+ @classmethod
1421
+ def check_lower(cls, value):
1422
+ if value is not None:
1423
+ _UniffiFfiConverterTypeDetectionConfig.check_lower(value)
1424
+
1425
+ @classmethod
1426
+ def write(cls, value, buf):
1427
+ if value is None:
1428
+ buf.write_u8(0)
1429
+ return
1430
+
1431
+ buf.write_u8(1)
1432
+ _UniffiFfiConverterTypeDetectionConfig.write(value, buf)
1433
+
1434
+ @classmethod
1435
+ def read(cls, buf):
1436
+ flag = buf.read_u8()
1437
+ if flag == 0:
1438
+ return None
1439
+ elif flag == 1:
1440
+ return _UniffiFfiConverterTypeDetectionConfig.read(buf)
1441
+ else:
1442
+ raise InternalError("Unexpected flag byte for optional type")
1443
+
1444
+ @dataclass
1445
+ class RecognitionConfig:
1446
+ def __init__(self, *, enabled:typing.Optional[bool], model_path:typing.Optional[str], dict_path:typing.Optional[str]):
1447
+ self.enabled = enabled
1448
+ self.model_path = model_path
1449
+ self.dict_path = dict_path
1450
+
1451
+
1452
+
1453
+
1454
+ def __str__(self):
1455
+ return "RecognitionConfig(enabled={}, model_path={}, dict_path={})".format(self.enabled, self.model_path, self.dict_path)
1456
+ def __eq__(self, other):
1457
+ if self.enabled != other.enabled:
1458
+ return False
1459
+ if self.model_path != other.model_path:
1460
+ return False
1461
+ if self.dict_path != other.dict_path:
1462
+ return False
1463
+ return True
1464
+
1465
+ class _UniffiFfiConverterTypeRecognitionConfig(_UniffiConverterRustBuffer):
1466
+ @staticmethod
1467
+ def read(buf):
1468
+ return RecognitionConfig(
1469
+ enabled=_UniffiFfiConverterOptionalBoolean.read(buf),
1470
+ model_path=_UniffiFfiConverterOptionalString.read(buf),
1471
+ dict_path=_UniffiFfiConverterOptionalString.read(buf),
1472
+ )
1473
+
1474
+ @staticmethod
1475
+ def check_lower(value):
1476
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.enabled)
1477
+ _UniffiFfiConverterOptionalString.check_lower(value.model_path)
1478
+ _UniffiFfiConverterOptionalString.check_lower(value.dict_path)
1479
+
1480
+ @staticmethod
1481
+ def write(value, buf):
1482
+ _UniffiFfiConverterOptionalBoolean.write(value.enabled, buf)
1483
+ _UniffiFfiConverterOptionalString.write(value.model_path, buf)
1484
+ _UniffiFfiConverterOptionalString.write(value.dict_path, buf)
1485
+
1486
+ class _UniffiFfiConverterOptionalTypeRecognitionConfig(_UniffiConverterRustBuffer):
1487
+ @classmethod
1488
+ def check_lower(cls, value):
1489
+ if value is not None:
1490
+ _UniffiFfiConverterTypeRecognitionConfig.check_lower(value)
1491
+
1492
+ @classmethod
1493
+ def write(cls, value, buf):
1494
+ if value is None:
1495
+ buf.write_u8(0)
1496
+ return
1497
+
1498
+ buf.write_u8(1)
1499
+ _UniffiFfiConverterTypeRecognitionConfig.write(value, buf)
1500
+
1501
+ @classmethod
1502
+ def read(cls, buf):
1503
+ flag = buf.read_u8()
1504
+ if flag == 0:
1505
+ return None
1506
+ elif flag == 1:
1507
+ return _UniffiFfiConverterTypeRecognitionConfig.read(buf)
1508
+ else:
1509
+ raise InternalError("Unexpected flag byte for optional type")
1510
+
1511
+ class _UniffiFfiConverterOptionalTypeClassificationConfig(_UniffiConverterRustBuffer):
1512
+ @classmethod
1513
+ def check_lower(cls, value):
1514
+ if value is not None:
1515
+ _UniffiFfiConverterTypeClassificationConfig.check_lower(value)
1516
+
1517
+ @classmethod
1518
+ def write(cls, value, buf):
1519
+ if value is None:
1520
+ buf.write_u8(0)
1521
+ return
1522
+
1523
+ buf.write_u8(1)
1524
+ _UniffiFfiConverterTypeClassificationConfig.write(value, buf)
1525
+
1526
+ @classmethod
1527
+ def read(cls, buf):
1528
+ flag = buf.read_u8()
1529
+ if flag == 0:
1530
+ return None
1531
+ elif flag == 1:
1532
+ return _UniffiFfiConverterTypeClassificationConfig.read(buf)
1533
+ else:
1534
+ raise InternalError("Unexpected flag byte for optional type")
1535
+
1536
+ @dataclass
1537
+ class OrientationConfig:
1538
+ def __init__(self, *, enabled:typing.Optional[bool], model_path:typing.Optional[str], thresh:typing.Optional[float]):
1539
+ self.enabled = enabled
1540
+ self.model_path = model_path
1541
+ self.thresh = thresh
1542
+
1543
+
1544
+
1545
+
1546
+ def __str__(self):
1547
+ return "OrientationConfig(enabled={}, model_path={}, thresh={})".format(self.enabled, self.model_path, self.thresh)
1548
+ def __eq__(self, other):
1549
+ if self.enabled != other.enabled:
1550
+ return False
1551
+ if self.model_path != other.model_path:
1552
+ return False
1553
+ if self.thresh != other.thresh:
1554
+ return False
1555
+ return True
1556
+
1557
+ class _UniffiFfiConverterTypeOrientationConfig(_UniffiConverterRustBuffer):
1558
+ @staticmethod
1559
+ def read(buf):
1560
+ return OrientationConfig(
1561
+ enabled=_UniffiFfiConverterOptionalBoolean.read(buf),
1562
+ model_path=_UniffiFfiConverterOptionalString.read(buf),
1563
+ thresh=_UniffiFfiConverterOptionalFloat32.read(buf),
1564
+ )
1565
+
1566
+ @staticmethod
1567
+ def check_lower(value):
1568
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.enabled)
1569
+ _UniffiFfiConverterOptionalString.check_lower(value.model_path)
1570
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.thresh)
1571
+
1572
+ @staticmethod
1573
+ def write(value, buf):
1574
+ _UniffiFfiConverterOptionalBoolean.write(value.enabled, buf)
1575
+ _UniffiFfiConverterOptionalString.write(value.model_path, buf)
1576
+ _UniffiFfiConverterOptionalFloat32.write(value.thresh, buf)
1577
+
1578
+ class _UniffiFfiConverterOptionalTypeOrientationConfig(_UniffiConverterRustBuffer):
1579
+ @classmethod
1580
+ def check_lower(cls, value):
1581
+ if value is not None:
1582
+ _UniffiFfiConverterTypeOrientationConfig.check_lower(value)
1583
+
1584
+ @classmethod
1585
+ def write(cls, value, buf):
1586
+ if value is None:
1587
+ buf.write_u8(0)
1588
+ return
1589
+
1590
+ buf.write_u8(1)
1591
+ _UniffiFfiConverterTypeOrientationConfig.write(value, buf)
1592
+
1593
+ @classmethod
1594
+ def read(cls, buf):
1595
+ flag = buf.read_u8()
1596
+ if flag == 0:
1597
+ return None
1598
+ elif flag == 1:
1599
+ return _UniffiFfiConverterTypeOrientationConfig.read(buf)
1600
+ else:
1601
+ raise InternalError("Unexpected flag byte for optional type")
1602
+
1603
+ @dataclass
1604
+ class UnwarpConfig:
1605
+ def __init__(self, *, enabled:typing.Optional[bool], model_path:typing.Optional[str]):
1606
+ self.enabled = enabled
1607
+ self.model_path = model_path
1608
+
1609
+
1610
+
1611
+
1612
+ def __str__(self):
1613
+ return "UnwarpConfig(enabled={}, model_path={})".format(self.enabled, self.model_path)
1614
+ def __eq__(self, other):
1615
+ if self.enabled != other.enabled:
1616
+ return False
1617
+ if self.model_path != other.model_path:
1618
+ return False
1619
+ return True
1620
+
1621
+ class _UniffiFfiConverterTypeUnwarpConfig(_UniffiConverterRustBuffer):
1622
+ @staticmethod
1623
+ def read(buf):
1624
+ return UnwarpConfig(
1625
+ enabled=_UniffiFfiConverterOptionalBoolean.read(buf),
1626
+ model_path=_UniffiFfiConverterOptionalString.read(buf),
1627
+ )
1628
+
1629
+ @staticmethod
1630
+ def check_lower(value):
1631
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.enabled)
1632
+ _UniffiFfiConverterOptionalString.check_lower(value.model_path)
1633
+
1634
+ @staticmethod
1635
+ def write(value, buf):
1636
+ _UniffiFfiConverterOptionalBoolean.write(value.enabled, buf)
1637
+ _UniffiFfiConverterOptionalString.write(value.model_path, buf)
1638
+
1639
+ class _UniffiFfiConverterOptionalTypeUnwarpConfig(_UniffiConverterRustBuffer):
1640
+ @classmethod
1641
+ def check_lower(cls, value):
1642
+ if value is not None:
1643
+ _UniffiFfiConverterTypeUnwarpConfig.check_lower(value)
1644
+
1645
+ @classmethod
1646
+ def write(cls, value, buf):
1647
+ if value is None:
1648
+ buf.write_u8(0)
1649
+ return
1650
+
1651
+ buf.write_u8(1)
1652
+ _UniffiFfiConverterTypeUnwarpConfig.write(value, buf)
1653
+
1654
+ @classmethod
1655
+ def read(cls, buf):
1656
+ flag = buf.read_u8()
1657
+ if flag == 0:
1658
+ return None
1659
+ elif flag == 1:
1660
+ return _UniffiFfiConverterTypeUnwarpConfig.read(buf)
1661
+ else:
1662
+ raise InternalError("Unexpected flag byte for optional type")
1663
+
1664
+ @dataclass
1665
+ class InitializeConfig:
1666
+ def __init__(self, *, template:typing.Optional[str], detection:typing.Optional[DetectionConfig], recognition:typing.Optional[RecognitionConfig], classification:typing.Optional[ClassificationConfig], orientation:typing.Optional[OrientationConfig], unwarp:typing.Optional[UnwarpConfig]):
1667
+ self.template = template
1668
+ self.detection = detection
1669
+ self.recognition = recognition
1670
+ self.classification = classification
1671
+ self.orientation = orientation
1672
+ self.unwarp = unwarp
1673
+
1674
+
1675
+
1676
+
1677
+ def __str__(self):
1678
+ return "InitializeConfig(template={}, detection={}, recognition={}, classification={}, orientation={}, unwarp={})".format(self.template, self.detection, self.recognition, self.classification, self.orientation, self.unwarp)
1679
+ def __eq__(self, other):
1680
+ if self.template != other.template:
1681
+ return False
1682
+ if self.detection != other.detection:
1683
+ return False
1684
+ if self.recognition != other.recognition:
1685
+ return False
1686
+ if self.classification != other.classification:
1687
+ return False
1688
+ if self.orientation != other.orientation:
1689
+ return False
1690
+ if self.unwarp != other.unwarp:
1691
+ return False
1692
+ return True
1693
+
1694
+ class _UniffiFfiConverterTypeInitializeConfig(_UniffiConverterRustBuffer):
1695
+ @staticmethod
1696
+ def read(buf):
1697
+ return InitializeConfig(
1698
+ template=_UniffiFfiConverterOptionalString.read(buf),
1699
+ detection=_UniffiFfiConverterOptionalTypeDetectionConfig.read(buf),
1700
+ recognition=_UniffiFfiConverterOptionalTypeRecognitionConfig.read(buf),
1701
+ classification=_UniffiFfiConverterOptionalTypeClassificationConfig.read(buf),
1702
+ orientation=_UniffiFfiConverterOptionalTypeOrientationConfig.read(buf),
1703
+ unwarp=_UniffiFfiConverterOptionalTypeUnwarpConfig.read(buf),
1704
+ )
1705
+
1706
+ @staticmethod
1707
+ def check_lower(value):
1708
+ _UniffiFfiConverterOptionalString.check_lower(value.template)
1709
+ _UniffiFfiConverterOptionalTypeDetectionConfig.check_lower(value.detection)
1710
+ _UniffiFfiConverterOptionalTypeRecognitionConfig.check_lower(value.recognition)
1711
+ _UniffiFfiConverterOptionalTypeClassificationConfig.check_lower(value.classification)
1712
+ _UniffiFfiConverterOptionalTypeOrientationConfig.check_lower(value.orientation)
1713
+ _UniffiFfiConverterOptionalTypeUnwarpConfig.check_lower(value.unwarp)
1714
+
1715
+ @staticmethod
1716
+ def write(value, buf):
1717
+ _UniffiFfiConverterOptionalString.write(value.template, buf)
1718
+ _UniffiFfiConverterOptionalTypeDetectionConfig.write(value.detection, buf)
1719
+ _UniffiFfiConverterOptionalTypeRecognitionConfig.write(value.recognition, buf)
1720
+ _UniffiFfiConverterOptionalTypeClassificationConfig.write(value.classification, buf)
1721
+ _UniffiFfiConverterOptionalTypeOrientationConfig.write(value.orientation, buf)
1722
+ _UniffiFfiConverterOptionalTypeUnwarpConfig.write(value.unwarp, buf)
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+ class OutputGranularity(enum.Enum):
1730
+
1731
+ LINES = 0
1732
+
1733
+ WORDS = 1
1734
+
1735
+ SPATIAL = 2
1736
+
1737
+
1738
+
1739
+ class _UniffiFfiConverterTypeOutputGranularity(_UniffiConverterRustBuffer):
1740
+ @staticmethod
1741
+ def read(buf):
1742
+ variant = buf.read_i32()
1743
+ if variant == 1:
1744
+ return OutputGranularity.LINES
1745
+ if variant == 2:
1746
+ return OutputGranularity.WORDS
1747
+ if variant == 3:
1748
+ return OutputGranularity.SPATIAL
1749
+ raise InternalError("Raw enum value doesn't match any cases")
1750
+
1751
+ @staticmethod
1752
+ def check_lower(value):
1753
+ if value == OutputGranularity.LINES:
1754
+ return
1755
+ if value == OutputGranularity.WORDS:
1756
+ return
1757
+ if value == OutputGranularity.SPATIAL:
1758
+ return
1759
+ raise ValueError(value)
1760
+
1761
+ @staticmethod
1762
+ def write(value, buf):
1763
+ if value == OutputGranularity.LINES:
1764
+ buf.write_i32(1)
1765
+ if value == OutputGranularity.WORDS:
1766
+ buf.write_i32(2)
1767
+ if value == OutputGranularity.SPATIAL:
1768
+ buf.write_i32(3)
1769
+
1770
+
1771
+
1772
+ class _UniffiFfiConverterOptionalTypeDetectionRunOptions(_UniffiConverterRustBuffer):
1773
+ @classmethod
1774
+ def check_lower(cls, value):
1775
+ if value is not None:
1776
+ _UniffiFfiConverterTypeDetectionRunOptions.check_lower(value)
1777
+
1778
+ @classmethod
1779
+ def write(cls, value, buf):
1780
+ if value is None:
1781
+ buf.write_u8(0)
1782
+ return
1783
+
1784
+ buf.write_u8(1)
1785
+ _UniffiFfiConverterTypeDetectionRunOptions.write(value, buf)
1786
+
1787
+ @classmethod
1788
+ def read(cls, buf):
1789
+ flag = buf.read_u8()
1790
+ if flag == 0:
1791
+ return None
1792
+ elif flag == 1:
1793
+ return _UniffiFfiConverterTypeDetectionRunOptions.read(buf)
1794
+ else:
1795
+ raise InternalError("Unexpected flag byte for optional type")
1796
+
1797
+ class _UniffiFfiConverterOptionalTypeCalibrationOptions(_UniffiConverterRustBuffer):
1798
+ @classmethod
1799
+ def check_lower(cls, value):
1800
+ if value is not None:
1801
+ _UniffiFfiConverterTypeCalibrationOptions.check_lower(value)
1802
+
1803
+ @classmethod
1804
+ def write(cls, value, buf):
1805
+ if value is None:
1806
+ buf.write_u8(0)
1807
+ return
1808
+
1809
+ buf.write_u8(1)
1810
+ _UniffiFfiConverterTypeCalibrationOptions.write(value, buf)
1811
+
1812
+ @classmethod
1813
+ def read(cls, buf):
1814
+ flag = buf.read_u8()
1815
+ if flag == 0:
1816
+ return None
1817
+ elif flag == 1:
1818
+ return _UniffiFfiConverterTypeCalibrationOptions.read(buf)
1819
+ else:
1820
+ raise InternalError("Unexpected flag byte for optional type")
1821
+
1822
+ @dataclass
1823
+ class OptimizationOptions:
1824
+ def __init__(self, *, crop_padding_x:typing.Optional[float], crop_padding_y:typing.Optional[float]):
1825
+ self.crop_padding_x = crop_padding_x
1826
+ self.crop_padding_y = crop_padding_y
1827
+
1828
+
1829
+
1830
+
1831
+ def __str__(self):
1832
+ return "OptimizationOptions(crop_padding_x={}, crop_padding_y={})".format(self.crop_padding_x, self.crop_padding_y)
1833
+ def __eq__(self, other):
1834
+ if self.crop_padding_x != other.crop_padding_x:
1835
+ return False
1836
+ if self.crop_padding_y != other.crop_padding_y:
1837
+ return False
1838
+ return True
1839
+
1840
+ class _UniffiFfiConverterTypeOptimizationOptions(_UniffiConverterRustBuffer):
1841
+ @staticmethod
1842
+ def read(buf):
1843
+ return OptimizationOptions(
1844
+ crop_padding_x=_UniffiFfiConverterOptionalFloat32.read(buf),
1845
+ crop_padding_y=_UniffiFfiConverterOptionalFloat32.read(buf),
1846
+ )
1847
+
1848
+ @staticmethod
1849
+ def check_lower(value):
1850
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.crop_padding_x)
1851
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.crop_padding_y)
1852
+
1853
+ @staticmethod
1854
+ def write(value, buf):
1855
+ _UniffiFfiConverterOptionalFloat32.write(value.crop_padding_x, buf)
1856
+ _UniffiFfiConverterOptionalFloat32.write(value.crop_padding_y, buf)
1857
+
1858
+ class _UniffiFfiConverterOptionalTypeOptimizationOptions(_UniffiConverterRustBuffer):
1859
+ @classmethod
1860
+ def check_lower(cls, value):
1861
+ if value is not None:
1862
+ _UniffiFfiConverterTypeOptimizationOptions.check_lower(value)
1863
+
1864
+ @classmethod
1865
+ def write(cls, value, buf):
1866
+ if value is None:
1867
+ buf.write_u8(0)
1868
+ return
1869
+
1870
+ buf.write_u8(1)
1871
+ _UniffiFfiConverterTypeOptimizationOptions.write(value, buf)
1872
+
1873
+ @classmethod
1874
+ def read(cls, buf):
1875
+ flag = buf.read_u8()
1876
+ if flag == 0:
1877
+ return None
1878
+ elif flag == 1:
1879
+ return _UniffiFfiConverterTypeOptimizationOptions.read(buf)
1880
+ else:
1881
+ raise InternalError("Unexpected flag byte for optional type")
1882
+
1883
+ @dataclass
1884
+ class OcrRunOptions:
1885
+ def __init__(self, *, output:OutputGranularity, line_y_threshold:typing.Optional[float], word_x_threshold:typing.Optional[float], text_score:typing.Optional[float], classification:typing.Optional[bool], orientation:typing.Optional[bool], min_height:typing.Optional[float], max_side_len:typing.Optional[float], min_side_len:typing.Optional[float], width_height_ratio:typing.Optional[float], detection:typing.Optional[DetectionRunOptions], postprocess:typing.Optional[PostprocessRunOptions], calibration:typing.Optional[CalibrationOptions], optimization:typing.Optional[OptimizationOptions]):
1886
+ self.output = output
1887
+ self.line_y_threshold = line_y_threshold
1888
+ self.word_x_threshold = word_x_threshold
1889
+ self.text_score = text_score
1890
+ self.classification = classification
1891
+ self.orientation = orientation
1892
+ self.min_height = min_height
1893
+ self.max_side_len = max_side_len
1894
+ self.min_side_len = min_side_len
1895
+ self.width_height_ratio = width_height_ratio
1896
+ self.detection = detection
1897
+ self.postprocess = postprocess
1898
+ self.calibration = calibration
1899
+ self.optimization = optimization
1900
+
1901
+
1902
+
1903
+
1904
+ def __str__(self):
1905
+ return "OcrRunOptions(output={}, line_y_threshold={}, word_x_threshold={}, text_score={}, classification={}, orientation={}, min_height={}, max_side_len={}, min_side_len={}, width_height_ratio={}, detection={}, postprocess={}, calibration={}, optimization={})".format(self.output, self.line_y_threshold, self.word_x_threshold, self.text_score, self.classification, self.orientation, self.min_height, self.max_side_len, self.min_side_len, self.width_height_ratio, self.detection, self.postprocess, self.calibration, self.optimization)
1906
+ def __eq__(self, other):
1907
+ if self.output != other.output:
1908
+ return False
1909
+ if self.line_y_threshold != other.line_y_threshold:
1910
+ return False
1911
+ if self.word_x_threshold != other.word_x_threshold:
1912
+ return False
1913
+ if self.text_score != other.text_score:
1914
+ return False
1915
+ if self.classification != other.classification:
1916
+ return False
1917
+ if self.orientation != other.orientation:
1918
+ return False
1919
+ if self.min_height != other.min_height:
1920
+ return False
1921
+ if self.max_side_len != other.max_side_len:
1922
+ return False
1923
+ if self.min_side_len != other.min_side_len:
1924
+ return False
1925
+ if self.width_height_ratio != other.width_height_ratio:
1926
+ return False
1927
+ if self.detection != other.detection:
1928
+ return False
1929
+ if self.postprocess != other.postprocess:
1930
+ return False
1931
+ if self.calibration != other.calibration:
1932
+ return False
1933
+ if self.optimization != other.optimization:
1934
+ return False
1935
+ return True
1936
+
1937
+ class _UniffiFfiConverterTypeOcrRunOptions(_UniffiConverterRustBuffer):
1938
+ @staticmethod
1939
+ def read(buf):
1940
+ return OcrRunOptions(
1941
+ output=_UniffiFfiConverterTypeOutputGranularity.read(buf),
1942
+ line_y_threshold=_UniffiFfiConverterOptionalFloat32.read(buf),
1943
+ word_x_threshold=_UniffiFfiConverterOptionalFloat32.read(buf),
1944
+ text_score=_UniffiFfiConverterOptionalFloat32.read(buf),
1945
+ classification=_UniffiFfiConverterOptionalBoolean.read(buf),
1946
+ orientation=_UniffiFfiConverterOptionalBoolean.read(buf),
1947
+ min_height=_UniffiFfiConverterOptionalFloat32.read(buf),
1948
+ max_side_len=_UniffiFfiConverterOptionalFloat32.read(buf),
1949
+ min_side_len=_UniffiFfiConverterOptionalFloat32.read(buf),
1950
+ width_height_ratio=_UniffiFfiConverterOptionalFloat32.read(buf),
1951
+ detection=_UniffiFfiConverterOptionalTypeDetectionRunOptions.read(buf),
1952
+ postprocess=_UniffiFfiConverterOptionalTypePostprocessRunOptions.read(buf),
1953
+ calibration=_UniffiFfiConverterOptionalTypeCalibrationOptions.read(buf),
1954
+ optimization=_UniffiFfiConverterOptionalTypeOptimizationOptions.read(buf),
1955
+ )
1956
+
1957
+ @staticmethod
1958
+ def check_lower(value):
1959
+ _UniffiFfiConverterTypeOutputGranularity.check_lower(value.output)
1960
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.line_y_threshold)
1961
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.word_x_threshold)
1962
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.text_score)
1963
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.classification)
1964
+ _UniffiFfiConverterOptionalBoolean.check_lower(value.orientation)
1965
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.min_height)
1966
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.max_side_len)
1967
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.min_side_len)
1968
+ _UniffiFfiConverterOptionalFloat32.check_lower(value.width_height_ratio)
1969
+ _UniffiFfiConverterOptionalTypeDetectionRunOptions.check_lower(value.detection)
1970
+ _UniffiFfiConverterOptionalTypePostprocessRunOptions.check_lower(value.postprocess)
1971
+ _UniffiFfiConverterOptionalTypeCalibrationOptions.check_lower(value.calibration)
1972
+ _UniffiFfiConverterOptionalTypeOptimizationOptions.check_lower(value.optimization)
1973
+
1974
+ @staticmethod
1975
+ def write(value, buf):
1976
+ _UniffiFfiConverterTypeOutputGranularity.write(value.output, buf)
1977
+ _UniffiFfiConverterOptionalFloat32.write(value.line_y_threshold, buf)
1978
+ _UniffiFfiConverterOptionalFloat32.write(value.word_x_threshold, buf)
1979
+ _UniffiFfiConverterOptionalFloat32.write(value.text_score, buf)
1980
+ _UniffiFfiConverterOptionalBoolean.write(value.classification, buf)
1981
+ _UniffiFfiConverterOptionalBoolean.write(value.orientation, buf)
1982
+ _UniffiFfiConverterOptionalFloat32.write(value.min_height, buf)
1983
+ _UniffiFfiConverterOptionalFloat32.write(value.max_side_len, buf)
1984
+ _UniffiFfiConverterOptionalFloat32.write(value.min_side_len, buf)
1985
+ _UniffiFfiConverterOptionalFloat32.write(value.width_height_ratio, buf)
1986
+ _UniffiFfiConverterOptionalTypeDetectionRunOptions.write(value.detection, buf)
1987
+ _UniffiFfiConverterOptionalTypePostprocessRunOptions.write(value.postprocess, buf)
1988
+ _UniffiFfiConverterOptionalTypeCalibrationOptions.write(value.calibration, buf)
1989
+ _UniffiFfiConverterOptionalTypeOptimizationOptions.write(value.optimization, buf)
1990
+
1991
+ @dataclass
1992
+ class Point2D:
1993
+ def __init__(self, *, x:float, y:float):
1994
+ self.x = x
1995
+ self.y = y
1996
+
1997
+
1998
+
1999
+
2000
+ def __str__(self):
2001
+ return "Point2D(x={}, y={})".format(self.x, self.y)
2002
+ def __eq__(self, other):
2003
+ if self.x != other.x:
2004
+ return False
2005
+ if self.y != other.y:
2006
+ return False
2007
+ return True
2008
+
2009
+ class _UniffiFfiConverterTypePoint2D(_UniffiConverterRustBuffer):
2010
+ @staticmethod
2011
+ def read(buf):
2012
+ return Point2D(
2013
+ x=_UniffiFfiConverterFloat32.read(buf),
2014
+ y=_UniffiFfiConverterFloat32.read(buf),
2015
+ )
2016
+
2017
+ @staticmethod
2018
+ def check_lower(value):
2019
+ _UniffiFfiConverterFloat32.check_lower(value.x)
2020
+ _UniffiFfiConverterFloat32.check_lower(value.y)
2021
+
2022
+ @staticmethod
2023
+ def write(value, buf):
2024
+ _UniffiFfiConverterFloat32.write(value.x, buf)
2025
+ _UniffiFfiConverterFloat32.write(value.y, buf)
2026
+
2027
+ class _UniffiFfiConverterSequenceTypePoint2D(_UniffiConverterRustBuffer):
2028
+ @classmethod
2029
+ def check_lower(cls, value):
2030
+ for item in value:
2031
+ _UniffiFfiConverterTypePoint2D.check_lower(item)
2032
+
2033
+ @classmethod
2034
+ def write(cls, value, buf):
2035
+ items = len(value)
2036
+ buf.write_i32(items)
2037
+ for item in value:
2038
+ _UniffiFfiConverterTypePoint2D.write(item, buf)
2039
+
2040
+ @classmethod
2041
+ def read(cls, buf):
2042
+ count = buf.read_i32()
2043
+ if count < 0:
2044
+ raise InternalError("Unexpected negative sequence length")
2045
+
2046
+ return [
2047
+ _UniffiFfiConverterTypePoint2D.read(buf) for i in range(count)
2048
+ ]
2049
+
2050
+ @dataclass
2051
+ class TextResult:
2052
+ def __init__(self, *, text:str, score:float, box_points:typing.List[Point2D], frame:Frame):
2053
+ self.text = text
2054
+ self.score = score
2055
+ self.box_points = box_points
2056
+ self.frame = frame
2057
+
2058
+
2059
+
2060
+
2061
+ def __str__(self):
2062
+ return "TextResult(text={}, score={}, box_points={}, frame={})".format(self.text, self.score, self.box_points, self.frame)
2063
+ def __eq__(self, other):
2064
+ if self.text != other.text:
2065
+ return False
2066
+ if self.score != other.score:
2067
+ return False
2068
+ if self.box_points != other.box_points:
2069
+ return False
2070
+ if self.frame != other.frame:
2071
+ return False
2072
+ return True
2073
+
2074
+ class _UniffiFfiConverterTypeTextResult(_UniffiConverterRustBuffer):
2075
+ @staticmethod
2076
+ def read(buf):
2077
+ return TextResult(
2078
+ text=_UniffiFfiConverterString.read(buf),
2079
+ score=_UniffiFfiConverterFloat32.read(buf),
2080
+ box_points=_UniffiFfiConverterSequenceTypePoint2D.read(buf),
2081
+ frame=_UniffiFfiConverterTypeFrame.read(buf),
2082
+ )
2083
+
2084
+ @staticmethod
2085
+ def check_lower(value):
2086
+ _UniffiFfiConverterString.check_lower(value.text)
2087
+ _UniffiFfiConverterFloat32.check_lower(value.score)
2088
+ _UniffiFfiConverterSequenceTypePoint2D.check_lower(value.box_points)
2089
+ _UniffiFfiConverterTypeFrame.check_lower(value.frame)
2090
+
2091
+ @staticmethod
2092
+ def write(value, buf):
2093
+ _UniffiFfiConverterString.write(value.text, buf)
2094
+ _UniffiFfiConverterFloat32.write(value.score, buf)
2095
+ _UniffiFfiConverterSequenceTypePoint2D.write(value.box_points, buf)
2096
+ _UniffiFfiConverterTypeFrame.write(value.frame, buf)
2097
+
2098
+ class _UniffiFfiConverterSequenceTypeTextResult(_UniffiConverterRustBuffer):
2099
+ @classmethod
2100
+ def check_lower(cls, value):
2101
+ for item in value:
2102
+ _UniffiFfiConverterTypeTextResult.check_lower(item)
2103
+
2104
+ @classmethod
2105
+ def write(cls, value, buf):
2106
+ items = len(value)
2107
+ buf.write_i32(items)
2108
+ for item in value:
2109
+ _UniffiFfiConverterTypeTextResult.write(item, buf)
2110
+
2111
+ @classmethod
2112
+ def read(cls, buf):
2113
+ count = buf.read_i32()
2114
+ if count < 0:
2115
+ raise InternalError("Unexpected negative sequence length")
2116
+
2117
+ return [
2118
+ _UniffiFfiConverterTypeTextResult.read(buf) for i in range(count)
2119
+ ]
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+
2126
+ class DetectTextResult:
2127
+ def __init__(self):
2128
+ raise RuntimeError("DetectTextResult cannot be instantiated directly")
2129
+
2130
+ # Each enum variant is a nested class of the enum itself.
2131
+ @dataclass
2132
+ class STRUCTURED:
2133
+
2134
+ def __init__(self, results:typing.List[TextResult]):
2135
+ self.results = results
2136
+
2137
+
2138
+ pass
2139
+
2140
+
2141
+
2142
+
2143
+
2144
+ def __str__(self):
2145
+ return "DetectTextResult.STRUCTURED(results={})".format(self.results)
2146
+ def __eq__(self, other):
2147
+ if not isinstance(other, DetectTextResult):
2148
+ return NotImplemented
2149
+ if not other.is_STRUCTURED():
2150
+ return False
2151
+ if self.results != other.results:
2152
+ return False
2153
+ return True
2154
+
2155
+ @dataclass
2156
+ class SPATIAL:
2157
+
2158
+ def __init__(self, text:str):
2159
+ self.text = text
2160
+
2161
+
2162
+ pass
2163
+
2164
+
2165
+
2166
+
2167
+
2168
+ def __str__(self):
2169
+ return "DetectTextResult.SPATIAL(text={})".format(self.text)
2170
+ def __eq__(self, other):
2171
+ if not isinstance(other, DetectTextResult):
2172
+ return NotImplemented
2173
+ if not other.is_SPATIAL():
2174
+ return False
2175
+ if self.text != other.text:
2176
+ return False
2177
+ return True
2178
+
2179
+
2180
+
2181
+ # For each variant, we have `is_NAME` and `is_name` methods for easily checking
2182
+ # whether an instance is that variant.
2183
+ def is_STRUCTURED(self) -> bool:
2184
+ return isinstance(self, DetectTextResult.STRUCTURED)
2185
+ def is_structured(self) -> bool:
2186
+ return isinstance(self, DetectTextResult.STRUCTURED)
2187
+ def is_SPATIAL(self) -> bool:
2188
+ return isinstance(self, DetectTextResult.SPATIAL)
2189
+ def is_spatial(self) -> bool:
2190
+ return isinstance(self, DetectTextResult.SPATIAL)
2191
+
2192
+
2193
+ # Now, a little trick - we make each nested variant class be a subclass of the main
2194
+ # enum class, so that method calls and instance checks etc will work intuitively.
2195
+ # We might be able to do this a little more neatly with a metaclass, but this'll do.
2196
+ DetectTextResult.STRUCTURED = type("DetectTextResult.STRUCTURED", (DetectTextResult.STRUCTURED, DetectTextResult,), {}) # type: ignore
2197
+ DetectTextResult.SPATIAL = type("DetectTextResult.SPATIAL", (DetectTextResult.SPATIAL, DetectTextResult,), {}) # type: ignore
2198
+
2199
+
2200
+
2201
+
2202
+ class _UniffiFfiConverterTypeDetectTextResult(_UniffiConverterRustBuffer):
2203
+ @staticmethod
2204
+ def read(buf):
2205
+ variant = buf.read_i32()
2206
+ if variant == 1:
2207
+ return DetectTextResult.STRUCTURED(
2208
+ _UniffiFfiConverterSequenceTypeTextResult.read(buf),
2209
+ )
2210
+ if variant == 2:
2211
+ return DetectTextResult.SPATIAL(
2212
+ _UniffiFfiConverterString.read(buf),
2213
+ )
2214
+ raise InternalError("Raw enum value doesn't match any cases")
2215
+
2216
+ @staticmethod
2217
+ def check_lower(value):
2218
+ if value.is_STRUCTURED():
2219
+ _UniffiFfiConverterSequenceTypeTextResult.check_lower(value.results)
2220
+ return
2221
+ if value.is_SPATIAL():
2222
+ _UniffiFfiConverterString.check_lower(value.text)
2223
+ return
2224
+ raise ValueError(value)
2225
+
2226
+ @staticmethod
2227
+ def write(value, buf):
2228
+ if value.is_STRUCTURED():
2229
+ buf.write_i32(1)
2230
+ _UniffiFfiConverterSequenceTypeTextResult.write(value.results, buf)
2231
+ if value.is_SPATIAL():
2232
+ buf.write_i32(2)
2233
+ _UniffiFfiConverterString.write(value.text, buf)
2234
+
2235
+
2236
+
2237
+ class _UniffiFfiConverterBytes(_UniffiConverterRustBuffer):
2238
+ @staticmethod
2239
+ def read(buf):
2240
+ size = buf.read_i32()
2241
+ if size < 0:
2242
+ raise InternalError("Unexpected negative byte string length")
2243
+ return buf.read(size)
2244
+
2245
+ @staticmethod
2246
+ def check_lower(value):
2247
+ try:
2248
+ memoryview(value)
2249
+ except TypeError:
2250
+ raise TypeError("a bytes-like object is required, not {!r}".format(type(value).__name__))
2251
+
2252
+ @staticmethod
2253
+ def write(value, buf):
2254
+ buf.write_i32(len(value))
2255
+ buf.write(value)
2256
+
2257
+
2258
+
2259
+
2260
+
2261
+
2262
+ class ImageSource:
2263
+ def __init__(self):
2264
+ raise RuntimeError("ImageSource cannot be instantiated directly")
2265
+
2266
+ # Each enum variant is a nested class of the enum itself.
2267
+ @dataclass
2268
+ class PATH:
2269
+
2270
+ def __init__(self, path:str):
2271
+ self.path = path
2272
+
2273
+
2274
+ pass
2275
+
2276
+
2277
+
2278
+
2279
+
2280
+ def __str__(self):
2281
+ return "ImageSource.PATH(path={})".format(self.path)
2282
+ def __eq__(self, other):
2283
+ if not isinstance(other, ImageSource):
2284
+ return NotImplemented
2285
+ if not other.is_PATH():
2286
+ return False
2287
+ if self.path != other.path:
2288
+ return False
2289
+ return True
2290
+
2291
+ @dataclass
2292
+ class BYTES:
2293
+
2294
+ def __init__(self, data:bytes):
2295
+ self.data = data
2296
+
2297
+
2298
+ pass
2299
+
2300
+
2301
+
2302
+
2303
+
2304
+ def __str__(self):
2305
+ return "ImageSource.BYTES(data={})".format(self.data)
2306
+ def __eq__(self, other):
2307
+ if not isinstance(other, ImageSource):
2308
+ return NotImplemented
2309
+ if not other.is_BYTES():
2310
+ return False
2311
+ if self.data != other.data:
2312
+ return False
2313
+ return True
2314
+
2315
+
2316
+
2317
+ # For each variant, we have `is_NAME` and `is_name` methods for easily checking
2318
+ # whether an instance is that variant.
2319
+ def is_PATH(self) -> bool:
2320
+ return isinstance(self, ImageSource.PATH)
2321
+ def is_path(self) -> bool:
2322
+ return isinstance(self, ImageSource.PATH)
2323
+ def is_BYTES(self) -> bool:
2324
+ return isinstance(self, ImageSource.BYTES)
2325
+ def is_bytes(self) -> bool:
2326
+ return isinstance(self, ImageSource.BYTES)
2327
+
2328
+
2329
+ # Now, a little trick - we make each nested variant class be a subclass of the main
2330
+ # enum class, so that method calls and instance checks etc will work intuitively.
2331
+ # We might be able to do this a little more neatly with a metaclass, but this'll do.
2332
+ ImageSource.PATH = type("ImageSource.PATH", (ImageSource.PATH, ImageSource,), {}) # type: ignore
2333
+ ImageSource.BYTES = type("ImageSource.BYTES", (ImageSource.BYTES, ImageSource,), {}) # type: ignore
2334
+
2335
+
2336
+
2337
+
2338
+ class _UniffiFfiConverterTypeImageSource(_UniffiConverterRustBuffer):
2339
+ @staticmethod
2340
+ def read(buf):
2341
+ variant = buf.read_i32()
2342
+ if variant == 1:
2343
+ return ImageSource.PATH(
2344
+ _UniffiFfiConverterString.read(buf),
2345
+ )
2346
+ if variant == 2:
2347
+ return ImageSource.BYTES(
2348
+ _UniffiFfiConverterBytes.read(buf),
2349
+ )
2350
+ raise InternalError("Raw enum value doesn't match any cases")
2351
+
2352
+ @staticmethod
2353
+ def check_lower(value):
2354
+ if value.is_PATH():
2355
+ _UniffiFfiConverterString.check_lower(value.path)
2356
+ return
2357
+ if value.is_BYTES():
2358
+ _UniffiFfiConverterBytes.check_lower(value.data)
2359
+ return
2360
+ raise ValueError(value)
2361
+
2362
+ @staticmethod
2363
+ def write(value, buf):
2364
+ if value.is_PATH():
2365
+ buf.write_i32(1)
2366
+ _UniffiFfiConverterString.write(value.path, buf)
2367
+ if value.is_BYTES():
2368
+ buf.write_i32(2)
2369
+ _UniffiFfiConverterBytes.write(value.data, buf)
2370
+
2371
+
2372
+
2373
+
2374
+
2375
+ # RustoBindingError
2376
+ # We want to define each variant as a nested class that's also a subclass,
2377
+ # which is tricky in Python. To accomplish this we're going to create each
2378
+ # class separately, then manually add the child classes to the base class's
2379
+ # __dict__. All of this happens in dummy class to avoid polluting the module
2380
+ # namespace.
2381
+ class RustoBindingError(Exception):
2382
+ pass
2383
+
2384
+ _UniffiTempRustoBindingError = RustoBindingError
2385
+
2386
+ class RustoBindingError: # type: ignore
2387
+
2388
+ class Initialization(_UniffiTempRustoBindingError):
2389
+
2390
+ def __init__(self, msg):
2391
+ super().__init__(", ".join([
2392
+ "msg={!r}".format(msg),
2393
+ ]))
2394
+ self.msg = msg
2395
+
2396
+ def __repr__(self):
2397
+ return "RustoBindingError.Initialization({})".format(str(self))
2398
+ _UniffiTempRustoBindingError.Initialization = Initialization # type: ignore
2399
+ class Preprocess(_UniffiTempRustoBindingError):
2400
+
2401
+ def __init__(self, msg):
2402
+ super().__init__(", ".join([
2403
+ "msg={!r}".format(msg),
2404
+ ]))
2405
+ self.msg = msg
2406
+
2407
+ def __repr__(self):
2408
+ return "RustoBindingError.Preprocess({})".format(str(self))
2409
+ _UniffiTempRustoBindingError.Preprocess = Preprocess # type: ignore
2410
+ class Inference(_UniffiTempRustoBindingError):
2411
+
2412
+ def __init__(self, msg):
2413
+ super().__init__(", ".join([
2414
+ "msg={!r}".format(msg),
2415
+ ]))
2416
+ self.msg = msg
2417
+
2418
+ def __repr__(self):
2419
+ return "RustoBindingError.Inference({})".format(str(self))
2420
+ _UniffiTempRustoBindingError.Inference = Inference # type: ignore
2421
+ class Postprocess(_UniffiTempRustoBindingError):
2422
+
2423
+ def __init__(self, msg):
2424
+ super().__init__(", ".join([
2425
+ "msg={!r}".format(msg),
2426
+ ]))
2427
+ self.msg = msg
2428
+
2429
+ def __repr__(self):
2430
+ return "RustoBindingError.Postprocess({})".format(str(self))
2431
+ _UniffiTempRustoBindingError.Postprocess = Postprocess # type: ignore
2432
+ class InvalidInput(_UniffiTempRustoBindingError):
2433
+
2434
+ def __init__(self, msg):
2435
+ super().__init__(", ".join([
2436
+ "msg={!r}".format(msg),
2437
+ ]))
2438
+ self.msg = msg
2439
+
2440
+ def __repr__(self):
2441
+ return "RustoBindingError.InvalidInput({})".format(str(self))
2442
+ _UniffiTempRustoBindingError.InvalidInput = InvalidInput # type: ignore
2443
+
2444
+ RustoBindingError = _UniffiTempRustoBindingError # type: ignore
2445
+ del _UniffiTempRustoBindingError
2446
+
2447
+
2448
+ class _UniffiFfiConverterTypeRustoBindingError(_UniffiConverterRustBuffer):
2449
+ @staticmethod
2450
+ def read(buf):
2451
+ variant = buf.read_i32()
2452
+ if variant == 1:
2453
+ return RustoBindingError.Initialization(
2454
+ _UniffiFfiConverterString.read(buf),
2455
+ )
2456
+ if variant == 2:
2457
+ return RustoBindingError.Preprocess(
2458
+ _UniffiFfiConverterString.read(buf),
2459
+ )
2460
+ if variant == 3:
2461
+ return RustoBindingError.Inference(
2462
+ _UniffiFfiConverterString.read(buf),
2463
+ )
2464
+ if variant == 4:
2465
+ return RustoBindingError.Postprocess(
2466
+ _UniffiFfiConverterString.read(buf),
2467
+ )
2468
+ if variant == 5:
2469
+ return RustoBindingError.InvalidInput(
2470
+ _UniffiFfiConverterString.read(buf),
2471
+ )
2472
+ raise InternalError("Raw enum value doesn't match any cases")
2473
+
2474
+ @staticmethod
2475
+ def check_lower(value):
2476
+ if isinstance(value, RustoBindingError.Initialization):
2477
+ _UniffiFfiConverterString.check_lower(value.msg)
2478
+ return
2479
+ if isinstance(value, RustoBindingError.Preprocess):
2480
+ _UniffiFfiConverterString.check_lower(value.msg)
2481
+ return
2482
+ if isinstance(value, RustoBindingError.Inference):
2483
+ _UniffiFfiConverterString.check_lower(value.msg)
2484
+ return
2485
+ if isinstance(value, RustoBindingError.Postprocess):
2486
+ _UniffiFfiConverterString.check_lower(value.msg)
2487
+ return
2488
+ if isinstance(value, RustoBindingError.InvalidInput):
2489
+ _UniffiFfiConverterString.check_lower(value.msg)
2490
+ return
2491
+
2492
+ @staticmethod
2493
+ def write(value, buf):
2494
+ if isinstance(value, RustoBindingError.Initialization):
2495
+ buf.write_i32(1)
2496
+ _UniffiFfiConverterString.write(value.msg, buf)
2497
+ if isinstance(value, RustoBindingError.Preprocess):
2498
+ buf.write_i32(2)
2499
+ _UniffiFfiConverterString.write(value.msg, buf)
2500
+ if isinstance(value, RustoBindingError.Inference):
2501
+ buf.write_i32(3)
2502
+ _UniffiFfiConverterString.write(value.msg, buf)
2503
+ if isinstance(value, RustoBindingError.Postprocess):
2504
+ buf.write_i32(4)
2505
+ _UniffiFfiConverterString.write(value.msg, buf)
2506
+ if isinstance(value, RustoBindingError.InvalidInput):
2507
+ buf.write_i32(5)
2508
+ _UniffiFfiConverterString.write(value.msg, buf)
2509
+
2510
+ class _UniffiFfiConverterUInt32(_UniffiConverterPrimitiveInt):
2511
+ CLASS_NAME = "u32"
2512
+ VALUE_MIN = 0
2513
+ VALUE_MAX = 2**32
2514
+
2515
+ @staticmethod
2516
+ def read(buf):
2517
+ return buf.read_u32()
2518
+
2519
+ @staticmethod
2520
+ def write(value, buf):
2521
+ buf.write_u32(value)
2522
+
2523
+ class _UniffiFfiConverterUInt64(_UniffiConverterPrimitiveInt):
2524
+ CLASS_NAME = "u64"
2525
+ VALUE_MIN = 0
2526
+ VALUE_MAX = 2**64
2527
+
2528
+ @staticmethod
2529
+ def read(buf):
2530
+ return buf.read_u64()
2531
+
2532
+ @staticmethod
2533
+ def write(value, buf):
2534
+ buf.write_u64(value)
2535
+
2536
+
2537
+ class RustOProtocol(typing.Protocol):
2538
+
2539
+ def detect_text(self, source: ImageSource,options: OcrRunOptions) -> DetectTextResult:
2540
+ raise NotImplementedError
2541
+ def detect_text_rgb(self, pixels: bytes,width: int,height: int,stride: int,options: OcrRunOptions) -> DetectTextResult:
2542
+ raise NotImplementedError
2543
+ def version(self, ) -> str:
2544
+ raise NotImplementedError
2545
+
2546
+ class RustO(RustOProtocol):
2547
+
2548
+ _handle: ctypes.c_uint64
2549
+ @classmethod
2550
+ def initialize(cls, config: InitializeConfig) -> RustO:
2551
+
2552
+ _UniffiFfiConverterTypeInitializeConfig.check_lower(config)
2553
+ _uniffi_lowered_args = (
2554
+ _UniffiFfiConverterTypeInitializeConfig.lower(config),
2555
+ )
2556
+ _uniffi_lift_return = _UniffiFfiConverterTypeRustO.lift
2557
+ _uniffi_error_converter = _UniffiFfiConverterTypeRustoBindingError
2558
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2559
+ _uniffi_error_converter,
2560
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize,
2561
+ *_uniffi_lowered_args,
2562
+ )
2563
+ return cls._uniffi_make_instance(_uniffi_ffi_result)
2564
+ @classmethod
2565
+ def initialize_from_json(cls, config_json: str) -> RustO:
2566
+
2567
+ _UniffiFfiConverterString.check_lower(config_json)
2568
+ _uniffi_lowered_args = (
2569
+ _UniffiFfiConverterString.lower(config_json),
2570
+ )
2571
+ _uniffi_lift_return = _UniffiFfiConverterTypeRustO.lift
2572
+ _uniffi_error_converter = _UniffiFfiConverterTypeRustoBindingError
2573
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2574
+ _uniffi_error_converter,
2575
+ _UniffiLib.uniffi_rusto_fn_constructor_rusto_initialize_from_json,
2576
+ *_uniffi_lowered_args,
2577
+ )
2578
+ return cls._uniffi_make_instance(_uniffi_ffi_result)
2579
+
2580
+ def __init__(self, *args, **kwargs):
2581
+ raise ValueError("This class has no default constructor")
2582
+
2583
+ def __del__(self):
2584
+ # In case of partial initialization of instances.
2585
+ handle = getattr(self, "_handle", None)
2586
+ if handle is not None:
2587
+ _uniffi_rust_call(_UniffiLib.uniffi_rusto_fn_free_rusto, handle)
2588
+
2589
+ def _uniffi_clone_handle(self):
2590
+ return _uniffi_rust_call(_UniffiLib.uniffi_rusto_fn_clone_rusto, self._handle)
2591
+
2592
+ # Used by alternative constructors or any methods which return this type.
2593
+ @classmethod
2594
+ def _uniffi_make_instance(cls, handle):
2595
+ # Lightly yucky way to bypass the usual __init__ logic
2596
+ # and just create a new instance with the required handle.
2597
+ inst = cls.__new__(cls)
2598
+ inst._handle = handle
2599
+ return inst
2600
+ def detect_text(self, source: ImageSource,options: OcrRunOptions) -> DetectTextResult:
2601
+
2602
+ _UniffiFfiConverterTypeImageSource.check_lower(source)
2603
+
2604
+ _UniffiFfiConverterTypeOcrRunOptions.check_lower(options)
2605
+ _uniffi_lowered_args = (
2606
+ self._uniffi_clone_handle(),
2607
+ _UniffiFfiConverterTypeImageSource.lower(source),
2608
+ _UniffiFfiConverterTypeOcrRunOptions.lower(options),
2609
+ )
2610
+ _uniffi_lift_return = _UniffiFfiConverterTypeDetectTextResult.lift
2611
+ _uniffi_error_converter = _UniffiFfiConverterTypeRustoBindingError
2612
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2613
+ _uniffi_error_converter,
2614
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text,
2615
+ *_uniffi_lowered_args,
2616
+ )
2617
+ return _uniffi_lift_return(_uniffi_ffi_result)
2618
+ def detect_text_rgb(self, pixels: bytes,width: int,height: int,stride: int,options: OcrRunOptions) -> DetectTextResult:
2619
+
2620
+ _UniffiFfiConverterBytes.check_lower(pixels)
2621
+
2622
+ _UniffiFfiConverterUInt32.check_lower(width)
2623
+
2624
+ _UniffiFfiConverterUInt32.check_lower(height)
2625
+
2626
+ _UniffiFfiConverterUInt64.check_lower(stride)
2627
+
2628
+ _UniffiFfiConverterTypeOcrRunOptions.check_lower(options)
2629
+ _uniffi_lowered_args = (
2630
+ self._uniffi_clone_handle(),
2631
+ _UniffiFfiConverterBytes.lower(pixels),
2632
+ _UniffiFfiConverterUInt32.lower(width),
2633
+ _UniffiFfiConverterUInt32.lower(height),
2634
+ _UniffiFfiConverterUInt64.lower(stride),
2635
+ _UniffiFfiConverterTypeOcrRunOptions.lower(options),
2636
+ )
2637
+ _uniffi_lift_return = _UniffiFfiConverterTypeDetectTextResult.lift
2638
+ _uniffi_error_converter = _UniffiFfiConverterTypeRustoBindingError
2639
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2640
+ _uniffi_error_converter,
2641
+ _UniffiLib.uniffi_rusto_fn_method_rusto_detect_text_rgb,
2642
+ *_uniffi_lowered_args,
2643
+ )
2644
+ return _uniffi_lift_return(_uniffi_ffi_result)
2645
+ def version(self, ) -> str:
2646
+ _uniffi_lowered_args = (
2647
+ self._uniffi_clone_handle(),
2648
+ )
2649
+ _uniffi_lift_return = _UniffiFfiConverterString.lift
2650
+ _uniffi_error_converter = None
2651
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2652
+ _uniffi_error_converter,
2653
+ _UniffiLib.uniffi_rusto_fn_method_rusto_version,
2654
+ *_uniffi_lowered_args,
2655
+ )
2656
+ return _uniffi_lift_return(_uniffi_ffi_result)
2657
+
2658
+
2659
+
2660
+
2661
+
2662
+ class _UniffiFfiConverterTypeRustO:
2663
+ @staticmethod
2664
+ def lift(value: int) -> RustO:
2665
+ return RustO._uniffi_make_instance(value)
2666
+
2667
+ @staticmethod
2668
+ def check_lower(value: RustO):
2669
+ if not isinstance(value, RustO):
2670
+ raise TypeError("Expected RustO instance, {} found".format(type(value).__name__))
2671
+
2672
+ @staticmethod
2673
+ def lower(value: RustO) -> ctypes.c_uint64:
2674
+ return value._uniffi_clone_handle()
2675
+
2676
+ @classmethod
2677
+ def read(cls, buf: _UniffiRustBuffer) -> RustO:
2678
+ ptr = buf.read_u64()
2679
+ if ptr == 0:
2680
+ raise InternalError("Raw handle value was null")
2681
+ return cls.lift(ptr)
2682
+
2683
+ @classmethod
2684
+ def write(cls, value: RustO, buf: _UniffiRustBuffer):
2685
+ buf.write_u64(cls.lower(value))
2686
+
2687
+ class _UniffiFfiConverterUInt8(_UniffiConverterPrimitiveInt):
2688
+ CLASS_NAME = "u8"
2689
+ VALUE_MIN = 0
2690
+ VALUE_MAX = 2**8
2691
+
2692
+ @staticmethod
2693
+ def read(buf):
2694
+ return buf.read_u8()
2695
+
2696
+ @staticmethod
2697
+ def write(value, buf):
2698
+ buf.write_u8(value)
2699
+ def create_initialize_config_ppv6(det_model_path: str,rec_model_path: str,dict_path: str) -> InitializeConfig:
2700
+
2701
+ _UniffiFfiConverterString.check_lower(det_model_path)
2702
+
2703
+ _UniffiFfiConverterString.check_lower(rec_model_path)
2704
+
2705
+ _UniffiFfiConverterString.check_lower(dict_path)
2706
+ _uniffi_lowered_args = (
2707
+ _UniffiFfiConverterString.lower(det_model_path),
2708
+ _UniffiFfiConverterString.lower(rec_model_path),
2709
+ _UniffiFfiConverterString.lower(dict_path),
2710
+ )
2711
+ _uniffi_lift_return = _UniffiFfiConverterTypeInitializeConfig.lift
2712
+ _uniffi_error_converter = None
2713
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2714
+ _uniffi_error_converter,
2715
+ _UniffiLib.uniffi_rusto_fn_func_create_initialize_config_ppv6,
2716
+ *_uniffi_lowered_args,
2717
+ )
2718
+ return _uniffi_lift_return(_uniffi_ffi_result)
2719
+ def default_ocr_run_options() -> OcrRunOptions:
2720
+ _uniffi_lowered_args = (
2721
+ )
2722
+ _uniffi_lift_return = _UniffiFfiConverterTypeOcrRunOptions.lift
2723
+ _uniffi_error_converter = None
2724
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2725
+ _uniffi_error_converter,
2726
+ _UniffiLib.uniffi_rusto_fn_func_default_ocr_run_options,
2727
+ *_uniffi_lowered_args,
2728
+ )
2729
+ return _uniffi_lift_return(_uniffi_ffi_result)
2730
+ def rusto_version() -> str:
2731
+ _uniffi_lowered_args = (
2732
+ )
2733
+ _uniffi_lift_return = _UniffiFfiConverterString.lift
2734
+ _uniffi_error_converter = None
2735
+ _uniffi_ffi_result = _uniffi_rust_call_with_error(
2736
+ _uniffi_error_converter,
2737
+ _UniffiLib.uniffi_rusto_fn_func_rusto_version,
2738
+ *_uniffi_lowered_args,
2739
+ )
2740
+ return _uniffi_lift_return(_uniffi_ffi_result)
2741
+
2742
+ __all__ = [
2743
+ "InternalError",
2744
+ "OutputGranularity",
2745
+ "DetectTextResult",
2746
+ "ImageSource",
2747
+ "RustoBindingError",
2748
+ "CalibrationOptions",
2749
+ "ClassificationConfig",
2750
+ "DetectionConfig",
2751
+ "PostprocessRunOptions",
2752
+ "DetectionRunOptions",
2753
+ "Frame",
2754
+ "RecognitionConfig",
2755
+ "OrientationConfig",
2756
+ "UnwarpConfig",
2757
+ "InitializeConfig",
2758
+ "OptimizationOptions",
2759
+ "OcrRunOptions",
2760
+ "Point2D",
2761
+ "TextResult",
2762
+ "create_initialize_config_ppv6",
2763
+ "default_ocr_run_options",
2764
+ "rusto_version",
2765
+ "RustO",
2766
+ "RustOProtocol",
2767
+ ]