{{ self::javadoc_block(ctor.doc, "    ") }}    public static {{ ctor.return_type }} {{ ctor.name }}({% for param in ctor.params %}{{ param.java_type }} {{ param.name }}{% if !loop.last %}, {% endif %}{% endfor %}) {
{%- for binding in ctor.input_bindings.direct_composites %}
        {{ binding.declaration() }};
{%- endfor %}
{%- if ctor.input_bindings.wire_writers.is_empty() %}
{%- if ctor.return_plan.is_direct() %}
        return Native.{{ ctor.ffi_name }}({% for param in ctor.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif ctor.return_plan.is_c_style_enum() %}
        return {{ ctor.return_plan.c_style_enum_class() }}.fromValue(Native.{{ ctor.ffi_name }}({% for param in ctor.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %}));
{%- elif ctor.return_plan.is_decode() %}
        byte[] _buf = Native.{{ ctor.ffi_name }}({% for param in ctor.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 {{ ctor.return_plan.decode_expr() }};
{%- elif ctor.return_plan.is_result() %}
        byte[] _buf = Native.{{ ctor.ffi_name }}({% for param in ctor.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 ctor.return_plan.result_err_throws_directly() %}
            throw {{ ctor.return_plan.result_err_decode() }};
{%- elif ctor.return_plan.result_has_typed_exception() %}
            throw new {{ ctor.return_plan.result_err_exception_class() }}({{ ctor.return_plan.result_err_decode() }});
{%- elif ctor.return_plan.result_err_is_string() %}
            throw new RuntimeException({{ ctor.return_plan.result_err_decode() }});
{%- else %}
            throw new RuntimeException(String.valueOf({{ ctor.return_plan.result_err_decode() }}));
{%- endif %}
        }
        return {{ ctor.return_plan.result_ok_decode() }};
{%- else %}
        throw new RuntimeException("Unsupported constructor return plan");
{%- endif %}
{%- else %}
        try (
{%- for writer in ctor.input_bindings.wire_writers %}
            WireWriter {{ writer.binding_name }} = new WireWriter({{ writer.size_expr }}){% if !loop.last %};{% endif %}
{%- endfor %}
        ) {
{%- for writer in ctor.input_bindings.wire_writers %}
            {{ writer.encode_expr }};
{%- endfor %}
{%- if ctor.return_plan.is_direct() %}
            return Native.{{ ctor.ffi_name }}({% for param in ctor.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %});
{%- elif ctor.return_plan.is_c_style_enum() %}
            return {{ ctor.return_plan.c_style_enum_class() }}.fromValue(Native.{{ ctor.ffi_name }}({% for param in ctor.native_params %}{{ param.expr }}{% if !loop.last %}, {% endif %}{% endfor %}));
{%- elif ctor.return_plan.is_decode() %}
            byte[] _buf = Native.{{ ctor.ffi_name }}({% for param in ctor.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 {{ ctor.return_plan.decode_expr() }};
{%- elif ctor.return_plan.is_result() %}
            byte[] _buf = Native.{{ ctor.ffi_name }}({% for param in ctor.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 ctor.return_plan.result_err_throws_directly() %}
                throw {{ ctor.return_plan.result_err_decode() }};
{%- elif ctor.return_plan.result_has_typed_exception() %}
                throw new {{ ctor.return_plan.result_err_exception_class() }}({{ ctor.return_plan.result_err_decode() }});
{%- elif ctor.return_plan.result_err_is_string() %}
                throw new RuntimeException({{ ctor.return_plan.result_err_decode() }});
{%- else %}
                throw new RuntimeException(String.valueOf({{ ctor.return_plan.result_err_decode() }}));
{%- endif %}
            }
            return {{ ctor.return_plan.result_ok_decode() }};
{%- else %}
            throw new RuntimeException("Unsupported constructor return plan");
{%- endif %}
        }
{%- endif %}
    }
