zerodds-c-api 1.0.0-rc.4

ZeroDDS C-FFI: extern "C" runtime hub for C++/C#/TypeScript bindings + Apex.AI plugin + ROS-2 RMW
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
/*
 * zerodds.h — ZeroDDS C-FFI (auto-generated by cbindgen, do not edit).
 *
 * This header is the language-agnostic hub used by:
 *  - C++ binding (psm-cxx Method-Bodies in `crates/cpp/`)
 *  - C# binding (P/Invoke wrapper in `crates/cs/`)
 *  - TypeScript binding (node-ffi-napi + WASM, `crates/ts-node-runtime/`)
 *  - Embedded C clients
 *  - Apex.AI performance_test ZeroDDS-Plugin
 *  - ROS 2 RMW adapter (rmw_zerodds)
 *
 * Java + Python use their own native bridges (jni-rs / pyo3) and
 * do NOT go through this header.
 *
 * Memory ownership: handles returned by zerodds_*_create() must be
 * released with the matching zerodds_*_destroy() — no auto-cleanup
 * on FFI boundaries. Bytes returned via zerodds_reader_take() must
 * be released with zerodds_buffer_free().
 */

/*
 * Condition handle types are OPAQUE on the C ABI (the binding holds an
 * opaque pointer only). On the Rust side they are repr(C) so the generic
 * condition dispatcher can read the ConditionKind discriminant at offset 0,
 * but their fields (incl. String/Vec in QueryCondition) must NOT leak into
 * this header - hence they are excluded from cbindgen and forward-declared
 * here. See crates/zerodds-c-api/src/condition_ffi.rs (F-PSM-CXX-readcond-segv).
 */
typedef struct zerodds_ZeroDdsGuardCondition zerodds_ZeroDdsGuardCondition;
typedef struct zerodds_ZeroDdsStatusCondition zerodds_ZeroDdsStatusCondition;
typedef struct zerodds_ZeroDdsReadCondition zerodds_ZeroDdsReadCondition;
typedef struct zerodds_ZeroDdsQueryCondition zerodds_ZeroDdsQueryCondition;


#ifndef ZERODDS_H
#define ZERODDS_H

/* WARNING: AUTO-GENERATED — DO NOT EDIT */

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

typedef void (*zerodds_Option_ZeroDdsDataCallback)(void *user_data, const uint8_t *payload, size_t payload_len, uint8_t representation, uint8_t big_endian);

typedef int (*zerodds_Option_ZeroDdsDecodeFn)(const uint8_t *buf, size_t len, void *out_sample);

typedef int (*zerodds_Option_ZeroDdsDecodeReprFn)(const uint8_t *buf, size_t len, uint8_t representation, void *out_sample);

typedef int (*zerodds_Option_ZeroDdsEncodeFn)(const void *sample, uint8_t *out_buf, size_t out_cap, size_t *out_len);

typedef struct zerodds_Option_ZeroDdsEndpointCallback zerodds_Option_ZeroDdsEndpointCallback;

typedef int (*zerodds_Option_ZeroDdsKeyHashFn)(const void *sample, uint8_t *out_hash);

typedef void (*zerodds_Option_ZeroDdsSampleFreeFn)(void *sample);

typedef struct zerodds_Option_ZeroDdsTopicCallback zerodds_Option_ZeroDdsTopicCallback;

/**
 * Opaque BuiltinSubscriber-Handle (Spec §2.2.2.2.1.7).
 */
typedef struct zerodds_ZeroDdsBuiltinSubscriber zerodds_ZeroDdsBuiltinSubscriber;

/**
 * ContentFilteredTopic (Spec §2.2.2.3.3).
 */
typedef struct zerodds_ZeroDdsContentFilteredTopic zerodds_ZeroDdsContentFilteredTopic;

/**
 * DataReader (Spec §2.2.2.5.2).
 */
typedef struct zerodds_ZeroDdsDataReader zerodds_ZeroDdsDataReader;

/**
 * DataWriter (Spec §2.2.2.4.2).
 */
typedef struct zerodds_ZeroDdsDataWriter zerodds_ZeroDdsDataWriter;

/**
 * DomainParticipant (Spec §2.2.2.2.1.1).
 */
typedef struct zerodds_ZeroDdsDomainParticipant zerodds_ZeroDdsDomainParticipant;

/**
 * Singleton DomainParticipantFactory (Spec §2.2.2.2.1).
 */
typedef struct zerodds_ZeroDdsDomainParticipantFactory zerodds_ZeroDdsDomainParticipantFactory;

/**
 * Publisher (Spec §2.2.2.4.1).
 */
typedef struct zerodds_ZeroDdsPublisher zerodds_ZeroDdsPublisher;

/**
 * Opaque reader handle.
 */
typedef struct zerodds_ZeroDdsReader zerodds_ZeroDdsReader;

/**
 * Opaque runtime handle. Holds the DcpsRuntime + spawned threads.
 */
typedef struct zerodds_ZeroDdsRuntime zerodds_ZeroDdsRuntime;

/**
 * Opaque builder for DDS-Security setup. All 6 path fields
 * must be set before `zerodds_runtime_create_secure` may be called
 * — otherwise NULL return + stderr diag.
 */
typedef struct zerodds_ZeroDdsSecurityConfig zerodds_ZeroDdsSecurityConfig;

/**
 * Subscriber (Spec §2.2.2.5.1).
 */
typedef struct zerodds_ZeroDdsSubscriber zerodds_ZeroDdsSubscriber;

/**
 * Topic (Spec §2.2.2.3.1).
 */
typedef struct zerodds_ZeroDdsTopic zerodds_ZeroDdsTopic;

/**
 * WaitSet (Spec §2.2.2.1.2.1.5).
 */
typedef struct zerodds_ZeroDdsWaitSet zerodds_ZeroDdsWaitSet;

/**
 * Opaque writer handle.
 */
typedef struct zerodds_ZeroDdsWriter zerodds_ZeroDdsWriter;

/**
 * `DCPSParticipant` sample (Spec §2.2.5.1).
 */
typedef struct zerodds_ZeroDdsParticipantBuiltinTopicData {
  /**
   * 16-byte GUID.
   */
  uint8_t guid[16];
  /**
   * Pointer to UserData bytes (static over the `dp` lifetime in the RC1
   * snapshot — the caller copies if it outlives the data).
   */
  const uint8_t *user_data;
  /**
   * UserData length.
   */
  uintptr_t user_data_len;
} zerodds_ZeroDdsParticipantBuiltinTopicData;

/**
 * `DCPSTopic` sample (Spec §2.2.5.2).
 */
typedef struct zerodds_ZeroDdsTopicBuiltinTopicData {
  /**
   * Synthetic topic key (16 byte).
   */
  uint8_t key[16];
  /**
   * Topic name as a C string (heap-allocated; the caller must
   * call `zerodds_string_free`).
   */
  char *name;
  /**
   * Type name (heap-allocated; the caller must call `zerodds_string_free`).
   */
  char *type_name;
  /**
   * Durability kind (0=Volatile, 1=TransientLocal, 2=Transient, 3=Persistent).
   */
  uint32_t durability_kind;
  /**
   * Reliability kind (1=BestEffort, 2=Reliable).
   */
  uint32_t reliability_kind;
} zerodds_ZeroDdsTopicBuiltinTopicData;

/**
 * UserDataQosPolicy.
 */
typedef struct zerodds_ZeroDdsUserDataQosPolicy {
  /**
   * Pointer to bytes (Caller-owned).
   */
  const uint8_t *value;
  /**
   * Length.
   */
  uintptr_t value_len;
} zerodds_ZeroDdsUserDataQosPolicy;

/**
 * EntityFactoryQosPolicy.
 */
typedef struct zerodds_ZeroDdsEntityFactoryQosPolicy {
  /**
   * autoenable_created_entities.
   */
  bool autoenable_created_entities;
} zerodds_ZeroDdsEntityFactoryQosPolicy;

/**
 * DomainParticipantQos.
 */
typedef struct zerodds_ZeroDdsDomainParticipantQos {
  /**
   * UserData.
   */
  struct zerodds_ZeroDdsUserDataQosPolicy user_data;
  /**
   * EntityFactory.
   */
  struct zerodds_ZeroDdsEntityFactoryQosPolicy entity_factory;
} zerodds_ZeroDdsDomainParticipantQos;

/**
 * DurabilityQosPolicy.
 */
typedef struct zerodds_ZeroDdsDurabilityQosPolicy {
  /**
   * Kind (0=Volatile, 1=TransientLocal, 2=Transient, 3=Persistent).
   */
  uint32_t kind;
} zerodds_ZeroDdsDurabilityQosPolicy;

/**
 * Duration (Spec §2.2.3.5 + IDL §9.3.2). seconds + nanoseconds form.
 */
typedef struct zerodds_ZeroDdsDuration {
  /**
   * Seconds.
   */
  int32_t sec;
  /**
   * Nanoseconds.
   */
  uint32_t nanosec;
} zerodds_ZeroDdsDuration;
/**
 * INFINITE marker.
 */
#define zerodds_ZeroDdsDuration_INFINITE (zerodds_ZeroDdsDuration){ .sec = INT32_MAX, .nanosec = UINT32_MAX }

/**
 * DurabilityServiceQosPolicy.
 */
typedef struct zerodds_ZeroDdsDurabilityServiceQosPolicy {
  /**
   * service_cleanup_delay.
   */
  struct zerodds_ZeroDdsDuration service_cleanup_delay;
  /**
   * history_kind (0=KeepLast, 1=KeepAll).
   */
  uint32_t history_kind;
  /**
   * history_depth.
   */
  int32_t history_depth;
  /**
   * max_samples.
   */
  int32_t max_samples;
  /**
   * max_instances.
   */
  int32_t max_instances;
  /**
   * max_samples_per_instance.
   */
  int32_t max_samples_per_instance;
} zerodds_ZeroDdsDurabilityServiceQosPolicy;

/**
 * DeadlineQosPolicy.
 */
typedef struct zerodds_ZeroDdsDeadlineQosPolicy {
  /**
   * period.
   */
  struct zerodds_ZeroDdsDuration period;
} zerodds_ZeroDdsDeadlineQosPolicy;

/**
 * LatencyBudgetQosPolicy.
 */
typedef struct zerodds_ZeroDdsLatencyBudgetQosPolicy {
  /**
   * duration.
   */
  struct zerodds_ZeroDdsDuration duration;
} zerodds_ZeroDdsLatencyBudgetQosPolicy;

/**
 * LivelinessQosPolicy.
 */
typedef struct zerodds_ZeroDdsLivelinessQosPolicy {
  /**
   * Kind.
   */
  uint32_t kind;
  /**
   * lease_duration.
   */
  struct zerodds_ZeroDdsDuration lease_duration;
} zerodds_ZeroDdsLivelinessQosPolicy;

/**
 * ReliabilityQosPolicy.
 */
typedef struct zerodds_ZeroDdsReliabilityQosPolicy {
  /**
   * Kind (1=BestEffort, 2=Reliable).
   */
  uint32_t kind;
  /**
   * max_blocking_time.
   */
  struct zerodds_ZeroDdsDuration max_blocking_time;
} zerodds_ZeroDdsReliabilityQosPolicy;

/**
 * DestinationOrderQosPolicy.
 */
typedef struct zerodds_ZeroDdsDestinationOrderQosPolicy {
  /**
   * Kind (0=ByReception, 1=BySource).
   */
  uint32_t kind;
} zerodds_ZeroDdsDestinationOrderQosPolicy;

/**
 * HistoryQosPolicy.
 */
typedef struct zerodds_ZeroDdsHistoryQosPolicy {
  /**
   * Kind (0=KeepLast, 1=KeepAll).
   */
  uint32_t kind;
  /**
   * Depth (for KeepLast).
   */
  int32_t depth;
} zerodds_ZeroDdsHistoryQosPolicy;

/**
 * ResourceLimitsQosPolicy.
 */
typedef struct zerodds_ZeroDdsResourceLimitsQosPolicy {
  /**
   * max_samples.
   */
  int32_t max_samples;
  /**
   * max_instances.
   */
  int32_t max_instances;
  /**
   * max_samples_per_instance.
   */
  int32_t max_samples_per_instance;
} zerodds_ZeroDdsResourceLimitsQosPolicy;

/**
 * TransportPriorityQosPolicy.
 */
typedef struct zerodds_ZeroDdsTransportPriorityQosPolicy {
  /**
   * priority.
   */
  int32_t value;
} zerodds_ZeroDdsTransportPriorityQosPolicy;

/**
 * LifespanQosPolicy.
 */
typedef struct zerodds_ZeroDdsLifespanQosPolicy {
  /**
   * duration.
   */
  struct zerodds_ZeroDdsDuration duration;
} zerodds_ZeroDdsLifespanQosPolicy;

/**
 * OwnershipQosPolicy.
 */
typedef struct zerodds_ZeroDdsOwnershipQosPolicy {
  /**
   * Kind (0=Shared, 1=Exclusive).
   */
  uint32_t kind;
} zerodds_ZeroDdsOwnershipQosPolicy;

/**
 * TopicDataQosPolicy.
 */
typedef struct zerodds_ZeroDdsUserDataQosPolicy zerodds_ZeroDdsTopicDataQosPolicy;

/**
 * TopicQos.
 */
typedef struct zerodds_ZeroDdsTopicQos {
  /**
   * Durability.
   */
  struct zerodds_ZeroDdsDurabilityQosPolicy durability;
  /**
   * DurabilityService.
   */
  struct zerodds_ZeroDdsDurabilityServiceQosPolicy durability_service;
  /**
   * Deadline.
   */
  struct zerodds_ZeroDdsDeadlineQosPolicy deadline;
  /**
   * LatencyBudget.
   */
  struct zerodds_ZeroDdsLatencyBudgetQosPolicy latency_budget;
  /**
   * Liveliness.
   */
  struct zerodds_ZeroDdsLivelinessQosPolicy liveliness;
  /**
   * Reliability.
   */
  struct zerodds_ZeroDdsReliabilityQosPolicy reliability;
  /**
   * DestinationOrder.
   */
  struct zerodds_ZeroDdsDestinationOrderQosPolicy destination_order;
  /**
   * History.
   */
  struct zerodds_ZeroDdsHistoryQosPolicy history;
  /**
   * ResourceLimits.
   */
  struct zerodds_ZeroDdsResourceLimitsQosPolicy resource_limits;
  /**
   * TransportPriority.
   */
  struct zerodds_ZeroDdsTransportPriorityQosPolicy transport_priority;
  /**
   * Lifespan.
   */
  struct zerodds_ZeroDdsLifespanQosPolicy lifespan;
  /**
   * Ownership.
   */
  struct zerodds_ZeroDdsOwnershipQosPolicy ownership;
  /**
   * TopicData.
   */
  zerodds_ZeroDdsTopicDataQosPolicy topic_data;
} zerodds_ZeroDdsTopicQos;

/**
 * PresentationQosPolicy.
 */
typedef struct zerodds_ZeroDdsPresentationQosPolicy {
  /**
   * access_scope.
   */
  uint32_t access_scope;
  /**
   * coherent_access.
   */
  bool coherent_access;
  /**
   * ordered_access.
   */
  bool ordered_access;
} zerodds_ZeroDdsPresentationQosPolicy;

/**
 * PartitionQosPolicy. List of C-string pointers + count.
 */
typedef struct zerodds_ZeroDdsPartitionQosPolicy {
  /**
   * Array von C-String-Pointern (Caller-owned).
   */
  const char *const *names;
  /**
   * Count.
   */
  uintptr_t names_len;
} zerodds_ZeroDdsPartitionQosPolicy;

/**
 * GroupDataQosPolicy.
 */
typedef struct zerodds_ZeroDdsUserDataQosPolicy zerodds_ZeroDdsGroupDataQosPolicy;

