summaryrefslogtreecommitdiff
path: root/src/lib/eet_data.c
blob: 84790234bba73df0d5e4bace0d9842febb15d8be (plain)
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
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#if HAVE___ATTRIBUTE__
#define __UNUSED__ __attribute__((unused))
#else
#define __UNUSED__
#endif

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

#if defined(_WIN32) && ! defined(__CEGCC__)
# include <winsock2.h>
#endif

#include <Eina.h>

#include "Eet.h"
#include "Eet_private.h"

/*
 * routines for doing data -> struct and struct -> data conversion
 *
 * types:
 *
 * basic types:
 *   a sequence of...
 *
 *   char
 *   short
 *   int
 *   long long
 *   float
 *   double
 *   unsigned char
 *   unsigned short
 *   unsigned int
 *   unsgined long long
 *   string
 *
 * groupings:
 *   multiple entries ordered as...
 *
 *   fixed size array    [ of basic types ]
 *   variable size array [ of basic types ]
 *   linked list         [ of basic types ]
 *   hash table          [ of basic types ]
 *
 * need to provide builder/accessor funcs for:
 *
 *   list_next
 *   list_append
 *
 *   hash_foreach
 *   hash_add
 *
 */

/*---*/

typedef struct _Eet_Data_Element            Eet_Data_Element;
typedef struct _Eet_Data_Basic_Type_Codec   Eet_Data_Basic_Type_Codec;
typedef struct _Eet_Data_Group_Type_Codec   Eet_Data_Group_Type_Codec;
typedef struct _Eet_Data_Chunk              Eet_Data_Chunk;
typedef struct _Eet_Data_Stream             Eet_Data_Stream;
typedef struct _Eet_Data_Descriptor_Hash    Eet_Data_Descriptor_Hash;
typedef struct _Eet_Data_Encode_Hash_Info   Eet_Data_Encode_Hash_Info;
typedef struct _Eet_Free		    Eet_Free;
typedef struct _Eet_Free_Context	    Eet_Free_Context;

/*---*/

/* TODO:
 * Eet_Data_Basic_Type_Codec (Coder, Decoder)
 * Eet_Data_Group_Type_Codec (Coder, Decoder)
 */
