// encodeVisitResult forwards a Go VisitResult to the FFI's HtmVisitorCallbacks
// out_custom/out_len protocol. For payload-bearing variants the visitor's
// string payload is heap-allocated via C.CString; the Rust side takes
// ownership and frees it with free().
func encodeVisitResult(r {{ result_type }}, outCustom **C.char, outLen *C.uintptr_t) C.int32_t {
switch r.Code {
{% for variant in result_variants %}
case {{ variant.code }}:
{% if variant.has_payload %}
var payload string
if r.Value != nil {
payload = *r.Value
}
if outCustom != nil {
cStr := C.CString(payload)
*outCustom = cStr
if outLen != nil {
*outLen = C.uintptr_t(len(payload))
}
}
return {{ variant.code }}
{% else %}
return {{ variant.code }}
{% endif %}
{% endfor %}
default:
return C.int32_t(r.Code)
}
}