/**
 * PublisherQos.
 */
typedef struct zerodds_ZeroDdsPublisherQos {
  /**
   * Presentation.
   */
  struct zerodds_ZeroDdsPresentationQosPolicy presentation;
  /**
   * Partition.
   */
  struct zerodds_ZeroDdsPartitionQosPolicy partition;
  /**
   * GroupData.
   */
  zerodds_ZeroDdsGroupDataQosPolicy group_data;
  /**
   * EntityFactory.
   */
  struct zerodds_ZeroDdsEntityFactoryQosPolicy entity_factory;
} zerodds_ZeroDdsPublisherQos;

/**
 * SubscriberQos.
 */
typedef struct zerodds_ZeroDdsPublisherQos zerodds_ZeroDdsSubscriberQos;

/**
 * OwnershipStrengthQosPolicy.
 */
typedef struct zerodds_ZeroDdsOwnershipStrengthQosPolicy {
  /**
   * strength.
   */
  int32_t value;
} zerodds_ZeroDdsOwnershipStrengthQosPolicy;

/**
 * WriterDataLifecycleQosPolicy.
 */
typedef struct zerodds_ZeroDdsWriterDataLifecycleQosPolicy {
  /**
   * autodispose_unregistered_instances.
   */
  bool autodispose_unregistered_instances;
} zerodds_ZeroDdsWriterDataLifecycleQosPolicy;

/**
 * DataWriterQos.
 */
typedef struct zerodds_ZeroDdsDataWriterQos {
  /**
   * Reliability.
   */
  struct zerodds_ZeroDdsReliabilityQosPolicy reliability;
  /**
   * Durability.
   */
  struct zerodds_ZeroDdsDurabilityQosPolicy durability;
  /**
   * DurabilityService.
   */
  struct zerodds_ZeroDdsDurabilityServiceQosPolicy durability_service;
  /**
   * Deadline.
   */
  struct zerodds_ZeroDdsDeadlineQosPolicy deadline;
  /**
   * LatencyBudget.
   */
  struct zerodds_ZeroDdsLatencyBudgetQosPolicy latency_budget;
  /**
   * Liveliness.
   */
  struct zerodds_ZeroDdsLivelinessQosPolicy liveliness;
  /**
   * DestinationOrder.
   */
  struct zerodds_ZeroDdsDestinationOrderQosPolicy destination_order;
  /**
   * Lifespan.
   */
  struct zerodds_ZeroDdsLifespanQosPolicy lifespan;
  /**
   * Ownership.
   */
  struct zerodds_ZeroDdsOwnershipQosPolicy ownership;
  /**
   * OwnershipStrength.
   */
  struct zerodds_ZeroDdsOwnershipStrengthQosPolicy ownership_strength;
  /**
   * Partition.
   */
  struct zerodds_ZeroDdsPartitionQosPolicy partition;
  /**
   * Presentation.
   */
  struct zerodds_ZeroDdsPresentationQosPolicy presentation;
  /**
   * History.
   */
  struct zerodds_ZeroDdsHistoryQosPolicy history;
  /**
   * ResourceLimits.
   */
  struct zerodds_ZeroDdsResourceLimitsQosPolicy resource_limits;
  /**
   * TransportPriority.
   */
  struct zerodds_ZeroDdsTransportPriorityQosPolicy transport_priority;
  /**
   * WriterDataLifecycle.
   */
  struct zerodds_ZeroDdsWriterDataLifecycleQosPolicy writer_data_lifecycle;
  /**
   * UserData.
   */
  struct zerodds_ZeroDdsUserDataQosPolicy user_data;
  /**
   * TopicData.
   */
  zerodds_ZeroDdsTopicDataQosPolicy topic_data;
  /**
   * GroupData.
   */
  zerodds_ZeroDdsGroupDataQosPolicy group_data;
} zerodds_ZeroDdsDataWriterQos;

/**
 * TimeBasedFilterQosPolicy.
 */
typedef struct zerodds_ZeroDdsTimeBasedFilterQosPolicy {
  /**
   * minimum_separation.
   */
  struct zerodds_ZeroDdsDuration minimum_separation;
} zerodds_ZeroDdsTimeBasedFilterQosPolicy;

/**
 * ReaderDataLifecycleQosPolicy.
 */
typedef struct zerodds_ZeroDdsReaderDataLifecycleQosPolicy {
  /**
   * autopurge_nowriter_samples_delay.
   */
  struct zerodds_ZeroDdsDuration autopurge_nowriter_samples_delay;
  /**
   * autopurge_disposed_samples_delay.
   */
  struct zerodds_ZeroDdsDuration autopurge_disposed_samples_delay;
} zerodds_ZeroDdsReaderDataLifecycleQosPolicy;

/**
 * DataReaderQos.
 */
typedef struct zerodds_ZeroDdsDataReaderQos {
  /**
   * Reliability.
   */
  struct zerodds_ZeroDdsReliabilityQosPolicy reliability;
  /**
   * Durability.
   */
  struct zerodds_ZeroDdsDurabilityQosPolicy durability;
  /**
   * Deadline.
   */
  struct zerodds_ZeroDdsDeadlineQosPolicy deadline;
  /**
   * LatencyBudget.
   */
  struct zerodds_ZeroDdsLatencyBudgetQosPolicy latency_budget;
  /**
   * Liveliness.
   */
  struct zerodds_ZeroDdsLivelinessQosPolicy liveliness;
  /**
   * DestinationOrder.
   */
  struct zerodds_ZeroDdsDestinationOrderQosPolicy destination_order;
  /**
   * Ownership.
   */
  struct zerodds_ZeroDdsOwnershipQosPolicy ownership;
  /**
   * Partition.
   */
  struct zerodds_ZeroDdsPartitionQosPolicy partition;
  /**
   * Presentation.
   */
  struct zerodds_ZeroDdsPresentationQosPolicy presentation;
  /**
   * History.
   */
  struct zerodds_ZeroDdsHistoryQosPolicy history;
  /**
   * ResourceLimits.
   */
  struct zerodds_ZeroDdsResourceLimitsQosPolicy resource_limits;
  /**
   * TimeBasedFilter.
   */
  struct zerodds_ZeroDdsTimeBasedFilterQosPolicy time_based_filter;
  /**
   * ReaderDataLifecycle.
   */
  struct zerodds_ZeroDdsReaderDataLifecycleQosPolicy reader_data_lifecycle;
  /**
   * UserData.
   */
  struct zerodds_ZeroDdsUserDataQosPolicy user_data;
  /**
   * TopicData.
   */
  zerodds_ZeroDdsTopicDataQosPolicy topic_data;
  /**
   * GroupData.
   */
  zerodds_ZeroDdsGroupDataQosPolicy group_data;
} zerodds_ZeroDdsDataReaderQos;

/**
 * `DCPSSubscription` sample (Spec §2.2.5.4).
 */
typedef struct zerodds_ZeroDdsSubscriptionBuiltinTopicData {
  /**
   * Endpoint GUID (reader).
   */
  uint8_t key[16];
  /**
   * Owning participant GUID.
   */
  uint8_t participant_key[16];
  /**
   * Topic name (heap-allocated).
   */
  char *topic_name;
  /**
   * Type name (heap-allocated).
   */
  char *type_name;
  /**
   * Durability.
   */
  uint32_t durability_kind;
  /**
   * Reliability.
   */
  uint32_t reliability_kind;
  /**
   * Ownership.
   */
  uint32_t ownership_kind;
  /**
   * Liveliness lease in seconds.
   */
  int32_t liveliness_lease_seconds;
  /**
   * Deadline period in seconds.
   */
  int32_t deadline_seconds;
} zerodds_ZeroDdsSubscriptionBuiltinTopicData;

/**
 * SampleInfo (Spec §2.2.2.5.4 + DDS-PSM-Cxx §7.5.8.1).
 */
typedef struct zerodds_ZeroDdsSampleInfo {
  /**
   * Sample-state bit (1=READ, 2=NOT_READ).
   */
  uint32_t sample_state;
  /**
   * View state (1=NEW, 2=NOT_NEW).
   */
  uint32_t view_state;
  /**
   * Instance state (1=ALIVE, 2=NOT_ALIVE_DISPOSED, 4=NOT_ALIVE_NO_WRITERS).
   */
  uint32_t instance_state;
  /**
   * disposed_generation_count.
   */
  int32_t disposed_generation_count;
  /**
   * no_writers_generation_count.
   */
  int32_t no_writers_generation_count;
  /**
   * sample_rank.
   */
  int32_t sample_rank;
  /**
   * generation_rank.
   */
  int32_t generation_rank;
  /**
   * absolute_generation_rank.
   */
  int32_t absolute_generation_rank;
  /**
   * source_timestamp seconds.
   */
  int32_t source_timestamp_sec;
  /**
   * source_timestamp nanoseconds.
   */
  uint32_t source_timestamp_nanosec;
  /**
   * Instance handle.
   */
  uint64_t instance_handle;
  /**
   * Publication handle (writer-GUID hash).
   */
  uint64_t publication_handle;
  /**
   * `true` if the payload actually has data (vs. a lifecycle marker).
   */
  bool valid_data;
  /**
   * XCDR version of the payload from the encapsulation header (RTPS 2.5
   * §10.5): `0` = XCDR1 (CDR/PL_CDR), `1` = XCDR2 (CDR2/D_CDR2/PL_CDR2).
   * The typed consumer needs this to apply the correct alignment rule.
   * `0` for lifecycle markers (no payload).
   */
  uint8_t representation;
  /**
   * Wire byte order of the payload: `0` = little-endian (the canonical
   * XCDR2 wire), `1` = big-endian — from the encapsulation representation
   * identifier's low bit. The typed consumer dispatches its little-endian
   * vs big-endian decoder on this. `0` for lifecycle markers.
   */
  uint8_t big_endian;
} zerodds_ZeroDdsSampleInfo;

/**
 * Sample array (Spec §5 mini-spec).
 */
typedef struct zerodds_ZeroDdsSampleArray {
  /**
   * Array of payload pointers.
   */
  uint8_t **buffers;
  /**
   * Array of payload lengths.
   */
  uintptr_t *lengths;
  /**
   * Array of SampleInfos.
   */
  struct zerodds_ZeroDdsSampleInfo *infos;
  /**
   * Number of samples.
   */
  uintptr_t count;
  /**
   * Internal loan token (pointer to a `Vec<UserSample>` box). Freed
   * by `return_loan`.
   */
  void *loan_token;
} zerodds_ZeroDdsSampleArray;

/**
 * `DCPSPublication` sample (Spec §2.2.5.3).
 */
typedef struct zerodds_ZeroDdsPublicationBuiltinTopicData {
  /**
   * Endpoint GUID (writer).
   */
  uint8_t key[16];
  /**
   * Owning participant GUID.
   */
  uint8_t participant_key[16];
  /**
   * Topic name (heap-allocated; via `zerodds_string_free`).
   */
  char *topic_name;
  /**
   * Type name (heap-allocated).
   */
  char *type_name;
  /**
   * Durability.
   */
  uint32_t durability_kind;
  /**
   * Reliability.
   */
  uint32_t reliability_kind;
  /**
   * Ownership (0=Shared, 1=Exclusive).
   */
  uint32_t ownership_kind;
  /**
   * Ownership strength.
   */
  int32_t ownership_strength;
  /**
   * Liveliness lease in seconds.
   */
  int32_t liveliness_lease_seconds;
  /**
   * Deadline period in seconds.
   */
  int32_t deadline_seconds;
  /**
   * Lifespan duration in seconds.
   */
  int32_t lifespan_seconds;
} zerodds_ZeroDdsPublicationBuiltinTopicData;

/**
 * DomainParticipantFactoryQos.
 */
typedef struct zerodds_ZeroDdsDomainParticipantFactoryQos {
  /**
   * EntityFactory.
   */
  struct zerodds_ZeroDdsEntityFactoryQosPolicy entity_factory;
} zerodds_ZeroDdsDomainParticipantFactoryQos;

/**
 * `DomainParticipantListener` — Spec §2.2.4.2.1.
 *
 * Alle Felder sind optional (NULL-Pointer = Callback ignoriert).
 * `user_data` wird unveraendert an jeden Callback gereicht.
 */
typedef struct zerodds_ZeroDdsDomainParticipantListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Inconsistent-Topic.
   */
  void (*on_inconsistent_topic)(void*, struct zerodds_ZeroDdsTopic*);
  /**
   * Aggregator: Data-On-Readers (Subscriber-Bubble-Up).
   */
  void (*on_data_on_readers)(void*, struct zerodds_ZeroDdsSubscriber*);
} zerodds_ZeroDdsDomainParticipantListener;

/**
 * `PublisherListener` — Spec §2.2.4.2.2.
 */
typedef struct zerodds_ZeroDdsPublisherListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Aggregator-Pfad: alle Writer-Status-Bubble-Ups.
   */
  void (*on_offered_deadline_missed)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Liveliness lost.
   */
  void (*on_liveliness_lost)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Offered-Incompatible-QoS.
   */
  void (*on_offered_incompatible_qos)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Publication-matched.
   */
  void (*on_publication_matched)(void*, struct zerodds_ZeroDdsDataWriter*);
} zerodds_ZeroDdsPublisherListener;

/**
 * `SubscriberListener` — Spec §2.2.4.2.3.
 */
typedef struct zerodds_ZeroDdsSubscriberListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Data-On-Readers (Sub-Aggregator).
   */
  void (*on_data_on_readers)(void*, struct zerodds_ZeroDdsSubscriber*);
  /**
   * Sample-Lost (Reader-Bubble-Up).
   */
  void (*on_sample_lost)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Sample-Rejected.
   */
  void (*on_sample_rejected)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Liveliness-Changed.
   */
  void (*on_liveliness_changed)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Subscription-Matched.
   */
  void (*on_subscription_matched)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Requested-Deadline-Missed.
   */
  void (*on_requested_deadline_missed)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Requested-Incompatible-QoS.
   */
  void (*on_requested_incompatible_qos)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Data-Available.
   */
  void (*on_data_available)(void*, struct zerodds_ZeroDdsDataReader*);
} zerodds_ZeroDdsSubscriberListener;

/**
 * `TopicListener` — Spec §2.2.4.2.4.
 */
typedef struct zerodds_ZeroDdsTopicListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Inconsistent-Topic.
   */
  void (*on_inconsistent_topic)(void*, struct zerodds_ZeroDdsTopic*);
} zerodds_ZeroDdsTopicListener;

/**
 * `DataWriterListener` — Spec §2.2.4.2.5.
 */
typedef struct zerodds_ZeroDdsDataWriterListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Liveliness-Lost.
   */
  void (*on_liveliness_lost)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Offered-Deadline-Missed.
   */
  void (*on_offered_deadline_missed)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Offered-Incompatible-QoS.
   */
  void (*on_offered_incompatible_qos)(void*, struct zerodds_ZeroDdsDataWriter*);
  /**
   * Publication-Matched.
   */
  void (*on_publication_matched)(void*, struct zerodds_ZeroDdsDataWriter*);
} zerodds_ZeroDdsDataWriterListener;

/**
 * `DataReaderListener` — Spec §2.2.4.2.6.
 */
typedef struct zerodds_ZeroDdsDataReaderListener {
  /**
   * Caller-State.
   */
  void *user_data;
  /**
   * Data-Available.
   */
  void (*on_data_available)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Sample-Rejected.
   */
  void (*on_sample_rejected)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Liveliness-Changed.
   */
  void (*on_liveliness_changed)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Requested-Deadline-Missed.
   */
  void (*on_requested_deadline_missed)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Requested-Incompatible-QoS.
   */
  void (*on_requested_incompatible_qos)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Subscription-Matched.
   */
  void (*on_subscription_matched)(void*, struct zerodds_ZeroDdsDataReader*);
  /**
   * Sample-Lost.
   */
  void (*on_sample_lost)(void*, struct zerodds_ZeroDdsDataReader*);
} zerodds_ZeroDdsDataReaderListener;