struct _Eet_Data_Basic_Type_Codec
{
   int         size;
   const char *name;
   int       (*get) (const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
   void     *(*put) (Eet_Dictionary *ed, const void *src, int *size_ret);
};

struct _Eet_Data_Group_Type_Codec
{
   int  (*get) (Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
   void (*put) (Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
};

struct _Eet_Data_Chunk
{
   char          *name;
   int            len;
   int            size;
   int            hash;
   void          *data;
   unsigned char  type;
   unsigned char  group_type;
};

struct _Eet_Data_Stream
{
   void *data;
   int   size;
   int   pos;
};

struct _Eet_Data_Descriptor_Hash
{
   Eet_Data_Element         *element;
   Eet_Data_Descriptor_Hash *next;
};

struct _Eet_Data_Descriptor
{
   const char           *name;
   const Eet_Dictionary *ed;
   int                   size;
   struct {
      void *(*mem_alloc) (size_t size);
      void  (*mem_free) (void *mem);
      char *(*str_alloc) (const char *str);
      char *(*str_direct_alloc) (const char *str);
      void  (*str_free) (const char *str);
      void  (*str_direct_free) (const char *str);
      void *(*list_next) (void *l);
      void *(*list_append) (void *l, void *d);
      void *(*list_data) (void *l);
      void *(*list_free) (void *l);
      void  (*hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt);
      void *(*hash_add) (void *h, const char *k, void *d);
      void  (*hash_free) (void *h);
   } func;
   struct {
      int                num;
      Eet_Data_Element  *set;
      struct {
	 int                             size;
	 Eet_Data_Descriptor_Hash       *buckets;
      } hash;
   } elements;
//   char *strings;
//   int   strings_len;
};

struct _Eet_Data_Element
{
   const char          *name;
   const char          *counter_name;
   const char          *directory_name_ptr;
   Eet_Data_Descriptor *subtype;
   int                  offset;         /* offset in bytes from the base element */
   int                  count;          /* number of elements for a fixed array */
   int                  counter_offset; /* for a variable array we need the offset of the count variable */
   unsigned char        type;           /* EET_T_XXX */
   unsigned char        group_type;     /* EET_G_XXX */
};

struct _Eet_Data_Encode_Hash_Info
{
  Eet_Data_Stream       *ds;
  Eet_Data_Element      *ede;
  Eet_Dictionary        *ed;
};

struct _Eet_Free
{
  int     ref;
  int     len[256];
  int     num[256];
  void  **list[256];
};

struct _Eet_Free_Context
{
   Eet_Free freelist;
   Eet_Free freelist_list;
   Eet_Free freelist_hash;
   Eet_Free freelist_str;
   Eet_Free freelist_direct_str;
};

/*---*/

static int   eet_data_get_char(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_char(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_short(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_short(Eet_Dictionary *ed, const void *src, int *size_ret);
static inline int   eet_data_get_int(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_int(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_long_long(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_long_long(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_f32p32(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_f32p32(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_f16p16(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_f16p16(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_f8p24(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_f8p24(Eet_Dictionary *ed, const void *src, int *size_ret);
static inline int   eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_string(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_istring(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_istring(Eet_Dictionary *ed, const void *src, int *size_ret);
static int   eet_data_get_null(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dest);
static void *eet_data_put_null(Eet_Dictionary *ed, const void *src, int *size_ret);

static int   eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest);
static void *eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret);

static void eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, int group_type, const char *name);
static void eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
static void eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
static void eet_data_dump_simple_type(int type, const char *name, void *dd,
				      int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);


static int  eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
static void eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
static void eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
static int  eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
static int  eet_data_get_list(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
static void eet_data_put_list(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
static void eet_data_put_hash(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
static int  eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);

static void            eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk, const void *src, int size);
static Eet_Data_Chunk *eet_data_chunk_new(void *data, int size, const char *name, int type, int group_type);
static void            eet_data_chunk_free(Eet_Data_Chunk *chnk);

static Eet_Data_Stream *eet_data_stream_new(void);
static void             eet_data_stream_write(Eet_Data_Stream *ds, const void *data, int size);
static void             eet_data_stream_free(Eet_Data_Stream *ds);

static void             eet_data_chunk_put(Eet_Dictionary *ed, Eet_Data_Chunk *chnk, Eet_Data_Stream *ds);

static int       eet_data_descriptor_encode_hash_cb(void *hash, const char *key, void *hdata, void *fdata);
static void     *_eet_data_descriptor_encode(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, const void *data_in, int *size_ret);
static void     *_eet_data_descriptor_decode(Eet_Free_Context *context,
					     const Eet_Dictionary *ed,
                                             Eet_Data_Descriptor *edd,
                                             const void *data_in,
                                             int size_in,
                                             int level,
                                             void (*dumpfunc) (void *data, const char *str),
                                             void *dumpdata);

/*---*/

static const Eet_Data_Basic_Type_Codec eet_basic_codec[] =
{
     {sizeof(char),      "char",       eet_data_get_char,      eet_data_put_char     },
     {sizeof(short),     "short",      eet_data_get_short,     eet_data_put_short    },
     {sizeof(int),       "int",        eet_data_get_int,       eet_data_put_int      },
     {sizeof(long long), "long_long",  eet_data_get_long_long, eet_data_put_long_long},
     {sizeof(float),     "float",      eet_data_get_float,     eet_data_put_float    },
     {sizeof(double),    "double",     eet_data_get_double,    eet_data_put_double   },
     {sizeof(char),      "uchar",      eet_data_get_char,      eet_data_put_char     },
     {sizeof(short),     "ushort",     eet_data_get_short,     eet_data_put_short    },
     {sizeof(int),       "uint",       eet_data_get_int,       eet_data_put_int      },
     {sizeof(long long), "ulong_long", eet_data_get_long_long, eet_data_put_long_long},
     {sizeof(char *),    "string",     eet_data_get_string,    eet_data_put_string   },
     {sizeof(char *),    "inlined",    eet_data_get_istring,   eet_data_put_istring  },
     {sizeof(void *),    "NULL",       eet_data_get_null,      eet_data_put_null     },
     {sizeof(Eina_F32p32),"f32p32",    eet_data_get_f32p32,    eet_data_put_f32p32   },
     {sizeof(Eina_F16p16),"f16p16",    eet_data_get_f16p16,    eet_data_put_f16p16   },
     {sizeof(Eina_F8p24),"f8p24",      eet_data_get_f8p24,     eet_data_put_f8p24    }
};

static const Eet_Data_Group_Type_Codec eet_group_codec[] =
{
     { eet_data_get_unknown,  eet_data_put_unknown },
     { eet_data_get_array,    eet_data_put_array },
     { eet_data_get_array,    eet_data_put_array },
     { eet_data_get_list,     eet_data_put_list },
     { eet_data_get_hash,     eet_data_put_hash }
};

static int words_bigendian = -1;

/*---*/

#define SWAP64(x) (x) = \
   ((((unsigned long long)(x) & 0x00000000000000ffULL ) << 56) |\
       (((unsigned long long)(x) & 0x000000000000ff00ULL ) << 40) |\
       (((unsigned long long)(x) & 0x0000000000ff0000ULL ) << 24) |\
       (((unsigned long long)(x) & 0x00000000ff000000ULL ) << 8) |\
       (((unsigned long long)(x) & 0x000000ff00000000ULL ) >> 8) |\
       (((unsigned long long)(x) & 0x0000ff0000000000ULL ) >> 24) |\
       (((unsigned long long)(x) & 0x00ff000000000000ULL ) >> 40) |\
       (((unsigned long long)(x) & 0xff00000000000000ULL ) >> 56))
#define SWAP32(x) (x) = \
   ((((int)(x) & 0x000000ff ) << 24) |\
       (((int)(x) & 0x0000ff00 ) << 8) |\
       (((int)(x) & 0x00ff0000 ) >> 8) |\
       (((int)(x) & 0xff000000 ) >> 24))
#define SWAP16(x) (x) = \
   ((((short)(x) & 0x00ff ) << 8) |\
       (((short)(x) & 0xff00 ) >> 8))

#define CONV8(x)
#define CONV16(x) {if (words_bigendian) SWAP16(x);}
#define CONV32(x) {if (words_bigendian) SWAP32(x);}
#define CONV64(x) {if (words_bigendian) SWAP64(x);}

#define IS_SIMPLE_TYPE(Type)    (Type > EET_T_UNKNOW && Type < EET_T_LAST)

/*---*/

/* CHAR TYPE */
static int
eet_data_get_char(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
{
   char *s, *d;

   if (((char *)src + sizeof(char)) > (char *)src_end) return -1;
   s = (char *)src;
   d = (char *)dst;
   *d = *s;
   CONV8(*d);
   return sizeof(char);
}

static void *
eet_data_put_char(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
{
   char *s, *d;

   d = (char *)malloc(sizeof(char));
   if (!d) return NULL;
   s = (char *)src;
   *d = *s;
   CONV8(*d);
   *size_ret = sizeof(char);
   return d;
}

/* SHORT TYPE */
static int
eet_data_get_short(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
{
   short *d;

   if (((char *)src + sizeof(short)) > (char *)src_end) return -1;
   memcpy(dst, src, sizeof(short));
   d = (short *)dst;
   CONV16(*d);
   return sizeof(short);
}

static void *
eet_data_put_short(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
{
   short *s, *d;

   d = (short *)malloc(sizeof(short));
   if (!d) return NULL;
   s = (short *)src;
   *d = *s;
   CONV16(*d);
   *size_ret = sizeof(short);
   return d;
}

/* INT TYPE */
static inline int
eet_data_get_int(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
{
   int *d;

   if (((char *)src + sizeof(int)) > (char *)src_end) return -1;
   memcpy(dst, src, sizeof(int));
   d = (int *)dst;
   CONV32(*d);
   return sizeof(int);
}

static void *
eet_data_put_int(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
{
   int *s, *d;

   d = (int *)malloc(sizeof(int));
   if (!d) return NULL;
   s = (int *)src;
   *d = *s;
   CONV32(*d);
   *size_ret = sizeof(int);
   return d;
}

/* LONG LONG TYPE */
static int
eet_data_get_long_long(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
{
   unsigned long long *d;

   if (((char *)src + sizeof(unsigned long long)) > (char *)src_end) return -1;
   memcpy(dst, src, sizeof(unsigned long long));
   d = (unsigned long long *)dst;
   CONV64(*d);
   return sizeof(unsigned long long);
}

static void *
eet_data_put_long_long(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
{
   unsigned long long *s, *d;

   d = (unsigned long long *)malloc(sizeof(unsigned long long));
   if (!d) return NULL;
   s = (unsigned long long *)src;
   *d = *s;
   CONV64(*d);
   *size_ret = sizeof(unsigned long long);
   return d;
}

/* STRING TYPE */
static inline int
eet_data_get_string_hash(const Eet_Dictionary *ed, const void *src, const void *src_end)
{
   if (ed)
     {
        int               index;

        if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;

        return eet_dictionary_string_get_hash(ed, index);
     }

   return -1;
}

static inline int
eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   char *s, **d;

   d = (char **)dst;

   if (ed)
     {
        const char       *str;
        int               index;

        if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;

        str = eet_dictionary_string_get_char(ed, index);
        if (str == NULL)
          return -1;

        *d = (char *) str;
        return eet_dictionary_string_get_size(ed, index);
     }

   s = (char *)src;
   if (s == NULL)
     {
        *d = NULL;
        return 0;
     }

   *d = s;
   return strlen(s) + 1;
}

static void *
eet_data_put_string(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   char *s, *d;
   int len;

   if (ed)
     {
        const char      *str;
        int              index;

        str = *((const char **) src);
        if (!str) return NULL;

        index = eet_dictionary_string_add(ed, str);
        if (index == -1) return NULL;

        return eet_data_put_int(ed, &index, size_ret);
     }

   s = (char *)(*((char **)src));
   if (!s) return NULL;
   len = strlen(s);
   d = malloc(len + 1);
   if (!d) return NULL;
   memcpy(d, s, len + 1);
   *size_ret = len + 1;
   return d;
}

/* ALWAYS INLINED STRING TYPE */
static int
eet_data_get_istring(const Eet_Dictionary *ed __UNUSED__, const void *src, const void *src_end, void *dst)
{
   return eet_data_get_string(NULL, src, src_end, dst);
}

static void *
eet_data_put_istring(Eet_Dictionary *ed __UNUSED__, const void *src, int *size_ret)
{
   return eet_data_put_string(NULL, src, size_ret);
}

/* ALWAYS NULL TYPE */
static int
eet_data_get_null(const Eet_Dictionary *ed __UNUSED__, const void *src __UNUSED__, const void *src_end __UNUSED__, void *dst)
{
   char **d;

   d = (char**) dst;

   *d = NULL;
   return 0;
}

static void *
eet_data_put_null(Eet_Dictionary *ed __UNUSED__, const void *src __UNUSED__, int *size_ret)
{
   *size_ret = 0;
   return NULL;
}

/**
 * Fast lookups of simple doubles/floats.
 *
 * These aren't properly a cache because they don't store pre-calculated
 * values, but have a so simple math that is almost as fast.
 */
static inline int
_eet_data_float_cache_get(const char *s, int len, float *d)
{
   /* fast handle of simple case 0xMp+E*/
   if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
     {
	int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
	int exponent = (s[5] - '0');

	if (s[4] == '+') *d = (float)(mantisse << exponent);
	else             *d = (float)mantisse / (float)(1 << exponent);

	return 1;
     }
   return 0;
}

static inline int
_eet_data_double_cache_get(const char *s, int len, double *d)
{
   /* fast handle of simple case 0xMp+E*/
   if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
     {
	int mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
	int exponent = (s[5] - '0');

	if (s[4] == '+') *d = (double)(mantisse << exponent);
	else             *d = (double)mantisse / (double)(1 << exponent);

	return 1;
     }
   return 0;
}

/* FLOAT TYPE */
static int
eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   float        *d;
   int           index;

   d = (float *) dst;
   if (!ed)
     {
        const char   *s, *p;
        long long     mantisse;
        long          exponent;
        int           len;

        s = (const char *)src;
        p = s;
        len = 0;
        while ((p < (const char *)src_end) && (*p != 0)) {len++; p++;}

        if (_eet_data_float_cache_get(s, len, d) != 0) return len + 1;

	if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
        *d = (float)ldexp((double)mantisse, exponent);

        return len + 1;
     }

   if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;

   if (!eet_dictionary_string_get_float(ed, index, d))
     return -1;
   return 1;
}

static void *
eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   char  buf[128];
   int   index;

   eina_convert_dtoa((double)(*(float *)src), buf);

   if (!ed)
     {
        char    *d;
        int      len;

        len = strlen(buf);
        d = malloc(len + 1);
        if (!d) return NULL;
	memcpy(d, buf, len + 1);
        *size_ret = len + 1;
        return d;
     }

   index = eet_dictionary_string_add(ed, buf);
   if (index == -1) return NULL;

   return eet_data_put_int(ed, &index, size_ret);
}

/* DOUBLE TYPE */
static int
eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   double       *d;
   int           index;

   d = (double *) dst;

   if (!ed)
     {
        const char     *s, *p;
        long long       mantisse = 0;
        long            exponent = 0;
        int             len;

        s = (const char *) src;
        p = s;
        len = 0;
        while ((p < (const char *)src_end) && (*p != 0)) {len++; p++;}

        if (_eet_data_double_cache_get(s, len, d) != 0) return len + 1;

	if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
        *d = ldexp((double) mantisse, exponent);

        return len + 1;
     }

   if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;

   if (!eet_dictionary_string_get_double(ed, index, d))
     return -1;
   return 1;
}

static void *
eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   char  buf[128];
   int   index;

   eina_convert_dtoa((double)(*(double *)src), buf);

   if (!ed)
     {
        char   *d;
        int     len;

        len = strlen(buf);
        d = malloc(len + 1);
        if (!d) return NULL;
	memcpy(d, buf, len + 1);
        *size_ret = len + 1;

        return d;
     }

   index = eet_dictionary_string_add(ed, buf);
   if (index == -1) return NULL;

   return eet_data_put_int(ed, &index, size_ret);
}

static int
eet_data_get_f32p32(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   Eina_F32p32 *fp;
   int index;

   fp = (Eina_F32p32*) dst;

   if (!ed) return -1;

   if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;

   if (!eet_dictionary_string_get_fp(ed, index, fp))
     return -1;
   return 1;
}

static void *
eet_data_put_f32p32(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   char  buf[128];
   int   index;

   if (!ed) return NULL;

   eina_convert_fptoa((Eina_F32p32)(*(Eina_F32p32 *)src), buf);

   index = eet_dictionary_string_add(ed, buf);
   if (index == -1) return NULL;

   return eet_data_put_int(ed, &index, size_ret);
}

static int
eet_data_get_f16p16(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   Eina_F32p32 tmp;
   Eina_F16p16 *fp;

   fp = (Eina_F16p16*) dst;

   if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0) return -1;

   *fp = eina_f32p32_to_f16p16(tmp);
   return 1;
}

static void *
eet_data_put_f16p16(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   Eina_F32p32 tmp;

   tmp = eina_f16p16_to_f32p32((Eina_F16p16)(*(Eina_F16p16 *)src));
   return eet_data_put_f32p32(ed, &tmp, size_ret);
}

static int
eet_data_get_f8p24(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
   Eina_F32p32 tmp;
   Eina_F8p24 *fp;

   fp = (Eina_F8p24*) dst;

   if (eet_data_get_f32p32(ed, src, src_end, &tmp) < 0) return -1;

   *fp = eina_f32p32_to_f8p24(tmp);
   return 1;
}

static void *
eet_data_put_f8p24(Eet_Dictionary *ed, const void *src, int *size_ret)
{
   Eina_F32p32 tmp;

   tmp = eina_f8p24_to_f32p32((Eina_F8p24)(*(Eina_F8p24 *)src));
   return eet_data_put_f32p32(ed, &tmp, size_ret);
}

static inline int
eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest)
{
   int ret;

   ret = eet_basic_codec[type - 1].get(ed, src, src_end, dest);
   return ret;
}

static inline void *
eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret)
{
   void *ret;

   ret = eet_basic_codec[type - 1].put(ed, src, size_ret);
   return ret;
}

static inline Eina_Bool
eet_data_type_match(int type1, int type2)
{
   if (type1 == type2) return EINA_TRUE;

   /* Note: All floating point type are equivalent and could be read
      without problem by any other floating point getter. */
   switch (type1)
     {
      case EET_T_FLOAT:
      case EET_T_DOUBLE:
      case EET_T_F32P32:
      case EET_T_F16P16:
      case EET_T_F8P24:
	 switch (type2)
	   {
	    case EET_T_FLOAT:
	    case EET_T_DOUBLE:
	    case EET_T_F32P32:
	    case EET_T_F16P16:
	    case EET_T_F8P24:
	       return EINA_TRUE;
	    default:
	       break;
	   }
	 break;
      default:
	 break;
     }

   return EINA_FALSE;
}

/* chunk format...
 *
 * char[4] = "CHnK"; // untyped data ... or
 * char[4] = "CHKx"; // typed data - x == type
 *
 * int     = chunk size (including magic string);
 * char[]  = chunk magic/name string (0 byte terminated);
 * ... sub-chunks (a chunk can contain chuncks recusrively) ...
 * or
 * ... payload data ...
 *
 */

static inline void
eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk,
		   const void *src, int size)
{
   const char *s;
   int ret1, ret2;

   if (!src) return;
   if (size <= 8) return;

   if (!chnk) return;

   s = src;
   if (s[2] == 'K')
     {
	if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K'))
	  return;

	chnk->type = (unsigned char)(s[3]);
	if (chnk->type > EET_T_LAST)
	  {
	     chnk->group_type = chnk->type;
	     chnk->type = EET_T_UNKNOW;
	  }
	else
	  chnk->group_type = EET_G_UNKNOWN;
	if ((chnk->type >= EET_T_LAST) ||
	    (chnk->group_type >= EET_G_LAST))
	  {
	     chnk->type = 0;
	     chnk->group_type = 0;
	  }
     }
   else
     {
	if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
	  return;
     }
   ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size));
   if (ret1 <= 0) return;
   if ((chnk->size < 0) || ((chnk->size + 8) > size)) return;
   ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name));
   if (ret2 <= 0) return;

   chnk->len = ret2;

   /* Precalc hash */
   chnk->hash = eet_data_get_string_hash(ed, (s + 8), (s + size));

   if (ed)
     {
        chnk->data = (char *)src + 4 + ret1 + sizeof(int);
        chnk->size -= sizeof(int);
     }
   else
     {
        chnk->data = (char *)src + 4 + ret1 + chnk->len;
        chnk->size -= chnk->len;
     }

   return;
}

static inline Eet_Data_Chunk *
eet_data_chunk_new(void *data, int size, const char *name, int type, int group_type)
{
   Eet_Data_Chunk *chnk;

   if (!name) return NULL;
   chnk = calloc(1, sizeof(Eet_Data_Chunk));
   if (!chnk) return NULL;

   /* Note: Another security, so older eet library could read file
    saved with fixed point value. */
   if (type == EET_T_F32P32
       || type == EET_T_F16P16
       || type == EET_T_F8P24)
     type = EET_T_DOUBLE;

   chnk->name = strdup(name);
   chnk->len = strlen(name) + 1;
   chnk->size = size;
   chnk->data = data;
   chnk->type = type;
   chnk->group_type = group_type;
   return chnk;
}

static inline void
eet_data_chunk_free(Eet_Data_Chunk *chnk)
{
   if (chnk->name) free(chnk->name);
   free(chnk);
}

static inline Eet_Data_Stream *
eet_data_stream_new(void)
{
   Eet_Data_Stream *ds;

   ds = calloc(1, sizeof(Eet_Data_Stream));
   if (!ds) return NULL;
   return ds;
}

static inline void
eet_data_stream_free(Eet_Data_Stream *ds)
{
   if (ds->data) free(ds->data);
   free(ds);
}

static inline void
eet_data_stream_write(Eet_Data_Stream *ds, const void *data, int size)
{
   char *p;

   if ((ds->pos + size) > ds->size)
     {
	ds->data = realloc(ds->data, ds->size + size + 512);
	if (!ds->data)
	  {
	     ds->pos = 0;
	     ds->size = 0;
	     return;
	  }
	ds->size = ds->size + size + 512;
     }
   p = ds->data;
   memcpy(p + ds->pos, data, size);
   ds->pos += size;
}

static void
eet_data_chunk_put(Eet_Dictionary *ed, Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
{
   int  *size;
   void *string;
   int   s;
   int   size_ret = 0;
   int   string_ret = 0;
   unsigned char buf[4] = "CHK";

   /* disable this check - it will allow empty chunks to be written. this is
    * right for corner-cases when y have a struct with empty fields (empty
    * strings or empty list ptrs etc.) */
   /* if (!chnk->data && chnk->type != EET_T_NULL) return; */
   /* chunk head */

/*   eet_data_stream_write(ds, "CHnK", 4);*/
   if (chnk->type != EET_T_UNKNOW) buf[3] = chnk->type;
   else buf[3] = chnk->group_type;

   string = eet_data_put_string(ed, &chnk->name, &string_ret);
   if (!string)
     return ;

   /* size of chunk payload data + name */
   s = chnk->size + string_ret;
   size = eet_data_put_int(ed, &s, &size_ret);

   /* FIXME: If something goes wrong the resulting file will be corrupted. */
   if (!size)
     goto on_error;

   eet_data_stream_write(ds, buf, 4);

   /* write chunk length */
   eet_data_stream_write(ds, size, size_ret);

   /* write chunk name */
   eet_data_stream_write(ds, string, string_ret);

   /* write payload */
   if (chnk->data)
     eet_data_stream_write(ds, chnk->data, chnk->size);

   free(string);
 on_error:
   free(size);
}

/*---*/

static void
_eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
{
   int i;

   edd->elements.hash.size = 1 << 6;
   edd->elements.hash.buckets = calloc(1, sizeof(Eet_Data_Descriptor_Hash) * edd->elements.hash.size);
   for (i = 0; i < edd->elements.num; i++)
     {
	Eet_Data_Element *ede;
	int hash;

	ede = &(edd->elements.set[i]);
	hash = _eet_hash_gen((char *) ede->name, 6);
	if (!edd->elements.hash.buckets[hash].element)
	  edd->elements.hash.buckets[hash].element = ede;
	else
	  {
	     Eet_Data_Descriptor_Hash *bucket;

	     bucket = calloc(1, sizeof(Eet_Data_Descriptor_Hash));
	     bucket->element = ede;
	     bucket->next = edd->elements.hash.buckets[hash].next;
	     edd->elements.hash.buckets[hash].next = bucket;
	  }
     }
}

static void
_eet_descriptor_hash_free(Eet_Data_Descriptor *edd)
{
   int i;

   for (i = 0; i < edd->elements.hash.size; i++)
     {
	Eet_Data_Descriptor_Hash *bucket, *pbucket;

	bucket = edd->elements.hash.buckets[i].next;
	while (bucket)
	  {
	     pbucket = bucket;
	     bucket = bucket->next;
	     free(pbucket);
	  }
     }
   if (edd->elements.hash.buckets) free(edd->elements.hash.buckets);
}

static Eet_Data_Element *
_eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name, int hash)
{
   Eet_Data_Descriptor_Hash *bucket;

   if (hash < 0) hash = _eet_hash_gen(name, 6);
   else hash &= 0x3f;
   if (!edd->elements.hash.buckets[hash].element) return NULL;
   /*
     When we use the dictionnary as a source for chunk name, we will always
     have the same pointer in name. It's a good idea to just compare pointer
     instead of running strcmp on both string.
   */
   if (edd->elements.hash.buckets[hash].element->directory_name_ptr == name)
     return edd->elements.hash.buckets[hash].element;
   if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
     {
	edd->elements.hash.buckets[hash].element->directory_name_ptr = name;
	return edd->elements.hash.buckets[hash].element;
     }
   bucket = edd->elements.hash.buckets[hash].next;
   while (bucket)
     {
	if (bucket->element->directory_name_ptr == name) return bucket->element;
	if (!strcmp(bucket->element->name, name))
	  {
	     bucket->element->directory_name_ptr = name;
	     return bucket->element;
	  }
	bucket = bucket->next;
     }
   return NULL;
}

static void *
_eet_mem_alloc(size_t size)
{
   return calloc(1, size);
}

static void
_eet_mem_free(void *mem)
{
   free(mem);
}

static char *
_eet_str_alloc(const char *str)
{
   return strdup(str);
}

static void
_eet_str_free(const char *str)
{
   free((char *)str);
}

static Eina_Hash *
_eet_eina_hash_add_alloc(Eina_Hash *hash, const char *key, void *data)
{
   if (!hash) hash = eina_hash_string_small_new(NULL);
   if (!hash) return NULL;

   eina_hash_add(hash, key, data);
   return hash;
}

static char *
_eet_str_direct_alloc(const char *str)
{
   return (char *)str;
}

static void
_eet_str_direct_free(const char *str)
{
}

/*---*/
EAPI Eina_Bool
eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size)
{
   if (!eddc || !name) return EINA_FALSE;

   eddc->name = name;
   eddc->size = size;
   eddc->version = 1;

   eddc->func.mem_alloc = _eet_mem_alloc;
   eddc->func.mem_free = _eet_mem_free;
   eddc->func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
   eddc->func.str_free = eina_stringshare_del;
   eddc->func.list_next = (void *(*)(void *))eina_list_next;
   eddc->func.list_append = (void *(*)(void *, void *))eina_list_append;
   eddc->func.list_data = (void *(*)(void *))eina_list_data_get;
   eddc->func.list_free = (void *(*)(void *))eina_list_free;
   eddc->func.hash_foreach = (void (*)(void *, int (*)(void *, const char *, void *, void *), void *))eina_hash_foreach;
   eddc->func.hash_add = (void* (*)(void *, const char *, void *)) _eet_eina_hash_add_alloc;
   eddc->func.hash_free = (void (*)(void *))eina_hash_free;

   return EINA_TRUE;
}

EAPI Eina_Bool
eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc, const char *name, int size)
{
   if (!eet_eina_stream_data_descriptor_class_set(eddc, name, size))
     return EINA_FALSE;

   eddc->version = 2;

   eddc->func.str_direct_alloc = _eet_str_direct_alloc;
   eddc->func.str_direct_free = _eet_str_direct_free;

   return EINA_TRUE;
}

static Eet_Data_Descriptor *
_eet_data_descriptor_new(const Eet_Data_Descriptor_Class *eddc, int version)
{
   Eet_Data_Descriptor *edd;

   if (!eddc) return NULL;
   if (eddc->version < version) return NULL;

   edd = calloc(1, sizeof (Eet_Data_Descriptor));
   if (!edd) return NULL;

   edd->name = eddc->name;
   edd->ed = NULL;
   edd->size = eddc->size;
   edd->func.mem_alloc = _eet_mem_alloc;
   edd->func.mem_free = _eet_mem_free;
   edd->func.str_alloc = _eet_str_alloc;
   edd->func.str_free = _eet_str_free;
   if (eddc->func.mem_alloc)
     edd->func.mem_alloc = eddc->func.mem_alloc;
   if (eddc->func.mem_free)
     edd->func.mem_free = eddc->func.mem_free;
   if (eddc->func.str_alloc)
     edd->func.str_alloc = eddc->func.str_alloc;
   if (eddc->func.str_free)
     edd->func.str_free = eddc->func.str_free;
   edd->func.list_next = eddc->func.list_next;
   edd->func.list_append = eddc->func.list_append;
   edd->func.list_data = eddc->func.list_data;
   edd->func.list_free = eddc->func.list_free;
   edd->func.hash_foreach = eddc->func.hash_foreach;
   edd->func.hash_add = eddc->func.hash_add;
   edd->func.hash_free = eddc->func.hash_free;

   if (version > 1)
     {
	edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
	edd->func.str_direct_free = eddc->func.str_direct_free;
     }

   return edd;
}

EAPI Eet_Data_Descriptor *
eet_data_descriptor_new(const char *name,
			int size,
			void *(*func_list_next) (void *l),
			void *(*func_list_append) (void *l, void *d),
			void *(*func_list_data) (void *l),
			void *(*func_list_free) (void *l),
			void  (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt),
			void *(*func_hash_add) (void *h, const char *k, void *d),
			void  (*func_hash_free) (void *h))
{
   Eet_Data_Descriptor_Class eddc;

   if (!name) return NULL;

   memset(&eddc, 0, sizeof (Eet_Data_Descriptor_Class));

   eddc.name = name;
   eddc.size = size;
   eddc.version = 0;

   eddc.func.list_next = func_list_next;
   eddc.func.list_append = func_list_append;
   eddc.func.list_data = func_list_data;
   eddc.func.list_free = func_list_free;
   eddc.func.hash_foreach = func_hash_foreach;
   eddc.func.hash_add = func_hash_add;
   eddc.func.hash_free = func_hash_free;

   return _eet_data_descriptor_new(&eddc, 0);
}

EAPI Eet_Data_Descriptor *
eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc)
{
   return _eet_data_descriptor_new(eddc, 1);
}

EAPI Eet_Data_Descriptor *
eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc)
{
   return _eet_data_descriptor_new(eddc, 2);
}

EAPI Eet_Data_Descriptor *
eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
{
   return _eet_data_descriptor_new(eddc, 1);
}

EAPI Eet_Data_Descriptor *
eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc)
{
   return _eet_data_descriptor_new(eddc, 2);
}

EAPI void
eet_data_descriptor_free(Eet_Data_Descriptor *edd)
{
   _eet_descriptor_hash_free(edd);
   if (edd->elements.set) free(edd->elements.set);
   free(edd);
}

EAPI void
eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
				const char *name,
				int type,
				int group_type,
				int offset,
				int count,
/* 				int counter_offset, */
				const char *counter_name /* Useless should go on a major release */,
				Eet_Data_Descriptor *subtype)
{
   Eet_Data_Element *ede;
   /* int l1, l2, p1, p2, i;
   char *ps;*/

   /* FIXME: Fail safely when realloc fail. */
   edd->elements.num++;
   edd->elements.set = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
   if (!edd->elements.set) return;
   ede = &(edd->elements.set[edd->elements.num - 1]);
   ede->name = name;
   ede->directory_name_ptr = NULL;

   /*
    * We do a special case when we do list,hash or whatever group of simple type.
    * Instead of handling it in encode/decode/dump/undump, we create an
    * implicit structure with only the simple type.
    */
   if (group_type > EET_G_UNKNOWN
       && group_type < EET_G_LAST
       && type > EET_T_UNKNOW && type < EET_T_STRING
       && subtype == NULL)
     {
	subtype = calloc(1, sizeof (Eet_Data_Descriptor));
	if (!subtype) return ;
	subtype->name = "implicit";
	subtype->size = eet_basic_codec[type - 1].size;
	memcpy(&subtype->func, &edd->func, sizeof(subtype->func));

	eet_data_descriptor_element_add(subtype, eet_basic_codec[type - 1].name, type,
					EET_G_UNKNOWN, 0, 0, /* 0,  */NULL, NULL);
	type = EET_T_UNKNOW;
     }

   ede->type = type;
   ede->group_type = group_type;
   ede->offset = offset;
   ede->count = count;
   /* FIXME: For the time being, EET_G_VAR_ARRAY will put the counter_offset in count. */
   ede->counter_offset = count;
/*    ede->counter_offset = counter_offset; */
   ede->counter_name = counter_name;

   ede->subtype = subtype;
}

EAPI void *
eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key)
{
   const Eet_Dictionary *ed = NULL;
   const void           *data = NULL;
   void                 *data_dec;
   Eet_Free_Context      context;
   int                   required_free = 0;
   int                   size;

   ed = eet_dictionary_get(ef);

   if (!key)
     data = eet_read_direct(ef, name, &size);
   if (!data)
     {
	required_free = 1;
	data = eet_read_cipher(ef, name, &size, key);
	if (!data) return NULL;
     }

   memset(&context, 0, sizeof (context));
   data_dec = _eet_data_descriptor_decode(&context, ed, edd, data, size, 0, NULL, NULL);
   if (required_free)
     free((void*)data);

   return data_dec;
}

EAPI void *
eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name)
{
   return eet_data_read_cipher(ef, edd, name, NULL);
}

EAPI int
eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key, const void *data, int compress)
{
   Eet_Dictionary       *ed;
   void                 *data_enc;
   int                   size;
   int                   val;

   ed = eet_dictionary_get(ef);

   data_enc = _eet_data_descriptor_encode(ed, edd, data, &size);
   if (!data_enc) return 0;
   val = eet_write_cipher(ef, name, data_enc, size, compress, key);
   free(data_enc);
   return val;
}

EAPI int
eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress)
{
   return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
}

