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
// Generated by Molecule 0.7.3

use molecule::prelude::*;

#[derive(Clone)]
pub struct U8(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for U8 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for U8 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for U8 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for U8 {
    fn default() -> Self {
        let v: Vec<u8> = vec![0];
        U8::new_unchecked(v.into())
    }
}

impl U8 {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn nth0(&self) -> Byte { Byte::new_unchecked(self.0.slice(0..1)) }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.as_bytes() }
    pub fn as_reader<'r>(&'r self) -> U8Reader<'r> { U8Reader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for U8 {
    type Builder = U8Builder;
    const NAME: &'static str = "U8";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { U8(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { U8Reader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { U8Reader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set([self.nth0(), ]) }
}

#[derive(Clone, Copy)]
pub struct U8Reader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for U8Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for U8Reader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for U8Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> U8Reader<'r> {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn nth0(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[0..1]) }
    pub fn raw_data(&self) -> &'r [u8] { self.as_slice() }
}

impl<'r> molecule::prelude::Reader<'r> for U8Reader<'r> {
    type Entity = U8;
    const NAME: &'static str = "U8Reader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { U8Reader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len != Self::TOTAL_SIZE { return ve!(Self , TotalSizeNotMatch , Self :: TOTAL_SIZE , slice_len); }
        Ok(())
    }
}

pub struct U8Builder(pub(crate) [Byte; 1]);

impl ::core::fmt::Debug for U8Builder { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:?})", Self::NAME, &self.0[..]) } }

impl ::core::default::Default for U8Builder { fn default() -> Self { U8Builder([Byte::default(), ]) } }

impl U8Builder {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn set(mut self, v: [Byte; 1]) -> Self {
        self.0 = v;
        self
    }
    pub fn nth0(mut self, v: Byte) -> Self {
        self.0[0] = v;
        self
    }
}

impl molecule::prelude::Builder for U8Builder {
    type Entity = U8;
    const NAME: &'static str = "U8Builder";
    fn expected_length(&self) -> usize { Self::TOTAL_SIZE }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(self.0[0].as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        U8::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct U128(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for U128 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for U128 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for U128 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for U128 {
    fn default() -> Self {
        let v: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        U128::new_unchecked(v.into())
    }
}

impl U128 {
    pub const TOTAL_SIZE: usize = 16;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 16;
    pub fn nth0(&self) -> Byte { Byte::new_unchecked(self.0.slice(0..1)) }
    pub fn nth1(&self) -> Byte { Byte::new_unchecked(self.0.slice(1..2)) }
    pub fn nth2(&self) -> Byte { Byte::new_unchecked(self.0.slice(2..3)) }
    pub fn nth3(&self) -> Byte { Byte::new_unchecked(self.0.slice(3..4)) }
    pub fn nth4(&self) -> Byte { Byte::new_unchecked(self.0.slice(4..5)) }
    pub fn nth5(&self) -> Byte { Byte::new_unchecked(self.0.slice(5..6)) }
    pub fn nth6(&self) -> Byte { Byte::new_unchecked(self.0.slice(6..7)) }
    pub fn nth7(&self) -> Byte { Byte::new_unchecked(self.0.slice(7..8)) }
    pub fn nth8(&self) -> Byte { Byte::new_unchecked(self.0.slice(8..9)) }
    pub fn nth9(&self) -> Byte { Byte::new_unchecked(self.0.slice(9..10)) }
    pub fn nth10(&self) -> Byte { Byte::new_unchecked(self.0.slice(10..11)) }
    pub fn nth11(&self) -> Byte { Byte::new_unchecked(self.0.slice(11..12)) }
    pub fn nth12(&self) -> Byte { Byte::new_unchecked(self.0.slice(12..13)) }
    pub fn nth13(&self) -> Byte { Byte::new_unchecked(self.0.slice(13..14)) }
    pub fn nth14(&self) -> Byte { Byte::new_unchecked(self.0.slice(14..15)) }
    pub fn nth15(&self) -> Byte { Byte::new_unchecked(self.0.slice(15..16)) }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.as_bytes() }
    pub fn as_reader<'r>(&'r self) -> U128Reader<'r> { U128Reader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for U128 {
    type Builder = U128Builder;
    const NAME: &'static str = "U128";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { U128(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { U128Reader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { U128Reader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set([self.nth0(), self.nth1(), self.nth2(), self.nth3(), self.nth4(), self.nth5(), self.nth6(), self.nth7(), self.nth8(), self.nth9(), self.nth10(), self.nth11(), self.nth12(), self.nth13(), self.nth14(), self.nth15(), ]) }
}

#[derive(Clone, Copy)]
pub struct U128Reader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for U128Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for U128Reader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for U128Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> U128Reader<'r> {
    pub const TOTAL_SIZE: usize = 16;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 16;
    pub fn nth0(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[0..1]) }
    pub fn nth1(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[1..2]) }
    pub fn nth2(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[2..3]) }
    pub fn nth3(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[3..4]) }
    pub fn nth4(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[4..5]) }
    pub fn nth5(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[5..6]) }
    pub fn nth6(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[6..7]) }
    pub fn nth7(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[7..8]) }
    pub fn nth8(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[8..9]) }
    pub fn nth9(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[9..10]) }
    pub fn nth10(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[10..11]) }
    pub fn nth11(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[11..12]) }
    pub fn nth12(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[12..13]) }
    pub fn nth13(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[13..14]) }
    pub fn nth14(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[14..15]) }
    pub fn nth15(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[15..16]) }
    pub fn raw_data(&self) -> &'r [u8] { self.as_slice() }
}

impl<'r> molecule::prelude::Reader<'r> for U128Reader<'r> {
    type Entity = U128;
    const NAME: &'static str = "U128Reader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { U128Reader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len != Self::TOTAL_SIZE { return ve!(Self , TotalSizeNotMatch , Self :: TOTAL_SIZE , slice_len); }
        Ok(())
    }
}

pub struct U128Builder(pub(crate) [Byte; 16]);

impl ::core::fmt::Debug for U128Builder { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:?})", Self::NAME, &self.0[..]) } }

impl ::core::default::Default for U128Builder { fn default() -> Self { U128Builder([Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), ]) } }

impl U128Builder {
    pub const TOTAL_SIZE: usize = 16;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 16;
    pub fn set(mut self, v: [Byte; 16]) -> Self {
        self.0 = v;
        self
    }
    pub fn nth0(mut self, v: Byte) -> Self {
        self.0[0] = v;
        self
    }
    pub fn nth1(mut self, v: Byte) -> Self {
        self.0[1] = v;
        self
    }
    pub fn nth2(mut self, v: Byte) -> Self {
        self.0[2] = v;
        self
    }
    pub fn nth3(mut self, v: Byte) -> Self {
        self.0[3] = v;
        self
    }
    pub fn nth4(mut self, v: Byte) -> Self {
        self.0[4] = v;
        self
    }
    pub fn nth5(mut self, v: Byte) -> Self {
        self.0[5] = v;
        self
    }
    pub fn nth6(mut self, v: Byte) -> Self {
        self.0[6] = v;
        self
    }
    pub fn nth7(mut self, v: Byte) -> Self {
        self.0[7] = v;
        self
    }
    pub fn nth8(mut self, v: Byte) -> Self {
        self.0[8] = v;
        self
    }
    pub fn nth9(mut self, v: Byte) -> Self {
        self.0[9] = v;
        self
    }
    pub fn nth10(mut self, v: Byte) -> Self {
        self.0[10] = v;
        self
    }
    pub fn nth11(mut self, v: Byte) -> Self {
        self.0[11] = v;
        self
    }
    pub fn nth12(mut self, v: Byte) -> Self {
        self.0[12] = v;
        self
    }
    pub fn nth13(mut self, v: Byte) -> Self {
        self.0[13] = v;
        self
    }
    pub fn nth14(mut self, v: Byte) -> Self {
        self.0[14] = v;
        self
    }
    pub fn nth15(mut self, v: Byte) -> Self {
        self.0[15] = v;
        self
    }
}

