    public static async IAsyncEnumerable<{{ item_type }}> {{ method_name }}({{ params_decl }})
    {
{{ setup_code }}        var iterHandle = NativeMethods.{{ start_method }}({{ native_args }});
        if (iterHandle == IntPtr.Zero) throw GetLastError();
        try
        {
            while (true)
            {
                var itemPtr = NativeMethods.{{ next_method }}(iterHandle);
                if (itemPtr == IntPtr.Zero) break;
                try
                {
                    var json = global::System.Runtime.InteropServices.Marshal.PtrToStringUTF8(itemPtr);
                    if (!string.IsNullOrEmpty(json))
                    {
                        var item = JsonSerializer.Deserialize<{{ item_type }}>(json, JsonOptions)!;
                        yield return item;
                    }
                }
                finally
                {
                    NativeMethods.FreeString(itemPtr);
                }
            }
        }
        finally
        {
            NativeMethods.{{ free_method }}(iterHandle);
{{ cleanup_code }}
        }
    }