static int
_eet_free_hash(void *data)
{
   unsigned long ptr = (unsigned long)(data);
   int hash;

   hash = ptr;
   hash ^= ptr >> 8;
   hash ^= ptr >> 16;
   hash ^= ptr >> 24;

#if LONG_BIT != 32
   hash ^= ptr >> 32;
   hash ^= ptr >> 40;
   hash ^= ptr >> 48;
   hash ^= ptr >> 56;
#endif

   return hash & 0xFF;
}

static void
_eet_free_add(Eet_Free *ef, void *data)
{
   int hash;
   int i;

   hash = _eet_free_hash(data);

   for (i = 0; i < ef->num[hash]; ++i)
     if (ef->list[hash][i] == data) return;

   ef->num[hash]++;
   if (ef->num[hash] > ef->len[hash])
     {
        void    **tmp;

        tmp = realloc(ef->list[hash], (ef->len[hash] + 16) * sizeof(void*));
        if (!tmp) return ;

        ef->len[hash] += 16;
        ef->list[hash] = tmp;
     }
   ef->list[hash][ef->num[hash] - 1] = data;
}
static void
_eet_free_reset(Eet_Free *ef)
{
   int i;

   if (ef->ref > 0) return ;
   for (i = 0; i < 256; ++i)
     {
	ef->len[i] = 0;
	ef->num[i] = 0;
	if (ef->list[i]) free(ef->list[i]);
	ef->list[i] = NULL;
     }
}
static void
_eet_free_ref(Eet_Free *ef)
{
   ef->ref++;
}
static void
_eet_free_unref(Eet_Free *ef)
{
   ef->ref--;
}

