{{ self::javadoc_block(method.doc, "    ") }}    public {% if method.is_static %}static {% endif %}{{ method.return_type }} {{ method.name }}({% for param in method.params %}{{ param.java_type }} {{ param.name }}{% if !loop.last %}, {% endif %}{% endfor %}) {
{%- for binding in method.input_bindings.direct_composites %}
        {{ binding.declaration() }};
{%- endfor %}
{%- if method.input_bindings.wire_writers.is_empty() %}
{%- if method.return_plan.is_void() %}
        Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif method.return_plan.is_direct() %}
        return Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif method.return_plan.is_c_style_enum() %}
        return {{ method.return_plan.c_style_enum_class() }}.fromValue(Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %}));
{%- elif method.return_plan.is_decode() %}
        byte[] _buf = Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
        if (_buf == null) throw new RuntimeException("FFI call returned null buffer");
        WireReader reader = new WireReader(_buf);
        return {{ method.return_plan.decode_expr() }};
{%- elif method.return_plan.is_result() %}
        byte[] _buf = Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
        if (_buf == null) throw new RuntimeException("FFI call returned null buffer");
        WireReader reader = new WireReader(_buf);
        if (reader.readI8() != 0) {
{%- if method.return_plan.result_err_throws_directly() %}
            throw {{ method.return_plan.result_err_decode() }};
{%- elif method.return_plan.result_has_typed_exception() %}
            throw new {{ method.return_plan.result_err_exception_class() }}({{ method.return_plan.result_err_decode() }});
{%- elif method.return_plan.result_err_is_string() %}
            throw new RuntimeException({{ method.return_plan.result_err_decode() }});
{%- else %}
            throw new RuntimeException(String.valueOf({{ method.return_plan.result_err_decode() }}));
{%- endif %}
        }
        return {{ method.return_plan.result_ok_decode() }};
{%- else %}
        throw new RuntimeException("Unsupported method return plan");
{%- endif %}
{%- else %}
        try (
{%- for writer in method.input_bindings.wire_writers %}
            WireWriter {{ writer.binding_name }} = new WireWriter({{ writer.size_expr }}){% if !loop.last %};{% endif %}
{%- endfor %}
        ) {
{%- for writer in method.input_bindings.wire_writers %}
            {{ writer.encode_expr }};
{%- endfor %}
{%- if method.return_plan.is_void() %}
            Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif method.return_plan.is_direct() %}
            return Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif method.return_plan.is_c_style_enum() %}
            return {{ method.return_plan.c_style_enum_class() }}.fromValue(Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %}));
{%- elif method.return_plan.is_decode() %}
            byte[] _buf = Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
            if (_buf == null) throw new RuntimeException("FFI call returned null buffer");
            WireReader reader = new WireReader(_buf);
            return {{ method.return_plan.decode_expr() }};
{%- elif method.return_plan.is_result() %}
            byte[] _buf = Native.{{ method.ffi_name }}({% for param in method.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
            if (_buf == null) throw new RuntimeException("FFI call returned null buffer");
            WireReader reader = new WireReader(_buf);
            if (reader.readI8() != 0) {
{%- if method.return_plan.result_err_throws_directly() %}
                throw {{ method.return_plan.result_err_decode() }};
{%- elif method.return_plan.result_has_typed_exception() %}
                throw new {{ method.return_plan.result_err_exception_class() }}({{ method.return_plan.result_err_decode() }});
{%- elif method.return_plan.result_err_is_string() %}
                throw new RuntimeException({{ method.return_plan.result_err_decode() }});
{%- else %}
                throw new RuntimeException(String.valueOf({{ method.return_plan.result_err_decode() }}));
{%- endif %}
            }
            return {{ method.return_plan.result_ok_decode() }};
{%- else %}
            throw new RuntimeException("Unsupported method return plan");
{%- endif %}
        }
{%- endif %}
    }