impl molecule::prelude::Builder for U128Builder {
    type Entity = U128;
    const NAME: &'static str = "U128Builder";
    fn expected_length(&self) -> usize { Self::TOTAL_SIZE }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(self.0[0].as_slice())?;
        writer.write_all(self.0[1].as_slice())?;
        writer.write_all(self.0[2].as_slice())?;
        writer.write_all(self.0[3].as_slice())?;
        writer.write_all(self.0[4].as_slice())?;
        writer.write_all(self.0[5].as_slice())?;
        writer.write_all(self.0[6].as_slice())?;
        writer.write_all(self.0[7].as_slice())?;
        writer.write_all(self.0[8].as_slice())?;
        writer.write_all(self.0[9].as_slice())?;
        writer.write_all(self.0[10].as_slice())?;
        writer.write_all(self.0[11].as_slice())?;
        writer.write_all(self.0[12].as_slice())?;
        writer.write_all(self.0[13].as_slice())?;
        writer.write_all(self.0[14].as_slice())?;
        writer.write_all(self.0[15].as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        U128::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct USize(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for USize {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for USize { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for USize {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for USize {
    fn default() -> Self {
        let v: Vec<u8> = vec![0, 0, 0, 0];
        USize::new_unchecked(v.into())
    }
}

impl USize {
    pub const TOTAL_SIZE: usize = 4;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 4;
    pub fn nth0(&self) -> Byte { Byte::new_unchecked(self.0.slice(0..1)) }
    pub fn nth1(&self) -> Byte { Byte::new_unchecked(self.0.slice(1..2)) }
    pub fn nth2(&self) -> Byte { Byte::new_unchecked(self.0.slice(2..3)) }
    pub fn nth3(&self) -> Byte { Byte::new_unchecked(self.0.slice(3..4)) }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.as_bytes() }
    pub fn as_reader<'r>(&'r self) -> USizeReader<'r> { USizeReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for USize {
    type Builder = USizeBuilder;
    const NAME: &'static str = "USize";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { USize(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { USizeReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { USizeReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set([self.nth0(), self.nth1(), self.nth2(), self.nth3(), ]) }
}

#[derive(Clone, Copy)]
pub struct USizeReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for USizeReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for USizeReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for USizeReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> USizeReader<'r> {
    pub const TOTAL_SIZE: usize = 4;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 4;
    pub fn nth0(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[0..1]) }
    pub fn nth1(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[1..2]) }
    pub fn nth2(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[2..3]) }
    pub fn nth3(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[3..4]) }
    pub fn raw_data(&self) -> &'r [u8] { self.as_slice() }
}

impl<'r> molecule::prelude::Reader<'r> for USizeReader<'r> {
    type Entity = USize;
    const NAME: &'static str = "USizeReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { USizeReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len != Self::TOTAL_SIZE { return ve!(Self , TotalSizeNotMatch , Self :: TOTAL_SIZE , slice_len); }
        Ok(())
    }
}

pub struct USizeBuilder(pub(crate) [Byte; 4]);

impl ::core::fmt::Debug for USizeBuilder { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:?})", Self::NAME, &self.0[..]) } }

impl ::core::default::Default for USizeBuilder { fn default() -> Self { USizeBuilder([Byte::default(), Byte::default(), Byte::default(), Byte::default(), ]) } }

impl USizeBuilder {
    pub const TOTAL_SIZE: usize = 4;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 4;
    pub fn set(mut self, v: [Byte; 4]) -> Self {
        self.0 = v;
        self
    }
    pub fn nth0(mut self, v: Byte) -> Self {
        self.0[0] = v;
        self
    }
    pub fn nth1(mut self, v: Byte) -> Self {
        self.0[1] = v;
        self
    }
    pub fn nth2(mut self, v: Byte) -> Self {
        self.0[2] = v;
        self
    }
    pub fn nth3(mut self, v: Byte) -> Self {
        self.0[3] = v;
        self
    }
}