#define _eet_freelist_add(Ctx, Data)	_eet_free_add(&Ctx->freelist, Data);
#define _eet_freelist_reset(Ctx)	_eet_free_reset(&Ctx->freelist);
#define _eet_freelist_ref(Ctx)		_eet_free_ref(&Ctx->freelist);
#define _eet_freelist_unref(Ctx)	_eet_free_unref(&Ctx->freelist);

static void
_eet_freelist_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
{
   int j;
   int i;

   if (context->freelist.ref > 0) return;
   for (j = 0; j < 256; ++j)
     for (i = 0; i < context->freelist.num[j]; ++i)
       {
	  if (edd)
	    edd->func.mem_free(context->freelist.list[j][i]);
	  else
	    free(context->freelist.list[j][i]);
       }
   _eet_free_reset(&context->freelist);
}

#define _eet_freelist_list_add(Ctx, Data)  _eet_free_add(&Ctx->freelist_list, Data);
#define _eet_freelist_list_reset(Ctx)      _eet_free_reset(&Ctx->freelist_list);
#define _eet_freelist_list_ref(Ctx)        _eet_free_ref(&Ctx->freelist_list);
#define _eet_freelist_list_unref(Ctx)      _eet_free_unref(&Ctx->freelist_list);

static void
_eet_freelist_list_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
{
   int j;
   int i;

   if (context->freelist_list.ref > 0) return;
   for (j = 0; j < 256; ++j)
     for (i = 0; i < context->freelist_list.num[j]; ++i)
       {
	  if (edd)
	    edd->func.list_free(*((void**)(context->freelist_list.list[j][i])));
       }
   _eet_free_reset(&context->freelist_list);
}

#define _eet_freelist_str_add(Ctx, Data)   _eet_free_add(&Ctx->freelist_str, Data);
#define _eet_freelist_str_reset(Ctx)       _eet_free_reset(&Ctx->freelist_str);
#define _eet_freelist_str_ref(Ctx)         _eet_free_ref(&Ctx->freelist_str);
#define _eet_freelist_str_unref(Ctx)       _eet_free_unref(&Ctx->freelist_str);

static void
_eet_freelist_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
{
   int j;
   int i;

   if (context->freelist_str.ref > 0) return;
   for (j = 0; j < 256; ++j)
     for (i = 0; i < context->freelist_str.num[j]; ++i)
       {
	  if (edd)
	    edd->func.str_free(context->freelist_str.list[j][i]);
	  else
	    free(context->freelist_str.list[j][i]);
       }
   _eet_free_reset(&context->freelist_str);
}

#define _eet_freelist_direct_str_add(Ctx, Data)    _eet_free_add(&Ctx->freelist_direct_str, Data);
#define _eet_freelist_direct_str_reset(Ctx)        _eet_free_reset(&Ctx->freelist_direct_str);
#define _eet_freelist_direct_str_ref(Ctx)          _eet_free_ref(&Ctx->freelist_direct_str);
#define _eet_freelist_direct_str_unref(Ctx)        _eet_free_unref(&Ctx->freelist_direct_str);

static void
_eet_freelist_direct_str_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
{
   int j;
   int i;

   if (context->freelist_direct_str.ref > 0) return;
   for (j = 0; j < 256; ++j)
     for (i = 0; i < context->freelist_direct_str.num[j]; ++i)
       {
	  if (edd)
	    edd->func.str_direct_free(context->freelist_direct_str.list[j][i]);
	  else
	    free(context->freelist_direct_str.list[j][i]);
       }
   _eet_free_reset(&context->freelist_direct_str);
}

#define _eet_freelist_hash_add(Ctx, Data) _eet_free_add(&Ctx->freelist_hash, Data);
#define _eet_freelist_hash_reset(Ctx)     _eet_free_reset(&Ctx->freelist_hash);
#define _eet_freelist_hash_ref(Ctx)	  _eet_free_ref(&Ctx->freelist_hash);
#define _eet_freelist_hash_unref(Ctx)	  _eet_free_unref(&Ctx->freelist_hash);

static void
_eet_freelist_hash_free(Eet_Free_Context *context, Eet_Data_Descriptor *edd)
{
   int j;
   int i;

   if (context->freelist_hash.ref > 0) return;
   for (j = 0; j < 256; ++j)
     for (i = 0; i < context->freelist_hash.num[j]; ++i)
       {
	  if (edd)
	    edd->func.hash_free(context->freelist_hash.list[j][i]);
	  else
	    free(context->freelist_hash.list[j][i]);
       }
   _eet_free_reset(&context->freelist_hash);
}

static void
_eet_freelist_all_ref(Eet_Free_Context *freelist_context)
{
   _eet_freelist_ref(freelist_context);
   _eet_freelist_str_ref(freelist_context);
   _eet_freelist_list_ref(freelist_context);
   _eet_freelist_hash_ref(freelist_context);
   _eet_freelist_direct_str_ref(freelist_context);
}

static void
_eet_freelist_all_unref(Eet_Free_Context *freelist_context)
{
   _eet_freelist_unref(freelist_context);
   _eet_freelist_str_unref(freelist_context);
   _eet_freelist_list_unref(freelist_context);
   _eet_freelist_hash_unref(freelist_context);
   _eet_freelist_direct_str_unref(freelist_context);
}

