boltffi_bindgen 0.2.0

Code generation library for BoltFFI - generates Swift, Kotlin, and TypeScript bindings
Documentation
{{ self::kdoc_block(doc, "") }}{%- if throws %}
@Throws({{ err_type }}::class)
{%- endif %}
suspend fun {{ method_name }}({% for param in signature_params %}{{ param.name }}: {{ param.kotlin_type }}{% if !loop.last %}, {% endif %}{% endfor %}){% match return_type %}{% when Some with (ret) %}: {{ ret }}{% when None %}{% endmatch %} = boltffiCallAsync(
{%- if wire_writers.is_empty() %}
    createFuture = { Native.{{ ffi_name }}({% if include_handle %}handle{% if native_args.len() > 0 %}, {% endif %}{% endif %}{% for arg in native_args %}{{ arg }}{% if !loop.last %}, {% endif %}{% endfor %}) },
{%- else %}
    createFuture = {
{%- for binding in wire_writers %}
        val {{ binding.binding_name }} = WireWriterPool.acquire({{ binding.size_expr }})
{%- endfor %}
        try {
{%- for binding in wire_writers %}
            run {
                val wire = {{ binding.binding_name }}.writer
                {{ binding.encode_expr }}
            }
{%- endfor %}
            Native.{{ ffi_name }}({% if include_handle %}handle{% if native_args.len() > 0 %}, {% endif %}{% endif %}{% for arg in native_args %}{{ arg }}{% if !loop.last %}, {% endif %}{% endfor %})
        } finally {
{%- for binding_name in wire_writer_closes %}
            {{ binding_name }}.close()
{%- endfor %}
        }
    },
{%- endif %}
    poll = { future, contHandle -> Native.{{ ffi_poll }}({% if include_handle %}handle, {% endif %}future, contHandle) },
    complete = { future ->
{%- if return_is_unit %}
        Native.{{ ffi_complete }}({% if include_handle %}handle, {% endif %}future)
{%- elif return_is_direct %}
        Native.{{ ffi_complete }}({% if include_handle %}handle, {% endif %}future){{ return_cast }}
{%- else %}
        val buf = Native.{{ ffi_complete }}({% if include_handle %}handle, {% endif %}future) ?: throw FfiException(-1, "Null buffer returned")
{%- if is_blittable_return %}
        useWireBytes(buf) { buffer ->
            {{ decode_expr }}
        }
{%- else %}
        val reader = WireReader(buf)
        {{ decode_expr }}
{%- endif %}
{%- endif %}
    },
    free = { future -> Native.{{ ffi_free }}({% if include_handle %}handle, {% endif %}future) },
    cancel = { future -> Native.{{ ffi_cancel }}({% if include_handle %}handle, {% endif %}future) }
)