impl molecule::prelude::Builder for USizeBuilder {
    type Entity = USize;
    const NAME: &'static str = "USizeBuilder";
    fn expected_length(&self) -> usize { Self::TOTAL_SIZE }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(self.0[0].as_slice())?;
        writer.write_all(self.0[1].as_slice())?;
        writer.write_all(self.0[2].as_slice())?;
        writer.write_all(self.0[3].as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        USize::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct Bytes32(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for Bytes32 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for Bytes32 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for Bytes32 {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for Bytes32 {
    fn default() -> Self {
        let v: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        Bytes32::new_unchecked(v.into())
    }
}

impl Bytes32 {
    pub const TOTAL_SIZE: usize = 32;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 32;
    pub fn nth0(&self) -> Byte { Byte::new_unchecked(self.0.slice(0..1)) }
    pub fn nth1(&self) -> Byte { Byte::new_unchecked(self.0.slice(1..2)) }
    pub fn nth2(&self) -> Byte { Byte::new_unchecked(self.0.slice(2..3)) }
    pub fn nth3(&self) -> Byte { Byte::new_unchecked(self.0.slice(3..4)) }
    pub fn nth4(&self) -> Byte { Byte::new_unchecked(self.0.slice(4..5)) }
    pub fn nth5(&self) -> Byte { Byte::new_unchecked(self.0.slice(5..6)) }
    pub fn nth6(&self) -> Byte { Byte::new_unchecked(self.0.slice(6..7)) }
    pub fn nth7(&self) -> Byte { Byte::new_unchecked(self.0.slice(7..8)) }
    pub fn nth8(&self) -> Byte { Byte::new_unchecked(self.0.slice(8..9)) }
    pub fn nth9(&self) -> Byte { Byte::new_unchecked(self.0.slice(9..10)) }
    pub fn nth10(&self) -> Byte { Byte::new_unchecked(self.0.slice(10..11)) }
    pub fn nth11(&self) -> Byte { Byte::new_unchecked(self.0.slice(11..12)) }
    pub fn nth12(&self) -> Byte { Byte::new_unchecked(self.0.slice(12..13)) }
    pub fn nth13(&self) -> Byte { Byte::new_unchecked(self.0.slice(13..14)) }
    pub fn nth14(&self) -> Byte { Byte::new_unchecked(self.0.slice(14..15)) }
    pub fn nth15(&self) -> Byte { Byte::new_unchecked(self.0.slice(15..16)) }
    pub fn nth16(&self) -> Byte { Byte::new_unchecked(self.0.slice(16..17)) }
    pub fn nth17(&self) -> Byte { Byte::new_unchecked(self.0.slice(17..18)) }
    pub fn nth18(&self) -> Byte { Byte::new_unchecked(self.0.slice(18..19)) }
    pub fn nth19(&self) -> Byte { Byte::new_unchecked(self.0.slice(19..20)) }
    pub fn nth20(&self) -> Byte { Byte::new_unchecked(self.0.slice(20..21)) }
    pub fn nth21(&self) -> Byte { Byte::new_unchecked(self.0.slice(21..22)) }
    pub fn nth22(&self) -> Byte { Byte::new_unchecked(self.0.slice(22..23)) }
    pub fn nth23(&self) -> Byte { Byte::new_unchecked(self.0.slice(23..24)) }
    pub fn nth24(&self) -> Byte { Byte::new_unchecked(self.0.slice(24..25)) }
    pub fn nth25(&self) -> Byte { Byte::new_unchecked(self.0.slice(25..26)) }
    pub fn nth26(&self) -> Byte { Byte::new_unchecked(self.0.slice(26..27)) }
    pub fn nth27(&self) -> Byte { Byte::new_unchecked(self.0.slice(27..28)) }
    pub fn nth28(&self) -> Byte { Byte::new_unchecked(self.0.slice(28..29)) }
    pub fn nth29(&self) -> Byte { Byte::new_unchecked(self.0.slice(29..30)) }
    pub fn nth30(&self) -> Byte { Byte::new_unchecked(self.0.slice(30..31)) }
    pub fn nth31(&self) -> Byte { Byte::new_unchecked(self.0.slice(31..32)) }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.as_bytes() }
    pub fn as_reader<'r>(&'r self) -> Bytes32Reader<'r> { Bytes32Reader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for Bytes32 {
    type Builder = Bytes32Builder;
    const NAME: &'static str = "Bytes32";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { Bytes32(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { Bytes32Reader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { Bytes32Reader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set([self.nth0(), self.nth1(), self.nth2(), self.nth3(), self.nth4(), self.nth5(), self.nth6(), self.nth7(), self.nth8(), self.nth9(), self.nth10(), self.nth11(), self.nth12(), self.nth13(), self.nth14(), self.nth15(), self.nth16(), self.nth17(), self.nth18(), self.nth19(), self.nth20(), self.nth21(), self.nth22(), self.nth23(), self.nth24(), self.nth25(), self.nth26(), self.nth27(), self.nth28(), self.nth29(), self.nth30(), self.nth31(), ]) }
}

#[derive(Clone, Copy)]
pub struct Bytes32Reader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for Bytes32Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for Bytes32Reader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for Bytes32Reader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> Bytes32Reader<'r> {
    pub const TOTAL_SIZE: usize = 32;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 32;
    pub fn nth0(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[0..1]) }
    pub fn nth1(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[1..2]) }
    pub fn nth2(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[2..3]) }
    pub fn nth3(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[3..4]) }
    pub fn nth4(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[4..5]) }
    pub fn nth5(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[5..6]) }
    pub fn nth6(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[6..7]) }
    pub fn nth7(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[7..8]) }
    pub fn nth8(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[8..9]) }
    pub fn nth9(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[9..10]) }
    pub fn nth10(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[10..11]) }
    pub fn nth11(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[11..12]) }
    pub fn nth12(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[12..13]) }
    pub fn nth13(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[13..14]) }
    pub fn nth14(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[14..15]) }
    pub fn nth15(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[15..16]) }
    pub fn nth16(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[16..17]) }
    pub fn nth17(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[17..18]) }
    pub fn nth18(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[18..19]) }
    pub fn nth19(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[19..20]) }
    pub fn nth20(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[20..21]) }
    pub fn nth21(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[21..22]) }
    pub fn nth22(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[22..23]) }
    pub fn nth23(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[23..24]) }
    pub fn nth24(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[24..25]) }
    pub fn nth25(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[25..26]) }
    pub fn nth26(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[26..27]) }
    pub fn nth27(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[27..28]) }
    pub fn nth28(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[28..29]) }
    pub fn nth29(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[29..30]) }
    pub fn nth30(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[30..31]) }
    pub fn nth31(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[31..32]) }
    pub fn raw_data(&self) -> &'r [u8] { self.as_slice() }
}

impl<'r> molecule::prelude::Reader<'r> for Bytes32Reader<'r> {
    type Entity = Bytes32;
    const NAME: &'static str = "Bytes32Reader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { Bytes32Reader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len != Self::TOTAL_SIZE { return ve!(Self , TotalSizeNotMatch , Self :: TOTAL_SIZE , slice_len); }
        Ok(())
    }
}

pub struct Bytes32Builder(pub(crate) [Byte; 32]);

impl ::core::fmt::Debug for Bytes32Builder { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:?})", Self::NAME, &self.0[..]) } }

impl ::core::default::Default for Bytes32Builder { fn default() -> Self { Bytes32Builder([Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), Byte::default(), ]) } }

impl Bytes32Builder {
    pub const TOTAL_SIZE: usize = 32;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 32;
    pub fn set(mut self, v: [Byte; 32]) -> Self {
        self.0 = v;
        self
    }
    pub fn nth0(mut self, v: Byte) -> Self {
        self.0[0] = v;
        self
    }
    pub fn nth1(mut self, v: Byte) -> Self {
        self.0[1] = v;
        self
    }
    pub fn nth2(mut self, v: Byte) -> Self {
        self.0[2] = v;
        self
    }
    pub fn nth3(mut self, v: Byte) -> Self {
        self.0[3] = v;
        self
    }
    pub fn nth4(mut self, v: Byte) -> Self {
        self.0[4] = v;
        self
    }
    pub fn nth5(mut self, v: Byte) -> Self {
        self.0[5] = v;
        self
    }
    pub fn nth6(mut self, v: Byte) -> Self {
        self.0[6] = v;
        self
    }
    pub fn nth7(mut self, v: Byte) -> Self {
        self.0[7] = v;
        self
    }
    pub fn nth8(mut self, v: Byte) -> Self {
        self.0[8] = v;
        self
    }
    pub fn nth9(mut self, v: Byte) -> Self {
        self.0[9] = v;
        self
    }
    pub fn nth10(mut self, v: Byte) -> Self {
        self.0[10] = v;
        self
    }
    pub fn nth11(mut self, v: Byte) -> Self {
        self.0[11] = v;
        self
    }
    pub fn nth12(mut self, v: Byte) -> Self {
        self.0[12] = v;
        self
    }
    pub fn nth13(mut self, v: Byte) -> Self {
        self.0[13] = v;
        self
    }
    pub fn nth14(mut self, v: Byte) -> Self {
        self.0[14] = v;
        self
    }
    pub fn nth15(mut self, v: Byte) -> Self {
        self.0[15] = v;
        self
    }
    pub fn nth16(mut self, v: Byte) -> Self {
        self.0[16] = v;
        self
    }
    pub fn nth17(mut self, v: Byte) -> Self {
        self.0[17] = v;
        self
    }
    pub fn nth18(mut self, v: Byte) -> Self {
        self.0[18] = v;
        self
    }
    pub fn nth19(mut self, v: Byte) -> Self {
        self.0[19] = v;
        self
    }
    pub fn nth20(mut self, v: Byte) -> Self {
        self.0[20] = v;
        self
    }
    pub fn nth21(mut self, v: Byte) -> Self {
        self.0[21] = v;
        self
    }
    pub fn nth22(mut self, v: Byte) -> Self {
        self.0[22] = v;
        self
    }
    pub fn nth23(mut self, v: Byte) -> Self {
        self.0[23] = v;
        self
    }
    pub fn nth24(mut self, v: Byte) -> Self {
        self.0[24] = v;
        self
    }
    pub fn nth25(mut self, v: Byte) -> Self {
        self.0[25] = v;
        self
    }
    pub fn nth26(mut self, v: Byte) -> Self {
        self.0[26] = v;
        self
    }
    pub fn nth27(mut self, v: Byte) -> Self {
        self.0[27] = v;
        self
    }
    pub fn nth28(mut self, v: Byte) -> Self {
        self.0[28] = v;
        self
    }
    pub fn nth29(mut self, v: Byte) -> Self {
        self.0[29] = v;
        self
    }
    pub fn nth30(mut self, v: Byte) -> Self {
        self.0[30] = v;
        self
    }
    pub fn nth31(mut self, v: Byte) -> Self {
        self.0[31] = v;
        self
    }
}