static int
eet_data_descriptor_encode_hash_cb(void *hash __UNUSED__, const char *key, void *hdata, void *fdata)
{
   Eet_Dictionary               *ed;
   Eet_Data_Encode_Hash_Info    *edehi;
   Eet_Data_Stream              *ds;
   Eet_Data_Element             *ede;
   Eet_Data_Chunk               *echnk;
   void                         *data = NULL;
   int                           size;

   edehi = fdata;
   ede = edehi->ede;
   ds = edehi->ds;
   ed = edehi->ed;

   /* Store key */
   data = eet_data_put_type(ed,
                            EET_T_STRING,
			    &key,
			    &size);
   if (data)
     {
	echnk = eet_data_chunk_new(data, size, ede->name, ede->type, ede->group_type);
	eet_data_chunk_put(ed, echnk, ds);
	eet_data_chunk_free(echnk);
	free(data);
	data = NULL;
     }

   EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );

   /* Store data */
   if (ede->type >= EET_T_STRING)
     eet_data_put_unknown(ed, NULL, ede, ds, &hdata);
   else
     {
	if (ede->subtype)
	  data = _eet_data_descriptor_encode(ed,
					     ede->subtype,
					     hdata,
					     &size);
	if (data)
	  {
	     echnk = eet_data_chunk_new(data, size, ede->name, ede->type, ede->group_type);
	     eet_data_chunk_put(ed, echnk, ds);
	     eet_data_chunk_free(echnk);
	     free(data);
	     data = NULL;
	  }
     }

   return 1;
}

static char *
_eet_data_string_escape(const char *str)
{
   char *s, *sp;
   const char *strp;
   int sz = 0;

   for (strp = str; *strp; strp++)
     {
	if (*strp == '\"') sz += 2;
	else if (*strp == '\\') sz += 2;
	else sz += 1;
     }
   s = malloc(sz + 1);
   if (!s) return NULL;
   for (strp = str, sp = s; *strp; strp++, sp++)
     {
	if (*strp == '\"')
	  {
	     *sp = '\\';
	     sp++;
	  }
	else if (*strp == '\\')
	  {
	     *sp = '\\';
	     sp++;
	  }
	*sp = *strp;
     }
   *sp = 0;
   return s;
}

static void
_eet_data_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char *str), const char *str)
{
   char *s;

   s = _eet_data_string_escape(str);
   if (s)
     {
	dumpfunc(dumpdata, s);
	free(s);
     }
}

static char *
_eet_data_dump_token_get(const char *src, int *len)
{
   const char *p;
   char *tok = NULL;
   int in_token = 0;
   int in_quote = 0;
   int tlen = 0, tsize = 0;

#define TOK_ADD(x) \
   { \
      tlen++; \
      if (tlen >= tsize) \
	{ \
	   tsize += 32; \
	   tok = realloc(tok, tsize); \
	} \
      tok[tlen - 1] = x; \
   }

   for (p = src; *len > 0; p++, (*len)--)
     {
	if (in_token)
	  {
	     if (in_quote)
	       {
		  if ((p[0] == '\"') && (p > src) && (p[-1] != '\\'))
		    {
		       in_quote = 0;
		    }
		  else if ((p[0] == '\\') && (*len > 1) && (p[1] == '\"'))
		    {
		       /* skip */
		    }
		  else if ((p[0] == '\\') && (p > src) && (p[-1] == '\\'))
		    {
		       /* skip */
		    }
		  else
		    TOK_ADD(p[0]);
	       }
	     else
	       {
		  if (p[0] == '\"') in_quote = 1;
		  else
		    {
		       if ((isspace(p[0])) || (p[0] == ';')) /* token ends here */
			 {
			    TOK_ADD(0);
			    (*len)--;
			    return tok;
			 }
		       else
			 TOK_ADD(p[0]);
		    }
	       }
	  }
	else
	  {
	     if (!((isspace(p[0])) || (p[0] == ';')))
	       {
		  in_token = 1;
		  (*len)++;
		  p--;
	       }
	  }
     }
   if (in_token)
     {
	TOK_ADD(0);
	return tok;
     }
   if (tok) free(tok);
   return NULL;
}