/**
 * Time point (Spec §2.2.3.5 + IDL §9.3.2). seconds + nanoseconds form
 * (the spec's `zerodds_Time`; cbindgen emits it as `zerodds_ZeroDdsTime`,
 * like every other FFI struct). Used by `zerodds_dp_get_current_time`.
 */
typedef struct zerodds_ZeroDdsTime {
  /**
   * Seconds.
   */
  int32_t sec;
  /**
   * Nanoseconds.
   */
  uint32_t nanosec;
} zerodds_ZeroDdsTime;

/**
 * LivelinessLostStatus (Spec §2.2.4.1).
 */
typedef struct zerodds_ZeroDdsLivelinessLostStatus {
  int32_t total_count;
  int32_t total_count_change;
} zerodds_ZeroDdsLivelinessLostStatus;

/**
 * OfferedDeadlineMissedStatus (Spec §2.2.4.1).
 */
typedef struct zerodds_ZeroDdsOfferedDeadlineMissedStatus {
  int32_t total_count;
  int32_t total_count_change;
  uint64_t last_instance_handle;
} zerodds_ZeroDdsOfferedDeadlineMissedStatus;

/**
 * OfferedIncompatibleQosStatus (Spec §2.2.4.1, without a per-policy list —
 * `last_policy_id` covers the mandatory path).
 */
typedef struct zerodds_ZeroDdsOfferedIncompatibleQosStatus {
  int32_t total_count;
  int32_t total_count_change;
  uint32_t last_policy_id;
} zerodds_ZeroDdsOfferedIncompatibleQosStatus;

/**
 * PublicationMatchedStatus (Spec §2.2.4.1).
 */
typedef struct zerodds_ZeroDdsPublicationMatchedStatus {
  int32_t total_count;
  int32_t total_count_change;
  int32_t current_count;
  int32_t current_count_change;
  uint64_t last_subscription_handle;
} zerodds_ZeroDdsPublicationMatchedStatus;

/**
 * LivelinessChangedStatus (Spec §2.2.4.1).
 */
typedef struct zerodds_ZeroDdsLivelinessChangedStatus {
  /**
   * Total alive count.
   */
  int32_t alive_count;
  /**
   * Total not-alive count.
   */
  int32_t not_alive_count;
  /**
   * Change in alive_count since last read.
   */
  int32_t alive_count_change;
  /**
   * Change in not_alive_count since last read.
   */
  int32_t not_alive_count_change;
  /**
   * Last writer that triggered a change.
   */
  uint64_t last_publication_handle;
} zerodds_ZeroDdsLivelinessChangedStatus;

/**
 * SubscriptionMatchedStatus.
 */
typedef struct zerodds_ZeroDdsSubscriptionMatchedStatus {
  /**
   * Total cumulative count.
   */
  int32_t total_count;
  /**
   * Change since last read.
   */
  int32_t total_count_change;
  /**
   * Currently matched.
   */
  int32_t current_count;
  /**
   * Change in current_count.
   */
  int32_t current_count_change;
  /**
   * Last DataWriter that matched.
   */
  uint64_t last_publication_handle;
} zerodds_ZeroDdsSubscriptionMatchedStatus;

/**
 * RequestedDeadlineMissedStatus.
 */
typedef struct zerodds_ZeroDdsRequestedDeadlineMissedStatus {
  /**
   * Total cumulative count.
   */
  int32_t total_count;
  /**
   * Change since last read.
   */
  int32_t total_count_change;
  /**
   * Last instance handle.
   */
  uint64_t last_instance_handle;
} zerodds_ZeroDdsRequestedDeadlineMissedStatus;

/**
 * RequestedIncompatibleQosStatus.
 */
typedef struct zerodds_ZeroDdsRequestedIncompatibleQosStatus {
  /**
   * Total cumulative count.
   */
  int32_t total_count;
  /**
   * Change since last read.
   */
  int32_t total_count_change;
  /**
   * Last policy id.
   */
  uint32_t last_policy_id;
} zerodds_ZeroDdsRequestedIncompatibleQosStatus;

/**
 * SampleLostStatus.
 */
typedef struct zerodds_ZeroDdsSampleLostStatus {
  /**
   * Total cumulative count.
   */
  int32_t total_count;
  /**
   * Change since last read.
   */
  int32_t total_count_change;
} zerodds_ZeroDdsSampleLostStatus;

/**
 * SampleRejectedStatus.
 */
typedef struct zerodds_ZeroDdsSampleRejectedStatus {
  /**
   * Total cumulative count.
   */
  int32_t total_count;
  /**
   * Change since last read.
   */
  int32_t total_count_change;
  /**
   * Reason kind: 0=NotRejected, 1=ByInstancesLimit, 2=BySamplesLimit,
   * 3=BySamplesPerInstanceLimit.
   */
  uint32_t last_reason;
  /**
   * Last instance handle.
   */
  uint64_t last_instance_handle;
} zerodds_ZeroDdsSampleRejectedStatus;

/**
 * InconsistentTopicStatus (Spec §2.2.4.2.4).
 */
typedef struct zerodds_ZeroDdsInconsistentTopicStatus {
  /**
   * Total count of inconsistent topic detections seen so far.
   */
  int32_t total_count;
  /**
   * Change in total_count since last get-call (Spec read-and-clear).
   */
  int32_t total_count_change;
} zerodds_ZeroDdsInconsistentTopicStatus;

/**
 * TypeSupport function table (vendor spec §2).
 *
 * ABI-stable; fields are versioned via `zerodds_c_api_version()`.
 * Per IDL type the C codegen emits exactly one `static const`
 * instance of this struct.
 *
 * Layout reasons:
 * - 16-byte `type_hash` first (XTypes EquivalenceHash).
 * - `type_name` as a NUL-terminated pointer (no owned String).
 * - `is_keyed` + `extensibility` as `u8` for compact packing.
 * - 6 bytes padding up to the function-pointer-aligned fields.
 * - 5 function pointers in fixed order.
 */
typedef struct zerodds_ZeroDdsTypeSupport {
  /**
   * 16-byte EquivalenceHash (XTypes §7.3.4).
   */
  uint8_t type_hash[16];
  /**
   * NUL-terminated type name (Module::Sub::Struct, ASCII).
   */
  const char *type_name;
  /**
   * 1 = at least one @key member present.
   */
  uint8_t is_keyed;
  /**
   * 0=Final, 1=Appendable, 2=Mutable.
   */
  uint8_t extensibility;
  /**
   * Reserved for future fields. MUST be 0.
   */
  uint8_t _reserved[6];
  /**
   * Encoder pointer (see `ZeroDdsEncodeFn`).
   */
  zerodds_Option_ZeroDdsEncodeFn encode;
  /**
   * Decoder pointer (see `ZeroDdsDecodeFn`).
   */
  zerodds_Option_ZeroDdsDecodeFn decode;
  /**
   * Key-hash pointer (see `ZeroDdsKeyHashFn`); NULL allowed if
   * `is_keyed = 0`.
   */
  zerodds_Option_ZeroDdsKeyHashFn key_hash;
  /**
   * Sample-free pointer (see `ZeroDdsSampleFreeFn`); NULL allowed
   * if the type has no heap fields.
   */
  zerodds_Option_ZeroDdsSampleFreeFn sample_free;
  /**
   * Representation-aware decoder (see `ZeroDdsDecodeReprFn`); Bug R4b.
   *
   * ADDITIVE TAIL FIELD (minor-bump ABI, `zerodds-c-api-1.0` §7): a
   * codegen table built before this field was added simply omits it
   * from its designated-initializer list, so it is zero-filled to
   * NULL — the take path then falls back to the legacy `decode`
   * pointer. New codegen that wants representation-correct alignment
   * for 64-bit members sets this pointer.
   */
  zerodds_Option_ZeroDdsDecodeReprFn decode_repr;
} zerodds_ZeroDdsTypeSupport;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
 * Creates a new ZeroDDS runtime on the given domain ID.
 *
 * # Safety
 * The return value is a heap-allocated pointer; the caller must
 * free it with `zerodds_runtime_destroy`.
 *
 * Returns `NULL` on error.
 */
struct zerodds_ZeroDdsRuntime *zerodds_runtime_create(uint32_t domain_id);

/**
 * Like [`zerodds_runtime_create`] but with the **ROS-2 out-of-the-box profile**
 * ([`RuntimeConfig::ros_defaults`]): the reader announces both XCDR1 and XCDR2
 * data representations, so a ZeroDDS node matches `rmw_cyclonedds`/
 * `rmw_fastrtps` writers that emit XCDR1 for final/simple types
 * (e.g. `std_msgs/String`) without any `ZERODDS_DATA_REPR_OFFER` env tuning.
 * This is what `rmw_zerodds` uses, so ROS-2 interop works config-free.
 *
 * # Safety
 * Same as [`zerodds_runtime_create`].
 */
struct zerodds_ZeroDdsRuntime *zerodds_runtime_create_ros_defaults(uint32_t domain_id);

/**
 * Destroys a runtime. NULL-safe.
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
void zerodds_runtime_destroy(struct zerodds_ZeroDdsRuntime *runtime);

/**
 * Prints phase timing counters to stderr (active only if the
 * runtime code was started with `ZERODDS_PHASE_TIMING=1`).
 *
 * This is called by the bench app code before `runtime_destroy`, because
 * the runtime drop-path threads hold the Arc refcount and the
 * real drop only fires on process exit.
 */
void zerodds_phase_dump(void);

/**
 * Waits until SPDP has discovered at least `min_count` remote
 * participants. Returns 0 (Ok) on success, -4 (Timeout) if the number is
 * not reached within `timeout_ms`.
 *
 * **Optional, not mandatory.** SEDP is reliable + keeps history,
 * so an endpoint registered too early will self-heal after 600-720 ms
 * (empirically llvm-Linux) as soon as SPDP sees the peer
 * and the heartbeat replay runs through. This helper is useful
 * when you want a deterministic test setup or want to avoid a long
 * publish loop.
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
int zerodds_runtime_wait_for_peers(struct zerodds_ZeroDdsRuntime *runtime,
                                   int min_count,
                                   uint64_t timeout_ms);

/**
 * Invokes `callback` once per discovered remote **publication**, passing the
 * raw DDS topic + type name. For ROS-2 graph introspection
 * (`rmw_get_topic_names_and_types`, `rmw_count_publishers`).
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
int zerodds_runtime_for_each_publication(struct zerodds_ZeroDdsRuntime *runtime,
                                         struct zerodds_Option_ZeroDdsTopicCallback callback,
                                         void *user_data);

/**
 * Invokes `callback` once per discovered remote **subscription**. Counterpart
 * to [`zerodds_runtime_for_each_publication`].
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
int zerodds_runtime_for_each_subscription(struct zerodds_ZeroDdsRuntime *runtime,
                                          struct zerodds_Option_ZeroDdsTopicCallback callback,
                                          void *user_data);

/**
 * Writes this runtime's 16-byte participant GUID (12-byte RTPS GUID prefix +
 * 4-byte `ENTITYID_PARTICIPANT` = `00 00 01 c1`) into `out_guid`. ROS 2 uses
 * this as the participant gid on `ros_discovery_info`; the first 12 bytes match
 * every endpoint GUID owned by this participant, so endpoint-info lookups can
 * resolve a node name from an endpoint's GUID prefix.
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL; `out_guid` must
 * point to at least 16 writable bytes.
 */
int zerodds_runtime_participant_guid(struct zerodds_ZeroDdsRuntime *runtime, uint8_t *out_guid);

/**
 * Writes a writer's 16-byte endpoint GUID (participant prefix + entity id) into
 * `out_guid`. The first 12 bytes equal the participant GUID, so ROS 2 can map
 * the endpoint to its owning node.
 *
 * # Safety
 * `writer` must come from `zerodds_writer_create` or be NULL; `out_guid` must
 * point to at least 16 writable bytes.
 */
int zerodds_writer_guid(struct zerodds_ZeroDdsWriter *writer, uint8_t *out_guid);

/**
 * Writes a reader's 16-byte endpoint GUID into `out_guid`. See
 * [`zerodds_writer_guid`].
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create` or be NULL; `out_guid` must
 * point to at least 16 writable bytes.
 */
int zerodds_reader_guid(struct zerodds_ZeroDdsReader *reader, uint8_t *out_guid);

/**
 * Invokes `callback` once per **publication** endpoint on this domain (local
 * user writers + remote SEDP), with full per-endpoint info (GUID + QoS).
 * Backs `rmw_get_publishers_info_by_topic`.
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
int zerodds_runtime_for_each_publication_endpoint(struct zerodds_ZeroDdsRuntime *runtime,
                                                  struct zerodds_Option_ZeroDdsEndpointCallback callback,
                                                  void *user_data);

/**
 * Counterpart to [`zerodds_runtime_for_each_publication_endpoint`] for
 * **subscription** endpoints. Backs `rmw_get_subscriptions_info_by_topic`.
 *
 * # Safety
 * `runtime` must come from `zerodds_runtime_create` or be NULL.
 */
int zerodds_runtime_for_each_subscription_endpoint(struct zerodds_ZeroDdsRuntime *runtime,
                                                   struct zerodds_Option_ZeroDdsEndpointCallback callback,
                                                   void *user_data);

/**
 * Creates a DataWriter on a topic. Topic + type are identified by name
 * (DDS spec §2.2.2).
 *
 * # Safety
 * `runtime` must be valid. `topic_name` and `type_name` must
 * be NUL-terminated UTF-8 strings.
 */
struct zerodds_ZeroDdsWriter *zerodds_writer_create(struct zerodds_ZeroDdsRuntime *runtime,
                                                    const char *topic_name,
                                                    const char *type_name,
                                                    int reliable);

/**
 * Creates a DataWriter with an explicit keyed/no-keyed flag.
 *
 * Cross-vendor interop: if the IDL type has no `@key`, `is_keyed=0`
 * MUST be set. Otherwise ZeroDDS publishes as a
 * WithKey writer (entityKind 0x02) and a remote reader (e.g. Cyclone)
 * rejects the DATA submessage due to a mismatch with its NoKey reader
 * (entityKind 0x04). Spec §9.3.1.2 Table 9.1.
 *
 * # Safety
 * Same as [`zerodds_writer_create`].
 */
struct zerodds_ZeroDdsWriter *zerodds_writer_create_kind(struct zerodds_ZeroDdsRuntime *runtime,
                                                         const char *topic_name,
                                                         const char *type_name,
                                                         int reliable,
                                                         int is_keyed);

/**
 * Writes a sample. `payload` points to already-CDR-encoded bytes.
 *
 * # Safety
 * `writer` and `payload` must be valid, `len` <= buffer size.
 */
int zerodds_writer_write(struct zerodds_ZeroDdsWriter *writer,
                         const uint8_t *payload,
                         uintptr_t len);

/**
 * Sets a writer's type extensibility, so that the
 * encapsulation header of the payload is declared correctly:
 * `0` = FINAL (PLAIN_CDR/PLAIN_CDR2), `1` = APPENDABLE (DELIMITED_CDR2),
 * `2` = MUTABLE (PL_CDR/PL_CDR2). The default without a call is FINAL.
 *
 * Only relevant for XCDR2 wire (offer XCDR2-first) with non-@final
 * types — otherwise the header is `CDR_LE` in both cases. The codegen
 * calls this after `zerodds_writer_create*` with the compile-time
 * extensibility of the type.
 *
 * # Safety
 * `writer` must come from `zerodds_writer_create*` and be valid.
 */
int zerodds_writer_set_wire_extensibility(struct zerodds_ZeroDdsWriter *writer, int extensibility);