impl molecule::prelude::Builder for Bytes32Builder {
    type Entity = Bytes32;
    const NAME: &'static str = "Bytes32Builder";
    fn expected_length(&self) -> usize { Self::TOTAL_SIZE }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(self.0[0].as_slice())?;
        writer.write_all(self.0[1].as_slice())?;
        writer.write_all(self.0[2].as_slice())?;
        writer.write_all(self.0[3].as_slice())?;
        writer.write_all(self.0[4].as_slice())?;
        writer.write_all(self.0[5].as_slice())?;
        writer.write_all(self.0[6].as_slice())?;
        writer.write_all(self.0[7].as_slice())?;
        writer.write_all(self.0[8].as_slice())?;
        writer.write_all(self.0[9].as_slice())?;
        writer.write_all(self.0[10].as_slice())?;
        writer.write_all(self.0[11].as_slice())?;
        writer.write_all(self.0[12].as_slice())?;
        writer.write_all(self.0[13].as_slice())?;
        writer.write_all(self.0[14].as_slice())?;
        writer.write_all(self.0[15].as_slice())?;
        writer.write_all(self.0[16].as_slice())?;
        writer.write_all(self.0[17].as_slice())?;
        writer.write_all(self.0[18].as_slice())?;
        writer.write_all(self.0[19].as_slice())?;
        writer.write_all(self.0[20].as_slice())?;
        writer.write_all(self.0[21].as_slice())?;
        writer.write_all(self.0[22].as_slice())?;
        writer.write_all(self.0[23].as_slice())?;
        writer.write_all(self.0[24].as_slice())?;
        writer.write_all(self.0[25].as_slice())?;
        writer.write_all(self.0[26].as_slice())?;
        writer.write_all(self.0[27].as_slice())?;
        writer.write_all(self.0[28].as_slice())?;
        writer.write_all(self.0[29].as_slice())?;
        writer.write_all(self.0[30].as_slice())?;
        writer.write_all(self.0[31].as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        Bytes32::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct Bytes(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for Bytes {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for Bytes { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for Bytes {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for Bytes {
    fn default() -> Self {
        let v: Vec<u8> = vec![0, 0, 0, 0];
        Bytes::new_unchecked(v.into())
    }
}

impl Bytes {
    pub const ITEM_SIZE: usize = 1;
    pub fn total_size(&self) -> usize { molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count() }
    pub fn item_count(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn len(&self) -> usize { self.item_count() }
    pub fn is_empty(&self) -> bool { self.len() == 0 }
    pub fn get(&self, idx: usize) -> Option<Byte> { if idx >= self.len() { None } else { Some(self.get_unchecked(idx)) } }
    pub fn get_unchecked(&self, idx: usize) -> Byte {
        let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
        let end = start + Self::ITEM_SIZE;
        Byte::new_unchecked(self.0.slice(start..end))
    }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.0.slice(molecule::NUMBER_SIZE..) }
    pub fn as_reader<'r>(&'r self) -> BytesReader<'r> { BytesReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for Bytes {
    type Builder = BytesBuilder;
    const NAME: &'static str = "Bytes";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { Bytes(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().extend(self.into_iter()) }
}

#[derive(Clone, Copy)]
pub struct BytesReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for BytesReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for BytesReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for BytesReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> BytesReader<'r> {
    pub const ITEM_SIZE: usize = 1;
    pub fn total_size(&self) -> usize { molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count() }
    pub fn item_count(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn len(&self) -> usize { self.item_count() }
    pub fn is_empty(&self) -> bool { self.len() == 0 }
    pub fn get(&self, idx: usize) -> Option<ByteReader<'r>> { if idx >= self.len() { None } else { Some(self.get_unchecked(idx)) } }
    pub fn get_unchecked(&self, idx: usize) -> ByteReader<'r> {
        let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
        let end = start + Self::ITEM_SIZE;
        ByteReader::new_unchecked(&self.as_slice()[start..end])
    }
    pub fn raw_data(&self) -> &'r [u8] { &self.as_slice()[molecule::NUMBER_SIZE..] }
}

impl<'r> molecule::prelude::Reader<'r> for BytesReader<'r> {
    type Entity = Bytes;
    const NAME: &'static str = "BytesReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { BytesReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len < molecule::NUMBER_SIZE { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE , slice_len); }
        let item_count = molecule::unpack_number(slice) as usize;
        if item_count == 0 {
            if slice_len != molecule::NUMBER_SIZE { return ve!(Self , TotalSizeNotMatch , molecule :: NUMBER_SIZE , slice_len); }
            return Ok(());
        }
        let total_size = molecule::NUMBER_SIZE + Self::ITEM_SIZE * item_count;
        if slice_len != total_size { return ve!(Self , TotalSizeNotMatch , total_size , slice_len); }
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct BytesBuilder(pub(crate) Vec<Byte>);

impl BytesBuilder {
    pub const ITEM_SIZE: usize = 1;
    pub fn set(mut self, v: Vec<Byte>) -> Self {
        self.0 = v;
        self
    }
    pub fn push(mut self, v: Byte) -> Self {
        self.0.push(v);
        self
    }
    pub fn extend<T: ::core::iter::IntoIterator<Item=Byte>>(mut self, iter: T) -> Self {
        for elem in iter { self.0.push(elem); }
        self
    }
    pub fn replace(&mut self, index: usize, v: Byte) -> Option<Byte> { self.0.get_mut(index).map(|item| ::core::mem::replace(item, v)) }
}

impl molecule::prelude::Builder for BytesBuilder {
    type Entity = Bytes;
    const NAME: &'static str = "BytesBuilder";
    fn expected_length(&self) -> usize { molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(&molecule::pack_number(self.0.len() as molecule::Number))?;
        for inner in &self.0[..] { writer.write_all(inner.as_slice())?; }
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        Bytes::new_unchecked(inner.into())
    }
}

pub struct BytesIterator(Bytes, usize, usize);

impl ::core::iter::Iterator for BytesIterator {
    type Item = Byte;
    fn next(&mut self) -> Option<Self::Item> {
        if self.1 >= self.2 { None } else {
            let ret = self.0.get_unchecked(self.1);
            self.1 += 1;
            Some(ret)
        }
    }
}

impl ::core::iter::ExactSizeIterator for BytesIterator { fn len(&self) -> usize { self.2 - self.1 } }

impl ::core::iter::IntoIterator for Bytes {
    type Item = Byte;
    type IntoIter = BytesIterator;
    fn into_iter(self) -> Self::IntoIter {
        let len = self.len();
        BytesIterator(self, 0, len)
    }
}

#[derive(Clone)]
pub struct BytesVec(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for BytesVec {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for BytesVec { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for BytesVec {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} [", Self::NAME)?;
        for i in 0..self.len() { if i == 0 { write!(f, "{}", self.get_unchecked(i))?; } else { write!(f, ", {}", self.get_unchecked(i))?; } }
        write!(f, "]")
    }
}

impl ::core::default::Default for BytesVec {
    fn default() -> Self {
        let v: Vec<u8> = vec![4, 0, 0, 0];
        BytesVec::new_unchecked(v.into())
    }
}

impl BytesVec {
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn item_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn len(&self) -> usize { self.item_count() }
    pub fn is_empty(&self) -> bool { self.len() == 0 }
    pub fn get(&self, idx: usize) -> Option<Bytes> { if idx >= self.len() { None } else { Some(self.get_unchecked(idx)) } }
    pub fn get_unchecked(&self, idx: usize) -> Bytes {
        let slice = self.as_slice();
        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
        if idx == self.len() - 1 { Bytes::new_unchecked(self.0.slice(start..)) } else {
            let end_idx = start_idx + molecule::NUMBER_SIZE;
            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
            Bytes::new_unchecked(self.0.slice(start..end))
        }
    }
    pub fn as_reader<'r>(&'r self) -> BytesVecReader<'r> { BytesVecReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for BytesVec {
    type Builder = BytesVecBuilder;
    const NAME: &'static str = "BytesVec";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { BytesVec(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesVecReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesVecReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().extend(self.into_iter()) }
}

#[derive(Clone, Copy)]
pub struct BytesVecReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for BytesVecReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for BytesVecReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for BytesVecReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} [", Self::NAME)?;
        for i in 0..self.len() { if i == 0 { write!(f, "{}", self.get_unchecked(i))?; } else { write!(f, ", {}", self.get_unchecked(i))?; } }
        write!(f, "]")
    }
}

impl<'r> BytesVecReader<'r> {
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn item_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn len(&self) -> usize { self.item_count() }
    pub fn is_empty(&self) -> bool { self.len() == 0 }
    pub fn get(&self, idx: usize) -> Option<BytesReader<'r>> { if idx >= self.len() { None } else { Some(self.get_unchecked(idx)) } }
    pub fn get_unchecked(&self, idx: usize) -> BytesReader<'r> {
        let slice = self.as_slice();
        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
        if idx == self.len() - 1 { BytesReader::new_unchecked(&self.as_slice()[start..]) } else {
            let end_idx = start_idx + molecule::NUMBER_SIZE;
            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
            BytesReader::new_unchecked(&self.as_slice()[start..end])
        }
    }
}

impl<'r> molecule::prelude::Reader<'r> for BytesVecReader<'r> {
    type Entity = BytesVec;
    const NAME: &'static str = "BytesVecReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { BytesVecReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len < molecule::NUMBER_SIZE { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE , slice_len); }
        let total_size = molecule::unpack_number(slice) as usize;
        if slice_len != total_size { return ve!(Self , TotalSizeNotMatch , total_size , slice_len); }
        if slice_len == molecule::NUMBER_SIZE { return Ok(()); }
        if slice_len < molecule::NUMBER_SIZE * 2 { return ve!(Self , TotalSizeNotMatch , molecule :: NUMBER_SIZE * 2 , slice_len); }
        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { return ve!(Self , OffsetsNotMatch); }
        if slice_len < offset_first { return ve!(Self , HeaderIsBroken , offset_first , slice_len); }
        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first].chunks_exact(molecule::NUMBER_SIZE).map(|x| molecule::unpack_number(x) as usize).collect();
        offsets.push(total_size);
        if offsets.windows(2).any(|i| i[0] > i[1]) { return ve!(Self , OffsetsNotMatch); }
        for pair in offsets.windows(2) {
            let start = pair[0];
            let end = pair[1];
            BytesReader::verify(&slice[start..end], compatible)?;
        }
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct BytesVecBuilder(pub(crate) Vec<Bytes>);

impl BytesVecBuilder {
    pub fn set(mut self, v: Vec<Bytes>) -> Self {
        self.0 = v;
        self
    }
    pub fn push(mut self, v: Bytes) -> Self {
        self.0.push(v);
        self
    }
    pub fn extend<T: ::core::iter::IntoIterator<Item=Bytes>>(mut self, iter: T) -> Self {
        for elem in iter { self.0.push(elem); }
        self
    }
    pub fn replace(&mut self, index: usize, v: Bytes) -> Option<Bytes> { self.0.get_mut(index).map(|item| ::core::mem::replace(item, v)) }
}

impl molecule::prelude::Builder for BytesVecBuilder {
    type Entity = BytesVec;
    const NAME: &'static str = "BytesVecBuilder";
    fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (self.0.len() + 1) + self.0.iter().map(|inner| inner.as_slice().len()).sum::<usize>() }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        let item_count = self.0.len();
        if item_count == 0 { writer.write_all(&molecule::pack_number(molecule::NUMBER_SIZE as molecule::Number))?; } else {
            let (total_size, offsets) = self.0.iter().fold((molecule::NUMBER_SIZE * (item_count + 1), Vec::with_capacity(item_count), ), |(start, mut offsets), inner| {
                offsets.push(start);
                (start + inner.as_slice().len(), offsets)
            }, );
            writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
            for offset in offsets.into_iter() { writer.write_all(&molecule::pack_number(offset as molecule::Number))?; }
            for inner in self.0.iter() { writer.write_all(inner.as_slice())?; }
        }
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        BytesVec::new_unchecked(inner.into())
    }
}