static void *
_eet_data_dump_encode(Eet_Dictionary *ed,
                      Eet_Node *node,
		      int *size_ret)
{
   Eet_Data_Chunk *chnk = NULL, *echnk = NULL;
   Eet_Data_Stream *ds;
   void *cdata, *data;
   int csize, size;
   Eet_Node *n;

   if (words_bigendian == -1)
     {
	unsigned long int v;

	v = htonl(0x12345678);
	if (v == 0x12345678) words_bigendian = 1;
	else words_bigendian = 0;
     }

   if (node == NULL) return NULL;

   ds = eet_data_stream_new();
   if (!ds) return NULL;

   switch (node->type)
     {
      case EET_G_UNKNOWN:
	for (n = node->values; n; n = n->next)
	  {
	     data = _eet_data_dump_encode(ed, n, &size);
	     if (data)
	       {
		  eet_data_stream_write(ds, data, size);
		  free(data);
	       }
	  }
	break;
      case EET_G_ARRAY:
      case EET_G_VAR_ARRAY:
	data = eet_data_put_type(ed,
				 EET_T_INT,
				 &node->count,
				 &size);
	if (data)
	  {
	     echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
	     eet_data_chunk_put(ed, echnk, ds);
	     eet_data_chunk_free(echnk);
	     free(data);
	  }
	for (n = node->values; n; n = n->next)
	  {
	     data = _eet_data_dump_encode(ed, n, &size);
	     if (data)
	       {
		  echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
		  eet_data_chunk_put(ed, echnk, ds);
		  eet_data_chunk_free(echnk);
		  free(data);
	       }
	  }

	/* Array is somekind of special case, so we should embed it inside another chunk. */
	*size_ret = ds->pos;
	cdata = ds->data;

	ds->data = NULL;
	ds->size = 0;
	eet_data_stream_free(ds);

	return cdata;
      case EET_G_LIST:
	for (n = node->values; n; n = n->next)
	  {
	     data = _eet_data_dump_encode(ed, n, &size);
	     if (data)
	       {
		  eet_data_stream_write(ds, data, size);
		  free(data);
	       }
	  }
	break;
      case EET_G_HASH:
	if (node->key)
	  {
	     data = eet_data_put_type(ed,
                                      EET_T_STRING,
				      &node->key,
				      &size);
	     if (data)
	       {
		  echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
		  eet_data_chunk_put(ed, echnk, ds);
		  eet_data_chunk_free(echnk);
		  free(data);
	       }
	  }
	for (n = node->values; n; n = n->next)
	  {
	     data = _eet_data_dump_encode(ed, n, &size);
	     if (data)
	       {
		  echnk = eet_data_chunk_new(data, size, node->name, node->type, node->type);
		  eet_data_chunk_put(ed, echnk, ds);
		  eet_data_chunk_free(echnk);
		  free(data);
	       }
	  }

	/* Hash is somekind of special case, so we should embed it inside another chunk. */
	*size_ret = ds->pos;
	cdata = ds->data;

	ds->data = NULL;
	ds->size = 0;
	eet_data_stream_free(ds);

	return cdata;
      case EET_T_NULL:
	 break;
      case EET_T_CHAR:
        data = eet_data_put_type(ed, node->type, &(node->data.c), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_SHORT:
        data = eet_data_put_type(ed, node->type, &(node->data.s), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_INT:
        data = eet_data_put_type(ed, node->type, &(node->data.i), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_LONG_LONG:
        data = eet_data_put_type(ed, node->type, &(node->data.l), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_FLOAT:
        data = eet_data_put_type(ed, node->type, &(node->data.f), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_DOUBLE:
        data = eet_data_put_type(ed, node->type, &(node->data.d), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_UCHAR:
        data = eet_data_put_type(ed, node->type, &(node->data.uc), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_USHORT:
        data = eet_data_put_type(ed, node->type, &(node->data.us), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_UINT:
        data = eet_data_put_type(ed, node->type, &(node->data.ui), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_ULONG_LONG:
        data = eet_data_put_type(ed, node->type, &(node->data.ul), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_INLINED_STRING:
        data = eet_data_put_type(ed, node->type, &(node->data.str), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      case EET_T_STRING:
        data = eet_data_put_type(ed, node->type, &(node->data.str), &size);
	if (data)
	  {
	     eet_data_stream_write(ds, data, size);
	     free(data);
	  }
	break;
      default:
	break;
     }

   if ((node->type >= EET_G_UNKNOWN) && (node->type < EET_G_LAST))
     chnk = eet_data_chunk_new(ds->data, ds->pos, node->name, EET_T_UNKNOW, node->type);
   else
     chnk = eet_data_chunk_new(ds->data, ds->pos, node->name, node->type, EET_G_UNKNOWN);
   ds->data = NULL;
   ds->size = 0;
   eet_data_stream_free(ds);

   ds = eet_data_stream_new();
   eet_data_chunk_put(ed, chnk, ds);
   cdata = ds->data;
   csize = ds->pos;

   ds->data = NULL;
   ds->size = 0;
   eet_data_stream_free(ds);
   *size_ret = csize;

   free(chnk->data);
   eet_data_chunk_free(chnk);

   return cdata;
}

static void *
_eet_data_dump_parse(Eet_Dictionary *ed,
                     int *size_ret,
		     const char *src,
		     int size)
{
   void *cdata = NULL;
   const char *p;
#define M_NONE 0
#define M_STRUCT 1
#define M_ 2
   int left, jump;
   Eet_Node *node_base = NULL;
   Eet_Node *node = NULL;
   Eet_Node *n, *nn;

   /* FIXME; handle parse errors */
#define TOK_GET(t) \
   jump = left; t = _eet_data_dump_token_get(p, &left); p += jump - left;
   left = size;
   for (p = src; p < (src + size);)
     {
	char *tok1, *tok2, *tok3, *tok4;

	TOK_GET(tok1);
	if (tok1)
	  {
	     if (!strcmp(tok1, "group"))
	       {
		  TOK_GET(tok2);
		  if (tok2)
		    {
		       TOK_GET(tok3);
		       if (tok3)
			 {
			    TOK_GET(tok4);
			    if (tok4)
			      {
				 if (!strcmp(tok4, "{"))
				   {
				      /* we have 'group NAM TYP {' */
				      n = calloc(1, sizeof(Eet_Node));
				      if (n)
					{
					   n->parent = node;
					   if (!node_base)
					     {
						node_base = n;
					     }
					   if (node)
					     {
						/* append node */
						if (!node->values)
						  node->values = n;
						else
						  {
						     for (nn = node->values; nn; nn = nn->next)
						       {
							  if (!nn->next)
							    {
							       nn->next = n;
							       break;
							    }
						       }
						  }
					     }
					   n->name = eina_stringshare_add(tok2);
					   if      (!strcmp(tok3, "struct"))    n->type = EET_G_UNKNOWN;
					   else if (!strcmp(tok3, "array"))     n->type = EET_G_ARRAY;
					   else if (!strcmp(tok3, "var_array")) n->type = EET_G_VAR_ARRAY;
					   else if (!strcmp(tok3, "list"))      n->type = EET_G_LIST;
					   else if (!strcmp(tok3, "hash"))      n->type = EET_G_HASH;
					   else
					     {
					       ERR("ERROR: group type '%s' invalid.", tok3);
					     }
					   node = n;
					}
				   }
				 free(tok4);
			      }
			    free(tok3);
			 }
		       free(tok2);
		    }
	       }
	     else if (!strcmp(tok1, "value"))
	       {
		  TOK_GET(tok2);
		  if (tok2)
		    {
		       TOK_GET(tok3);
		       if (tok3)
			 {
			    TOK_GET(tok4);
			    if (tok4)
			      {
				 /* we have 'value NAME TYP XXX' */
				 if (node_base)
				   {
				      n = calloc(1, sizeof(Eet_Node));
				      if (n)
					{
					   n->parent = node;
					   /* append node */
					   if (!node->values)
					     node->values = n;
					   else
					     {
						for (nn = node->values; nn; nn = nn->next)
						  {
						     if (!nn->next)
						       {
							  nn->next = n;
							  break;
						       }
						  }
					     }
					   n->name = eina_stringshare_add(tok2);
					   if      (!strcmp(tok3, "char:"))
					     {
						n->type = EET_T_CHAR;
						sscanf(tok4, "%hhi", &(n->data.c));
					     }
					   else if (!strcmp(tok3, "short:"))
					     {
						n->type = EET_T_SHORT;
						sscanf(tok4, "%hi", &(n->data.s));
					     }
					   else if (!strcmp(tok3, "int:"))
					     {
						n->type = EET_T_INT;
						sscanf(tok4, "%i", &(n->data.i));
					     }
					   else if (!strcmp(tok3, "long_long:"))
					     {
						n->type = EET_T_LONG_LONG;
						sscanf(tok4, "%lli", &(n->data.l));
					     }
					   else if (!strcmp(tok3, "float:"))
					     {
						n->type = EET_T_FLOAT;
						sscanf(tok4, "%f", &(n->data.f));
					     }
					   else if (!strcmp(tok3, "double:"))
					     {
						n->type = EET_T_DOUBLE;
						sscanf(tok4, "%lf", &(n->data.d));
					     }
					   else if (!strcmp(tok3, "uchar:"))
					     {
						n->type = EET_T_UCHAR;
						sscanf(tok4, "%hhu", &(n->data.uc));
					     }
					   else if (!strcmp(tok3, "ushort:"))
					     {
						n->type = EET_T_USHORT;
						sscanf(tok4, "%hu", &(n->data.us));
					     }
					   else if (!strcmp(tok3, "uint:"))
					     {
						n->type = EET_T_UINT;
						sscanf(tok4, "%u", &(n->data.ui));
					     }
					   else if (!strcmp(tok3, "ulong_long:"))
					     {
						n->type = EET_T_ULONG_LONG;
						sscanf(tok4, "%llu", &(n->data.ul));
					     }
					   else if (!strcmp(tok3, "string:"))
					     {
						n->type = EET_T_STRING;
						n->data.str = eina_stringshare_add(tok4);
					     }
					   else if (!strcmp(tok3, "inlined:"))
					     {
						n->type = EET_T_INLINED_STRING;
						n->data.str = eina_stringshare_add(tok4);
					     }
					   else if (!strcmp(tok3, "null"))
					     {
						n->type = EET_T_NULL;
						n->data.str = NULL;
					     }
					   else
					     {
						ERR("ERROR: value type '%s' invalid.", tok4);
					     }
					}
				   }
				 free(tok4);
			      }
			    free(tok3);
			 }
		       free(tok2);
		    }
	       }
	     else if (!strcmp(tok1, "key"))
	       {
		  TOK_GET(tok2);
		  if (tok2)
		    {
		       /* we have 'key NAME' */
		       if (node)
			 {
			    node->key = eina_stringshare_add(tok2);
			 }
		       free(tok2);
		    }
	       }
	     else if (!strcmp(tok1, "count"))
	       {
		  TOK_GET(tok2);
		  if (tok2)
		    {
		       /* we have a 'count COUNT' */
		       if (node)
			 {
			    sscanf(tok2, "%i", &(node->count));
			 }
		       free(tok2);
		    }
	       }
	     else if (!strcmp(tok1, "}"))
	       {
		  /* we have an end of the group */
		  if (node) node = node->parent;
	       }
	     free(tok1);
	  }
     }

   if (node_base)
     {
	cdata = _eet_data_dump_encode(ed, node_base, size_ret);
	eet_node_del(node_base);
     }
   return cdata;
}

#define NEXT_CHUNK(P, Size, Echnk, Ed)                  \
  {                                                     \
     int        tmp;                                    \
     tmp = Ed ? (int) (sizeof(int) * 2) : Echnk.len + 4;\
     P += (4 + Echnk.size + tmp);                       \
     Size -= (4 + Echnk.size + tmp);                    \
  }

static const char *_dump_g_name[6] = {
  "struct",
  "array",
  "var_array",
  "list",
  "hash",
  "???"
};

static const char *_dump_t_name[14][2] = {
  { "???: ", "???" },
  { "char: ", "%hhi" },
  { "short: ", "%hi" },
  { "int: ", "%i" },
  { "long_long: ", "%lli" },
  { "float: ", "%1.25f" },
  { "double: ", "%1.25f" },
  { "uchar: ", "%hhu" },
  { "ushort: ", "%i" },
  { "uint: ", "%u" },
  { "ulong_long: ", "%llu" },
  { "null", "" }
};

static void *
_eet_data_descriptor_decode(Eet_Free_Context *context,
			    const Eet_Dictionary *ed,
                            Eet_Data_Descriptor *edd,
			    const void *data_in,
			    int size_in,
			    int level,
			    void (*dumpfunc) (void *data, const char *str),
			    void *dumpdata)
{
   void *data = NULL;
   char *p;
   int size, i, dump;
   Eet_Data_Chunk chnk;

   if (words_bigendian == -1)
     {
	unsigned long int v;

	v = htonl(0x12345678);
	if (v == 0x12345678) words_bigendian = 1;
	else words_bigendian = 0;
     }

   if (edd)
     {
	data = edd->func.mem_alloc(edd->size);
	if (!data) return NULL;
	if (edd->ed != ed)
	  {
	     for (i = 0; i < edd->elements.num; i++)
	       edd->elements.set[i].directory_name_ptr = NULL;
	     edd->ed = ed;
	  }
     }
   _eet_freelist_all_ref(context);
   if (data) _eet_freelist_add(context, data);
   dump = 0;
   memset(&chnk, 0, sizeof(Eet_Data_Chunk));
   eet_data_chunk_get(ed, &chnk, data_in, size_in);
   if (!chnk.name) goto error;
   if (edd)
     {
	if (strcmp(chnk.name, edd->name)) goto error;
     }
   p = chnk.data;
   if (ed)
     size = size_in - (4 + sizeof(int) * 2);
   else
     size = size_in - (4 + 4 + chnk.len);
   if (edd)
     {
	if (!edd->elements.hash.buckets) _eet_descriptor_hash_new(edd);
     }
   else if (dumpfunc)
     {
	dump = 1;
	if (chnk.type == EET_T_UNKNOW)
	  eet_data_dump_group_start(level, dumpfunc, dumpdata, chnk.group_type, chnk.name);
     }
   while (size > 0)
     {
	Eet_Data_Chunk echnk;
	Eet_Data_Element *ede = NULL;
	unsigned char dd[128];
	int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
	int ret = 0;

	/* get next data chunk */
	memset(&echnk, 0, sizeof(Eet_Data_Chunk));
	eet_data_chunk_get(ed, &echnk, p, size);
	if (!echnk.name) goto error;
	/* FIXME: don't REPLY on edd - work without */
	if ((edd) && (!dumpfunc))
	  {
	     ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
	     if (ede)
	       {
		  group_type = ede->group_type;
		  type = ede->type;
		  if ((echnk.type == 0) && (echnk.group_type == 0))
		    {
		       type = ede->type;
		       group_type = ede->group_type;
		    }
		  else
		    {
		       if (IS_SIMPLE_TYPE(echnk.type) &&
			   eet_data_type_match(echnk.type, ede->type))
			 type = echnk.type;
		       else if ((echnk.group_type > EET_G_UNKNOWN) &&
				(echnk.group_type < EET_G_LAST) &&
				(echnk.group_type == ede->group_type))
			 group_type = echnk.group_type;
		    }
	       }
	  }
	/*...... dump func */
	else if (dumpfunc)
	  {
	     if ((echnk.type > EET_T_UNKNOW) &&
		 (echnk.type < EET_T_LAST))
	       type = echnk.type;
	     else if ((echnk.group_type > EET_G_UNKNOWN) &&
		      (echnk.group_type < EET_G_LAST))
	       group_type = echnk.group_type;
	  }

	if (dumpfunc && group_type == EET_G_UNKNOWN && IS_SIMPLE_TYPE(type))
	  {
	     ret = eet_data_get_type(ed,
				     type,
				     echnk.data,
				     ((char *)echnk.data) + echnk.size,
				     dd);
	     if (ret <= 0) goto error;

	     eet_data_dump_simple_type(type, echnk.name, dd, level, dumpfunc, dumpdata);
	  }
	else
	  {
	     ret = eet_group_codec[group_type - 100].get(context,
							 ed, edd, ede, &echnk,
							 type, group_type, ede ? (void*) (((char *)data) + ede->offset) : dd,
							 level, dumpfunc, dumpdata,
							 &p, &size);
	     if (ret <= 0) goto error;
	  }
	/* advance to next chunk */
        NEXT_CHUNK(p, size, echnk, ed);
     }

   _eet_freelist_all_unref(context);
   if (dumpfunc)
     {
	_eet_freelist_str_free(context, edd);
	_eet_freelist_direct_str_free(context, edd);
	_eet_freelist_list_free(context, edd);
	_eet_freelist_hash_free(context, edd);
	_eet_freelist_free(context, edd);
     }
   else
     {
	_eet_freelist_reset(context);
	_eet_freelist_str_reset(context);
	_eet_freelist_list_reset(context);
	_eet_freelist_hash_reset(context);
	_eet_freelist_direct_str_reset(context);
     }
   if (dumpfunc)
     {
	if (dump)
	  {
	     if (chnk.type == EET_T_UNKNOW)
	       {
		  for (i = 0; i < level; i++) dumpfunc(dumpdata, "  ");
		  dumpfunc(dumpdata, "}\n");
	       }
	  }
	return (void *)1;
     }
   return data;

error:
   _eet_freelist_all_unref(context);
   _eet_freelist_str_free(context, edd);
   _eet_freelist_direct_str_free(context, edd);
   _eet_freelist_list_free(context, edd);
   _eet_freelist_hash_free(context, edd);
   _eet_freelist_free(context, edd);
   if (dumpfunc)
     {
	if (dump)
	  {
	     if (chnk.type == EET_T_UNKNOW)
	       {
		  for (i = 0; i < level; i++) dumpfunc(dumpdata, "  ");
		  dumpfunc(dumpdata, "}\n");
	       }
	  }
     }
   return NULL;
}

static void
eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
{
   int i;

   for (i = 0; i < level; i++) dumpfunc(dumpdata, "  ");
}

static void
eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
			  int group_type, const char *name)
{
   int chnk_type;

   chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
     group_type : EET_G_LAST;

   eet_data_dump_level(level, dumpfunc, dumpdata);
   dumpfunc(dumpdata, "group \"");
   _eet_data_dump_string_escape(dumpdata, dumpfunc, name);
   dumpfunc(dumpdata, "\" ");

   dumpfunc(dumpdata, _dump_g_name[chnk_type - EET_G_UNKNOWN]);
   dumpfunc(dumpdata, " {\n");
}

static void
eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
{
   eet_data_dump_level(level, dumpfunc, dumpdata);
   dumpfunc(dumpdata, "  }\n");
}

static int
eet_data_get_list(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
		  int type, int group_type __UNUSED__, void *data,
		  int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
		  char **p, int *size)
{
   Eet_Data_Descriptor *subtype = NULL;
   void *list = NULL;
   void **ptr;
   void *data_ret;
   int et = EET_T_UNKNOW;

   EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);

   if (edd)
     {
	subtype = ede->subtype;
	et = ede->type;
     }
   else if (dumpfunc)
     {
	eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
     }

   ptr = (void **)data;
   list = *ptr;
   data_ret = NULL;

   if (et >= EET_T_STRING)
     {
	int ret;

	ret = eet_data_get_unknown(context, ed, edd, ede, echnk, et, EET_G_UNKNOWN,
				   &data_ret, level, dumpfunc, dumpdata, p, size);
	if (!ret) return 0;
     }
   else
     {
	data_ret = _eet_data_descriptor_decode(context, ed, subtype,
					       echnk->data, echnk->size,
					       level + 2, dumpfunc, dumpdata);
	if (!data_ret) return 0;
     }

   if (edd)
     {
	list = edd->func.list_append(list, data_ret);
	*ptr = list;
	_eet_freelist_list_add(context, ptr);
     }
   else if (dumpfunc)
     eet_data_dump_group_end(level, dumpfunc, dumpdata);

   return 1;
}

static int
eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
		  int type, int group_type __UNUSED__, void *data,
		  int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
		  char **p, int *size)
{
   void **ptr;
   void *hash = NULL;
   char *key = NULL;
   void *data_ret = NULL;
   int ret = 0;

   EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);

   ptr = (void **)data;
   hash = *ptr;

   /* Read key */
   ret = eet_data_get_type(ed,
			   EET_T_STRING,
			   echnk->data,
			   ((char *)echnk->data) + echnk->size,
			   &key);
   if (ret <= 0) goto on_error;

   /* Advance to next chunk */
   NEXT_CHUNK((*p), (*size), (*echnk), ed);
   memset(echnk, 0, sizeof(Eet_Data_Chunk));

   /* Read value */
   eet_data_chunk_get(ed, echnk, *p, *size);
   if (!echnk->name) goto on_error;

   if (dumpfunc && key)
     {
	eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);

	eet_data_dump_level(level, dumpfunc, dumpdata);
	dumpfunc(dumpdata, "    key \"");
	_eet_data_dump_string_escape(dumpdata, dumpfunc, key);
	dumpfunc(dumpdata, "\";\n");
     }

   if (type >= EET_T_STRING)
     {
	int ret;

	ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
				   &data_ret, level, dumpfunc, dumpdata, p, size);
	if (!ret) return 0;
     }
   else
     {
	data_ret = _eet_data_descriptor_decode(context,
					       ed,
					       ede ? ede->subtype : NULL,
					       echnk->data,
					       echnk->size,
					       level + 2,
					       dumpfunc,
					       dumpdata);
	if (!data_ret) goto on_error;
     }

   if (edd)
     {
	hash = edd->func.hash_add(hash, key, data_ret);
	*ptr = hash;
	_eet_freelist_hash_add(context, ptr);
     }
   else if (dumpfunc)
     eet_data_dump_group_end(level, dumpfunc, dumpdata);

   return 1;

 on_error:
   return ret;
}

/* var arrays and fixed arrays have to
 * get all chunks at once. for fixed arrays
 * we can get each chunk and increment a
 * counter stored on the element itself but
 * it wont be thread safe. for var arrays
 * we still need a way to get the number of
 * elements from the data, so storing the
 * number of elements and the element data on
 * each chunk is pointless.
 */
static int
eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__,
		   Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
		   int type, int group_type, void *data,
		   int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
		   char **p, int *size)
{
   const char *name;
   void *ptr;
   int count;
   int ret;
   int subsize = 0;
   int i;

   EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);

   ptr = data;
   /* read the number of elements */
   ret = eet_data_get_type(ed,
			   EET_T_INT,
			   echnk->data,
			   ((char *)echnk->data) + echnk->size,
			   &count);
   if (ret <= 0) return ret;

   name = echnk->name;

   if (ede)
     {
	if (type >= EET_T_STRING)
	  subsize = eet_basic_codec[ede->type].size;
	else
	  subsize = ede->subtype->size;

	if (group_type == EET_G_VAR_ARRAY)
	  {
	     /* store the number of elements
	      * on the counter offset */
	     *(int *)(((char *)data) + ede->count - ede->offset) = count;
	     /* allocate space for the array of elements */
	     *(void **)ptr = edd->func.mem_alloc(count * subsize);

	     if (!*(void **)ptr) return 0;

	     memset(*(void **)ptr, 0, count * subsize);

	     _eet_freelist_add(context, *(void **)ptr);
	  }
     }
   else
     {
	char tbuf[256];

	eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);

	eet_data_dump_level(level, dumpfunc, dumpdata);
	dumpfunc(dumpdata, "    count ");
	eina_convert_itoa(count, tbuf);
	dumpfunc(dumpdata, tbuf);
	dumpfunc(dumpdata, ";\n");
     }

   /* get all array elements */
   for (i = 0; i < count; i++)
     {
	void *dst = NULL;
	void *data_ret = NULL;

	/* Advance to next chunk */
	NEXT_CHUNK((*p), (*size), (*echnk), ed);
	memset(echnk, 0, sizeof(Eet_Data_Chunk));

	eet_data_chunk_get(ed, echnk, *p, *size);
	if (!echnk->name || strcmp(echnk->name, name) != 0) return 0;
	/* get the data */

	/* get the destination pointer */
	if (ede)
	  {
	     if (group_type == EET_G_ARRAY)
	       dst = (char *)ptr + (subsize * i);
	     else
	       dst = *(char **)ptr + (subsize * i);
	  }

	if (type >= EET_T_STRING)
	  {
	     int ret;

	     ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
					&data_ret, level, dumpfunc, dumpdata, p, size);
	     if (!ret) return 0;
	     if (dst) memcpy(dst, &data_ret, subsize);
	  }
	else
	  {
	     data_ret = _eet_data_descriptor_decode(context, ed, ede ? ede->subtype : NULL,
						    echnk->data, echnk->size,
						    level + 2, dumpfunc, dumpdata);
	     if (!data_ret) return 0;
	     if (dst)
	       {
		  memcpy(dst, data_ret, subsize);
		  _eet_freelist_add(context, data_ret);
	       }
	  }
     }

   if (dumpfunc)
     eet_data_dump_group_end(level, dumpfunc, dumpdata);

   return 1;
}

static void
eet_data_dump_simple_type(int type, const char *name, void *dd,
			 int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
{
   const char *type_name = NULL;
   char tbuf[256];

   eet_data_dump_level(level, dumpfunc, dumpdata);
   dumpfunc(dumpdata, "  value \"");
   _eet_data_dump_string_escape(dumpdata, dumpfunc, name);
   dumpfunc(dumpdata, "\" ");

#define EET_T_TYPE(Eet_Type, Type)					\
   case Eet_Type:							\
     {									\
	dumpfunc(dumpdata, _dump_t_name[Eet_Type][0]);			\
	snprintf(tbuf, sizeof (tbuf), _dump_t_name[Eet_Type][1], *((Type *)dd)); \
	dumpfunc(dumpdata, tbuf);					\
	break;								\
     }

   switch (type)
     {
	EET_T_TYPE(EET_T_CHAR, char);
	EET_T_TYPE(EET_T_SHORT, short);
	EET_T_TYPE(EET_T_INT, int);
	EET_T_TYPE(EET_T_LONG_LONG, long long);
	EET_T_TYPE(EET_T_FLOAT, float);
	EET_T_TYPE(EET_T_DOUBLE, double);
	EET_T_TYPE(EET_T_UCHAR, unsigned char);
	EET_T_TYPE(EET_T_USHORT, unsigned short);
	EET_T_TYPE(EET_T_UINT, unsigned int);
	EET_T_TYPE(EET_T_ULONG_LONG, unsigned long long);
      case EET_T_INLINED_STRING:
	 type_name = "inlined: \"";
      case EET_T_STRING:
	 if (!type_name) type_name = "string: \"";

	 {
	    char *s;

	    s = *((char **)dd);
	    if (s)
	      {
		 dumpfunc(dumpdata, type_name);
		 _eet_data_dump_string_escape(dumpdata, dumpfunc, s);
		 dumpfunc(dumpdata, "\"");
	      }
	 }
	 break;
      case EET_T_NULL:
	 dumpfunc(dumpdata, "null");
	 break;
      default:
	 dumpfunc(dumpdata, "???: ???");
	 break;
     }
   dumpfunc(dumpdata, ";\n");
}

static int
eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
		     int type, int group_type __UNUSED__, void *data,
		     int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
		     char **p __UNUSED__, int *size __UNUSED__)
{
   int ret;
   void *data_ret;

   if (IS_SIMPLE_TYPE(type))
     {
	ret = eet_data_get_type(ed, type, echnk->data, ((char *)echnk->data) + echnk->size, ((char *)data));
	if (ret <= 0) return ret;

	if (!edd && dumpfunc)
	  {
	     eet_data_dump_simple_type(type, echnk->name, data, level, dumpfunc, dumpdata);
	  }
	else if (edd && type == EET_T_STRING)
	  {
	     char **str;

	     str = (char **)(((char *)data));
	     if (*str)
	       {
		  if ((ed == NULL) || (edd->func.str_direct_alloc == NULL))
		    {
		       *str = edd->func.str_alloc(*str);
		       _eet_freelist_str_add(context, *str);
		    }
		  else
		    {
		       *str = edd->func.str_direct_alloc(*str);
		       _eet_freelist_direct_str_add(context, *str);
		    }
	       }
	  }
	else if (edd && type == EET_T_INLINED_STRING)
	  {
	     char **str;

	     str = (char **)(((char *)data));
	     if (*str)
	       {
		  *str = edd->func.str_alloc(*str);
		  _eet_freelist_str_add(context, *str);
	       }
	  }
     }
   else
     {
	Eet_Data_Descriptor *subtype;

	subtype = ede ? ede->subtype : NULL;

	if (subtype || dumpfunc)
	  {
	     void **ptr;

	     data_ret = _eet_data_descriptor_decode(context, ed, subtype, echnk->data, echnk->size, level + 1, dumpfunc, dumpdata);
	     if (!data_ret) return 0;

	     ptr = (void **)(((char *)data));
	     *ptr = (void *)data_ret;
	  }
     }

   return 1;
}

static void
eet_data_encode(Eet_Dictionary *ed, Eet_Data_Stream *ds, void *data, const char *name, int size, int type, int group_type)
{
   Eet_Data_Chunk *echnk;

   echnk = eet_data_chunk_new(data, size, name, type, group_type);
   eet_data_chunk_put(ed, echnk, ds);
   eet_data_chunk_free(echnk);
   if (data) free(data);
}

static void
eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
{
   void *data;
   int offset = 0;
   int subsize;
   int count;
   int size;
   int j;

   EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );

   if (ede->group_type == EET_G_ARRAY)
     count = ede->counter_offset;
   else
     count = *(int *)(((char *)data_in) + ede->count - ede->offset);

   if (count <= 0) return;
   /* Store number of elements */
   data = eet_data_put_type(ed, EET_T_INT, &count, &size);
   if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);

   if (ede->type >= EET_T_STRING)
     subsize = eet_basic_codec[ede->type].size;
   else
     subsize = ede->subtype->size;

   for (j = 0; j < count; j++)
     {
	void *d;
	int pos = ds->pos;

	if (ede->group_type == EET_G_ARRAY)
	  d = (void *)(((char *)data_in) + offset);
	else
	  d = *(((char **)data_in)) + offset;

	if (ede->type >= EET_T_STRING)
	  eet_data_put_unknown(ed, NULL, ede, ds, d);
	else
	  {
	     data = _eet_data_descriptor_encode(ed, ede->subtype, d, &size);
	     if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
	  }

	if (pos == ds->pos)
	  {
	     /* Add a NULL element just to have the correct array layout. */
	     eet_data_encode(ed, ds, NULL, ede->name, 0, EET_T_NULL, ede->group_type);
	  }

	offset += subsize;
     }
}