/**
 * Waits until at least `min_count` subscriptions have matched or
 * the timeout elapses. `timeout_ms` = 0 -> non-blocking poll.
 *
 * # Safety
 * `writer` must be valid.
 */
int zerodds_writer_wait_for_matched(struct zerodds_ZeroDdsWriter *writer,
                                    int min_count,
                                    uint64_t timeout_ms);

/**
 * Sends a lifecycle marker (Spec §9.6.3.9 PID_STATUS_INFO):
 * `dispose` sets the DISPOSED bit, so that remote readers classify the
 * instance as NotAliveDisposed. The caller must pass the 16-byte
 * key hash of the instance (PLAIN_CDR2-BE encoding with zero
 * padding, or MD5 if > 16 bytes).
 *
 * # Safety
 * `writer` and `key_hash` must be valid; `key_hash` must point to
 * exactly 16 bytes.
 */
int zerodds_writer_dispose(struct zerodds_ZeroDdsWriter *writer, const uint8_t *key_hash);

/**
 * Sends an UNREGISTER marker (Spec §2.2.2.4.2.7). Sets only the
 * UNREGISTERED bit (no autodispose). A caller wanting spec-default
 * behavior (autodispose=true) should instead use
 * `zerodds_writer_unregister_with_dispose`.
 *
 * # Safety
 * Like [`zerodds_writer_dispose`].
 */
int zerodds_writer_unregister(struct zerodds_ZeroDdsWriter *writer, const uint8_t *key_hash);

/**
 * Sends a combined DISPOSE+UNREGISTER marker (Spec §2.2.3.21 with
 * `autodispose_unregistered_instances=true`). The reader sees both
 * NotAliveDisposed and NotAliveNoWriters.
 *
 * # Safety
 * Like [`zerodds_writer_dispose`].
 */
int zerodds_writer_unregister_with_dispose(struct zerodds_ZeroDdsWriter *writer,
                                           const uint8_t *key_hash);

/**
 * Number of remote DataReaders currently matched to this writer (DDS 1.4
 * §2.2.4.2 PublicationMatchedStatus.current_count). Powers
 * `rmw_publisher_count_matched_subscriptions` → `Publisher.get_subscription_count()`
 * in rclpy/rclcpp. Returns `0` on a NULL handle.
 *
 * # Safety
 * `writer` must come from `zerodds_writer_create*` or be NULL.
 */
uintptr_t zerodds_writer_matched_count(struct zerodds_ZeroDdsWriter *writer);

/**
 * Number of remote DataWriters currently matched to this reader (DDS 1.4
 * §2.2.4.2 SubscriptionMatchedStatus.current_count). Powers
 * `rmw_subscription_count_matched_publishers` → `Subscription.get_publisher_count()`.
 * Returns `0` on a NULL handle.
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create*` or be NULL.
 */
uintptr_t zerodds_reader_matched_count(struct zerodds_ZeroDdsReader *reader);

/**
 * Destroys a writer. NULL-safe.
 *
 * # Safety
 * `writer` must come from `zerodds_writer_create` or be NULL.
 */
void zerodds_writer_destroy(struct zerodds_ZeroDdsWriter *writer);

/**
 * Creates a DataReader on a topic.
 *
 * # Safety
 * Like `zerodds_writer_create`.
 */
struct zerodds_ZeroDdsReader *zerodds_reader_create(struct zerodds_ZeroDdsRuntime *runtime,
                                                    const char *topic_name,
                                                    const char *type_name,
                                                    int reliable);

/**
 * Like [`zerodds_reader_create`] but with an explicit keyed/no-keyed
 * flag. Cross-vendor interop: the reader kind must match the writer kind
 * (Spec §9.3.1.2 Table 9.1).
 *
 * # Safety
 * Same as [`zerodds_reader_create`].
 */
struct zerodds_ZeroDdsReader *zerodds_reader_create_kind(struct zerodds_ZeroDdsRuntime *runtime,
                                                         const char *topic_name,
                                                         const char *type_name,
                                                         int reliable,
                                                         int is_keyed);

/**
 * Tries to read a sample.
 * * On success: writes an allocated buffer into `*out_buf`, its
 *   length into `*out_len`. The caller MUST call `zerodds_buffer_free(*out_buf)`.
 * * On no sample: `*out_buf = NULL`, `*out_len = 0`, returns Ok.
 * * On error: a negative status code.
 *
 * `out_repr` (nullable): receives the XCDR version of the sample —
 * `0` = XCDR1, `1` = XCDR2 — from the encapsulation header of the
 * wire sample. The typed consumer needs this to decode the body
 * with the correct alignment rule. NULL = ignore.
 *
 * This little-endian-default form does not surface the wire byte order;
 * a consumer that must decode a big-endian peer uses
 * [`zerodds_reader_take_endian`].
 *
 * # Safety
 * Pointers must be valid. `out_repr` may be NULL.
 */
int zerodds_reader_take(struct zerodds_ZeroDdsReader *reader,
                        uint8_t **out_buf,
                        uintptr_t *out_len,
                        uint8_t *out_repr);

/**
 * Like [`zerodds_reader_take`], plus `out_be` (nullable): receives the wire
 * byte order — `0` = little-endian (the canonical XCDR2 wire), `1` =
 * big-endian — derived from the encapsulation representation identifier
 * (RTPS 2.5 §10.5). A typed FFI consumer dispatches its little-endian vs
 * big-endian decoder on this, so a big-endian peer's sample decodes
 * correctly. NULL = ignore (assume little-endian).
 *
 * # Safety
 * Pointers must be valid. `out_repr` and `out_be` may be NULL.
 */
int zerodds_reader_take_endian(struct zerodds_ZeroDdsReader *reader,
                               uint8_t **out_buf,
                               uintptr_t *out_len,
                               uint8_t *out_repr,
                               uint8_t *out_be);

/**
 * Fixed-buffer `take` convenience: copies one sample's payload into a
 * caller-supplied buffer and returns the byte count — no heap
 * allocation, no `zerodds_buffer_free`.
 *
 * This is the ergonomic shape for plain-C / FFI consumers that prefer a
 * stack buffer + return-length idiom (Go/Zig/Ada/MATLAB cgo bindings,
 * the C quickstart) over the allocate-and-out-param
 * [`zerodds_reader_take`].
 *
 * Returns:
 * * `> 0`: number of payload bytes written into `buf` (one sample).
 * * `0`: no sample available right now.
 * * `< 0`: a negative status code (bad handle, or — if the sample is
 *   larger than `cap` — `ZeroDdsStatus::OutOfResources`, in which case
 *   the sample is consumed; use [`zerodds_reader_take`] for unbounded
 *   samples).
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create*` or be NULL. `buf`
 * must point to at least `cap` writable bytes (or be NULL iff
 * `cap == 0`).
 */
intptr_t zerodds_reader_take_into(struct zerodds_ZeroDdsReader *reader,
                                  uint8_t *buf,
                                  uintptr_t cap);

/**
 * Waits until at least `min_count` publications have matched.
 *
 * # Safety
 * `reader` must be valid.
 */
int zerodds_reader_wait_for_matched(struct zerodds_ZeroDdsReader *reader,
                                    int min_count,
                                    uint64_t timeout_ms);

/**
 * Returns the number of samples dropped because of an unknown writer (no
 * matching writer_proxy). Diagnosis for interop bugs:
 * if the writer_proxy was not created from SEDP PublicationData
 * (e.g. because of an entity-id mismatch between the SEDP pub and the DATA submessage),
 * this counter increments for every incoming DATA sample.
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create*` or be NULL.
 */
uint64_t zerodds_reader_unknown_src_count(struct zerodds_ZeroDdsReader *reader);

/**
 * A2 — arm TIME_BASED_FILTER (DDS 1.4 §2.2.3.12) on a reader: it then delivers
 * at most one sample per instance per `min_separation_nanos`; closer-spaced
 * samples are dropped before `zerodds_reader_take`/the data callback sees them.
 * `0` disables the filter. ROS 2 exposes no TIME_BASED_FILTER field in
 * `rmw_qos_profile_t`, so `rmw_zerodds` calls this from the
 * `ZERODDS_TIME_BASED_FILTER` env to rate-limit a subscription. Returns `0` on
 * success, `-1` on a NULL/unknown reader.
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create*` or be NULL.
 */
int zerodds_reader_set_time_based_filter_ns(struct zerodds_ZeroDdsReader *reader,
                                            uint64_t min_separation_nanos);

/**
 * Destroys a reader handle and releases its resources.
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create*` or be NULL and
 * must not be used afterwards.
 */
void zerodds_reader_destroy(struct zerodds_ZeroDdsReader *reader);

/**
 * Sets a data-available callback (or clears it with NULL).
 * See the `ZeroDdsDataCallback` docs for the full contract.
 *
 * # Safety
 * `reader` must come from `zerodds_reader_create`.
 */
int zerodds_reader_set_data_callback(struct zerodds_ZeroDdsReader *reader,
                                     zerodds_Option_ZeroDdsDataCallback callback,
                                     void *user_data);

/**
 * Frees a buffer that a previous `zerodds_reader_take`
 * allocated. NULL-safe.
 *
 * # Safety
 * `buf` must come from `zerodds_reader_take` or be NULL.
 * `len` must be exactly the value belonging to that buffer.
 */
void zerodds_buffer_free(uint8_t *buf, uintptr_t len);

/**
 * Loan-based `take`: returns a live pointer into an
 * internal `Arc<[u8]>` without a copy.
 *
 * On success:
 * * `*out_buf` points to the payload (read-only),
 * * `*out_len` is the length,
 * * `*out_loan_handle` is an opaque pointer that must later be passed to
 *   [`zerodds_reader_return_loan`].
 *
 * On no sample: `*out_buf = NULL`, `*out_len = 0`,
 * `*out_loan_handle = NULL`, returns Ok.
 *
 * # Safety
 * All pointers must be valid. The returned `*out_buf` is
 * valid only while `*out_loan_handle` lives; after
 * `zerodds_reader_return_loan` the read lifetime has ended.
 */
int zerodds_reader_loan(struct zerodds_ZeroDdsReader *reader,
                        const uint8_t **out_buf,
                        uintptr_t *out_len,
                        void **out_loan_handle);

/**
 * Returns a loan that a previous [`zerodds_reader_loan`]
 * created. After this call the associated `*out_buf`
 * pointer is invalid (the Arc refcount may go to 0 and the bytes
 * are freed).
 *
 * NULL-safe — a `loan_handle = NULL` is a no-op.
 *
 * # Safety
 * `loan_handle` must come from [`zerodds_reader_loan`] or be NULL.
 * Do not return it twice.
 */
void zerodds_reader_return_loan(void *loan_handle);

/**
 * Reserves an output buffer at the writer for zero-copy publish.
 * The caller writes the sample into the returned pointer and
 * then commits it via [`zerodds_writer_commit_loan`].
 *
 * Returns 0 (Ok) on success + fills `*out_ptr` and `*out_len`.
 * On today's malloc-backed path `*out_len = len`; for
 * SHM-backed loans `*out_len > len` is possible (slot boundary).
 *
 * # Safety
 * `writer` valid; `out_ptr`/`out_len` non-null.
 */
int zerodds_writer_loan_message(struct zerodds_ZeroDdsWriter *writer,
                                uintptr_t len,
                                uint8_t **out_ptr,
                                uintptr_t *out_len);

/**
 * Commit path: writes the loaned buffer as a sample and frees
 * it. The caller must not read the pointer afterwards.
 *
 * # Safety
 * `writer` from `zerodds_writer_create`; `ptr` from
 * `zerodds_writer_loan_message`; `len` the same value as returned in
 * `out_len`.
 */
int zerodds_writer_commit_loan(struct zerodds_ZeroDdsWriter *writer, uint8_t *ptr, uintptr_t len);

/**
 * Discards a loan without publishing it. The buffer is freed.
 *
 * # Safety
 * Like `zerodds_writer_commit_loan`.
 */
int zerodds_writer_discard_loan(struct zerodds_ZeroDdsWriter *_writer, uint8_t *ptr, uintptr_t len);

/**
 * Sets the delivery mode of a runtime-path DataWriter (the handle the ROS-2
 * RMW bridge uses). `0`=Portable (default, interop-safe), `1`=RawSameHost
 * (same-host, no wire). `2`=Iceoryx is not yet wired → `Unsupported`. Other
 * values → `BadParameter`.
 *
 * # Safety
 * `writer` from `zerodds_writer_create`.
 */
int zerodds_writer_set_delivery_mode(struct zerodds_ZeroDdsWriter *writer, int mode);

/**
 * Enables zero-copy SHM loan on a runtime-path DataWriter (the handle the
 * ROS-2 RMW bridge uses). Creates a POSIX shared-memory segment of
 * `slot_count` slots × `slot_capacity` bytes at the flink path `name`. After
 * this, `zerodds_writer_loan_message` returns a pointer into a SHM slot and
 * `zerodds_writer_commit_loan` finalizes it in place — no staging copy.
 *
 * The loan state is keyed by `(runtime, entity-id)`, so a writer reached
 * through the DCPS FFI (`zerodds_dw_*`) and this runtime FFI shares the same
 * backend. Without this feature/call the loan path stays on the heap box.
 *
 * # Safety
 * `writer` from `zerodds_writer_create`; `name` is a NUL-terminated C string.
 */
int zerodds_writer_enable_shm_loan(struct zerodds_ZeroDdsWriter *writer,
                                   const char *name,
                                   uintptr_t slot_count,
                                   uintptr_t slot_capacity);

/**
 * Maps the writer's SHM segment at flink path `name` on a runtime-path
 * DataReader for zero-copy reads. `reader_index` is the reader's bit (0..32)
 * in the slot reader-mask.
 *
 * # Safety
 * `reader` from `zerodds_reader_create`; `name` is a NUL-terminated C string.
 */
int zerodds_reader_enable_shm(struct zerodds_ZeroDdsReader *reader,
                              const char *name,
                              uint8_t reader_index);

/**
 * Zero-copy take on a runtime-path DataReader: returns a read-only pointer
 * into the writer's SHM slot, its length and the slot index (for
 * `zerodds_reader_release_shm`). Returns `NoData` when nothing is pending.
 * The pointer stays valid until `zerodds_reader_release_shm`.
 *
 * # Safety
 * `reader`/`out_ptr`/`out_len`/`out_slot` valid.
 */
int zerodds_reader_take_shm(struct zerodds_ZeroDdsReader *reader,
                            const uint8_t **out_ptr,
                            uintptr_t *out_len,
                            uint32_t *out_slot);

/**
 * Releases a slot previously returned by `zerodds_reader_take_shm`.
 *
 * # Safety
 * `reader` valid; `slot_index` from a prior `zerodds_reader_take_shm`.
 */
int zerodds_reader_release_shm(struct zerodds_ZeroDdsReader *reader, uint32_t slot_index);

/**
 * Blocks until this reader's raw source (RawSameHost SHM segment or Iceoryx
 * service) signals a new sample, or `timeout_ms` elapses — event-driven (SHM
 * change-generation futex / iceoryx2 listener), no busy-poll. Lets a consumer
 * (e.g. the ROS-2 RMW `rmw_wait` doorbell) park on raw-data arrival instead of
 * polling. A spurious wake is harmless — re-check with `zerodds_reader_take_shm`.
 * Returns `Ok` when woken or timed out, `PreconditionNotMet` if no raw source.
 *
 * # Safety
 * `reader` from `zerodds_reader_create` or NULL.
 */
int zerodds_reader_raw_wait(struct zerodds_ZeroDdsReader *reader, uint64_t timeout_ms);

/**
 * Enables `Iceoryx` delivery on a runtime-path DataWriter (feature
 * `delivery-iceoryx`): publishes its samples over the iceoryx2 service
 * `service_name` (max `max_len` bytes/sample). The loan API then routes through
 * iceoryx2; commit does not publish over RTPS.
 *
 * # Safety
 * `writer` from `zerodds_writer_create`; `service_name` is a NUL-terminated C
 * string.
 */