pub struct BytesVecIterator(BytesVec, usize, usize);

impl ::core::iter::Iterator for BytesVecIterator {
    type Item = Bytes;
    fn next(&mut self) -> Option<Self::Item> {
        if self.1 >= self.2 { None } else {
            let ret = self.0.get_unchecked(self.1);
            self.1 += 1;
            Some(ret)
        }
    }
}

impl ::core::iter::ExactSizeIterator for BytesVecIterator { fn len(&self) -> usize { self.2 - self.1 } }

impl ::core::iter::IntoIterator for BytesVec {
    type Item = Bytes;
    type IntoIter = BytesVecIterator;
    fn into_iter(self) -> Self::IntoIter {
        let len = self.len();
        BytesVecIterator(self, 0, len)
    }
}

impl<'r> BytesVecReader<'r> { pub fn iter<'t>(&'t self) -> BytesVecReaderIterator<'t, 'r> { BytesVecReaderIterator(&self, 0, self.len()) } }

pub struct BytesVecReaderIterator<'t, 'r> (&'t BytesVecReader<'r>, usize, usize);

impl<'t : 'r, 'r> ::core::iter::Iterator for BytesVecReaderIterator<'t, 'r> {
    type Item = BytesReader<'t>;
    fn next(&mut self) -> Option<Self::Item> {
        if self.1 >= self.2 { None } else {
            let ret = self.0.get_unchecked(self.1);
            self.1 += 1;
            Some(ret)
        }
    }
}

impl<'t : 'r, 'r> ::core::iter::ExactSizeIterator for BytesVecReaderIterator<'t, 'r> { fn len(&self) -> usize { self.2 - self.1 } }

