Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/CallbackInterfaceRuntime.kt

raw
1 // Magic number for the Rust proxy to call using the same mechanism as every other method,
2 // to free the callback once it's dropped by Rust.
3 internal const val IDX_CALLBACK_FREE = 0
4 // Callback return codes
5 internal const val UNIFFI_CALLBACK_SUCCESS = 0
6 internal const val UNIFFI_CALLBACK_ERROR = 1
7 internal const val UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
8
9 /**
10 * @suppress
11 */
12 public abstract class FfiConverterCallbackInterface<CallbackInterface: Any>: FfiConverter<CallbackInterface, Long> {
13 internal val handleMap = UniffiHandleMap<CallbackInterface>()
14
15 internal fun drop(handle: Long) {
16 handleMap.remove(handle)
17 }
18
19 override fun lift(value: Long): CallbackInterface {
20 return handleMap.get(value)
21 }
22
23 override fun read(buf: ByteBuffer) = lift(buf.getLong())
24
25 override fun lower(value: CallbackInterface) = handleMap.insert(value)
26
27 override fun allocationSize(value: CallbackInterface) = 8UL
28
29 override fun write(value: CallbackInterface, buf: ByteBuffer) {
30 buf.putLong(lower(value))
31 }
32 }