int zerodds_writer_enable_iceoryx(struct zerodds_ZeroDdsWriter *writer,
                                  const char *service_name,
                                  uintptr_t max_len);

/**
 * Enables `Iceoryx` delivery on a runtime-path DataReader: receives from the
 * iceoryx2 service `service_name` via `zerodds_reader_take_shm` /
 * `zerodds_reader_release_shm`.
 *
 * # Safety
 * `reader` from `zerodds_reader_create`; `service_name` is a NUL-terminated C
 * string.
 */
int zerodds_reader_enable_iceoryx(struct zerodds_ZeroDdsReader *reader, const char *service_name);

/**
 * Version string of the C-FFI. Static, not to be freed.
 */
const char *zerodds_version(void);

/**
 * Returns the InstanceHandles of all discovered topics.
 *
 * # Safety
 * `p`, `out`, `out_count` valid.
 */
int zerodds_dp_get_discovered_topics(struct zerodds_ZeroDdsDomainParticipant *p,
                                     uint64_t *out,
                                     uintptr_t *out_count,
                                     uintptr_t cap);

/**
 * Returns the `ParticipantBuiltinTopicData` for an InstanceHandle.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_discovered_participant_data(struct zerodds_ZeroDdsDomainParticipant *p,
                                               uint64_t handle,
                                               struct zerodds_ZeroDdsParticipantBuiltinTopicData *out);

/**
 * Returns a previously allocated UserData slice.
 *
 * # Safety
 * `p[0..len]` must come from `dp_get_discovered_participant_data`.
 */
void zerodds_builtin_userdata_free(const uint8_t *p, uintptr_t len);

/**
 * Returns the `TopicBuiltinTopicData` for an InstanceHandle.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_discovered_topic_data(struct zerodds_ZeroDdsDomainParticipant *p,
                                         uint64_t handle,
                                         struct zerodds_ZeroDdsTopicBuiltinTopicData *out);

/**
 * Number of discovered publications (Spec §2.2.2.2.1.13).
 *
 * # Safety
 * `p` valid.
 */