static void
eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd __UNUSED__, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
{
   void *data = NULL;
   int size;

   if (IS_SIMPLE_TYPE(ede->type))
     data = eet_data_put_type(ed, ede->type, data_in, &size);
   else if (ede->subtype)
     {
	if (*((char **)data_in))
	  data = _eet_data_descriptor_encode(ed,
					     ede->subtype,
					     *((char **)((char *)(data_in))),
					     &size);
     }
   if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
}

static void
eet_data_put_list(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
{
   void *data;
   void *l;
   int size;

   EET_ASSERT(!((ede->type > EET_T_UNKNOW) && (ede->type < EET_T_STRING)), return );

   l = *((void **)(((char *)data_in)));
   for (; l; l = edd->func.list_next(l))
     {
	if (ede->type >= EET_T_STRING)
	  {
	     const char *str = edd->func.list_data(l);
	     eet_data_put_unknown(ed, NULL, ede, ds, &str);
	  }
	else
	  {
	     data = _eet_data_descriptor_encode(ed,
						ede->subtype,
						edd->func.list_data(l),
						&size);
	     if (data) eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
	  }
     }
}

static void
eet_data_put_hash(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in)
{
   Eet_Data_Encode_Hash_Info fdata;
   void *l;

   l = *((void **)(((char *)data_in)));
   fdata.ds = ds;
   fdata.ede = ede;
   fdata.ed = ed;
   edd->func.hash_foreach(l, eet_data_descriptor_encode_hash_cb, &fdata);
}

EAPI int
eet_data_dump_cipher(Eet_File *ef,
		     const char *name, const char *key,
		     void (*dumpfunc) (void *data, const char *str),
		     void *dumpdata)
{
   const Eet_Dictionary *ed = NULL;
   const void		*data = NULL;
   Eet_Free_Context      context;
   int			 ret = 0;
   int			 required_free = 0;
   int			 size;

   ed = eet_dictionary_get(ef);

   if (!key)
     data = eet_read_direct(ef, name, &size);
   if (!data)
     {
	required_free = 1;
	data = eet_read_cipher(ef, name, &size, key);
	if (!data) return 0;
     }

   memset(&context, 0, sizeof (context));
   if (_eet_data_descriptor_decode(&context, ed, NULL, data, size, 0,
				   dumpfunc, dumpdata))
     ret = 1;

   if (required_free)
     free((void*)data);

   return ret;
}

EAPI int
eet_data_dump(Eet_File *ef,
	      const char *name,
	      void (*dumpfunc) (void *data, const char *str),
	      void *dumpdata)
{
   return eet_data_dump_cipher(ef, name, NULL, dumpfunc, dumpdata);
}


EAPI int
eet_data_text_dump_cipher(const void *data_in,
			  const char *key, int size_in,
			  void (*dumpfunc) (void *data, const char *str),
			  void *dumpdata)
{
   void *ret = NULL;
   Eet_Free_Context context;
   unsigned int ret_len = 0;

   if (data_in && key)
     {
       if (eet_decipher(data_in, size_in, key, strlen(key), &ret, &ret_len))
	 {
	   if (ret) free(ret);
	   return 1;
	 }
       memset(&context, 0, sizeof (context));
       if (_eet_data_descriptor_decode(&context, NULL, NULL, ret, ret_len, 0,
				       dumpfunc, dumpdata))
	 {
	   free(ret);
	   return 1;
	 }
       free(ret);
       return 0;
     }
   memset(&context, 0, sizeof (context));
   if (_eet_data_descriptor_decode(&context, NULL, NULL, data_in, size_in, 0,
				   dumpfunc, dumpdata))
     return 1;
   return 0;
}

EAPI int
eet_data_text_dump(const void *data_in,
		   int size_in,
		   void (*dumpfunc) (void *data, const char *str),
		   void *dumpdata)
{
   return eet_data_text_dump_cipher(data_in, NULL, size_in, dumpfunc, dumpdata);
}

EAPI void *
eet_data_text_undump_cipher(const char *text,
			    const char *key,
			    int textlen,
			    int *size_ret)
{
   void *ret = NULL;

   ret = _eet_data_dump_parse(NULL, size_ret, text, textlen);
   if (ret && key)
     {
	void *ciphered = NULL;
	unsigned int ciphered_len;

	if (eet_cipher(ret, *size_ret, key, strlen(key), &ciphered, &ciphered_len))
	  {
	     if (ciphered) free(ciphered);
	     size_ret = 0;
	     free(ret);
	     return NULL;
	  }
	free(ret);
	*size_ret = ciphered_len;
	ret = ciphered;
     }
   return ret;
}

EAPI void *
eet_data_text_undump(const char *text,
		     int textlen,
		     int *size_ret)
{
   return eet_data_text_undump_cipher(text, NULL, textlen, size_ret);
}

EAPI int
eet_data_undump_cipher(Eet_File *ef,
		       const char *name,
		       const char *key,
		       const char *text,
		       int textlen,
		       int compress)
{
   Eet_Dictionary       *ed;
   void                 *data_enc;
   int                   size;
   int                   val;

   ed = eet_dictionary_get(ef);

   data_enc = _eet_data_dump_parse(ed, &size, text, textlen);
   if (!data_enc) return 0;
   val = eet_write_cipher(ef, name, data_enc, size, compress, key);
   free(data_enc);
   return val;
}

EAPI int
eet_data_undump(Eet_File *ef,
		const char *name,
		const char *text,
		int textlen,
		int compress)
{
   return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
}

EAPI void *
eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
				  const void *data_in,
				  const char *key,
				  int size_in)
{
   void *deciphered = NULL;
   void *ret;
   Eet_Free_Context context;
   unsigned int deciphered_len = 0;

   if (key && data_in)
     {
       if (eet_decipher(data_in, size_in, key, strlen(key), &deciphered, &deciphered_len))
	 {
	   if (deciphered) free(deciphered);
	   return NULL;
	 }
       memset(&context, 0, sizeof (context));
       ret = _eet_data_descriptor_decode(&context, NULL, edd, deciphered, deciphered_len, 0,
					 NULL, NULL);
       free(deciphered);
       return ret;
     }
   memset(&context, 0, sizeof (context));
   return _eet_data_descriptor_decode(&context, NULL, edd, data_in, size_in, 0,
                                      NULL, NULL);
}