#[derive(Clone)]
pub struct Bool(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for Bool {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for Bool { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for Bool {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl ::core::default::Default for Bool {
    fn default() -> Self {
        let v: Vec<u8> = vec![0];
        Bool::new_unchecked(v.into())
    }
}

impl Bool {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn nth0(&self) -> Byte { Byte::new_unchecked(self.0.slice(0..1)) }
    pub fn raw_data(&self) -> molecule::bytes::Bytes { self.as_bytes() }
    pub fn as_reader<'r>(&'r self) -> BoolReader<'r> { BoolReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for Bool {
    type Builder = BoolBuilder;
    const NAME: &'static str = "Bool";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { Bool(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BoolReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BoolReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set([self.nth0(), ]) }
}

#[derive(Clone, Copy)]
pub struct BoolReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for BoolReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for BoolReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for BoolReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        let raw_data = hex_string(&self.raw_data());
        write!(f, "{}(0x{})", Self::NAME, raw_data)
    }
}

impl<'r> BoolReader<'r> {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn nth0(&self) -> ByteReader<'r> { ByteReader::new_unchecked(&self.as_slice()[0..1]) }
    pub fn raw_data(&self) -> &'r [u8] { self.as_slice() }
}

impl<'r> molecule::prelude::Reader<'r> for BoolReader<'r> {
    type Entity = Bool;
    const NAME: &'static str = "BoolReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { BoolReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len != Self::TOTAL_SIZE { return ve!(Self , TotalSizeNotMatch , Self :: TOTAL_SIZE , slice_len); }
        Ok(())
    }
}

pub struct BoolBuilder(pub(crate) [Byte; 1]);

impl ::core::fmt::Debug for BoolBuilder { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:?})", Self::NAME, &self.0[..]) } }

impl ::core::default::Default for BoolBuilder { fn default() -> Self { BoolBuilder([Byte::default(), ]) } }

impl BoolBuilder {
    pub const TOTAL_SIZE: usize = 1;
    pub const ITEM_SIZE: usize = 1;
    pub const ITEM_COUNT: usize = 1;
    pub fn set(mut self, v: [Byte; 1]) -> Self {
        self.0 = v;
        self
    }
    pub fn nth0(mut self, v: Byte) -> Self {
        self.0[0] = v;
        self
    }
}

impl molecule::prelude::Builder for BoolBuilder {
    type Entity = Bool;
    const NAME: &'static str = "BoolBuilder";
    fn expected_length(&self) -> usize { Self::TOTAL_SIZE }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        writer.write_all(self.0[0].as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        Bool::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct BoolOpt(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for BoolOpt {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for BoolOpt { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for BoolOpt { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(v) = self.to_opt() { write!(f, "{}(Some({}))", Self::NAME, v) } else { write!(f, "{}(None)", Self::NAME) } } }

impl ::core::default::Default for BoolOpt {
    fn default() -> Self {
        let v: Vec<u8> = vec![];
        BoolOpt::new_unchecked(v.into())
    }
}

impl BoolOpt {
    pub fn is_none(&self) -> bool { self.0.is_empty() }
    pub fn is_some(&self) -> bool { !self.0.is_empty() }
    pub fn to_opt(&self) -> Option<Bool> { if self.is_none() { None } else { Some(Bool::new_unchecked(self.0.clone())) } }
    pub fn as_reader<'r>(&'r self) -> BoolOptReader<'r> { BoolOptReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for BoolOpt {
    type Builder = BoolOptBuilder;
    const NAME: &'static str = "BoolOpt";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { BoolOpt(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BoolOptReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BoolOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set(self.to_opt()) }
}

#[derive(Clone, Copy)]
pub struct BoolOptReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for BoolOptReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for BoolOptReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for BoolOptReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(v) = self.to_opt() { write!(f, "{}(Some({}))", Self::NAME, v) } else { write!(f, "{}(None)", Self::NAME) } } }

impl<'r> BoolOptReader<'r> {
    pub fn is_none(&self) -> bool { self.0.is_empty() }
    pub fn is_some(&self) -> bool { !self.0.is_empty() }
    pub fn to_opt(&self) -> Option<BoolReader<'r>> { if self.is_none() { None } else { Some(BoolReader::new_unchecked(self.as_slice())) } }
}

impl<'r> molecule::prelude::Reader<'r> for BoolOptReader<'r> {
    type Entity = BoolOpt;
    const NAME: &'static str = "BoolOptReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { BoolOptReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
        if !slice.is_empty() { BoolReader::verify(&slice[..], compatible)?; }
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct BoolOptBuilder(pub(crate) Option<Bool>);

impl BoolOptBuilder {
    pub fn set(mut self, v: Option<Bool>) -> Self {
        self.0 = v;
        self
    }
}

impl molecule::prelude::Builder for BoolOptBuilder {
    type Entity = BoolOpt;
    const NAME: &'static str = "BoolOptBuilder";
    fn expected_length(&self) -> usize { self.0.as_ref().map(|ref inner| inner.as_slice().len()).unwrap_or(0) }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> { self.0.as_ref().map(|ref inner| writer.write_all(inner.as_slice())).unwrap_or(Ok(())) }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        BoolOpt::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct BytesOpt(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for BytesOpt {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for BytesOpt { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for BytesOpt { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(v) = self.to_opt() { write!(f, "{}(Some({}))", Self::NAME, v) } else { write!(f, "{}(None)", Self::NAME) } } }

impl ::core::default::Default for BytesOpt {
    fn default() -> Self {
        let v: Vec<u8> = vec![];
        BytesOpt::new_unchecked(v.into())
    }
}

impl BytesOpt {
    pub fn is_none(&self) -> bool { self.0.is_empty() }
    pub fn is_some(&self) -> bool { !self.0.is_empty() }
    pub fn to_opt(&self) -> Option<Bytes> { if self.is_none() { None } else { Some(Bytes::new_unchecked(self.0.clone())) } }
    pub fn as_reader<'r>(&'r self) -> BytesOptReader<'r> { BytesOptReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for BytesOpt {
    type Builder = BytesOptBuilder;
    const NAME: &'static str = "BytesOpt";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { BytesOpt(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesOptReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { BytesOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().set(self.to_opt()) }
}

#[derive(Clone, Copy)]
pub struct BytesOptReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for BytesOptReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for BytesOptReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for BytesOptReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(v) = self.to_opt() { write!(f, "{}(Some({}))", Self::NAME, v) } else { write!(f, "{}(None)", Self::NAME) } } }

impl<'r> BytesOptReader<'r> {
    pub fn is_none(&self) -> bool { self.0.is_empty() }
    pub fn is_some(&self) -> bool { !self.0.is_empty() }
    pub fn to_opt(&self) -> Option<BytesReader<'r>> { if self.is_none() { None } else { Some(BytesReader::new_unchecked(self.as_slice())) } }
}

impl<'r> molecule::prelude::Reader<'r> for BytesOptReader<'r> {
    type Entity = BytesOpt;
    const NAME: &'static str = "BytesOptReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { BytesOptReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
        if !slice.is_empty() { BytesReader::verify(&slice[..], compatible)?; }
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct BytesOptBuilder(pub(crate) Option<Bytes>);

impl BytesOptBuilder {
    pub fn set(mut self, v: Option<Bytes>) -> Self {
        self.0 = v;
        self
    }
}

impl molecule::prelude::Builder for BytesOptBuilder {
    type Entity = BytesOpt;
    const NAME: &'static str = "BytesOptBuilder";
    fn expected_length(&self) -> usize { self.0.as_ref().map(|ref inner| inner.as_slice().len()).unwrap_or(0) }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> { self.0.as_ref().map(|ref inner| writer.write_all(inner.as_slice())).unwrap_or(Ok(())) }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        BytesOpt::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct SporeData(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for SporeData {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for SporeData { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for SporeData {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} {{ ", Self::NAME)?;
        write!(f, "{}: {}", "content_type", self.content_type())?;
        write!(f, ", {}: {}", "content", self.content())?;
        write!(f, ", {}: {}", "cluster_id", self.cluster_id())?;
        let extra_count = self.count_extra_fields();
        if extra_count != 0 { write!(f, ", .. ({} fields)", extra_count)?; }
        write!(f, " }}")
    }
}

impl ::core::default::Default for SporeData {
    fn default() -> Self {
        let v: Vec<u8> = vec![24, 0, 0, 0, 16, 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        SporeData::new_unchecked(v.into())
    }
}

impl SporeData {
    pub const FIELD_COUNT: usize = 3;
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn field_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn count_extra_fields(&self) -> usize { self.field_count() - Self::FIELD_COUNT }
    pub fn has_extra_fields(&self) -> bool { Self::FIELD_COUNT != self.field_count() }
    pub fn content_type(&self) -> Bytes {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[4..]) as usize;
        let end = molecule::unpack_number(&slice[8..]) as usize;
        Bytes::new_unchecked(self.0.slice(start..end))
    }
    pub fn content(&self) -> Bytes {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[8..]) as usize;
        let end = molecule::unpack_number(&slice[12..]) as usize;
        Bytes::new_unchecked(self.0.slice(start..end))
    }
    pub fn cluster_id(&self) -> BytesOpt {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[12..]) as usize;
        if self.has_extra_fields() {
            let end = molecule::unpack_number(&slice[16..]) as usize;
            BytesOpt::new_unchecked(self.0.slice(start..end))
        } else { BytesOpt::new_unchecked(self.0.slice(start..)) }
    }
    pub fn as_reader<'r>(&'r self) -> SporeDataReader<'r> { SporeDataReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for SporeData {
    type Builder = SporeDataBuilder;
    const NAME: &'static str = "SporeData";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { SporeData(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { SporeDataReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { SporeDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().content_type(self.content_type()).content(self.content()).cluster_id(self.cluster_id()) }
}

#[derive(Clone, Copy)]
pub struct SporeDataReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for SporeDataReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for SporeDataReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for SporeDataReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} {{ ", Self::NAME)?;
        write!(f, "{}: {}", "content_type", self.content_type())?;
        write!(f, ", {}: {}", "content", self.content())?;
        write!(f, ", {}: {}", "cluster_id", self.cluster_id())?;
        let extra_count = self.count_extra_fields();
        if extra_count != 0 { write!(f, ", .. ({} fields)", extra_count)?; }
        write!(f, " }}")
    }
}

impl<'r> SporeDataReader<'r> {
    pub const FIELD_COUNT: usize = 3;
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn field_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn count_extra_fields(&self) -> usize { self.field_count() - Self::FIELD_COUNT }
    pub fn has_extra_fields(&self) -> bool { Self::FIELD_COUNT != self.field_count() }
    pub fn content_type(&self) -> BytesReader<'r> {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[4..]) as usize;
        let end = molecule::unpack_number(&slice[8..]) as usize;
        BytesReader::new_unchecked(&self.as_slice()[start..end])
    }
    pub fn content(&self) -> BytesReader<'r> {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[8..]) as usize;
        let end = molecule::unpack_number(&slice[12..]) as usize;
        BytesReader::new_unchecked(&self.as_slice()[start..end])
    }
    pub fn cluster_id(&self) -> BytesOptReader<'r> {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[12..]) as usize;
        if self.has_extra_fields() {
            let end = molecule::unpack_number(&slice[16..]) as usize;
            BytesOptReader::new_unchecked(&self.as_slice()[start..end])
        } else { BytesOptReader::new_unchecked(&self.as_slice()[start..]) }
    }
}