uintptr_t zerodds_dp_discovered_publications_count(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Number of discovered subscriptions.
 *
 * # Safety
 * `p` valid.
 */
uintptr_t zerodds_dp_discovered_subscriptions_count(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Reads the current trigger status of a condition (Spec §2.2.2.1.2.1.1).
 *
 * # Safety
 * `c` valid or NULL.
 */
bool zerodds_condition_get_trigger_value(const void *c);

/**
 * Creates a GuardCondition.
 */
zerodds_ZeroDdsGuardCondition *zerodds_guardcondition_create(void);

/**
 * Deletes a GuardCondition.
 *
 * # Safety
 * `g` must come from `zerodds_guardcondition_create`.
 */
void zerodds_guardcondition_destroy(zerodds_ZeroDdsGuardCondition *g);

/**
 * Sets the trigger value.
 *
 * # Safety
 * `g` valid.
 */
int zerodds_guardcondition_set_trigger_value(zerodds_ZeroDdsGuardCondition *g, bool v);

/**
 * Creates a StatusCondition for an entity. RC1: allows any
 * `*mut c_void` as the entity slot — the match logic reads the status per
 * entity type via the listener FFI (follow-up WP).
 *
 * # Safety
 * `entity` valid or NULL.
 */
zerodds_ZeroDdsStatusCondition *zerodds_entity_get_statuscondition(void *entity);

/**
 * Enables the status bits set in `mask`.
 *
 * # Safety
 * `c` valid.
 */
int zerodds_statuscondition_set_enabled_statuses(zerodds_ZeroDdsStatusCondition *c, uint32_t mask);

/**
 * Reads the enabled status bits.
 *
 * # Safety
 * `c` valid.
 */
uint32_t zerodds_statuscondition_get_enabled_statuses(zerodds_ZeroDdsStatusCondition *c);

/**
 * Deletes a StatusCondition.
 *
 * # Safety
 * `c` valid.
 */
void zerodds_statuscondition_destroy(zerodds_ZeroDdsStatusCondition *c);

/**
 * Creates a ReadCondition (Spec §2.2.2.5.2.4).
 *
 * # Safety
 * `dr` valid.
 */
zerodds_ZeroDdsReadCondition *zerodds_dr_create_readcondition(struct zerodds_ZeroDdsDataReader *dr,
                                                              uint32_t sample_states,
                                                              uint32_t view_states,
                                                              uint32_t instance_states);

/**
 * Creates a QueryCondition (Spec §2.2.2.5.2.5).
 *
 * # Safety
 * `dr`, `expr` valid; `params[0..param_count]` valid.
 */
zerodds_ZeroDdsQueryCondition *zerodds_dr_create_querycondition(struct zerodds_ZeroDdsDataReader *dr,
                                                                uint32_t sample_states,
                                                                uint32_t view_states,
                                                                uint32_t instance_states,
                                                                const char *expr,
                                                                const char *const *params,
                                                                uintptr_t param_count);

/**
 * Deletes a ReadCondition or QueryCondition.
 *
 * # Safety
 * `c` valid; must come from `dr_create_readcondition` or
 * `dr_create_querycondition`.
 */
int zerodds_dr_delete_readcondition(struct zerodds_ZeroDdsDataReader *_dr, void *c);

/**
 * Creates a WaitSet.
 */
struct zerodds_ZeroDdsWaitSet *zerodds_waitset_create(void);

/**
 * Deletes a WaitSet.
 *
 * # Safety
 * `w` valid.
 */
void zerodds_waitset_destroy(struct zerodds_ZeroDdsWaitSet *w);

/**
 * Attach Condition.
 *
 * # Safety
 * `w`, `cond` valid.
 */
int zerodds_waitset_attach_condition(struct zerodds_ZeroDdsWaitSet *w, void *cond);

/**
 * Detach Condition.
 *
 * # Safety
 * `w`, `cond` valid.
 */
int zerodds_waitset_detach_condition(struct zerodds_ZeroDdsWaitSet *w, void *cond);

/**
 * Waits until at least one condition triggers or a timeout.
 * Writes active conditions into `out_active[0..*out_count]`.
 *
 * # Safety
 * `w`, `out_active`, `out_count`, `timeout` valid.
 */
int zerodds_waitset_wait(struct zerodds_ZeroDdsWaitSet *w,
                         void **out_active,
                         uintptr_t cap,
                         uintptr_t *out_count,
                         int32_t timeout_sec,
                         uint32_t timeout_nanosec);

/**
 * Returns all attached conditions.
 *
 * # Safety
 * `w`, `out`, `out_count` valid.
 */
int zerodds_waitset_get_conditions(struct zerodds_ZeroDdsWaitSet *w,
                                   void **out,
                                   uintptr_t cap,
                                   uintptr_t *out_count);

/**
 * `lookup_topicdescription(name)` — Spec §2.2.2.2.1.13.
 * Returns the first topic with the same name, or NULL.
 *
 * # Safety
 * `p`, `name` valid.
 */
struct zerodds_ZeroDdsTopic *zerodds_dp_lookup_topicdescription(struct zerodds_ZeroDdsDomainParticipant *p,
                                                                const char *name);

/**
 * `get_builtin_subscriber()` — Spec §2.2.2.2.1.7.
 * Returns a pointer to a wrapper around the DCPS BuiltinSubscriber.
 * The caller must call `zerodds_builtin_subscriber_destroy`.
 *
 * # Safety
 * `p` valid.
 */
struct zerodds_ZeroDdsBuiltinSubscriber *zerodds_dp_get_builtin_subscriber(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Deletes a BuiltinSubscriber wrapper.
 *
 * # Safety
 * `bs` valid or NULL.
 */
void zerodds_builtin_subscriber_destroy(struct zerodds_ZeroDdsBuiltinSubscriber *bs);

/**
 * Sets the DomainParticipant QoS (Spec §2.2.2.2.1.3).
 *
 * # Safety
 * `p` valid; `qos` darf NULL sein (Reset auf Default).
 */
int zerodds_dp_set_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                       const struct zerodds_ZeroDdsDomainParticipantQos *qos);

/**
 * Reads the DomainParticipant QoS into `out` (Spec §2.2.2.2.1.4).
 * `out.user_data.value` must be initialized by the caller with a sufficient
 * buffer. On a too-small buffer the required
 * size is written back into `out.user_data.value_len` + `OutOfResources`.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                       struct zerodds_ZeroDdsDomainParticipantQos *out);

/**
 * Set-Default-Topic-QoS.
 *
 * # Safety
 * `p` valid; `qos` darf NULL sein.
 */
int zerodds_dp_set_default_topic_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                     const struct zerodds_ZeroDdsTopicQos *qos);

/**
 * Get-Default-Topic-QoS-Snapshot.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_default_topic_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                     struct zerodds_ZeroDdsTopicQos *out);

/**
 * Set-Default-Publisher-QoS.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_set_default_publisher_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                         const struct zerodds_ZeroDdsPublisherQos *qos);

/**
 * Get-Default-Publisher-QoS.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_default_publisher_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                         struct zerodds_ZeroDdsPublisherQos *out);

/**
 * Set-Default-Subscriber-QoS.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_set_default_subscriber_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                          const zerodds_ZeroDdsSubscriberQos *qos);

/**
 * Get-Default-Subscriber-QoS.
 *
 * # Safety
 * `p`, `out` valid.
 */
int zerodds_dp_get_default_subscriber_qos(struct zerodds_ZeroDdsDomainParticipant *p,
                                          zerodds_ZeroDdsSubscriberQos *out);

/**
 * Publisher set/get QoS.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_set_qos(struct zerodds_ZeroDdsPublisher *pub_,
                        const struct zerodds_ZeroDdsPublisherQos *qos);

/**
 * Publisher get_qos.
 *
 * # Safety
 * `pub_`, `out` valid.
 */
int zerodds_pub_get_qos(struct zerodds_ZeroDdsPublisher *pub_,
                        struct zerodds_ZeroDdsPublisherQos *out);

/**
 * Pub set_default_datawriter_qos.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_set_default_datawriter_qos(struct zerodds_ZeroDdsPublisher *pub_,
                                           const struct zerodds_ZeroDdsDataWriterQos *qos);

/**
 * Pub get_default_datawriter_qos.
 *
 * # Safety
 * `pub_`, `out` valid.
 */
int zerodds_pub_get_default_datawriter_qos(struct zerodds_ZeroDdsPublisher *pub_,
                                           struct zerodds_ZeroDdsDataWriterQos *out);

/**
 * Pub copy_from_topic_qos: copies the policies from TopicQos into
 * the DataWriterQos `history`/`durability`/`reliability`/etc. in place.
 *
 * # Safety
 * Both pointers valid.
 */
int zerodds_pub_copy_from_topic_qos(struct zerodds_ZeroDdsPublisher *_pub,
                                    struct zerodds_ZeroDdsDataWriterQos *dwqos_inout,
                                    const struct zerodds_ZeroDdsTopicQos *tqos);

/**
 * Sub set/get QoS.
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_set_qos(struct zerodds_ZeroDdsSubscriber *sub,
                        const zerodds_ZeroDdsSubscriberQos *qos);

/**
 * Sub get_qos.
 *
 * # Safety
 * `sub`, `out` valid.
 */
int zerodds_sub_get_qos(struct zerodds_ZeroDdsSubscriber *sub, zerodds_ZeroDdsSubscriberQos *out);

/**
 * Sub set_default_datareader_qos.
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_set_default_datareader_qos(struct zerodds_ZeroDdsSubscriber *sub,
                                           const struct zerodds_ZeroDdsDataReaderQos *qos);

/**
 * Sub get_default_datareader_qos.
 *
 * # Safety
 * `sub`, `out` valid.
 */
int zerodds_sub_get_default_datareader_qos(struct zerodds_ZeroDdsSubscriber *sub,
                                           struct zerodds_ZeroDdsDataReaderQos *out);

/**
 * Sub copy_from_topic_qos.
 *
 * # Safety
 * Both pointers valid.
 */
int zerodds_sub_copy_from_topic_qos(struct zerodds_ZeroDdsSubscriber *_sub,
                                    struct zerodds_ZeroDdsDataReaderQos *drqos_inout,
                                    const struct zerodds_ZeroDdsTopicQos *tqos);

/**
 * DataWriter set_qos.
 *
 * # Safety
 * `dw` valid.
 */
int zerodds_dw_set_qos(struct zerodds_ZeroDdsDataWriter *dw,
                       const struct zerodds_ZeroDdsDataWriterQos *qos);

/**
 * DataWriter get_qos.
 *
 * # Safety
 * `dw`, `out` valid.
 */
int zerodds_dw_get_qos(struct zerodds_ZeroDdsDataWriter *dw,
                       struct zerodds_ZeroDdsDataWriterQos *out);

/**
 * DataReader set_qos.
 *
 * # Safety
 * `dr` valid.
 */
int zerodds_dr_set_qos(struct zerodds_ZeroDdsDataReader *dr,
                       const struct zerodds_ZeroDdsDataReaderQos *qos);

/**
 * DataReader get_qos.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_get_qos(struct zerodds_ZeroDdsDataReader *dr,
                       struct zerodds_ZeroDdsDataReaderQos *out);

/**
 * `register_instance` — vendor variant: the caller provides a 16-byte key hash
 * instead of a generic `T instance_data`. The wire path knows only bytes.
 *
 * # Safety
 * `dw` valid; `key`+`out_handle` valid.
 */
int zerodds_dw_register_instance(struct zerodds_ZeroDdsDataWriter *dw,
                                 const uint8_t *key,
                                 uintptr_t key_len,
                                 uint64_t *out_handle);

/**
 * `register_instance_w_timestamp`. RC1: source timestamp ignored
 * (same path as register_instance, documented in the vendor spec).
 *
 * # Safety
 * Wie `register_instance`.
 */
int zerodds_dw_register_instance_w_timestamp(struct zerodds_ZeroDdsDataWriter *dw,
                                             const uint8_t *key,
                                             uintptr_t key_len,
                                             int32_t _ts_sec,
                                             uint32_t _ts_nanosec,
                                             uint64_t *out_handle);

/**
 * `unregister_instance` — emits the UNREGISTERED lifecycle.
 *
 * # Safety
 * `dw` valid; `handle` must come from `register_instance`.
 */
int zerodds_dw_unregister_instance(struct zerodds_ZeroDdsDataWriter *dw, uint64_t handle);

/**
 * `unregister_instance_w_timestamp`.
 *
 * # Safety
 * Wie `unregister_instance`.
 */
int zerodds_dw_unregister_instance_w_timestamp(struct zerodds_ZeroDdsDataWriter *dw,
                                               uint64_t handle,
                                               int32_t _ts_sec,
                                               uint32_t _ts_nanosec);

/**
 * `lookup_instance` — vendor variant: returns a deterministic
 * handle from the first 8 key-hash bytes.
 *
 * # Safety
 * `key[0..16]` valid.
 */
int zerodds_dw_lookup_instance(struct zerodds_ZeroDdsDataWriter *_dw,
                               const uint8_t *key,
                               uintptr_t key_len,
                               uint64_t *out_handle);

/**
 * `get_key_value(handle)` — in the C-FFI only a vendor variant: copies
 * 8 bytes of the handle into `out_buf[0..8]`. The full spec round-trip
 * (T-encoded key) is the codegen path.
 *
 * # Safety
 * `dw` valid; `out_buf[0..*inout_len]` valid.
 */
int zerodds_dw_get_key_value(struct zerodds_ZeroDdsDataWriter *_dw,
                             uint64_t handle,
                             uint8_t *out_buf,
                             uintptr_t *inout_len);

/**
 * `dispose_w_timestamp`.
 *
 * # Safety
 * Wie `dispose`.
 */
int zerodds_dw_dispose_w_timestamp(struct zerodds_ZeroDdsDataWriter *dw,
                                   const uint8_t *key_hash,
                                   uint64_t handle,
                                   int32_t _ts_sec,
                                   uint32_t _ts_nanosec);

/**
 * `get_matched_subscriptions` — list of the `InstanceHandle`s of all
 * matched remote readers (Spec §2.2.2.4.2.x).
 *
 * # Safety
 * `dw` valid; `out_handles[0..cap]` writeable; `out_count` valid.
 */
int zerodds_dw_get_matched_subscriptions(struct zerodds_ZeroDdsDataWriter *dw,
                                         uint64_t *out_handles,
                                         uintptr_t *out_count,
                                         uintptr_t cap);

/**
 * `get_matched_subscription_data(handle)` — Spec §2.2.2.4.2.x.
 * Returns the `SubscriptionBuiltinTopicData` for a matched
 * reader, obtained from the BuiltinSubscriber SEDP cache.
 *
 * # Safety
 * `dw` and `out` valid.
 */
int zerodds_dw_get_matched_subscription_data(struct zerodds_ZeroDdsDataWriter *dw,
                                             uint64_t handle,
                                             struct zerodds_ZeroDdsSubscriptionBuiltinTopicData *out);

/**
 * `loan_message` — zero-copy loan via a heap box (vendor variant).
 * Allocates a Box<[u8]>, leaks the pointer; the caller writes into
 * the buffer and calls `commit_loan` (sends via write_user_sample)
 * or `discard_loan` (frees the buffer without sending).
 *
 * **Vendor decision (Spec §2.2.2.4.2 loan API + vendor spec
 * `zerodds-flatdata-1.0.md` §4):** real Iceoryx SHM zero-copy
 * requires a separate `zerodds-flatdata` Iceoryx backend wireup;
 * the heap-loan variant exposed here fulfills the DDS spec
 * contract (the caller writes into the buffer, then commit/discard)
 * without the SHM optimization. The real SHM loan is transparent via the
 * `zerodds-flatdata` Iceoryx backend when it is active.
 *
 * # Safety
 * Alle Pointers valid; `len > 0`.
 */
int zerodds_dw_loan_message(struct zerodds_ZeroDdsDataWriter *dw,
                            uintptr_t len,
                            uint8_t **out_ptr,
                            uintptr_t *out_len);

/**
 * `commit_loan` — writes the loan buffer as a sample and frees the
 * buffer.
 *
 * # Safety
 * `dw`, `ptr` valid; `(ptr, len)` from `loan_message`.
 */
int zerodds_dw_commit_loan(struct zerodds_ZeroDdsDataWriter *dw, uint8_t *ptr, uintptr_t len);

/**
 * `discard_loan` — frees the loan buffer without sending.
 *
 * # Safety
 * `dw`, `ptr` valid; `(ptr, len)` from `loan_message`.
 */
int zerodds_dw_discard_loan(struct zerodds_ZeroDdsDataWriter *_dw, uint8_t *ptr, uintptr_t len);

/**
 * `read_instance(handle)` — Spec §2.2.2.5.3.5: returns only samples
 * of this instance.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_read_instance(struct zerodds_ZeroDdsDataReader *dr,
                             uint64_t handle,
                             struct zerodds_ZeroDdsSampleArray *out,
                             uintptr_t max,
                             uint32_t s,
                             uint32_t v,
                             uint32_t i);

/**
 * `take_instance(handle)`.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_take_instance(struct zerodds_ZeroDdsDataReader *dr,
                             uint64_t handle,
                             struct zerodds_ZeroDdsSampleArray *out,
                             uintptr_t max,
                             uint32_t s,
                             uint32_t v,
                             uint32_t i);

/**
 * `read_next_instance(prev_handle)` — Spec §2.2.2.5.3.7: returns
 * samples of the next instance > prev_handle.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_read_next_instance(struct zerodds_ZeroDdsDataReader *dr,
                                  uint64_t prev_handle,
                                  struct zerodds_ZeroDdsSampleArray *out,
                                  uintptr_t max,
                                  uint32_t s,
                                  uint32_t v,
                                  uint32_t i);

/**
 * `take_next_instance(prev_handle)`.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_take_next_instance(struct zerodds_ZeroDdsDataReader *dr,
                                  uint64_t prev_handle,
                                  struct zerodds_ZeroDdsSampleArray *out,
                                  uintptr_t max,
                                  uint32_t s,
                                  uint32_t v,
                                  uint32_t i);

/**
 * `read_w_condition` — Spec §2.2.2.5.3.4: returns only samples that
 * match the condition state mask (ReadCondition.sample_states/
 * view_states/instance_states).
 *
 * # Safety
 * `dr`, `out` valid; `cond` is a ReadCondition or QueryCondition.
 */
int zerodds_dr_read_w_condition(struct zerodds_ZeroDdsDataReader *dr,
                                struct zerodds_ZeroDdsSampleArray *out,
                                uintptr_t max,
                                void *cond);

/**
 * `take_w_condition`.
 *
 * # Safety
 * Wie `read_w_condition`.
 */
int zerodds_dr_take_w_condition(struct zerodds_ZeroDdsDataReader *dr,
                                struct zerodds_ZeroDdsSampleArray *out,
                                uintptr_t max,
                                void *cond);

/**
 * `lookup_instance` (Reader).
 *
 * # Safety
 * `key[0..16]` valid; `out_handle` valid.
 */
int zerodds_dr_lookup_instance(struct zerodds_ZeroDdsDataReader *_dr,
                               const uint8_t *key,
                               uintptr_t key_len,
                               uint64_t *out_handle);

/**
 * `get_key_value` (Reader) — analog zu Writer.
 *
 * # Safety
 * `out_buf[0..*inout_len]` valid.
 */
int zerodds_dr_get_key_value(struct zerodds_ZeroDdsDataReader *_dr,
                             uint64_t handle,
                             uint8_t *out_buf,
                             uintptr_t *inout_len);

/**
 * `wait_for_historical_data(timeout)` — RC1: Volatile default → Ok without wait.
 *
 * # Safety
 * `dr` valid.
 */
int zerodds_dr_wait_for_historical_data(struct zerodds_ZeroDdsDataReader *dr,
                                        int32_t _timeout_sec,
                                        uint32_t _timeout_nanosec);

/**
 * `get_matched_publications` — list of the `InstanceHandle`s of all
 * matched remote writers (Spec §2.2.2.5.x).
 *
 * # Safety
 * `dr` valid; `out_handles[0..cap]` writeable; `out_count` valid.
 */
int zerodds_dr_get_matched_publications(struct zerodds_ZeroDdsDataReader *dr,
                                        uint64_t *out_handles,
                                        uintptr_t *out_count,
                                        uintptr_t cap);

/**
 * `get_matched_publication_data(handle)` — Spec §2.2.2.5.x.
 * Returns `PublicationBuiltinTopicData` from the BuiltinSubscriber cache.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_get_matched_publication_data(struct zerodds_ZeroDdsDataReader *dr,
                                            uint64_t handle,
                                            struct zerodds_ZeroDdsPublicationBuiltinTopicData *out);

/**
 * Get singleton: returns the global factory pointer. Never NULL.
 * The caller must **not** free the pointer.
 */
const struct zerodds_ZeroDdsDomainParticipantFactory *zerodds_dpf_get_instance(void);

/**
 * Creates a new DomainParticipant.
 *
 * # Safety
 * `f` must come from `zerodds_dpf_get_instance` or be NULL.
 * `qos` may be NULL (default).
 */
struct zerodds_ZeroDdsDomainParticipant *zerodds_dpf_create_participant(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                                                                        uint32_t domain_id,
                                                                        const struct zerodds_ZeroDdsDomainParticipantQos *qos);

/**
 * Deletes a DomainParticipant.
 *
 * # Safety
 * `f` and `p` must be valid handles. `p` must not have any
 * contained entities (topics, publishers, subscribers) at the time
 * of the call — the caller must call `delete_contained_entities`.
 */
int zerodds_dpf_delete_participant(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                                   struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Finds an active participant for the given domain ID. Returns
 * NULL if none exists.
 *
 * # Safety
 * `f` must be valid.
 */
struct zerodds_ZeroDdsDomainParticipant *zerodds_dpf_lookup_participant(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                                                                        uint32_t domain_id);

/**
 * Get default participant QoS via a pass-through pointer to an
 * `Arc<...>`-internal snapshot. The caller may only read the pointer,
 * not free it (static lifetime of the singleton factory).
 *
 * In this RC1 surface form the default QoS is returned as an opaque
 * `Arc<DomainParticipantQos>` — the full field getter/setter
 * comes with the `qos.rs` structs in a follow-up pass.
 *
 * # Safety
 * `f` valid.
 */
int zerodds_dpf_set_default_participant_qos(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                                            const struct zerodds_ZeroDdsDomainParticipantQos *qos);

/**
 * Returns a copy of the current default participant QoS in `out`.
 * As long as the `zerodds_DomainParticipantQos` struct is not defined in the
 * `qos.rs` layer, `out` is an opaque `void*`.
 *
 * # Safety
 * `f` valid; `out` may be NULL (no-op).
 */
int zerodds_dpf_get_default_participant_qos(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                                            struct zerodds_ZeroDdsDomainParticipantQos *out);

/**
 * Sets the factory's own QoS (Spec §2.2.2.2.2.6).
 *
 * # Safety
 * `f` valid; `qos` may be NULL (reset).
 */
int zerodds_dpf_set_qos(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                        const struct zerodds_ZeroDdsDomainParticipantFactoryQos *qos);

/**
 * Reads the factory's own QoS.
 *
 * # Safety
 * `f`, `out` valid.
 */
int zerodds_dpf_get_qos(const struct zerodds_ZeroDdsDomainParticipantFactory *f,
                        struct zerodds_ZeroDdsDomainParticipantFactoryQos *out);

/**
 * `dp_set_listener`. NULL = clear.
 *
 * # Safety
 * `p` valide; `l` darf NULL sein.
 */
int zerodds_dp_set_listener(struct zerodds_ZeroDdsDomainParticipant *p,
                            const struct zerodds_ZeroDdsDomainParticipantListener *l,
                            uint32_t status_mask);

/**
 * `pub_set_listener`.
 *
 * # Safety
 * `pub_` valide.
 */
int zerodds_pub_set_listener(struct zerodds_ZeroDdsPublisher *pub_,
                             const struct zerodds_ZeroDdsPublisherListener *l,
                             uint32_t status_mask);

/**
 * `sub_set_listener`.
 *
 * # Safety
 * `sub` valide.
 */
int zerodds_sub_set_listener(struct zerodds_ZeroDdsSubscriber *sub,
                             const struct zerodds_ZeroDdsSubscriberListener *l,
                             uint32_t status_mask);

/**
 * `topic_set_listener`.
 *
 * # Safety
 * `t` valide.
 */
int zerodds_topic_set_listener(struct zerodds_ZeroDdsTopic *t,
                               const struct zerodds_ZeroDdsTopicListener *l,
                               uint32_t status_mask);

/**
 * `dw_set_listener`.
 *
 * # Safety
 * `dw` valide.
 */
int zerodds_dw_set_listener(struct zerodds_ZeroDdsDataWriter *dw,
                            const struct zerodds_ZeroDdsDataWriterListener *l,
                            uint32_t status_mask);

/**
 * `dr_set_listener`.
 *
 * # Safety
 * `dr` valide.
 */
int zerodds_dr_set_listener(struct zerodds_ZeroDdsDataReader *dr,
                            const struct zerodds_ZeroDdsDataReaderListener *l,
                            uint32_t status_mask);

/**
 * `dp_get_listener` — liefert den zuletzt gesetzten Pointer oder NULL.
 *
 * # Safety
 * `p` valide.
 */
const struct zerodds_ZeroDdsDomainParticipantListener *zerodds_dp_get_listener(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * `dw_get_listener`.
 *
 * # Safety
 * `dw` valide.
 */
const struct zerodds_ZeroDdsDataWriterListener *zerodds_dw_get_listener(struct zerodds_ZeroDdsDataWriter *dw);

/**
 * `dr_get_listener`.
 *
 * # Safety
 * `dr` valide.
 */
const struct zerodds_ZeroDdsDataReaderListener *zerodds_dr_get_listener(struct zerodds_ZeroDdsDataReader *dr);

/**
 * Polls all registered listeners and fires callbacks on status counter
 * deltas. Each entity level (DataWriter/DataReader) and each aggregator
 * level (Publisher/Subscriber/DomainParticipant/Topic) fires independently
 * — multi-bind semantics, no first-match suppression. Returns the number
 * of callbacks fired.
 *
 * # Safety
 * The caller must guarantee that every entity pointer registered in the
 * registry (including the contained child entities) and every listener
 * pointer is still valid (not freed via `*_destroy` without a preceding
 * `set_listener(NULL)`).
 */
uintptr_t zerodds_poll_listeners(void);

/**
 * Creates a topic. Returns NULL on NULL arguments or a topic-name
 * conflict with another type.
 *
 * # Safety
 * `p`, `name`, `type_name` must be valid. `qos` may be NULL
 * (default from `default_topic_qos`).
 */
struct zerodds_ZeroDdsTopic *zerodds_dp_create_topic(struct zerodds_ZeroDdsDomainParticipant *p,
                                                     const char *name,
                                                     const char *type_name,
                                                     const struct zerodds_ZeroDdsTopicQos *qos);

/**
 * Deletes a topic.
 *
 * # Safety
 * `p` and `t` must be valid handles and belong together.
 */
int zerodds_dp_delete_topic(struct zerodds_ZeroDdsDomainParticipant *p,
                            struct zerodds_ZeroDdsTopic *t);

/**
 * Finds an already-created topic by name. Returns NULL if none.
 *
 * # Safety
 * `p`, `name` valid.
 */
struct zerodds_ZeroDdsTopic *zerodds_dp_find_topic(struct zerodds_ZeroDdsDomainParticipant *p,
                                                   const char *name);

/**
 * Creates a publisher.
 *
 * # Safety
 * `p` valid; `qos` may be NULL.
 */
struct zerodds_ZeroDdsPublisher *zerodds_dp_create_publisher(struct zerodds_ZeroDdsDomainParticipant *p,
                                                             const struct zerodds_ZeroDdsPublisherQos *qos);

/**
 * Deletes a publisher.
 *
 * # Safety
 * Both handles valid; the publisher must contain no more DataWriters.
 */
int zerodds_dp_delete_publisher(struct zerodds_ZeroDdsDomainParticipant *p,
                                struct zerodds_ZeroDdsPublisher *pubh);

/**
 * Creates a subscriber.
 *
 * # Safety
 * `p` valid; `qos` may be NULL.
 */
struct zerodds_ZeroDdsSubscriber *zerodds_dp_create_subscriber(struct zerodds_ZeroDdsDomainParticipant *p,
                                                               const zerodds_ZeroDdsSubscriberQos *qos);

/**
 * Deletes a subscriber.
 *
 * # Safety
 * Both handles valid; the subscriber must hold no more DataReaders.
 */
int zerodds_dp_delete_subscriber(struct zerodds_ZeroDdsDomainParticipant *p,
                                 struct zerodds_ZeroDdsSubscriber *sub);

/**
 * Creates a ContentFilteredTopic.
 *
 * # Safety
 * `p`, `name`, `related`, `filter_expression` valid.
 */
struct zerodds_ZeroDdsContentFilteredTopic *zerodds_dp_create_contentfilteredtopic(struct zerodds_ZeroDdsDomainParticipant *p,
                                                                                   const char *name,
                                                                                   struct zerodds_ZeroDdsTopic *related,
                                                                                   const char *filter_expression,
                                                                                   const char *const *parameters,
                                                                                   uintptr_t param_count);

/**
 * Sets the positional CDR field schema on a ContentFilteredTopic so the
 * untyped C-FFI filter actually evaluates the payload (Spec §2.2.2.3.3).
 *
 * `names[i]` is the field name referenced by the filter expression;
 * `kinds[i]` is its CDR encoding (0=bool, 1=int32, 2=int64, 3=float32,
 * 4=float64, 5=string). The fields MUST be listed in their on-wire
 * declaration order, starting from the first member of the payload.
 *
 * This variant assumes a `@final` payload (no leading DHEADER, offset 0). For
 * an `@appendable`/`@mutable` payload use [`zerodds_cft_set_schema_ex`].
 *
 * Note: filter literals are passed as-is — the SQL `WHERE` expression carries
 * its own typed literals (e.g. `seq > 4`, `name = 'foo'`); the schema only
 * declares how to decode the payload columns, it does not coerce the literals.
 *
 * # Safety
 * `cft` valid; `names[0..count]` valid NUL-terminated C strings;
 * `kinds[0..count]` readable.
 */
int zerodds_cft_set_schema(struct zerodds_ZeroDdsContentFilteredTopic *cft,
                           const char *const *names,
                           const uint32_t *kinds,
                           uintptr_t count);

/**
 * Like [`zerodds_cft_set_schema`] but additionally declares the payload's type
 * `extensibility` (XTypes 1.3 §7.3.1.2.1): `0 = @final`, `1 = @appendable`,
 * `2 = @mutable`. For `@appendable`/`@mutable` the XCDR2 stream is prefixed
 * with a 4-byte DHEADER (§7.4.3.4.2) before the first member, so the
 * positional decoder skips 4 bytes; for `@final` the first member is at
 * offset 0. Any other value is rejected.
 *
 * Filter literals are passed as-is (see [`zerodds_cft_set_schema`]).
 *
 * # Safety
 * `cft` valid; `names[0..count]` valid NUL-terminated C strings;
 * `kinds[0..count]` readable.
 */
int zerodds_cft_set_schema_ex(struct zerodds_ZeroDdsContentFilteredTopic *cft,
                              const char *const *names,
                              const uint32_t *kinds,
                              uintptr_t count,
                              uint32_t extensibility);

/**
 * Deletes a ContentFilteredTopic.
 *
 * # Safety
 * Both handles valid.
 */
int zerodds_dp_delete_contentfilteredtopic(struct zerodds_ZeroDdsDomainParticipant *p,
                                           struct zerodds_ZeroDdsContentFilteredTopic *cft);

/**
 * Ignore Participant by InstanceHandle.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_ignore_participant(struct zerodds_ZeroDdsDomainParticipant *p, uint64_t handle);

/**
 * Ignore Topic by InstanceHandle.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_ignore_topic(struct zerodds_ZeroDdsDomainParticipant *p, uint64_t handle);

/**
 * Ignore Publication by InstanceHandle.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_ignore_publication(struct zerodds_ZeroDdsDomainParticipant *p, uint64_t handle);

/**
 * Ignore Subscription by InstanceHandle.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_ignore_subscription(struct zerodds_ZeroDdsDomainParticipant *p, uint64_t handle);

/**
 * Domain ID of the participant.
 *
 * # Safety
 * `p` valid.
 */
uint32_t zerodds_dp_get_domain_id(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Asserts liveliness for all MANUAL_BY_PARTICIPANT writers held by the
 * participant.
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_assert_liveliness(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Writes the participant's current wall-clock time into `*out`
 * (Spec §2.2.2.1.1.21 `get_current_time`).
 *
 * # Safety
 * `p` and `out` valid.
 */
int zerodds_dp_get_current_time(struct zerodds_ZeroDdsDomainParticipant *p,
                                struct zerodds_ZeroDdsTime *out);

/**
 * Deletes all topics, publishers, subscribers held by the participant
 * recursively (Spec §2.2.2.2.1.10).
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_delete_contained_entities(struct zerodds_ZeroDdsDomainParticipant *p);

/**
 * Checks whether an InstanceHandle belongs to an entity in this participant
 * (Spec §2.2.2.2.1.11).
 *
 * # Safety
 * `p` valid.
 */
int zerodds_dp_contains_entity(struct zerodds_ZeroDdsDomainParticipant *p, uint64_t handle);

/**
 * Returns the InstanceHandles of all discovered remote participants.
 * `out_handles[0..*out_count]` are written, max `cap`.
 *
 * # Safety
 * `p`, `out_handles`, `out_count` valid; `out_handles[0..cap]` writeable.
 */
int zerodds_dp_get_discovered_participants(struct zerodds_ZeroDdsDomainParticipant *p,
                                           uint64_t *out_handles,
                                           uintptr_t *out_count,
                                           uintptr_t cap);

/**
 * Returns the owning participant.
 *
 * # Safety
 * `pub_` valid.
 */
struct zerodds_ZeroDdsDomainParticipant *zerodds_pub_get_participant(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * Suspend publications (Spec §2.2.2.4.1.10). Sets a flag — the
 * hot path queues writes instead of sending them, until `resume_publications`.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_suspend_publications(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * Resume publications.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_resume_publications(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * begin_coherent_changes (Spec §2.2.2.4.1.12). In RC1 a no-bracket
 * marker — a spec-conformant tracker at the publisher level; the coherent-set
 * result wire frames live at the writer level and take effect independently.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_begin_coherent_changes(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * end_coherent_changes.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_end_coherent_changes(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * wait_for_acknowledgments(timeout_ms) — waits until all DWs are
 * acked or the timeout fires.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_wait_for_acknowledgments(struct zerodds_ZeroDdsPublisher *pub_,
                                         uint64_t timeout_ms);

/**
 * Creates a DataWriter over the topic.
 *
 * # Safety
 * `pub_`, `topic` valid; `qos` may be NULL (default = pub.default_dw_qos).
 */
struct zerodds_ZeroDdsDataWriter *zerodds_pub_create_datawriter(struct zerodds_ZeroDdsPublisher *pub_,
                                                                struct zerodds_ZeroDdsTopic *topic,
                                                                const struct zerodds_ZeroDdsDataWriterQos *qos);

/**
 * Deletes a DataWriter.
 *
 * # Safety
 * `pub_`, `dw` valid and belonging together.
 */
int zerodds_pub_delete_datawriter(struct zerodds_ZeroDdsPublisher *pub_,
                                  struct zerodds_ZeroDdsDataWriter *dw);

/**
 * Returns the DataWriter for a topic name, or NULL.
 *
 * # Safety
 * `pub_`, `topic_name` valid.
 */
struct zerodds_ZeroDdsDataWriter *zerodds_pub_lookup_datawriter(struct zerodds_ZeroDdsPublisher *pub_,
                                                                const char *topic_name);

/**
 * Deletes all DataWriters held by the publisher.
 *
 * # Safety
 * `pub_` valid.
 */
int zerodds_pub_delete_contained_entities(struct zerodds_ZeroDdsPublisher *pub_);

/**
 * Returns the topic.
 *
 * # Safety
 * `dw` valid.
 */
struct zerodds_ZeroDdsTopic *zerodds_dw_get_topic(struct zerodds_ZeroDdsDataWriter *dw);

/**
 * Returns the publisher.
 *
 * # Safety
 * `dw` valid.
 */
struct zerodds_ZeroDdsPublisher *zerodds_dw_get_publisher(struct zerodds_ZeroDdsDataWriter *dw);

/**
 * Writes a pre-made CDR payload (the caller serializes via
 * idl codegen or DynamicData). The encap header prefix is added by the
 * runtime.
 *
 * # Safety
 * `dw`, `payload[0..len]` valid. `handle` is a spec-mandatory param that
 * identifies the instance — `0` = HANDLE_NIL = "writer computes it".
 */
int zerodds_dw_write(struct zerodds_ZeroDdsDataWriter *dw,
                     const uint8_t *payload,
                     uintptr_t len,
                     uint64_t _handle);

/**
 * Writes with a source timestamp. RC1 surface: forwards to `write`
 * — the source timestamp lands in the future inline-QoS implementation.
 *
 * # Safety
 * Like `zerodds_dw_write`.
 */
int zerodds_dw_write_w_timestamp(struct zerodds_ZeroDdsDataWriter *dw,
                                 const uint8_t *payload,
                                 uintptr_t len,
                                 uint64_t handle,
                                 int32_t _ts_sec,
                                 uint32_t _ts_nanosec);

/**
 * Dispose: emits a DISPOSED lifecycle marker for the instance.
 *
 * # Safety
 * `dw` valid; `key_hash[0..16]` readable. `handle` informational.
 */
int zerodds_dw_dispose(struct zerodds_ZeroDdsDataWriter *dw,
                       const uint8_t *key_hash,
                       uint64_t _handle);

/**
 * Waits until all currently outstanding writes are acked or a timeout.
 *
 * # Safety
 * `dw` valid.
 */
int zerodds_dw_wait_for_acknowledgments(struct zerodds_ZeroDdsDataWriter *dw, uint64_t timeout_ms);

/**
 * Manually asserts liveliness for this writer.
 *
 * # Safety
 * `dw` valid.
 */
int zerodds_dw_assert_liveliness(struct zerodds_ZeroDdsDataWriter *dw);

/**
 * Waits until at least `min` matched subscriptions exist or a timeout.
 *
 * # Safety
 * `dw` valid.
 */
int zerodds_dw_wait_for_matched(struct zerodds_ZeroDdsDataWriter *dw,
                                int32_t min,
                                uint64_t timeout_ms);

/**
 * `LIVELINESS_LOST_STATUS` (Spec §2.2.2.4.2.x).
 *
 * # Safety
 * `dw` and `out` valid.
 */
int zerodds_dw_get_liveliness_lost_status(struct zerodds_ZeroDdsDataWriter *dw,
                                          struct zerodds_ZeroDdsLivelinessLostStatus *out);

/**
 * `OFFERED_DEADLINE_MISSED_STATUS`.
 *
 * # Safety
 * `dw` and `out` valid.
 */
int zerodds_dw_get_offered_deadline_missed_status(struct zerodds_ZeroDdsDataWriter *dw,
                                                  struct zerodds_ZeroDdsOfferedDeadlineMissedStatus *out);

/**
 * `OFFERED_INCOMPATIBLE_QOS_STATUS`.
 *
 * # Safety
 * `dw` and `out` valid.
 */
int zerodds_dw_get_offered_incompatible_qos_status(struct zerodds_ZeroDdsDataWriter *dw,
                                                   struct zerodds_ZeroDdsOfferedIncompatibleQosStatus *out);

/**
 * `PUBLICATION_MATCHED_STATUS`.
 *
 * # Safety
 * `dw` and `out` valid.
 */
int zerodds_dw_get_publication_matched_status(struct zerodds_ZeroDdsDataWriter *dw,
                                              struct zerodds_ZeroDdsPublicationMatchedStatus *out);

/**
 * Creates an empty security config builder.
 *
 * # Safety
 * The return value is Box::into_raw — the caller owns it + must
 * pair `zerodds_security_config_destroy`.
 */
struct zerodds_ZeroDdsSecurityConfig *zerodds_security_config_create(void);

/**
 * Destroys the config builder. NULL-safe.
 *
 * # Safety
 * `cfg` must come from `zerodds_security_config_create` or be NULL.
 */
void zerodds_security_config_destroy(struct zerodds_ZeroDdsSecurityConfig *cfg);

/**
 * Setter `identity_ca_path` (PEM bundle, trust anchors).
 *
 * # Safety
 * `cfg` from `zerodds_security_config_create`, `path` null-terminated or NULL.
 */
int32_t zerodds_security_set_identity_ca_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                              const char *path);

/**
 * Setter `identity_cert_path` (PEM, local identity cert).
 *
 * # Safety
 * See [`zerodds_security_set_identity_ca_path`].
 */
int32_t zerodds_security_set_identity_cert_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                                const char *path);

/**
 * Setter `identity_key_path` (PKCS#8 PEM private key).
 *
 * # Safety
 * See [`zerodds_security_set_identity_ca_path`].
 */
int32_t zerodds_security_set_private_key_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                              const char *path);

/**
 * Setter `permissions_ca_path` (PEM bundle, often = identity_ca).
 *
 * # Safety
 * See [`zerodds_security_set_identity_ca_path`].
 */
int32_t zerodds_security_set_permissions_ca_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                                 const char *path);

/**
 * Setter `governance_path` (CMS-signed governance XML, `.p7s`).
 *
 * # Safety
 * See [`zerodds_security_set_identity_ca_path`].
 */
int32_t zerodds_security_set_governance_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                             const char *path);

/**
 * Setter `permissions_path` (CMS-signed permissions XML, `.p7s`).
 *
 * # Safety
 * See [`zerodds_security_set_identity_ca_path`].
 */
int32_t zerodds_security_set_permissions_path(struct zerodds_ZeroDdsSecurityConfig *cfg,
                                              const char *path);

/**
 * Creates a ZeroDDS runtime with DDS-Security 1.2 active.
 *
 * `cfg` must have all 6 paths set; PKI + CMS verify + governance/
 * permissions parsing run synchronously on the call. On error in
 * one of the steps: NULL return + stderr diag, **but** `cfg`
 * stays unchanged (no auto-destroy).
 *
 * # Safety
 * `cfg` from `zerodds_security_config_create` (or NULL). `cfg` must
 * not be mutated concurrently from another thread.
 */
struct zerodds_ZeroDdsRuntime *zerodds_runtime_create_secure(uint32_t domain_id,
                                                             const struct zerodds_ZeroDdsSecurityConfig *cfg);

/**
 * Creates a ZeroDDS runtime with DDS-Security from an **SROS2 enclave**
 * (C7 "secure by default"). Reads `ZERODDS_SECURITY_DIR` (enclave directory)
 * and `ROS_DOMAIN_ID`, and builds the `SecurityProfile` in one call — no
 * per-path setter ceremony.
 *
 * Return: NULL if `ZERODDS_SECURITY_DIR` is not set (the caller then falls
 * back to the plain path) OR on a load/verify error (stderr diag);
 * otherwise the secured runtime. `domain_id` does not override `ROS_DOMAIN_ID` —
 * it is the explicit value the runtime starts with.
 *
 * # Safety
 * No pointer arguments; always callable.
 */
struct zerodds_ZeroDdsRuntime *zerodds_runtime_create_secure_from_env(uint32_t domain_id);

/**
 * Enables zero-copy SHM loan on a DCPS DataWriter. Creates a POSIX
 * shared-memory segment of `slot_count` slots × `slot_capacity` bytes at the
 * flink path `name`. After this, `zerodds_dw_loan_message` returns a pointer
 * into a SHM slot and `zerodds_dw_commit_loan` finalizes it in place.
 *
 * # Safety
 * `dw` is a valid registered DataWriter; `name` is a NUL-terminated C string.
 */
int zerodds_dw_enable_shm_loan(struct zerodds_ZeroDdsDataWriter *dw,
                               const char *name,
                               uintptr_t slot_count,
                               uintptr_t slot_capacity);

/**
 * Sets the delivery mode of a DCPS DataWriter (`zerodds-delivery-modes-1.0`
 * §3/§4): `0`=Portable (default, interop-safe), `1`=RawSameHost (same-host,
 * no wire). `2`=Iceoryx is not yet wired → `Unsupported`. Other values →
 * `BadParameter`.
 *
 * # Safety
 * `dw` is a valid registered DataWriter.
 */
int zerodds_dw_set_delivery_mode(struct zerodds_ZeroDdsDataWriter *dw, int mode);

/**
 * Maps the writer's SHM segment at flink path `name` on a DCPS DataReader for
 * zero-copy reads. `reader_index` is the reader's bit (0..32) in the slot mask.
 *
 * # Safety
 * `dr` valid; `name` is a NUL-terminated C string.
 */
int zerodds_dr_enable_shm(struct zerodds_ZeroDdsDataReader *dr,
                          const char *name,
                          uint8_t reader_index);

/**
 * Zero-copy take on a DCPS DataReader: returns a read-only pointer into the
 * writer's SHM slot, its length and the slot index (for
 * `zerodds_dr_release_shm`). `NoData` when nothing is pending.
 *
 * # Safety
 * `dr`/`out_ptr`/`out_len`/`out_slot` valid.
 */
int zerodds_dr_take_shm(struct zerodds_ZeroDdsDataReader *dr,
                        const uint8_t **out_ptr,
                        uintptr_t *out_len,
                        uint32_t *out_slot);

/**
 * Releases a slot previously returned by `zerodds_dr_take_shm`.
 *
 * # Safety
 * `dr` valid; `slot_index` from a prior `zerodds_dr_take_shm`.
 */
int zerodds_dr_release_shm(struct zerodds_ZeroDdsDataReader *dr, uint32_t slot_index);

/**
 * Enables `Iceoryx` delivery on a DCPS DataWriter (feature `delivery-iceoryx`):
 * publishes the writer's samples over the iceoryx2 service `service_name`, with
 * a max payload of `max_len` bytes. The loan API then routes through iceoryx2
 * and commit does not publish over RTPS.
 *
 * # Safety
 * `dw` is a valid registered DataWriter; `service_name` is a NUL-terminated C
 * string.
 */
int zerodds_dw_enable_iceoryx(struct zerodds_ZeroDdsDataWriter *dw,
                              const char *service_name,
                              uintptr_t max_len);

/**
 * Enables `Iceoryx` delivery on a DCPS DataReader: receives samples from the
 * iceoryx2 service `service_name` via `zerodds_dr_take_shm` /
 * `zerodds_dr_release_shm`.
 *
 * # Safety
 * `dr` valid; `service_name` is a NUL-terminated C string.
 */
int zerodds_dr_enable_iceoryx(struct zerodds_ZeroDdsDataReader *dr, const char *service_name);

/**
 * Returns the owning participant.
 *
 * # Safety
 * `sub` valid.
 */
struct zerodds_ZeroDdsDomainParticipant *zerodds_sub_get_participant(struct zerodds_ZeroDdsSubscriber *sub);

/**
 * `begin_access` (Spec §2.2.2.5.1.13). RC1: no-op marker for
 * coherent sets — the real set boundaries are on the reader wire path.
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_begin_access(struct zerodds_ZeroDdsSubscriber *sub);

/**
 * `end_access`.
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_end_access(struct zerodds_ZeroDdsSubscriber *sub);

/**
 * Returns the list of active DataReaders.
 *
 * # Safety
 * `sub`, `out`, `out_count` valid.
 */
int zerodds_sub_get_datareaders(struct zerodds_ZeroDdsSubscriber *sub,
                                struct zerodds_ZeroDdsDataReader **out,
                                uintptr_t *out_count,
                                uintptr_t cap);

/**
 * `notify_datareaders` (Spec §2.2.2.5.1.16). RC1: no-op — the listener bubble-up
 * runs per-reader, the subscriber aggregator is wired in the WP "Listeners-FFI".
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_notify_datareaders(struct zerodds_ZeroDdsSubscriber *sub);

/**
 * Creates a DataReader.
 *
 * # Safety
 * `sub`, `topic` valid; `qos` may be NULL.
 */
struct zerodds_ZeroDdsDataReader *zerodds_sub_create_datareader(struct zerodds_ZeroDdsSubscriber *sub,
                                                                struct zerodds_ZeroDdsTopic *topic,
                                                                const struct zerodds_ZeroDdsDataReaderQos *qos);

/**
 * Creates a DataReader on a ContentFilteredTopic.
 * On every `take`/`read` the filter expression is evaluated
 * (Spec §2.2.2.3.3 + §2.2.2.5.2.5).
 *
 * # Safety
 * `sub`, `cft` valid; `qos` may be NULL.
 */
struct zerodds_ZeroDdsDataReader *zerodds_sub_create_datareader_with_cft(struct zerodds_ZeroDdsSubscriber *sub,
                                                                         struct zerodds_ZeroDdsContentFilteredTopic *cft,
                                                                         const struct zerodds_ZeroDdsDataReaderQos *qos);

/**
 * Deletes a DataReader.
 *
 * # Safety
 * `sub`, `dr` valid and belonging together.
 */
int zerodds_sub_delete_datareader(struct zerodds_ZeroDdsSubscriber *sub,
                                  struct zerodds_ZeroDdsDataReader *dr);

/**
 * Look up a DataReader by topic name.
 *
 * # Safety
 * `sub`, `topic_name` valid.
 */
struct zerodds_ZeroDdsDataReader *zerodds_sub_lookup_datareader(struct zerodds_ZeroDdsSubscriber *sub,
                                                                const char *topic_name);

/**
 * Deletes all DataReaders held by the subscriber.
 *
 * # Safety
 * `sub` valid.
 */
int zerodds_sub_delete_contained_entities(struct zerodds_ZeroDdsSubscriber *sub);

/**
 * Returns the TopicDescription handle (in RC1: the topic pointer).
 *
 * # Safety
 * `dr` valid.
 */
struct zerodds_ZeroDdsTopic *zerodds_dr_get_topicdescription(struct zerodds_ZeroDdsDataReader *dr);

/**
 * Returns the subscriber.
 *
 * # Safety
 * `dr` valid.
 */
struct zerodds_ZeroDdsSubscriber *zerodds_dr_get_subscriber(struct zerodds_ZeroDdsDataReader *dr);

/**
 * Take: consumes samples from the cache + channel (Spec §2.2.2.5.3).
 * Goes through read_cache (sample-state READ + NOT_READ) and the channel
 * (sample-state NOT_READ), removes all delivered samples.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_take(struct zerodds_ZeroDdsDataReader *dr,
                    struct zerodds_ZeroDdsSampleArray *out,
                    uintptr_t max_samples,
                    uint32_t _sample_states,
                    uint32_t _view_states,
                    uint32_t _instance_states);

/**
 * Read: non-destructive variant of take (Spec §2.2.2.5.3).
 * Returns samples from the cache + channel, but ALL of them remain afterwards
 * in the read cache with sample-state = READ.
 *
 * # Safety
 * `dr`, `out` valid.
 */
int zerodds_dr_read(struct zerodds_ZeroDdsDataReader *dr,
                    struct zerodds_ZeroDdsSampleArray *out,
                    uintptr_t max_samples,
                    uint32_t _sample_states,
                    uint32_t _view_states,
                    uint32_t _instance_states);

/**
 * Take next single sample.
 *
 * # Safety
 * `dr`, `out_buf`, `out_len`, `out_info` valid.
 */
int zerodds_dr_take_next_sample(struct zerodds_ZeroDdsDataReader *dr,
                                uint8_t **out_buf,
                                uintptr_t *out_len,
                                struct zerodds_ZeroDdsSampleInfo *out_info);

/**
 * Read next single sample. Identical to take_next_sample in RC1.
 *
 * # Safety
 * Like `take_next_sample`.
 */
int zerodds_dr_read_next_sample(struct zerodds_ZeroDdsDataReader *dr,
                                uint8_t **out_buf,
                                uintptr_t *out_len,
                                struct zerodds_ZeroDdsSampleInfo *out_info);

/**
 * Returns loaned sample buffers.
 *
 * # Safety
 * `arr` must come from a previous `zerodds_dr_take`/`read`,
 * `loan_token` must still be valid.
 */
int zerodds_dr_return_loan(struct zerodds_ZeroDdsDataReader *_dr,
                           struct zerodds_ZeroDdsSampleArray *arr);

/**
 * Waits until `min` matched publications or a timeout.
 *
 * # Safety
 * `dr` valid.
 */
int zerodds_dr_wait_for_matched(struct zerodds_ZeroDdsDataReader *dr,
                                int32_t min,
                                uint64_t timeout_ms);

/**
 * `LIVELINESS_CHANGED_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_liveliness_changed_status(struct zerodds_ZeroDdsDataReader *dr,
                                             struct zerodds_ZeroDdsLivelinessChangedStatus *out);

/**
 * `SUBSCRIPTION_MATCHED_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_subscription_matched_status(struct zerodds_ZeroDdsDataReader *dr,
                                               struct zerodds_ZeroDdsSubscriptionMatchedStatus *out);

/**
 * `REQUESTED_DEADLINE_MISSED_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_requested_deadline_missed_status(struct zerodds_ZeroDdsDataReader *dr,
                                                    struct zerodds_ZeroDdsRequestedDeadlineMissedStatus *out);

/**
 * `REQUESTED_INCOMPATIBLE_QOS_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_requested_incompatible_qos_status(struct zerodds_ZeroDdsDataReader *dr,
                                                     struct zerodds_ZeroDdsRequestedIncompatibleQosStatus *out);

/**
 * `SAMPLE_LOST_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_sample_lost_status(struct zerodds_ZeroDdsDataReader *dr,
                                      struct zerodds_ZeroDdsSampleLostStatus *out);

/**
 * `SAMPLE_REJECTED_STATUS`.
 *
 * # Safety
 * `dr` and `out` valid.
 */
int zerodds_dr_get_sample_rejected_status(struct zerodds_ZeroDdsDataReader *dr,
                                          struct zerodds_ZeroDdsSampleRejectedStatus *out);

/**
 * Returns the topic name as a heap-allocated C string. The caller must
 * call `zerodds_string_free`.
 *
 * # Safety
 * `t` valid.
 */
char *zerodds_topic_get_name(struct zerodds_ZeroDdsTopic *t);

/**
 * Returns the topic type name. The caller must call `zerodds_string_free`.
 *
 * # Safety
 * `t` valid.
 */
char *zerodds_topic_get_type_name(struct zerodds_ZeroDdsTopic *t);

/**
 * Returns the owning participant.
 *
 * # Safety
 * `t` valid.
 */
struct zerodds_ZeroDdsDomainParticipant *zerodds_topic_get_participant(struct zerodds_ZeroDdsTopic *t);

/**
 * Frees a C string previously allocated by `zerodds_topic_get_*`.
 *
 * # Safety
 * `s` must come from a `zerodds_*_get_*` function that produces a
 * `*mut c_char` via `CString::into_raw`.
 */
void zerodds_string_free(char *s);

/**
 * Get QoS into `out` (Spec §2.2.2.3.2.x).
 * `out` is `*mut ZeroDdsTopicQos` with a caller-supplied buffer for
 * `topic_data.value` (variable length).
 *
 * # Safety
 * `t`, `out` valid.
 */
int zerodds_topic_get_qos(struct zerodds_ZeroDdsTopic *t, struct zerodds_ZeroDdsTopicQos *out);

/**
 * Set QoS (Spec §2.2.2.3.2.x). NULL = default.
 *
 * # Safety
 * `t` valid.
 */
int zerodds_topic_set_qos(struct zerodds_ZeroDdsTopic *t,
                          const struct zerodds_ZeroDdsTopicQos *qos);

/**
 * Returns the InconsistentTopicStatus.
 *
 * # Safety
 * `t` and `out` valid.
 */
int zerodds_topic_get_inconsistent_topic_status(struct zerodds_ZeroDdsTopic *t,
                                                struct zerodds_ZeroDdsInconsistentTopicStatus *out);

/**
 * Creates a typed topic handle. Stores the TypeSupport
 * table so that writer/reader operations can access it.
 *
 * `out_topic` must be non-NULL and is set to the newly allocated
 * topic handle. The caller MUST later call
 * `zerodds_topic_destroy_typed`.
 *
 * # Safety
 * `participant`/`topic_name`/`type_support`/`out_topic` must be valid
 * pointers. `topic_name` must be NUL-terminated. `type_support`
 * MUST point to a static table with live function pointers.
 */
int zerodds_topic_create_typed(struct zerodds_ZeroDdsRuntime *participant,
                               const char *topic_name,
                               const struct zerodds_ZeroDdsTypeSupport *type_support,
                               struct zerodds_ZeroDdsTopic **out_topic);

/**
 * Destroys a topic handle. NULL-safe.
 *
 * # Safety
 * `topic` must come from `zerodds_topic_create_typed` or be NULL.
 */
void zerodds_topic_destroy_typed(struct zerodds_ZeroDdsTopic *topic);

/**
 * Standalone encoder. Calls `ts.encode(sample, out_buf, out_cap, out_len)`
 * and passes the return code through.
 *
 * `out_buf=NULL` with `out_cap=0` is a size probe: the codegen encoder
 * MUST set `out_len` to the needed size and
 * return `BUFFER_TOO_SMALL`.
 *
 * # Safety
 * `ts`, `sample`, `out_len` must be valid pointers. `out_buf` may
 * be NULL if `out_cap = 0`.
 */
int zerodds_xcdr2_encode(const struct zerodds_ZeroDdsTypeSupport *ts,
                         const void *sample,
                         uint8_t *out_buf,
                         uintptr_t out_cap,
                         uintptr_t *out_len);

/**
 * Standalone decoder. Calls `ts.decode(buf, len, out_sample)`.
 *
 * # Safety
 * `ts`/`buf`/`out_sample` valid; `buf` must be readable for `len` bytes;
 * `out_sample` must point zero-initialized to the language type.
 */
int zerodds_xcdr2_decode(const struct zerodds_ZeroDdsTypeSupport *ts,
                         const uint8_t *buf,
                         uintptr_t len,
                         void *out_sample);

/**
 * Standalone representation-aware decoder (Bug R4b). Prefers
 * `ts.decode_repr(buf, len, representation, out_sample)` when present so
 * the decoder can pick the correct `max_align` (8 for XCDR1 = `0`,
 * 4 for XCDR2 = `1`); falls back to the legacy `ts.decode` when the
 * TypeSupport table predates the repr-aware entry-point.
 *
 * `representation`: `0` = XCDR1, `1` = XCDR2 (the value reported by
 * `zerodds_reader_take`'s `out_repr`).
 *
 * # Safety
 * `ts`/`buf`/`out_sample` valid; `buf` readable for `len` bytes;
 * `out_sample` zero-initialized to the language type.
 */
int zerodds_xcdr2_decode_repr(const struct zerodds_ZeroDdsTypeSupport *ts,
                              const uint8_t *buf,
                              uintptr_t len,
                              uint8_t representation,
                              void *out_sample);

/**
 * Writes a typed sample. Encodes via
 * `ts.encode` into an internal heap buffer and passes the bytes to
 * `zerodds_writer_write`.
 *
 * Strategy:
 * 1. Size probe (`out_buf=NULL`).
 * 2. Allocate a heap buffer of the probed size.
 * 3. Real encode in.
 * 4. `zerodds_writer_write(writer, bytes, len)`.
 *
 * # Safety
 * `writer`/`ts`/`sample` valid; cf. `zerodds_writer_write` and
 * `zerodds_xcdr2_encode`.
 */
int zerodds_writer_write_typed(struct zerodds_ZeroDdsWriter *writer,
                               const struct zerodds_ZeroDdsTypeSupport *ts,
                               const void *sample);

/**
 * Reads a typed sample. Fetches bytes via `zerodds_reader_take`
 * and decodes them via `ts.decode` into `out_sample`.
 *
 * `out_info` is currently unused (reserved for the sample-info spec
 * rollout); MUST be NULL or point to a caller-allocated
 * `zerodds_sample_info_t` that is filled with default values.
 *
 * Returns:
 * - 0 (Ok) if a sample was decoded successfully.
 * - `NoData` (-7) if the reader is empty.
 * - other negative codes on a decoder error.
 *
 * # Safety
 * `reader`/`ts`/`out_sample` valid. `out_info` NULL or valid.
 */
int zerodds_reader_take_typed(struct zerodds_ZeroDdsReader *reader,
                              const struct zerodds_ZeroDdsTypeSupport *ts,
                              void *out_sample,
                              void *out_info);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* ZERODDS_H */