EAPI void *
eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
			   const void *data_in,
			   int size_in)
{
   return eet_data_descriptor_decode_cipher(edd, data_in, NULL, size_in);
}

static void *
_eet_data_descriptor_encode(Eet_Dictionary *ed,
                            Eet_Data_Descriptor *edd,
                            const void *data_in,
                            int *size_ret)
{
   Eet_Data_Stream      *ds;
   Eet_Data_Chunk       *chnk;
   void                 *cdata;
   int                   csize;
   int                   i;

   if (words_bigendian == -1)
     {
	unsigned long int v;

	v = htonl(0x12345678);
	if (v == 0x12345678) words_bigendian = 1;
	else words_bigendian = 0;
     }

   ds = eet_data_stream_new();
   for (i = 0; i < edd->elements.num; i++)
     {
	Eet_Data_Element *ede;

	ede = &(edd->elements.set[i]);
	eet_group_codec[ede->group_type - 100].put(ed, edd, ede, ds, ((char *)data_in) + ede->offset);
     }
   chnk = eet_data_chunk_new(ds->data, ds->pos, edd->name, EET_T_UNKNOW, EET_G_UNKNOWN);
   ds->data = NULL;
   ds->size = 0;
   eet_data_stream_free(ds);

   ds = eet_data_stream_new();
   eet_data_chunk_put(ed, chnk, ds);
   cdata = ds->data;
   csize = ds->pos;

   ds->data = NULL;
   ds->size = 0;
   eet_data_stream_free(ds);
   *size_ret = csize;

   free(chnk->data);
   eet_data_chunk_free(chnk);

   return cdata;
}

EAPI int
eet_data_node_write_cipher(Eet_File *ef, const char *name, const char *key, Eet_Node *node, int compress)
{
   Eet_Dictionary       *ed;
   void                 *data_enc;
   int                   size;
   int                   val;

   ed = eet_dictionary_get(ef);

   data_enc = _eet_data_dump_encode(ed, node, &size);
   if (!data_enc) return 0;
   val = eet_write_cipher(ef, name, data_enc, size, compress, key);
   free(data_enc);
   return val;
}

EAPI void *
eet_data_node_encode_cipher(Eet_Node *node,
			    const char *key,
			    int *size_ret)
{
   void *ret = NULL;
   void *ciphered = NULL;
   unsigned int ciphered_len = 0;
   int size;

   ret = _eet_data_dump_encode(NULL, node, &size);
   if (key && ret)
     {
	if (eet_cipher(ret, size, key, strlen(key), &ciphered, &ciphered_len))
	  {
	     if (ciphered) free(ciphered);
	     if (size_ret) *size_ret = 0;
	     free(ret);
	     return NULL;
	  }
	free(ret);
	size = (int) ciphered_len;
	ret = ciphered;
     }

   if (size_ret) *size_ret = size;
   return ret;
}

EAPI void *
eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
				  const void *data_in,
				  const char *key,
				  int *size_ret)
{
   void *ret = NULL;
   void *ciphered = NULL;
   unsigned int ciphered_len = 0;
   int size;

   ret = _eet_data_descriptor_encode(NULL, edd, data_in, &size);
   if (key && ret)
     {
       if (eet_cipher(ret, size, key, strlen(key), &ciphered, &ciphered_len))
	 {
	   if (ciphered) free(ciphered);
	   if (size_ret) *size_ret = 0;
	   free(ret);
	   return NULL;
	 }
       free(ret);
       size = ciphered_len;
       ret = ciphered;
     }

   if (size_ret) *size_ret = size;
   return ret;
}

EAPI void *
eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
			   const void *data_in,
			   int *size_ret)
{
   return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
}