impl<'r> molecule::prelude::Reader<'r> for SporeDataReader<'r> {
    type Entity = SporeData;
    const NAME: &'static str = "SporeDataReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { SporeDataReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len < molecule::NUMBER_SIZE { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE , slice_len); }
        let total_size = molecule::unpack_number(slice) as usize;
        if slice_len != total_size { return ve!(Self , TotalSizeNotMatch , total_size , slice_len); }
        if slice_len == molecule::NUMBER_SIZE && Self::FIELD_COUNT == 0 { return Ok(()); }
        if slice_len < molecule::NUMBER_SIZE * 2 { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE * 2 , slice_len); }
        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { return ve!(Self , OffsetsNotMatch); }
        if slice_len < offset_first { return ve!(Self , HeaderIsBroken , offset_first , slice_len); }
        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
        if field_count < Self::FIELD_COUNT { return ve!(Self , FieldCountNotMatch , Self :: FIELD_COUNT , field_count); } else if !compatible && field_count > Self::FIELD_COUNT { return ve!(Self , FieldCountNotMatch , Self :: FIELD_COUNT , field_count); };
        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first].chunks_exact(molecule::NUMBER_SIZE).map(|x| molecule::unpack_number(x) as usize).collect();
        offsets.push(total_size);
        if offsets.windows(2).any(|i| i[0] > i[1]) { return ve!(Self , OffsetsNotMatch); }
        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
        BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
        BytesOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct SporeDataBuilder {
    pub(crate) content_type: Bytes,
    pub(crate) content: Bytes,
    pub(crate) cluster_id: BytesOpt,
}

impl SporeDataBuilder {
    pub const FIELD_COUNT: usize = 3;
    pub fn content_type(mut self, v: Bytes) -> Self {
        self.content_type = v;
        self
    }
    pub fn content(mut self, v: Bytes) -> Self {
        self.content = v;
        self
    }
    pub fn cluster_id(mut self, v: BytesOpt) -> Self {
        self.cluster_id = v;
        self
    }
}

impl molecule::prelude::Builder for SporeDataBuilder {
    type Entity = SporeData;
    const NAME: &'static str = "SporeDataBuilder";
    fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.content_type.as_slice().len() + self.content.as_slice().len() + self.cluster_id.as_slice().len() }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
        offsets.push(total_size);
        total_size += self.content_type.as_slice().len();
        offsets.push(total_size);
        total_size += self.content.as_slice().len();
        offsets.push(total_size);
        total_size += self.cluster_id.as_slice().len();
        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
        for offset in offsets.into_iter() { writer.write_all(&molecule::pack_number(offset as molecule::Number))?; }
        writer.write_all(self.content_type.as_slice())?;
        writer.write_all(self.content.as_slice())?;
        writer.write_all(self.cluster_id.as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        SporeData::new_unchecked(inner.into())
    }
}

#[derive(Clone)]
pub struct ClusterData(molecule::bytes::Bytes);

impl ::core::fmt::LowerHex for ClusterData {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl ::core::fmt::Debug for ClusterData { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl ::core::fmt::Display for ClusterData {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} {{ ", Self::NAME)?;
        write!(f, "{}: {}", "name", self.name())?;
        write!(f, ", {}: {}", "description", self.description())?;
        let extra_count = self.count_extra_fields();
        if extra_count != 0 { write!(f, ", .. ({} fields)", extra_count)?; }
        write!(f, " }}")
    }
}

impl ::core::default::Default for ClusterData {
    fn default() -> Self {
        let v: Vec<u8> = vec![20, 0, 0, 0, 12, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        ClusterData::new_unchecked(v.into())
    }
}

impl ClusterData {
    pub const FIELD_COUNT: usize = 2;
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn field_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn count_extra_fields(&self) -> usize { self.field_count() - Self::FIELD_COUNT }
    pub fn has_extra_fields(&self) -> bool { Self::FIELD_COUNT != self.field_count() }
    pub fn name(&self) -> Bytes {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[4..]) as usize;
        let end = molecule::unpack_number(&slice[8..]) as usize;
        Bytes::new_unchecked(self.0.slice(start..end))
    }
    pub fn description(&self) -> Bytes {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[8..]) as usize;
        if self.has_extra_fields() {
            let end = molecule::unpack_number(&slice[12..]) as usize;
            Bytes::new_unchecked(self.0.slice(start..end))
        } else { Bytes::new_unchecked(self.0.slice(start..)) }
    }
    pub fn as_reader<'r>(&'r self) -> ClusterDataReader<'r> { ClusterDataReader::new_unchecked(self.as_slice()) }
}

impl molecule::prelude::Entity for ClusterData {
    type Builder = ClusterDataBuilder;
    const NAME: &'static str = "ClusterData";
    fn new_unchecked(data: molecule::bytes::Bytes) -> Self { ClusterData(data) }
    fn as_bytes(&self) -> molecule::bytes::Bytes { self.0.clone() }
    fn as_slice(&self) -> &[u8] { &self.0[..] }
    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { ClusterDataReader::from_slice(slice).map(|reader| reader.to_entity()) }
    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> { ClusterDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) }
    fn new_builder() -> Self::Builder { ::core::default::Default::default() }
    fn as_builder(self) -> Self::Builder { Self::new_builder().name(self.name()).description(self.description()) }
}

#[derive(Clone, Copy)]
pub struct ClusterDataReader<'r> (&'r [u8]);

impl<'r> ::core::fmt::LowerHex for ClusterDataReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        use molecule::hex_string;
        if f.alternate() { write!(f, "0x")?; }
        write!(f, "{}", hex_string(self.as_slice()))
    }
}

impl<'r> ::core::fmt::Debug for ClusterDataReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{}({:#x})", Self::NAME, self) } }

impl<'r> ::core::fmt::Display for ClusterDataReader<'r> {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        write!(f, "{} {{ ", Self::NAME)?;
        write!(f, "{}: {}", "name", self.name())?;
        write!(f, ", {}: {}", "description", self.description())?;
        let extra_count = self.count_extra_fields();
        if extra_count != 0 { write!(f, ", .. ({} fields)", extra_count)?; }
        write!(f, " }}")
    }
}

impl<'r> ClusterDataReader<'r> {
    pub const FIELD_COUNT: usize = 2;
    pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize }
    pub fn field_count(&self) -> usize { if self.total_size() == molecule::NUMBER_SIZE { 0 } else { (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 } }
    pub fn count_extra_fields(&self) -> usize { self.field_count() - Self::FIELD_COUNT }
    pub fn has_extra_fields(&self) -> bool { Self::FIELD_COUNT != self.field_count() }
    pub fn name(&self) -> BytesReader<'r> {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[4..]) as usize;
        let end = molecule::unpack_number(&slice[8..]) as usize;
        BytesReader::new_unchecked(&self.as_slice()[start..end])
    }
    pub fn description(&self) -> BytesReader<'r> {
        let slice = self.as_slice();
        let start = molecule::unpack_number(&slice[8..]) as usize;
        if self.has_extra_fields() {
            let end = molecule::unpack_number(&slice[12..]) as usize;
            BytesReader::new_unchecked(&self.as_slice()[start..end])
        } else { BytesReader::new_unchecked(&self.as_slice()[start..]) }
    }
}

impl<'r> molecule::prelude::Reader<'r> for ClusterDataReader<'r> {
    type Entity = ClusterData;
    const NAME: &'static str = "ClusterDataReader";
    fn to_entity(&self) -> Self::Entity { Self::Entity::new_unchecked(self.as_slice().to_owned().into()) }
    fn new_unchecked(slice: &'r [u8]) -> Self { ClusterDataReader(slice) }
    fn as_slice(&self) -> &'r [u8] { self.0 }
    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
        use molecule::verification_error as ve;
        let slice_len = slice.len();
        if slice_len < molecule::NUMBER_SIZE { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE , slice_len); }
        let total_size = molecule::unpack_number(slice) as usize;
        if slice_len != total_size { return ve!(Self , TotalSizeNotMatch , total_size , slice_len); }
        if slice_len == molecule::NUMBER_SIZE && Self::FIELD_COUNT == 0 { return Ok(()); }
        if slice_len < molecule::NUMBER_SIZE * 2 { return ve!(Self , HeaderIsBroken , molecule :: NUMBER_SIZE * 2 , slice_len); }
        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { return ve!(Self , OffsetsNotMatch); }
        if slice_len < offset_first { return ve!(Self , HeaderIsBroken , offset_first , slice_len); }
        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
        if field_count < Self::FIELD_COUNT { return ve!(Self , FieldCountNotMatch , Self :: FIELD_COUNT , field_count); } else if !compatible && field_count > Self::FIELD_COUNT { return ve!(Self , FieldCountNotMatch , Self :: FIELD_COUNT , field_count); };
        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first].chunks_exact(molecule::NUMBER_SIZE).map(|x| molecule::unpack_number(x) as usize).collect();
        offsets.push(total_size);
        if offsets.windows(2).any(|i| i[0] > i[1]) { return ve!(Self , OffsetsNotMatch); }
        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
        BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
        Ok(())
    }
}

#[derive(Debug, Default)]
pub struct ClusterDataBuilder {
    pub(crate) name: Bytes,
    pub(crate) description: Bytes,
}

impl ClusterDataBuilder {
    pub const FIELD_COUNT: usize = 2;
    pub fn name(mut self, v: Bytes) -> Self {
        self.name = v;
        self
    }
    pub fn description(mut self, v: Bytes) -> Self {
        self.description = v;
        self
    }
}

impl molecule::prelude::Builder for ClusterDataBuilder {
    type Entity = ClusterData;
    const NAME: &'static str = "ClusterDataBuilder";
    fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.name.as_slice().len() + self.description.as_slice().len() }
    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
        offsets.push(total_size);
        total_size += self.name.as_slice().len();
        offsets.push(total_size);
        total_size += self.description.as_slice().len();
        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
        for offset in offsets.into_iter() { writer.write_all(&molecule::pack_number(offset as molecule::Number))?; }
        writer.write_all(self.name.as_slice())?;
        writer.write_all(self.description.as_slice())?;
        Ok(())
    }
    fn build(&self) -> Self::Entity {
        let mut inner = Vec::with_capacity(self.expected_length());
        self.write(&mut inner).unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
        ClusterData::new_unchecked(inner.into())
    }
}