From d1e5b0a6f90d1cebfbc5a0c7c0c357785c69d002 Mon Sep 17 00:00:00 2001 From: xjd Date: Mon, 14 Aug 2023 10:46:50 +0800 Subject: [PATCH] Add lazy reader tests Including fuzzing tests --- Makefile | 12 +- examples/lazy-reader-tests/.gitignore | 2 +- examples/lazy-reader-tests/Cargo.lock | 314 +- examples/lazy-reader-tests/Cargo.toml | 15 +- examples/lazy-reader-tests/Makefile | 6 +- examples/lazy-reader-tests/fuzz/.gitignore | 5 + examples/lazy-reader-tests/fuzz/Cargo.lock | 154 + examples/lazy-reader-tests/fuzz/Cargo.toml | 28 + examples/lazy-reader-tests/fuzz/Makefile | 17 + .../fuzz/fuzz_targets/fuzz_target_1.rs | 19 + .../lazy-reader-tests/fuzz/rust-toolchain | 1 + examples/lazy-reader-tests/src/lib.rs | 210 +- .../lazy-reader-tests/src/types_all_data.rs | 542 + examples/lazy-reader-tests/src/types_api.rs | 20507 ++++++++++++++++ .../src/{types.rs => types_api2.rs} | 122 +- .../lazy-reader-tests/src/types_api2_mol2.rs | 795 + examples/lazy-reader-tests/src/types_array.rs | 367 + .../src/types_moleculec_check.rs | 680 + .../lazy-reader-tests/src/types_option.rs | 217 + .../lazy-reader-tests/src/types_struct.rs | 282 + examples/lazy-reader-tests/src/types_table.rs | 302 + examples/lazy-reader-tests/src/types_vec.rs | 218 + 22 files changed, 24526 insertions(+), 289 deletions(-) create mode 100644 examples/lazy-reader-tests/fuzz/.gitignore create mode 100644 examples/lazy-reader-tests/fuzz/Cargo.lock create mode 100644 examples/lazy-reader-tests/fuzz/Cargo.toml create mode 100644 examples/lazy-reader-tests/fuzz/Makefile create mode 100644 examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs create mode 100644 examples/lazy-reader-tests/fuzz/rust-toolchain create mode 100644 examples/lazy-reader-tests/src/types_all_data.rs create mode 100644 examples/lazy-reader-tests/src/types_api.rs rename examples/lazy-reader-tests/src/{types.rs => types_api2.rs} (99%) create mode 100644 examples/lazy-reader-tests/src/types_api2_mol2.rs create mode 100644 examples/lazy-reader-tests/src/types_array.rs create mode 100644 examples/lazy-reader-tests/src/types_moleculec_check.rs create mode 100644 examples/lazy-reader-tests/src/types_option.rs create mode 100644 examples/lazy-reader-tests/src/types_struct.rs create mode 100644 examples/lazy-reader-tests/src/types_table.rs create mode 100644 examples/lazy-reader-tests/src/types_vec.rs diff --git a/Makefile b/Makefile index 8e39093..d8c8650 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ ci: @set -eu; \ export RUSTFLAGS='-D warnings'; \ make fmt clippy; \ + make ci-lazy-reader; \ make ci-examples ci-crates; \ echo "Success!" @@ -63,4 +64,13 @@ ci-crates: ci-examples: @set -eu; \ cd examples/ci-tests; \ - make clean test + make clean test; \ + cd - > /dev/null; \ + +ci-lazy-reader: + @set -eu; \ + cd examples/lazy-reader-tests; \ + make test; \ + cd - > /dev/null; \ + + diff --git a/examples/lazy-reader-tests/.gitignore b/examples/lazy-reader-tests/.gitignore index 2f7896d..eb5a316 100644 --- a/examples/lazy-reader-tests/.gitignore +++ b/examples/lazy-reader-tests/.gitignore @@ -1 +1 @@ -target/ +target diff --git a/examples/lazy-reader-tests/Cargo.lock b/examples/lazy-reader-tests/Cargo.lock index f522eab..8b3bc80 100644 --- a/examples/lazy-reader-tests/Cargo.lock +++ b/examples/lazy-reader-tests/Cargo.lock @@ -2,32 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - [[package]] name = "bytes" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" - -[[package]] -name = "case" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" - -[[package]] -name = "cc" -version = "1.0.78" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cfg-if" @@ -36,55 +15,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "cpufeatures" -version = "0.2.5" +name = "getrandom" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ + "cfg-if", "libc", + "wasi", ] [[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +name = "lazy-reader-tests" +version = "0.1.0" dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", + "lazy_static", + "molecule", + "rand", ] [[package]] -name = "faster-hex" -version = "0.6.1" +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" - -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "molecule" @@ -92,244 +52,46 @@ version = "0.7.5" dependencies = [ "bytes", "cfg-if", - "faster-hex", -] - -[[package]] -name = "molecule-codegen" -version = "0.7.5" -dependencies = [ - "case", - "molecule", - "pest", - "pest_derive", - "proc-macro2", - "property", - "quote", - "same-file", - "semver", - "syn 2.0.28", -] - -[[package]] -name = "molecule-lazy-reader-tests" -version = "0.7.5" -dependencies = [ - "cc", - "molecule", - "molecule-codegen", -] - -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - -[[package]] -name = "pest" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn 1.0.107", -] - -[[package]] -name = "pest_meta" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" -dependencies = [ - "once_cell", - "pest", - "sha1", -] - -[[package]] -name = "proc-macro2" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "property" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "889bff6ebe76dbef2685598944997eb7f15c9854a2e34db853a51c6ac158b9d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", -] - -[[package]] -name = "quote" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "syn" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", ] [[package]] -name = "syn" -version = "2.0.28" +name = "ppv-lite86" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "thiserror" -version = "1.0.38" +name = "rand" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "thiserror-impl", + "libc", + "rand_chacha", + "rand_core", ] [[package]] -name = "thiserror-impl" -version = "1.0.38" +name = "rand_chacha" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", + "ppv-lite86", + "rand_core", ] [[package]] -name = "typenum" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" - -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - -[[package]] -name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "winapi", + "getrandom", ] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/examples/lazy-reader-tests/Cargo.toml b/examples/lazy-reader-tests/Cargo.toml index e487d35..2a26caf 100644 --- a/examples/lazy-reader-tests/Cargo.toml +++ b/examples/lazy-reader-tests/Cargo.toml @@ -1,12 +1,11 @@ [package] -name = "molecule-lazy-reader-tests" -version = "0.7.5" -authors = ["Nervos Core Dev "] -edition = "2018" +name = "lazy-reader-tests" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] molecule = { path = "../../bindings/rust", default-features = false } - -[features] -default = ["std"] -std = ["molecule/std"] +lazy_static = "1.4.0" +rand = "0.8.5" diff --git a/examples/lazy-reader-tests/Makefile b/examples/lazy-reader-tests/Makefile index 25de4d4..cea9a50 100644 --- a/examples/lazy-reader-tests/Makefile +++ b/examples/lazy-reader-tests/Makefile @@ -3,9 +3,13 @@ all: gen gen: - PATH=../../tools/compiler/target/debug:$PATH moleculec --schema-file ../../test/schemas/types.mol --language rust-lazy-reader > src/types.rs + PATH=../../tools/compiler/target/debug:$PATH moleculec --schema-file ../../test/schemas/types.mol --language rust-lazy-reader > src/types_api2.rs + PATH=../../tools/compiler/target/debug:$PATH moleculec --schema-file ../../test/schemas/types.mol --language rust > src/types_api.rs cargo fmt +test: + cargo test + .PHONY: gen all diff --git a/examples/lazy-reader-tests/fuzz/.gitignore b/examples/lazy-reader-tests/fuzz/.gitignore new file mode 100644 index 0000000..ee85b42 --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/.gitignore @@ -0,0 +1,5 @@ +target +corpus +artifacts +coverage +coverage.html diff --git a/examples/lazy-reader-tests/fuzz/Cargo.lock b/examples/lazy-reader-tests/fuzz/Cargo.lock new file mode 100644 index 0000000..35d5f4c --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/Cargo.lock @@ -0,0 +1,154 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arbitrary" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "faster-hex" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy-reader-tests" +version = "0.1.0" +dependencies = [ + "lazy_static", + "molecule", + "rand", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "libfuzzer-sys" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beb09950ae85a0a94b27676cccf37da5ff13f27076aa1adbc6545dd0d0e1bd4e" +dependencies = [ + "arbitrary", + "cc", + "once_cell", +] + +[[package]] +name = "molecule" +version = "0.7.5" +dependencies = [ + "bytes", + "cfg-if", + "faster-hex", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "types_rust-fuzz" +version = "0.0.0" +dependencies = [ + "lazy-reader-tests", + "libfuzzer-sys", + "molecule", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/examples/lazy-reader-tests/fuzz/Cargo.toml b/examples/lazy-reader-tests/fuzz/Cargo.toml new file mode 100644 index 0000000..497a994 --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "types_rust-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +molecule = { path = "../../../bindings/rust" } + +[dependencies.lazy-reader-tests] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[profile.release] +debug = 1 + +[[bin]] +name = "fuzz_target_1" +path = "fuzz_targets/fuzz_target_1.rs" +test = false +doc = false diff --git a/examples/lazy-reader-tests/fuzz/Makefile b/examples/lazy-reader-tests/fuzz/Makefile new file mode 100644 index 0000000..c0b5294 --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/Makefile @@ -0,0 +1,17 @@ + +all: + cargo fuzz run -j40 fuzz_target_1 + +cov: + cargo fuzz coverage fuzz_target_1 + cargo cov -- show target/x86_64-unknown-linux-gnu/release/fuzz_target_1 \ + --format=html \ + -instr-profile=coverage/fuzz_target_1/coverage.profdata \ + > coverage.html + +install: + rustup component add llvm-tools-preview + +.PHONY: + all cov install + diff --git a/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs b/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs new file mode 100644 index 0000000..547625c --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs @@ -0,0 +1,19 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; +use molecule::prelude::{Entity, Reader}; +use molecule::lazy_reader::Cursor; +use lazy_reader_tests::{types_api, types_api2, types_moleculec_check::check_mol}; + +fuzz_target!(|data: &[u8]| { + let cursor = Cursor::new(data.len(), Box::new(data.to_vec())); + + if types_api::AllInOneReader::verify(data, true).is_err() { + return; + } + + let all1 = types_api::AllInOne::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let all2: types_api2::AllInOne = cursor.into(); + + check_mol(&all1, &all2).expect("check mol"); +}); diff --git a/examples/lazy-reader-tests/fuzz/rust-toolchain b/examples/lazy-reader-tests/fuzz/rust-toolchain new file mode 100644 index 0000000..70e4fd0 --- /dev/null +++ b/examples/lazy-reader-tests/fuzz/rust-toolchain @@ -0,0 +1 @@ +nightly-2023-07-26 \ No newline at end of file diff --git a/examples/lazy-reader-tests/src/lib.rs b/examples/lazy-reader-tests/src/lib.rs index cd40856..008e565 100644 --- a/examples/lazy-reader-tests/src/lib.rs +++ b/examples/lazy-reader-tests/src/lib.rs @@ -1 +1,209 @@ -pub mod types; +pub mod types_api; +pub mod types_api2; + +pub mod types_all_data; +pub mod types_api2_mol2; +pub mod types_array; +pub mod types_moleculec_check; +pub mod types_option; +pub mod types_struct; +pub mod types_table; +pub mod types_vec; + +use molecule::prelude::{Builder, Entity}; +use rand::{rngs::ThreadRng, thread_rng, Rng}; +use std::fmt::Debug; + +pub use types_api2_mol2::*; +pub use types_array::*; +pub use types_moleculec_check::*; +pub use types_option::*; +pub use types_struct::*; +pub use types_table::*; +pub use types_vec::*; + +pub trait BaseTypes { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self; +} +impl BaseTypes for u8 { + fn new_rng(rng: &mut ThreadRng, _config: &TypesConfig) -> Self { + rng.gen() + } +} + +pub enum OptionFillType { + FillRand, + FillSome, + FillNone, +} +pub struct TypesConfig { + pub option_fill: OptionFillType, + pub large_vec: bool, +} + +impl Default for TypesConfig { + fn default() -> Self { + Self { + option_fill: OptionFillType::FillRand, + large_vec: false, + } + } +} + +#[derive(Debug)] +pub enum TypesCheckErr { + Lenght(String), + Data(String), + Opt(String), + Mol2Err(String), +} +pub type ResCheckErr = Result<(), TypesCheckErr>; + +impl TypesCheckErr { + pub fn to(&self, des: String) -> Self { + match self { + Self::Lenght(_) => Self::Lenght(des), + Self::Data(_) => Self::Data(des), + Self::Opt(_) => Self::Opt(des), + Self::Mol2Err(_) => Self::Mol2Err(des), + } + } + pub fn as_str(&self) -> &str { + match self { + Self::Lenght(v) => v, + Self::Data(v) => v, + Self::Opt(v) => v, + Self::Mol2Err(v) => v, + } + } + pub fn check_lenght(l1: usize, l2: usize) -> Result<(), Self> { + if l1 == l2 { + Ok(()) + } else { + Err(Self::Lenght(format!("different length : {} {}", l1, l2))) + } + } + + pub fn check_1_data(d1: &T, d2: &T) -> Result<(), Self> { + if d1 == d2 { + Ok(()) + } else { + Err(Self::Data(format!( + "different data: {:02x?} {:02x?}", + d1, d2 + ))) + } + } + + pub fn check_data>(d1: &T, d2: &[T1]) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + + for i in 0..d1.mol_len()? { + TypesCheckErr::check_1_data(&d1.mol_get(i)?, &d2[i])?; + } + + Ok(()) + } + + pub fn check_mol_data, T2: Mol2Vec>( + d1: &T1, + d2: &T2, + ) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.mol_len()?)?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_1_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) + } + + pub fn check_option(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + Ok(()) + } +} +impl From for TypesCheckErr { + fn from(value: molecule::lazy_reader::Error) -> Self { + use molecule::lazy_reader::Error::*; + match value { + Common(v) => Self::Mol2Err(format!("Common({})", v)), + TotalSize(v) => Self::Mol2Err(format!("TotalSize({})", v)), + Header(v) => Self::Mol2Err(format!("Header({})", v)), + Offset(v) => Self::Mol2Err(format!("Offset({})", v)), + UnknownItem(v) => Self::Mol2Err(format!("UnknownItem({})", v)), + OutOfBound(v) => Self::Mol2Err(format!("OutOfBound({})", v)), + FieldCount(v) => Self::Mol2Err(format!("FieldCount({})", v)), + Data(v) => Self::Mol2Err(format!("Data({})", v)), + Overflow(v) => Self::Mol2Err(format!("Overflow({})", v)), + Read(v) => Self::Mol2Err(format!("Read({})", v)), + } + } +} + +pub enum TypesUnionA { + Byte(TypesArray), + Word(TypesArrayWord), + StructA(TypesStructA), + Bytes(TypesVec), + Words(TypesVec), + Table0(TypesTable0), + Table6(TypesTable6), + Table6Opt(TypesOption), +} +impl BaseTypes for TypesUnionA { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + let v = rng.gen_range(0..8); + match v { + 0 => Self::Byte(TypesArray::new_rng(rng, config)), + 1 => Self::Word(TypesArrayWord::new_rng(rng, config)), + 2 => Self::StructA(TypesStructA::new_rng(rng, config)), + 3 => Self::Bytes(TypesVec::new_rng(rng, config)), + 4 => Self::Words(TypesVec::new_rng(rng, config)), + 5 => Self::Table0(TypesTable0::new_rng(rng, config)), + 6 => Self::Table6(TypesTable6::new_rng(rng, config)), + 7 => Self::Table6Opt(TypesOption::new_rng(rng, config)), + + _ => panic!("unknow error"), + } + } +} +impl Default for TypesUnionA { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesUnionA { + pub fn to_mol(&self) -> types_api::UnionA { + let t = match self { + Self::Byte(v) => types_api::UnionAUnion::Byte(v.to_mol()), + Self::Word(v) => types_api::UnionAUnion::Word(v.to_mol2()), + Self::StructA(v) => types_api::UnionAUnion::StructA(v.to_mol()), + Self::Bytes(v) => types_api::UnionAUnion::Bytes(v.to_mol()), + Self::Words(v) => types_api::UnionAUnion::Words(v.to_mol()), + Self::Table0(v) => types_api::UnionAUnion::Table0(v.to_mol()), + Self::Table6(v) => types_api::UnionAUnion::Table6(v.to_mol()), + Self::Table6Opt(v) => types_api::UnionAUnion::Table6Opt(v.to_mol()), + }; + types_api::UnionA::new_builder().set(t).build() + } + + pub fn check(&self, d: &types_api2::UnionA) -> ResCheckErr { + // let item_id = d.item_id(); + + match self { + Self::Byte(v) => v.check(&d.as_byte()?), + Self::Word(v) => v.check2(&d.as_word()?.into()), + Self::StructA(v) => v.check(&d.as_structa()?), + Self::Bytes(v) => v.check(&d.as_bytes()?.try_into().unwrap()), + Self::Words(v) => v.check(&d.as_words()?.into()), + Self::Table0(v) => v.check(&d.as_table0()?), + Self::Table6(v) => v.check(&d.as_table6()?), + Self::Table6Opt(v) => v.check(&d.as_table6opt()?), + } + } +} diff --git a/examples/lazy-reader-tests/src/types_all_data.rs b/examples/lazy-reader-tests/src/types_all_data.rs new file mode 100644 index 0000000..01dace3 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_all_data.rs @@ -0,0 +1,542 @@ +#![allow(unused_imports)] +// #![allow(dead_code)] + +use crate::types_api; +use crate::types_api2; + +use core::convert::TryInto; +use lazy_static::lazy_static; +use molecule::lazy_reader::Cursor; +use molecule::prelude::{Builder, Entity, Reader}; +use molecule::{bytes::Bytes, prelude::Byte}; +use rand::{random, rngs::ThreadRng, thread_rng, Rng, RngCore}; + +use super::*; + +#[derive(Default)] +pub struct TypesAll { + f0: TypesArray, + f1: TypesArray, + f2: TypesArray, + f3: TypesArray, + f4: TypesArray, + f5: TypesArray, + f6: TypesArray, + f7: TypesArray, + f8: TypesArray, + f9: TypesArray, + f10: TypesArray, + f11: TypesArray, + f12: TypesArray, + f13: TypesArray, + f14: TypesArray, + f15: TypesArray, + + f16: TypesArrayWord, + f17: TypesArray, + f18: TypesArray, + f19: TypesArray, + f20: TypesArray, + f21: TypesArray, + f22: TypesArray, + f23: TypesArray, + + f24: TypesArray, 3>, + f25: TypesArray, 3>, + f26: TypesArray, 3>, + f27: TypesArray, 3>, + + f28: TypesStructA, + f29: TypesStructB, + f30: TypesStructC, + f31: TypesStructD, + f32: TypesStructE, + f33: TypesStructF, + f34: TypesStructG, + f35: TypesStructH, + f36: TypesStructI, + f37: TypesStructJ, + f38: TypesStructIx3, + f39: TypesStructO, + f40: TypesStructP, + + f41: TypesVec, + f42: TypesVec, + f43: TypesVec>, + f44: TypesVec>, + f45: TypesVec, + f46: TypesVec, + f47: TypesVec, + f48: TypesVec>, + f49: TypesVec>, + + f50: TypesTable0, + f51: TypesTable1, + f52: TypesTable2, + f53: TypesTable3, + f54: TypesTable4, + f55: TypesTable5, + f56: TypesTable6, + + f57: TypesOption, + f58: TypesOption, + f59: TypesOption, + f60: TypesOption, + f61: TypesOption>, + f62: TypesOption>, + f63: TypesOption>>, + f64: TypesOption>>, + f65: TypesOption, + f66: TypesOption, + f67: TypesOption>, + + f68: TypesVec>, + f69: TypesVec>, + f70: TypesVec>>, + f71: TypesVec>>, + + f72: TypesUnionA, + f73: TypesTableA, +} + +impl TypesAll { + pub fn new_by_config(config: &TypesConfig) -> Self { + let mut rng = thread_rng(); + Self { + f0: TypesArray::new_rng(&mut rng, config), + f1: TypesArray::new_rng(&mut rng, config), + f2: TypesArray::new_rng(&mut rng, config), + f3: TypesArray::new_rng(&mut rng, config), + f4: TypesArray::new_rng(&mut rng, config), + f5: TypesArray::new_rng(&mut rng, config), + f6: TypesArray::new_rng(&mut rng, config), + f7: TypesArray::new_rng(&mut rng, config), + f8: TypesArray::new_rng(&mut rng, config), + f9: TypesArray::new_rng(&mut rng, config), + f10: TypesArray::new_rng(&mut rng, config), + f11: TypesArray::new_rng(&mut rng, config), + f12: TypesArray::new_rng(&mut rng, config), + f13: TypesArray::new_rng(&mut rng, config), + f14: TypesArray::new_rng(&mut rng, config), + f15: TypesArray::new_rng(&mut rng, config), + f16: TypesArray::new_rng(&mut rng, config), + f17: TypesArray::new_rng(&mut rng, config), + f18: TypesArray::new_rng(&mut rng, config), + f19: TypesArray::new_rng(&mut rng, config), + f20: TypesArray::new_rng(&mut rng, config), + f21: TypesArray::new_rng(&mut rng, config), + f22: TypesArray::new_rng(&mut rng, config), + f23: TypesArray::new_rng(&mut rng, config), + f24: TypesArray::new_rng(&mut rng, config), + f25: TypesArray::new_rng(&mut rng, config), + f26: TypesArray::new_rng(&mut rng, config), + f27: TypesArray::new_rng(&mut rng, config), + f28: TypesStructA::new_rng(&mut rng, config), + f29: TypesStructB::new_rng(&mut rng, config), + f30: TypesStructC::new_rng(&mut rng, config), + f31: TypesStructD::new_rng(&mut rng, config), + f32: TypesStructE::new_rng(&mut rng, config), + f33: TypesStructF::new_rng(&mut rng, config), + f34: TypesStructG::new_rng(&mut rng, config), + f35: TypesStructH::new_rng(&mut rng, config), + f36: TypesStructI::new_rng(&mut rng, config), + f37: TypesStructJ::new_rng(&mut rng, config), + f38: TypesStructIx3::new_rng(&mut rng, config), + f39: TypesStructO::new_rng(&mut rng, config), + f40: TypesStructP::new_rng(&mut rng, config), + f41: TypesVec::new_rng(&mut rng, config), + f42: TypesVec::new_rng(&mut rng, config), + f43: TypesVec::new_rng(&mut rng, config), + f44: TypesVec::new_rng(&mut rng, config), + f45: TypesVec::new_rng(&mut rng, config), + f46: TypesVec::new_rng(&mut rng, config), + f47: TypesVec::new_rng(&mut rng, config), + f48: TypesVec::new_rng(&mut rng, config), + f49: TypesVec::new_rng(&mut rng, config), + f50: TypesTable0::new_rng(&mut rng, config), + f51: TypesTable1::new_rng(&mut rng, config), + f52: TypesTable2::new_rng(&mut rng, config), + f53: TypesTable3::new_rng(&mut rng, config), + f54: TypesTable4::new_rng(&mut rng, config), + f55: TypesTable5::new_rng(&mut rng, config), + f56: TypesTable6::new_rng(&mut rng, config), + f57: TypesOption::new_rng(&mut rng, config), + f58: TypesOption::new_rng(&mut rng, config), + f59: TypesOption::new_rng(&mut rng, config), + f60: TypesOption::new_rng(&mut rng, config), + f61: TypesOption::new_rng(&mut rng, config), + f62: TypesOption::new_rng(&mut rng, config), + f63: TypesOption::new_rng(&mut rng, config), + f64: TypesOption::new_rng(&mut rng, config), + f65: TypesOption::new_rng(&mut rng, config), + f66: TypesOption::new_rng(&mut rng, config), + f67: TypesOption::new_rng(&mut rng, config), + f68: TypesVec::new_rng(&mut rng, config), + f69: TypesVec::new_rng(&mut rng, config), + f70: TypesVec::new_rng(&mut rng, config), + f71: TypesVec::new_rng(&mut rng, config), + f72: TypesUnionA::new_rng(&mut rng, config), + f73: TypesTableA::new_rng(&mut rng, config), + } + } + pub fn to_bytes(&self) -> Vec { + use crate::types_api::*; + + let builder = types_api::AllInOneBuilder::default() + .f0(self.f0.to_mol()) + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .f5(self.f5.to_mol()) + .f6(self.f6.to_mol()) + .f7(self.f7.to_mol()) + .f8(self.f8.to_mol()) + .f9(self.f9.to_mol()) + .f10(self.f10.to_mol()) + .f11(self.f11.to_mol()) + .f12(self.f12.to_mol()) + .f13(self.f13.to_mol()) + .f14(self.f14.to_mol()) + .f15(self.f15.to_mol()) + .f16( + types_api::Word::new_builder() + .set(self.f16.d.map(|f| f.into())) + .build(), + ) + .f17(self.f17.to_mol()) + .f18(self.f18.to_mol()) + .f19(self.f19.to_mol()) + .f20(self.f20.to_mol()) + .f21(self.f21.to_mol()) + .f22(self.f22.to_mol()) + .f23(self.f23.to_mol()) + .f24(self.f24.to_mol()) + .f25(self.f25.to_mol()) + .f26(self.f26.to_mol()) + .f27(self.f27.to_mol()) + .f28(self.f28.to_mol()) + .f29(self.f29.to_mol()) + .f30(self.f30.to_mol()) + .f31(self.f31.to_mol()) + .f32(self.f32.to_mol()) + .f33(self.f33.to_mol()) + .f34(self.f34.to_mol()) + .f35(self.f35.to_mol()) + .f36(self.f36.to_mol()) + .f37(self.f37.to_mol()) + .f38(self.f38.to_mol()) + .f39(self.f39.to_mol()) + .f40(self.f40.to_mol()) + .f41(self.f41.to_mol()) + .f42(self.f42.to_mol()) + .f43(self.f43.to_mol()) + .f44(self.f44.to_mol()) + .f45(self.f45.to_mol()) + .f46(self.f46.to_mol()) + .f47(self.f47.to_mol()) + .f48(self.f48.to_mol()) + .f49(self.f49.to_mol()) + .f50(self.f50.to_mol()) + .f51(self.f51.to_mol()) + .f52(self.f52.to_mol()) + .f53(self.f53.to_mol()) + .f54(self.f54.to_mol()) + .f55(self.f55.to_mol()) + .f56(self.f56.to_mol()) + .f57(self.f57.to_mol()) + .f58(self.f58.to_mol()) + .f59(self.f59.to_mol()) + .f60(self.f60.to_mol()) + .f61(self.f61.to_mol()) + .f62(self.f62.to_mol()) + .f63(self.f63.to_mol()) + .f64(self.f64.to_mol()) + .f65(self.f65.to_mol()) + .f66(self.f66.to_mol()) + .f67(self.f67.to_mol()) + .f68(self.f68.to_mol()) + .f69(self.f69.to_mol()) + .f70(self.f70.to_mol()) + .f71(self.f71.to_mol()) + .f72(self.f72.to_mol()) + .f73(self.f73.to_mol()) + .build(); + + builder.as_reader().as_slice().to_vec() + } + + pub fn check(&self, data: &[u8]) -> ResCheckErr { + use crate::types_api2_mol2::Mol2Vec; + use types_api2::*; + + let cursor = Cursor::new(data.len(), Box::new(data.to_vec())); + let all_in_one = AllInOne { cursor }; + + self.f0 + .check(&all_in_one.f0()?) + .map_err(|f| f.to(format!("f0:{}", f.as_str())))?; + self.f1 + .check(&all_in_one.f1()?.into()) + .map_err(|f| f.to(format!("f1:{}", f.as_str())))?; + self.f2 + .check(&all_in_one.f2()?.into()) + .map_err(|f| f.to(format!("f2:{}", f.as_str())))?; + self.f3 + .check(&all_in_one.f3()?.into()) + .map_err(|f| f.to(format!("f3:{}", f.as_str())))?; + self.f4 + .check(&all_in_one.f4()?.into()) + .map_err(|f| f.to(format!("f74:{}", f.as_str())))?; + self.f5 + .check(&all_in_one.f5()?.into()) + .map_err(|f| f.to(format!("f5:{}", f.as_str())))?; + self.f6 + .check(&all_in_one.f6()?.into()) + .map_err(|f| f.to(format!("f6:{}", f.as_str())))?; + self.f7 + .check(&all_in_one.f7()?.into()) + .map_err(|f| f.to(format!("f7:{}", f.as_str())))?; + self.f8 + .check(&all_in_one.f8()?.into()) + .map_err(|f| f.to(format!("f8:{}", f.as_str())))?; + self.f9 + .check(&all_in_one.f9()?.into()) + .map_err(|f| f.to(format!("f9:{}", f.as_str())))?; + self.f10 + .check(&all_in_one.f10()?.into()) + .map_err(|f| f.to(format!("f10:{}", f.as_str())))?; + self.f11 + .check(&all_in_one.f11()?.into()) + .map_err(|f| f.to(format!("f11:{}", f.as_str())))?; + self.f12 + .check(&all_in_one.f12()?.into()) + .map_err(|f| f.to(format!("f12:{}", f.as_str())))?; + self.f13 + .check(&all_in_one.f13()?.into()) + .map_err(|f| f.to(format!("f13:{}", f.as_str())))?; + self.f14 + .check(&all_in_one.f14()?.into()) + .map_err(|f| f.to(format!("f14:{}", f.as_str())))?; + self.f15 + .check(&all_in_one.f15()?.into()) + .map_err(|f| f.to(format!("f15:{}", f.as_str())))?; + + self.f16 + .check2(&all_in_one.f16()?.into()) + .map_err(|f| f.to(format!("f16:{}", f.as_str())))?; + self.f17 + .check(&all_in_one.f17()?.into()) + .map_err(|f| f.to(format!("f17:{}", f.as_str())))?; + self.f18 + .check(&all_in_one.f18()?.into()) + .map_err(|f| f.to(format!("f18:{}", f.as_str())))?; + self.f19 + .check(&all_in_one.f19()?.into()) + .map_err(|f| f.to(format!("f19:{}", f.as_str())))?; + self.f20 + .check(&all_in_one.f20()?.into()) + .map_err(|f| f.to(format!("f20:{}", f.as_str())))?; + self.f21 + .check(&all_in_one.f21()?.into()) + .map_err(|f| f.to(format!("f21:{}", f.as_str())))?; + self.f22 + .check(&all_in_one.f22()?.into()) + .map_err(|f| f.to(format!("f22:{}", f.as_str())))?; + self.f23 + .check(&all_in_one.f23()?.into()) + .map_err(|f| f.to(format!("f23:{}", f.as_str())))?; + + self.f24 + .check(&all_in_one.f24()?.into()) + .map_err(|f| f.to(format!("f24:{}", f.as_str())))?; + self.f25 + .check(&all_in_one.f25()?.into()) + .map_err(|f| f.to(format!("f25:{}", f.as_str())))?; + self.f26 + .check(&all_in_one.f26()?.into()) + .map_err(|f| f.to(format!("f26:{}", f.as_str())))?; + self.f27 + .check(&all_in_one.f27()?.into()) + .map_err(|f| f.to(format!("f27:{}", f.as_str())))?; + + self.f28 + .check(&all_in_one.f28()?.into()) + .map_err(|f| f.to(format!("f28:{}", f.as_str())))?; + self.f29 + .check(&all_in_one.f29()?.into()) + .map_err(|f| f.to(format!("f29:{}", f.as_str())))?; + self.f30 + .check(&all_in_one.f30()?.into()) + .map_err(|f| f.to(format!("f30:{}", f.as_str())))?; + self.f31 + .check(&all_in_one.f31()?.into()) + .map_err(|f| f.to(format!("f31:{}", f.as_str())))?; + self.f32 + .check(&all_in_one.f32()?.into()) + .map_err(|f| f.to(format!("f32:{}", f.as_str())))?; + self.f33 + .check(&all_in_one.f33()?.into()) + .map_err(|f| f.to(format!("f33:{}", f.as_str())))?; + self.f34 + .check(&all_in_one.f34()?.into()) + .map_err(|f| f.to(format!("f34:{}", f.as_str())))?; + self.f35 + .check(&all_in_one.f35()?.into()) + .map_err(|f| f.to(format!("f35:{}", f.as_str())))?; + self.f36 + .check(&all_in_one.f36()?.into()) + .map_err(|f| f.to(format!("f36:{}", f.as_str())))?; + self.f37 + .check(&all_in_one.f37()?.into()) + .map_err(|f| f.to(format!("f37:{}", f.as_str())))?; + self.f38 + .check(&all_in_one.f38()?.into()) + .map_err(|f| f.to(format!("f38:{}", f.as_str())))?; + self.f39 + .check(&all_in_one.f39()?.into()) + .map_err(|f| f.to(format!("f39:{}", f.as_str())))?; + self.f40 + .check(&all_in_one.f40()?.into()) + .map_err(|f| f.to(format!("f40:{}", f.as_str())))?; + + self.f41 + .check(&all_in_one.f41()?.try_into().unwrap()) + .map_err(|f| f.to(format!("f41:{}", f.as_str())))?; + self.f42 + .check(&all_in_one.f42()?.into()) + .map_err(|f| f.to(format!("f42:{}", f.as_str())))?; + self.f43 + .check(&all_in_one.f43()?.into()) + .map_err(|f| f.to(format!("f43:{}", f.as_str())))?; + self.f44 + .check(&all_in_one.f44()?.into()) + .map_err(|f| f.to(format!("f44:{}", f.as_str())))?; + self.f45 + .check(&all_in_one.f45()?.into()) + .map_err(|f| f.to(format!("f45:{}", f.as_str())))?; + self.f46 + .check(&all_in_one.f46()?.into()) + .map_err(|f| f.to(format!("f46:{}", f.as_str())))?; + self.f47 + .check(&all_in_one.f47()?.into()) + .map_err(|f| f.to(format!("f47:{}", f.as_str())))?; + self.f48 + .check(&all_in_one.f48()?.into()) + .map_err(|f| f.to(format!("f48:{}", f.as_str())))?; + self.f49 + .check(&all_in_one.f49()?.into()) + .map_err(|f| f.to(format!("f49:{}", f.as_str())))?; + + self.f50 + .check(&all_in_one.f50()?.into()) + .map_err(|f| f.to(format!("f50:{}", f.as_str())))?; + self.f51 + .check(&all_in_one.f51()?.into()) + .map_err(|f| f.to(format!("f51:{}", f.as_str())))?; + self.f52 + .check(&all_in_one.f52()?.into()) + .map_err(|f| f.to(format!("f52:{}", f.as_str())))?; + self.f53 + .check(&all_in_one.f53()?.into()) + .map_err(|f| f.to(format!("f53:{}", f.as_str())))?; + self.f54 + .check(&all_in_one.f54()?.into()) + .map_err(|f| f.to(format!("f54:{}", f.as_str())))?; + self.f55 + .check(&all_in_one.f55()?.into()) + .map_err(|f| f.to(format!("f55:{}", f.as_str())))?; + self.f56 + .check(&all_in_one.f56()?.into()) + .map_err(|f| f.to(format!("f56:{}", f.as_str())))?; + self.f57 + .check(&all_in_one.f57()?.into()) + .map_err(|f| f.to(format!("f57:{}", f.as_str())))?; + self.f58 + .check(&all_in_one.f58()?.map(|f| f.into())) + .map_err(|f| f.to(format!("f58:{}", f.as_str())))?; + self.f59 + .check(&all_in_one.f59()?) + .map_err(|f| f.to(format!("f59:{}", f.as_str())))?; + self.f60 + .check(&all_in_one.f60()?) + .map_err(|f| f.to(format!("f60:{}", f.as_str())))?; + self.f61 + .check(&all_in_one.f61()?) + .map_err(|f| f.to(format!("f61:{}", f.as_str())))?; + self.f62 + .check(&all_in_one.f62()?) + .map_err(|f| f.to(format!("f62:{}", f.as_str())))?; + self.f63 + .check(&all_in_one.f63()?) + .map_err(|f| f.to(format!("f63:{}", f.as_str())))?; + self.f64 + .check(&all_in_one.f64()?) + .map_err(|f| f.to(format!("f64:{}", f.as_str())))?; + self.f65 + .check(&all_in_one.f65()?) + .map_err(|f| f.to(format!("f65:{}", f.as_str())))?; + self.f66 + .check(&all_in_one.f66()?) + .map_err(|f| f.to(format!("f66:{}", f.as_str())))?; + self.f67 + .check(&all_in_one.f67()?) + .map_err(|f| f.to(format!("f67:{}", f.as_str())))?; + self.f68 + .check(&all_in_one.f68()?) + .map_err(|f| f.to(format!("f68:{}", f.as_str())))?; + self.f69 + .check(&all_in_one.f69()?) + .map_err(|f| f.to(format!("f69:{}", f.as_str())))?; + self.f70 + .check(&all_in_one.f70()?) + .map_err(|f| f.to(format!("f70:{}", f.as_str())))?; + self.f71 + .check(&all_in_one.f71()?) + .map_err(|f| f.to(format!("f71:{}", f.as_str())))?; + self.f72 + .check(&all_in_one.f72()?) + .map_err(|f| f.to(format!("f72:{}", f.as_str())))?; + self.f73 + .check(&all_in_one.f73()?) + .map_err(|f| f.to(format!("f73:{}", f.as_str())))?; + + check_mol( + &types_api::AllInOne::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())), + &all_in_one, + ) + .map_err(|f| f.to(format!("check mol and mol2 failed: {:?}", f.as_str())))?; + + Ok(()) + } +} + +#[test] +fn test_base() { + let test_data = TypesAll::default(); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); +} + +#[test] +fn test_opt_all_none() { + let mut config: TypesConfig = TypesConfig::default(); + config.option_fill = OptionFillType::FillNone; + let test_data = TypesAll::new_by_config(&config); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); + + config.option_fill = OptionFillType::FillSome; + let test_data = TypesAll::new_by_config(&config); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); +} + +// #[test] +// fn test_large_buf() { +// let mut config = TypesConfig::default(); +// config.large_vec = true; +// let test_data = TypesAll::new_by_config(&config); +// let data = test_data.to_bytes(); +// test_data.check(&data).expect("test base"); +// } diff --git a/examples/lazy-reader-tests/src/types_api.rs b/examples/lazy-reader-tests/src/types_api.rs new file mode 100644 index 0000000..c050fa9 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_api.rs @@ -0,0 +1,20507 @@ +// Generated by Molecule 0.7.5 + +use molecule::prelude::*; +#[derive(Clone)] +pub struct Byte2(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte2 { + 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 Byte2 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte2 { + 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 Byte2 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte2::new_unchecked(v) + } +} +impl Byte2 { + const DEFAULT_VALUE: [u8; 2] = [0, 0]; + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte2 { + type Builder = Byte2Builder; + const NAME: &'static str = "Byte2"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte2(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 { + Byte2Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte2Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte2Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte2Reader<'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 Byte2Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte2Reader<'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> Byte2Reader<'r> { + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte2Reader<'r> { + type Entity = Byte2; + const NAME: &'static str = "Byte2Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte2Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte2Builder(pub(crate) [Byte; 2]); +impl ::core::fmt::Debug for Byte2Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte2Builder { + fn default() -> Self { + Byte2Builder([Byte::default(), Byte::default()]) + } +} +impl Byte2Builder { + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + pub fn set(mut self, v: [Byte; 2]) -> 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 + } +} +impl molecule::prelude::Builder for Byte2Builder { + type Entity = Byte2; + const NAME: &'static str = "Byte2Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.0[0].as_slice())?; + writer.write_all(self.0[1].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)); + Byte2::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte3 { + 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 Byte3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte3 { + 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 Byte3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte3::new_unchecked(v) + } +} +impl Byte3 { + const DEFAULT_VALUE: [u8; 3] = [0, 0, 0]; + pub const TOTAL_SIZE: usize = 3; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 3; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte3 { + type Builder = Byte3Builder; + const NAME: &'static str = "Byte3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte3(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 { + Byte3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte3Reader<'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 Byte3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte3Reader<'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> Byte3Reader<'r> { + pub const TOTAL_SIZE: usize = 3; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 3; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte3Reader<'r> { + type Entity = Byte3; + const NAME: &'static str = "Byte3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte3Builder(pub(crate) [Byte; 3]); +impl ::core::fmt::Debug for Byte3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte3Builder { + fn default() -> Self { + Byte3Builder([Byte::default(), Byte::default(), Byte::default()]) + } +} +impl Byte3Builder { + pub const TOTAL_SIZE: usize = 3; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Byte; 3]) -> 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 + } +} +impl molecule::prelude::Builder for Byte3Builder { + type Entity = Byte3; + const NAME: &'static str = "Byte3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte4(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte4 { + 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 Byte4 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte4 { + 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 Byte4 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte4::new_unchecked(v) + } +} +impl Byte4 { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + 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) -> Byte4Reader<'r> { + Byte4Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte4 { + type Builder = Byte4Builder; + const NAME: &'static str = "Byte4"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte4(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 { + Byte4Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte4Reader::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 Byte4Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte4Reader<'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 Byte4Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte4Reader<'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> Byte4Reader<'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 Byte4Reader<'r> { + type Entity = Byte4; + const NAME: &'static str = "Byte4Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte4Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte4Builder(pub(crate) [Byte; 4]); +impl ::core::fmt::Debug for Byte4Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte4Builder { + fn default() -> Self { + Byte4Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte4Builder { + 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 Byte4Builder { + type Entity = Byte4; + const NAME: &'static str = "Byte4Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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)); + Byte4::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte5(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte5 { + 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 Byte5 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte5 { + 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 Byte5 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte5::new_unchecked(v) + } +} +impl Byte5 { + const DEFAULT_VALUE: [u8; 5] = [0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 5; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 5; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte5Reader<'r> { + Byte5Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte5 { + type Builder = Byte5Builder; + const NAME: &'static str = "Byte5"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte5(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 { + Byte5Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte5Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte5Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte5Reader<'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 Byte5Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte5Reader<'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> Byte5Reader<'r> { + pub const TOTAL_SIZE: usize = 5; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 5; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte5Reader<'r> { + type Entity = Byte5; + const NAME: &'static str = "Byte5Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte5Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte5Builder(pub(crate) [Byte; 5]); +impl ::core::fmt::Debug for Byte5Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte5Builder { + fn default() -> Self { + Byte5Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte5Builder { + pub const TOTAL_SIZE: usize = 5; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 5; + pub fn set(mut self, v: [Byte; 5]) -> 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 + } +} +impl molecule::prelude::Builder for Byte5Builder { + type Entity = Byte5; + const NAME: &'static str = "Byte5Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte5::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte6(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte6 { + 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 Byte6 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte6 { + 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 Byte6 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte6::new_unchecked(v) + } +} +impl Byte6 { + const DEFAULT_VALUE: [u8; 6] = [0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 6; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte6Reader<'r> { + Byte6Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte6 { + type Builder = Byte6Builder; + const NAME: &'static str = "Byte6"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte6(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 { + Byte6Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte6Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte6Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte6Reader<'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 Byte6Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte6Reader<'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> Byte6Reader<'r> { + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 6; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte6Reader<'r> { + type Entity = Byte6; + const NAME: &'static str = "Byte6Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte6Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte6Builder(pub(crate) [Byte; 6]); +impl ::core::fmt::Debug for Byte6Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte6Builder { + fn default() -> Self { + Byte6Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte6Builder { + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 6; + pub fn set(mut self, v: [Byte; 6]) -> 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 + } +} +impl molecule::prelude::Builder for Byte6Builder { + type Entity = Byte6; + const NAME: &'static str = "Byte6Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte6::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte7(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte7 { + 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 Byte7 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte7 { + 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 Byte7 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte7::new_unchecked(v) + } +} +impl Byte7 { + const DEFAULT_VALUE: [u8; 7] = [0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 7; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 7; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte7Reader<'r> { + Byte7Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte7 { + type Builder = Byte7Builder; + const NAME: &'static str = "Byte7"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte7(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 { + Byte7Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte7Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte7Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte7Reader<'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 Byte7Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte7Reader<'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> Byte7Reader<'r> { + pub const TOTAL_SIZE: usize = 7; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 7; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte7Reader<'r> { + type Entity = Byte7; + const NAME: &'static str = "Byte7Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte7Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte7Builder(pub(crate) [Byte; 7]); +impl ::core::fmt::Debug for Byte7Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte7Builder { + fn default() -> Self { + Byte7Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte7Builder { + pub const TOTAL_SIZE: usize = 7; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 7; + pub fn set(mut self, v: [Byte; 7]) -> 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 + } +} +impl molecule::prelude::Builder for Byte7Builder { + type Entity = Byte7; + const NAME: &'static str = "Byte7Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte7::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte8(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte8 { + 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 Byte8 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte8 { + 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 Byte8 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte8::new_unchecked(v) + } +} +impl Byte8 { + const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 8; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte8Reader<'r> { + Byte8Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte8 { + type Builder = Byte8Builder; + const NAME: &'static str = "Byte8"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte8(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 { + Byte8Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte8Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte8Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte8Reader<'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 Byte8Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte8Reader<'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> Byte8Reader<'r> { + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 8; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte8Reader<'r> { + type Entity = Byte8; + const NAME: &'static str = "Byte8Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte8Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte8Builder(pub(crate) [Byte; 8]); +impl ::core::fmt::Debug for Byte8Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte8Builder { + fn default() -> Self { + Byte8Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte8Builder { + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 8; + pub fn set(mut self, v: [Byte; 8]) -> 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 + } +} +impl molecule::prelude::Builder for Byte8Builder { + type Entity = Byte8; + const NAME: &'static str = "Byte8Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte8::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte9(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte9 { + 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 Byte9 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte9 { + 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 Byte9 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte9::new_unchecked(v) + } +} +impl Byte9 { + const DEFAULT_VALUE: [u8; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 9; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte9Reader<'r> { + Byte9Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte9 { + type Builder = Byte9Builder; + const NAME: &'static str = "Byte9"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte9(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 { + Byte9Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte9Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte9Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte9Reader<'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 Byte9Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte9Reader<'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> Byte9Reader<'r> { + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 9; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte9Reader<'r> { + type Entity = Byte9; + const NAME: &'static str = "Byte9Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte9Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte9Builder(pub(crate) [Byte; 9]); +impl ::core::fmt::Debug for Byte9Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte9Builder { + fn default() -> Self { + Byte9Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte9Builder { + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 9; + pub fn set(mut self, v: [Byte; 9]) -> 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 + } +} +impl molecule::prelude::Builder for Byte9Builder { + type Entity = Byte9; + const NAME: &'static str = "Byte9Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte9::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte10(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte10 { + 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 Byte10 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte10 { + 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 Byte10 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte10::new_unchecked(v) + } +} +impl Byte10 { + const DEFAULT_VALUE: [u8; 10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 10; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte10Reader<'r> { + Byte10Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte10 { + type Builder = Byte10Builder; + const NAME: &'static str = "Byte10"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte10(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 { + Byte10Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte10Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte10Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte10Reader<'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 Byte10Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte10Reader<'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> Byte10Reader<'r> { + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 10; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte10Reader<'r> { + type Entity = Byte10; + const NAME: &'static str = "Byte10Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte10Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte10Builder(pub(crate) [Byte; 10]); +impl ::core::fmt::Debug for Byte10Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte10Builder { + fn default() -> Self { + Byte10Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte10Builder { + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 10; + pub fn set(mut self, v: [Byte; 10]) -> 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 + } +} +impl molecule::prelude::Builder for Byte10Builder { + type Entity = Byte10; + const NAME: &'static str = "Byte10Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte10::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte11(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte11 { + 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 Byte11 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte11 { + 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 Byte11 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte11::new_unchecked(v) + } +} +impl Byte11 { + const DEFAULT_VALUE: [u8; 11] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 11; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 11; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte11Reader<'r> { + Byte11Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte11 { + type Builder = Byte11Builder; + const NAME: &'static str = "Byte11"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte11(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 { + Byte11Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte11Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte11Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte11Reader<'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 Byte11Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte11Reader<'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> Byte11Reader<'r> { + pub const TOTAL_SIZE: usize = 11; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 11; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte11Reader<'r> { + type Entity = Byte11; + const NAME: &'static str = "Byte11Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte11Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte11Builder(pub(crate) [Byte; 11]); +impl ::core::fmt::Debug for Byte11Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte11Builder { + fn default() -> Self { + Byte11Builder([ + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + Byte::default(), + ]) + } +} +impl Byte11Builder { + pub const TOTAL_SIZE: usize = 11; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 11; + pub fn set(mut self, v: [Byte; 11]) -> 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 + } +} +impl molecule::prelude::Builder for Byte11Builder { + type Entity = Byte11; + const NAME: &'static str = "Byte11Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte11::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte12(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte12 { + 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 Byte12 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte12 { + 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 Byte12 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte12::new_unchecked(v) + } +} +impl Byte12 { + const DEFAULT_VALUE: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 12; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte12Reader<'r> { + Byte12Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte12 { + type Builder = Byte12Builder; + const NAME: &'static str = "Byte12"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte12(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 { + Byte12Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte12Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte12Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte12Reader<'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 Byte12Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte12Reader<'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> Byte12Reader<'r> { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 12; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte12Reader<'r> { + type Entity = Byte12; + const NAME: &'static str = "Byte12Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte12Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte12Builder(pub(crate) [Byte; 12]); +impl ::core::fmt::Debug for Byte12Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte12Builder { + fn default() -> Self { + Byte12Builder([ + 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 Byte12Builder { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 12; + pub fn set(mut self, v: [Byte; 12]) -> 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 + } +} +impl molecule::prelude::Builder for Byte12Builder { + type Entity = Byte12; + const NAME: &'static str = "Byte12Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte12::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte13(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte13 { + 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 Byte13 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte13 { + 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 Byte13 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte13::new_unchecked(v) + } +} +impl Byte13 { + const DEFAULT_VALUE: [u8; 13] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 13; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 13; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte13Reader<'r> { + Byte13Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte13 { + type Builder = Byte13Builder; + const NAME: &'static str = "Byte13"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte13(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 { + Byte13Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte13Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte13Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte13Reader<'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 Byte13Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte13Reader<'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> Byte13Reader<'r> { + pub const TOTAL_SIZE: usize = 13; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 13; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte13Reader<'r> { + type Entity = Byte13; + const NAME: &'static str = "Byte13Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte13Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte13Builder(pub(crate) [Byte; 13]); +impl ::core::fmt::Debug for Byte13Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte13Builder { + fn default() -> Self { + Byte13Builder([ + 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 Byte13Builder { + pub const TOTAL_SIZE: usize = 13; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 13; + pub fn set(mut self, v: [Byte; 13]) -> 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 + } +} +impl molecule::prelude::Builder for Byte13Builder { + type Entity = Byte13; + const NAME: &'static str = "Byte13Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte13::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte14(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte14 { + 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 Byte14 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte14 { + 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 Byte14 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte14::new_unchecked(v) + } +} +impl Byte14 { + const DEFAULT_VALUE: [u8; 14] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 14; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte14Reader<'r> { + Byte14Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte14 { + type Builder = Byte14Builder; + const NAME: &'static str = "Byte14"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte14(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 { + Byte14Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte14Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte14Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte14Reader<'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 Byte14Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte14Reader<'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> Byte14Reader<'r> { + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 14; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte14Reader<'r> { + type Entity = Byte14; + const NAME: &'static str = "Byte14Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte14Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte14Builder(pub(crate) [Byte; 14]); +impl ::core::fmt::Debug for Byte14Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte14Builder { + fn default() -> Self { + Byte14Builder([ + 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 Byte14Builder { + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 14; + pub fn set(mut self, v: [Byte; 14]) -> 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 + } +} +impl molecule::prelude::Builder for Byte14Builder { + type Entity = Byte14; + const NAME: &'static str = "Byte14Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte14::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte15(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte15 { + 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 Byte15 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte15 { + 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 Byte15 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte15::new_unchecked(v) + } +} +impl Byte15 { + const DEFAULT_VALUE: [u8; 15] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 15; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> Byte15Reader<'r> { + Byte15Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte15 { + type Builder = Byte15Builder; + const NAME: &'static str = "Byte15"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte15(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 { + Byte15Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte15Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Byte15Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte15Reader<'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 Byte15Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte15Reader<'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> Byte15Reader<'r> { + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 15; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte15Reader<'r> { + type Entity = Byte15; + const NAME: &'static str = "Byte15Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte15Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte15Builder(pub(crate) [Byte; 15]); +impl ::core::fmt::Debug for Byte15Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte15Builder { + fn default() -> Self { + Byte15Builder([ + 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 Byte15Builder { + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 15; + pub fn set(mut self, v: [Byte; 15]) -> 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 + } +} +impl molecule::prelude::Builder for Byte15Builder { + type Entity = Byte15; + const NAME: &'static str = "Byte15Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte15::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte16(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte16 { + 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 Byte16 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte16 { + 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 Byte16 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte16::new_unchecked(v) + } +} +impl Byte16 { + const DEFAULT_VALUE: [u8; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + 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) -> Byte16Reader<'r> { + Byte16Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte16 { + type Builder = Byte16Builder; + const NAME: &'static str = "Byte16"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte16(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 { + Byte16Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte16Reader::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 Byte16Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte16Reader<'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 Byte16Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte16Reader<'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> Byte16Reader<'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 Byte16Reader<'r> { + type Entity = Byte16; + const NAME: &'static str = "Byte16Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte16Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte16Builder(pub(crate) [Byte; 16]); +impl ::core::fmt::Debug for Byte16Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte16Builder { + fn default() -> Self { + Byte16Builder([ + 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 Byte16Builder { + 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 Byte16Builder { + type Entity = Byte16; + const NAME: &'static str = "Byte16Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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)); + Byte16::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word { + 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 Word { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word { + 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 Word { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word::new_unchecked(v) + } +} +impl Word { + const DEFAULT_VALUE: [u8; 2] = [0, 0]; + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + 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 raw_data(&self) -> molecule::bytes::Bytes { + self.as_bytes() + } + pub fn as_reader<'r>(&'r self) -> WordReader<'r> { + WordReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word { + type Builder = WordBuilder; + const NAME: &'static str = "Word"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word(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 { + WordReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordReader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct WordReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordReader<'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 WordReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordReader<'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> WordReader<'r> { + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + 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 raw_data(&self) -> &'r [u8] { + self.as_slice() + } +} +impl<'r> molecule::prelude::Reader<'r> for WordReader<'r> { + type Entity = Word; + const NAME: &'static str = "WordReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordReader(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(()) + } +} +#[derive(Clone)] +pub struct WordBuilder(pub(crate) [Byte; 2]); +impl ::core::fmt::Debug for WordBuilder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for WordBuilder { + fn default() -> Self { + WordBuilder([Byte::default(), Byte::default()]) + } +} +impl WordBuilder { + pub const TOTAL_SIZE: usize = 2; + pub const ITEM_SIZE: usize = 1; + pub const ITEM_COUNT: usize = 2; + pub fn set(mut self, v: [Byte; 2]) -> 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 + } +} +impl molecule::prelude::Builder for WordBuilder { + type Entity = Word; + const NAME: &'static str = "WordBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.0[0].as_slice())?; + writer.write_all(self.0[1].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)); + Word::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word2(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word2 { + 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 Word2 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word2 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word2 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word2::new_unchecked(v) + } +} +impl Word2 { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 4; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 2; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn as_reader<'r>(&'r self) -> Word2Reader<'r> { + Word2Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word2 { + type Builder = Word2Builder; + const NAME: &'static str = "Word2"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word2(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 { + Word2Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word2Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Word2Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word2Reader<'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 Word2Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word2Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, "]") + } +} +impl<'r> Word2Reader<'r> { + pub const TOTAL_SIZE: usize = 4; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 2; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word2Reader<'r> { + type Entity = Word2; + const NAME: &'static str = "Word2Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word2Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word2Builder(pub(crate) [Word; 2]); +impl ::core::fmt::Debug for Word2Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word2Builder { + fn default() -> Self { + Word2Builder([Word::default(), Word::default()]) + } +} +impl Word2Builder { + pub const TOTAL_SIZE: usize = 4; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 2; + pub fn set(mut self, v: [Word; 2]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } +} +impl molecule::prelude::Builder for Word2Builder { + type Entity = Word2; + const NAME: &'static str = "Word2Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.0[0].as_slice())?; + writer.write_all(self.0[1].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)); + Word2::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word3 { + 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 Word3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word3::new_unchecked(v) + } +} +impl Word3 { + const DEFAULT_VALUE: [u8; 6] = [0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn as_reader<'r>(&'r self) -> Word3Reader<'r> { + Word3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word3 { + type Builder = Word3Builder; + const NAME: &'static str = "Word3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word3(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 { + Word3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Word3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word3Reader<'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 Word3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> Word3Reader<'r> { + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word3Reader<'r> { + type Entity = Word3; + const NAME: &'static str = "Word3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word3Builder(pub(crate) [Word; 3]); +impl ::core::fmt::Debug for Word3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word3Builder { + fn default() -> Self { + Word3Builder([Word::default(), Word::default(), Word::default()]) + } +} +impl Word3Builder { + pub const TOTAL_SIZE: usize = 6; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Word; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for Word3Builder { + type Entity = Word3; + const NAME: &'static str = "Word3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Word3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word4(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word4 { + 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 Word4 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word4 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word4 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word4::new_unchecked(v) + } +} +impl Word4 { + const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 4; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn nth3(&self) -> Word { + Word::new_unchecked(self.0.slice(6..8)) + } + pub fn as_reader<'r>(&'r self) -> Word4Reader<'r> { + Word4Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word4 { + type Builder = Word4Builder; + const NAME: &'static str = "Word4"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word4(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 { + Word4Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word4Reader::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 Word4Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word4Reader<'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 Word4Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word4Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, "]") + } +} +impl<'r> Word4Reader<'r> { + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 4; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn nth3(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[6..8]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word4Reader<'r> { + type Entity = Word4; + const NAME: &'static str = "Word4Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word4Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word4Builder(pub(crate) [Word; 4]); +impl ::core::fmt::Debug for Word4Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word4Builder { + fn default() -> Self { + Word4Builder([ + Word::default(), + Word::default(), + Word::default(), + Word::default(), + ]) + } +} +impl Word4Builder { + pub const TOTAL_SIZE: usize = 8; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 4; + pub fn set(mut self, v: [Word; 4]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } + pub fn nth3(mut self, v: Word) -> Self { + self.0[3] = v; + self + } +} +impl molecule::prelude::Builder for Word4Builder { + type Entity = Word4; + const NAME: &'static str = "Word4Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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)); + Word4::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word5(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word5 { + 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 Word5 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word5 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word5 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word5::new_unchecked(v) + } +} +impl Word5 { + const DEFAULT_VALUE: [u8; 10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 5; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn nth3(&self) -> Word { + Word::new_unchecked(self.0.slice(6..8)) + } + pub fn nth4(&self) -> Word { + Word::new_unchecked(self.0.slice(8..10)) + } + pub fn as_reader<'r>(&'r self) -> Word5Reader<'r> { + Word5Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word5 { + type Builder = Word5Builder; + const NAME: &'static str = "Word5"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word5(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 { + Word5Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word5Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Word5Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word5Reader<'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 Word5Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word5Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, "]") + } +} +impl<'r> Word5Reader<'r> { + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 5; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn nth3(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[6..8]) + } + pub fn nth4(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[8..10]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word5Reader<'r> { + type Entity = Word5; + const NAME: &'static str = "Word5Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word5Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word5Builder(pub(crate) [Word; 5]); +impl ::core::fmt::Debug for Word5Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word5Builder { + fn default() -> Self { + Word5Builder([ + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + ]) + } +} +impl Word5Builder { + pub const TOTAL_SIZE: usize = 10; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 5; + pub fn set(mut self, v: [Word; 5]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } + pub fn nth3(mut self, v: Word) -> Self { + self.0[3] = v; + self + } + pub fn nth4(mut self, v: Word) -> Self { + self.0[4] = v; + self + } +} +impl molecule::prelude::Builder for Word5Builder { + type Entity = Word5; + const NAME: &'static str = "Word5Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Word5::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word6(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word6 { + 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 Word6 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word6 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word6 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word6::new_unchecked(v) + } +} +impl Word6 { + const DEFAULT_VALUE: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 6; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn nth3(&self) -> Word { + Word::new_unchecked(self.0.slice(6..8)) + } + pub fn nth4(&self) -> Word { + Word::new_unchecked(self.0.slice(8..10)) + } + pub fn nth5(&self) -> Word { + Word::new_unchecked(self.0.slice(10..12)) + } + pub fn as_reader<'r>(&'r self) -> Word6Reader<'r> { + Word6Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word6 { + type Builder = Word6Builder; + const NAME: &'static str = "Word6"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word6(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 { + Word6Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word6Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Word6Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word6Reader<'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 Word6Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word6Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, "]") + } +} +impl<'r> Word6Reader<'r> { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 6; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn nth3(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[6..8]) + } + pub fn nth4(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[8..10]) + } + pub fn nth5(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[10..12]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word6Reader<'r> { + type Entity = Word6; + const NAME: &'static str = "Word6Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word6Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word6Builder(pub(crate) [Word; 6]); +impl ::core::fmt::Debug for Word6Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word6Builder { + fn default() -> Self { + Word6Builder([ + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + ]) + } +} +impl Word6Builder { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 6; + pub fn set(mut self, v: [Word; 6]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } + pub fn nth3(mut self, v: Word) -> Self { + self.0[3] = v; + self + } + pub fn nth4(mut self, v: Word) -> Self { + self.0[4] = v; + self + } + pub fn nth5(mut self, v: Word) -> Self { + self.0[5] = v; + self + } +} +impl molecule::prelude::Builder for Word6Builder { + type Entity = Word6; + const NAME: &'static str = "Word6Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Word6::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word7(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word7 { + 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 Word7 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word7 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, ", {}", self.nth6())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word7 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word7::new_unchecked(v) + } +} +impl Word7 { + const DEFAULT_VALUE: [u8; 14] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 7; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn nth3(&self) -> Word { + Word::new_unchecked(self.0.slice(6..8)) + } + pub fn nth4(&self) -> Word { + Word::new_unchecked(self.0.slice(8..10)) + } + pub fn nth5(&self) -> Word { + Word::new_unchecked(self.0.slice(10..12)) + } + pub fn nth6(&self) -> Word { + Word::new_unchecked(self.0.slice(12..14)) + } + pub fn as_reader<'r>(&'r self) -> Word7Reader<'r> { + Word7Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word7 { + type Builder = Word7Builder; + const NAME: &'static str = "Word7"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word7(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 { + Word7Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word7Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Word7Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word7Reader<'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 Word7Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word7Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, ", {}", self.nth6())?; + write!(f, "]") + } +} +impl<'r> Word7Reader<'r> { + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 7; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn nth3(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[6..8]) + } + pub fn nth4(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[8..10]) + } + pub fn nth5(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[10..12]) + } + pub fn nth6(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[12..14]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word7Reader<'r> { + type Entity = Word7; + const NAME: &'static str = "Word7Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word7Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word7Builder(pub(crate) [Word; 7]); +impl ::core::fmt::Debug for Word7Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word7Builder { + fn default() -> Self { + Word7Builder([ + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + ]) + } +} +impl Word7Builder { + pub const TOTAL_SIZE: usize = 14; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 7; + pub fn set(mut self, v: [Word; 7]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } + pub fn nth3(mut self, v: Word) -> Self { + self.0[3] = v; + self + } + pub fn nth4(mut self, v: Word) -> Self { + self.0[4] = v; + self + } + pub fn nth5(mut self, v: Word) -> Self { + self.0[5] = v; + self + } + pub fn nth6(mut self, v: Word) -> Self { + self.0[6] = v; + self + } +} +impl molecule::prelude::Builder for Word7Builder { + type Entity = Word7; + const NAME: &'static str = "Word7Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Word7::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Word8(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Word8 { + 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 Word8 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Word8 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, ", {}", self.nth6())?; + write!(f, ", {}", self.nth7())?; + write!(f, "]") + } +} +impl ::core::default::Default for Word8 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Word8::new_unchecked(v) + } +} +impl Word8 { + const DEFAULT_VALUE: [u8; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 16; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 8; + pub fn nth0(&self) -> Word { + Word::new_unchecked(self.0.slice(0..2)) + } + pub fn nth1(&self) -> Word { + Word::new_unchecked(self.0.slice(2..4)) + } + pub fn nth2(&self) -> Word { + Word::new_unchecked(self.0.slice(4..6)) + } + pub fn nth3(&self) -> Word { + Word::new_unchecked(self.0.slice(6..8)) + } + pub fn nth4(&self) -> Word { + Word::new_unchecked(self.0.slice(8..10)) + } + pub fn nth5(&self) -> Word { + Word::new_unchecked(self.0.slice(10..12)) + } + pub fn nth6(&self) -> Word { + Word::new_unchecked(self.0.slice(12..14)) + } + pub fn nth7(&self) -> Word { + Word::new_unchecked(self.0.slice(14..16)) + } + pub fn as_reader<'r>(&'r self) -> Word8Reader<'r> { + Word8Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Word8 { + type Builder = Word8Builder; + const NAME: &'static str = "Word8"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Word8(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 { + Word8Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Word8Reader::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(), + ]) + } +} +#[derive(Clone, Copy)] +pub struct Word8Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Word8Reader<'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 Word8Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Word8Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, ", {}", self.nth3())?; + write!(f, ", {}", self.nth4())?; + write!(f, ", {}", self.nth5())?; + write!(f, ", {}", self.nth6())?; + write!(f, ", {}", self.nth7())?; + write!(f, "]") + } +} +impl<'r> Word8Reader<'r> { + pub const TOTAL_SIZE: usize = 16; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 8; + pub fn nth0(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[0..2]) + } + pub fn nth1(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn nth2(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn nth3(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[6..8]) + } + pub fn nth4(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[8..10]) + } + pub fn nth5(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[10..12]) + } + pub fn nth6(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[12..14]) + } + pub fn nth7(&self) -> WordReader<'r> { + WordReader::new_unchecked(&self.as_slice()[14..16]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Word8Reader<'r> { + type Entity = Word8; + const NAME: &'static str = "Word8Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Word8Reader(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(()) + } +} +#[derive(Clone)] +pub struct Word8Builder(pub(crate) [Word; 8]); +impl ::core::fmt::Debug for Word8Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Word8Builder { + fn default() -> Self { + Word8Builder([ + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + Word::default(), + ]) + } +} +impl Word8Builder { + pub const TOTAL_SIZE: usize = 16; + pub const ITEM_SIZE: usize = 2; + pub const ITEM_COUNT: usize = 8; + pub fn set(mut self, v: [Word; 8]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Word) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Word) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Word) -> Self { + self.0[2] = v; + self + } + pub fn nth3(mut self, v: Word) -> Self { + self.0[3] = v; + self + } + pub fn nth4(mut self, v: Word) -> Self { + self.0[4] = v; + self + } + pub fn nth5(mut self, v: Word) -> Self { + self.0[5] = v; + self + } + pub fn nth6(mut self, v: Word) -> Self { + self.0[6] = v; + self + } + pub fn nth7(mut self, v: Word) -> Self { + self.0[7] = v; + self + } +} +impl molecule::prelude::Builder for Word8Builder { + type Entity = Word8; + const NAME: &'static str = "Word8Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Word8::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte3x3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte3x3 { + 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 Byte3x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte3x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for Byte3x3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte3x3::new_unchecked(v) + } +} +impl Byte3x3 { + const DEFAULT_VALUE: [u8; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 3; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(0..3)) + } + pub fn nth1(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(3..6)) + } + pub fn nth2(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(6..9)) + } + pub fn as_reader<'r>(&'r self) -> Byte3x3Reader<'r> { + Byte3x3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte3x3 { + type Builder = Byte3x3Builder; + const NAME: &'static str = "Byte3x3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte3x3(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 { + Byte3x3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte3x3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte3x3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte3x3Reader<'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 Byte3x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte3x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> Byte3x3Reader<'r> { + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 3; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[0..3]) + } + pub fn nth1(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[3..6]) + } + pub fn nth2(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[6..9]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte3x3Reader<'r> { + type Entity = Byte3x3; + const NAME: &'static str = "Byte3x3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte3x3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte3x3Builder(pub(crate) [Byte3; 3]); +impl ::core::fmt::Debug for Byte3x3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte3x3Builder { + fn default() -> Self { + Byte3x3Builder([Byte3::default(), Byte3::default(), Byte3::default()]) + } +} +impl Byte3x3Builder { + pub const TOTAL_SIZE: usize = 9; + pub const ITEM_SIZE: usize = 3; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Byte3; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Byte3) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Byte3) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Byte3) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for Byte3x3Builder { + type Entity = Byte3x3; + const NAME: &'static str = "Byte3x3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte3x3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte5x3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte5x3 { + 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 Byte5x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte5x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for Byte5x3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte5x3::new_unchecked(v) + } +} +impl Byte5x3 { + const DEFAULT_VALUE: [u8; 15] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 5; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte5 { + Byte5::new_unchecked(self.0.slice(0..5)) + } + pub fn nth1(&self) -> Byte5 { + Byte5::new_unchecked(self.0.slice(5..10)) + } + pub fn nth2(&self) -> Byte5 { + Byte5::new_unchecked(self.0.slice(10..15)) + } + pub fn as_reader<'r>(&'r self) -> Byte5x3Reader<'r> { + Byte5x3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte5x3 { + type Builder = Byte5x3Builder; + const NAME: &'static str = "Byte5x3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte5x3(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 { + Byte5x3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte5x3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte5x3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte5x3Reader<'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 Byte5x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte5x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> Byte5x3Reader<'r> { + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 5; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte5Reader<'r> { + Byte5Reader::new_unchecked(&self.as_slice()[0..5]) + } + pub fn nth1(&self) -> Byte5Reader<'r> { + Byte5Reader::new_unchecked(&self.as_slice()[5..10]) + } + pub fn nth2(&self) -> Byte5Reader<'r> { + Byte5Reader::new_unchecked(&self.as_slice()[10..15]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte5x3Reader<'r> { + type Entity = Byte5x3; + const NAME: &'static str = "Byte5x3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte5x3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte5x3Builder(pub(crate) [Byte5; 3]); +impl ::core::fmt::Debug for Byte5x3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte5x3Builder { + fn default() -> Self { + Byte5x3Builder([Byte5::default(), Byte5::default(), Byte5::default()]) + } +} +impl Byte5x3Builder { + pub const TOTAL_SIZE: usize = 15; + pub const ITEM_SIZE: usize = 5; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Byte5; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Byte5) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Byte5) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Byte5) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for Byte5x3Builder { + type Entity = Byte5x3; + const NAME: &'static str = "Byte5x3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte5x3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte7x3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte7x3 { + 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 Byte7x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte7x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for Byte7x3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte7x3::new_unchecked(v) + } +} +impl Byte7x3 { + const DEFAULT_VALUE: [u8; 21] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + pub const TOTAL_SIZE: usize = 21; + pub const ITEM_SIZE: usize = 7; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte7 { + Byte7::new_unchecked(self.0.slice(0..7)) + } + pub fn nth1(&self) -> Byte7 { + Byte7::new_unchecked(self.0.slice(7..14)) + } + pub fn nth2(&self) -> Byte7 { + Byte7::new_unchecked(self.0.slice(14..21)) + } + pub fn as_reader<'r>(&'r self) -> Byte7x3Reader<'r> { + Byte7x3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte7x3 { + type Builder = Byte7x3Builder; + const NAME: &'static str = "Byte7x3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte7x3(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 { + Byte7x3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte7x3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte7x3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte7x3Reader<'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 Byte7x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte7x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> Byte7x3Reader<'r> { + pub const TOTAL_SIZE: usize = 21; + pub const ITEM_SIZE: usize = 7; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte7Reader<'r> { + Byte7Reader::new_unchecked(&self.as_slice()[0..7]) + } + pub fn nth1(&self) -> Byte7Reader<'r> { + Byte7Reader::new_unchecked(&self.as_slice()[7..14]) + } + pub fn nth2(&self) -> Byte7Reader<'r> { + Byte7Reader::new_unchecked(&self.as_slice()[14..21]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte7x3Reader<'r> { + type Entity = Byte7x3; + const NAME: &'static str = "Byte7x3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte7x3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte7x3Builder(pub(crate) [Byte7; 3]); +impl ::core::fmt::Debug for Byte7x3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte7x3Builder { + fn default() -> Self { + Byte7x3Builder([Byte7::default(), Byte7::default(), Byte7::default()]) + } +} +impl Byte7x3Builder { + pub const TOTAL_SIZE: usize = 21; + pub const ITEM_SIZE: usize = 7; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Byte7; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Byte7) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Byte7) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Byte7) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for Byte7x3Builder { + type Entity = Byte7x3; + const NAME: &'static str = "Byte7x3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte7x3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Byte9x3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte9x3 { + 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 Byte9x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte9x3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for Byte9x3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte9x3::new_unchecked(v) + } +} +impl Byte9x3 { + const DEFAULT_VALUE: [u8; 27] = [ + 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, + ]; + pub const TOTAL_SIZE: usize = 27; + pub const ITEM_SIZE: usize = 9; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte9 { + Byte9::new_unchecked(self.0.slice(0..9)) + } + pub fn nth1(&self) -> Byte9 { + Byte9::new_unchecked(self.0.slice(9..18)) + } + pub fn nth2(&self) -> Byte9 { + Byte9::new_unchecked(self.0.slice(18..27)) + } + pub fn as_reader<'r>(&'r self) -> Byte9x3Reader<'r> { + Byte9x3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte9x3 { + type Builder = Byte9x3Builder; + const NAME: &'static str = "Byte9x3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte9x3(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 { + Byte9x3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte9x3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct Byte9x3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte9x3Reader<'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 Byte9x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte9x3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> Byte9x3Reader<'r> { + pub const TOTAL_SIZE: usize = 27; + pub const ITEM_SIZE: usize = 9; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> Byte9Reader<'r> { + Byte9Reader::new_unchecked(&self.as_slice()[0..9]) + } + pub fn nth1(&self) -> Byte9Reader<'r> { + Byte9Reader::new_unchecked(&self.as_slice()[9..18]) + } + pub fn nth2(&self) -> Byte9Reader<'r> { + Byte9Reader::new_unchecked(&self.as_slice()[18..27]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte9x3Reader<'r> { + type Entity = Byte9x3; + const NAME: &'static str = "Byte9x3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte9x3Reader(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(()) + } +} +#[derive(Clone)] +pub struct Byte9x3Builder(pub(crate) [Byte9; 3]); +impl ::core::fmt::Debug for Byte9x3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for Byte9x3Builder { + fn default() -> Self { + Byte9x3Builder([Byte9::default(), Byte9::default(), Byte9::default()]) + } +} +impl Byte9x3Builder { + pub const TOTAL_SIZE: usize = 27; + pub const ITEM_SIZE: usize = 9; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [Byte9; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: Byte9) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: Byte9) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: Byte9) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for Byte9x3Builder { + type Entity = Byte9x3; + const NAME: &'static str = "Byte9x3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + Byte9x3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructA(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructA { + 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 StructA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructA { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructA::new_unchecked(v) + } +} +impl StructA { + const DEFAULT_VALUE: [u8; 6] = [0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(1..2)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(2..4)) + } + pub fn f4(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(4..6)) + } + pub fn as_reader<'r>(&'r self) -> StructAReader<'r> { + StructAReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructA { + type Builder = StructABuilder; + const NAME: &'static str = "StructA"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructA(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 { + StructAReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructAReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructAReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructAReader<'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 StructAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructAReader<'r> { + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[1..2]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn f4(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[4..6]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructAReader<'r> { + type Entity = StructA; + const NAME: &'static str = "StructAReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructAReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructABuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Byte2, +} +impl StructABuilder { + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte2) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructABuilder { + type Entity = StructA; + const NAME: &'static str = "StructABuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructA::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructB(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructB { + 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 StructB { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructB { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructB { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructB::new_unchecked(v) + } +} +impl StructB { + const DEFAULT_VALUE: [u8; 7] = [0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 3]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(1..2)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(2..4)) + } + pub fn f4(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(4..7)) + } + pub fn as_reader<'r>(&'r self) -> StructBReader<'r> { + StructBReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructB { + type Builder = StructBBuilder; + const NAME: &'static str = "StructB"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructB(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 { + StructBReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructBReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructBReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructBReader<'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 StructBReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructBReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructBReader<'r> { + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 3]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[1..2]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn f4(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[4..7]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructBReader<'r> { + type Entity = StructB; + const NAME: &'static str = "StructBReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructBReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructBBuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Byte3, +} +impl StructBBuilder { + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 3]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte3) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructBBuilder { + type Entity = StructB; + const NAME: &'static str = "StructBBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructB::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructC(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructC { + 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 StructC { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructC { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructC { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructC::new_unchecked(v) + } +} +impl StructC { + const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(1..2)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(2..4)) + } + pub fn f4(&self) -> Byte4 { + Byte4::new_unchecked(self.0.slice(4..8)) + } + pub fn as_reader<'r>(&'r self) -> StructCReader<'r> { + StructCReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructC { + type Builder = StructCBuilder; + const NAME: &'static str = "StructC"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructC(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 { + StructCReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructCReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructCReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructCReader<'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 StructCReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructCReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructCReader<'r> { + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[1..2]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn f4(&self) -> Byte4Reader<'r> { + Byte4Reader::new_unchecked(&self.as_slice()[4..8]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructCReader<'r> { + type Entity = StructC; + const NAME: &'static str = "StructCReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructCReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructCBuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Byte4, +} +impl StructCBuilder { + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte4) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructCBuilder { + type Entity = StructC; + const NAME: &'static str = "StructCBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructC::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructD(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructD { + 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 StructD { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructD { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructD { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructD::new_unchecked(v) + } +} +impl StructD { + const DEFAULT_VALUE: [u8; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 9; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 5]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(1..2)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(2..4)) + } + pub fn f4(&self) -> Byte5 { + Byte5::new_unchecked(self.0.slice(4..9)) + } + pub fn as_reader<'r>(&'r self) -> StructDReader<'r> { + StructDReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructD { + type Builder = StructDBuilder; + const NAME: &'static str = "StructD"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructD(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 { + StructDReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructDReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructDReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructDReader<'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 StructDReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructDReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructDReader<'r> { + pub const TOTAL_SIZE: usize = 9; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 5]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[1..2]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[2..4]) + } + pub fn f4(&self) -> Byte5Reader<'r> { + Byte5Reader::new_unchecked(&self.as_slice()[4..9]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructDReader<'r> { + type Entity = StructD; + const NAME: &'static str = "StructDReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructDReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructDBuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Byte5, +} +impl StructDBuilder { + pub const TOTAL_SIZE: usize = 9; + pub const FIELD_SIZES: [usize; 4] = [1, 1, 2, 5]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte5) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructDBuilder { + type Entity = StructD; + const NAME: &'static str = "StructDBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructD::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructE(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructE { + 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 StructE { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructE { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructE { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructE::new_unchecked(v) + } +} +impl StructE { + const DEFAULT_VALUE: [u8; 6] = [0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 2, 1, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(1..3)) + } + pub fn f3(&self) -> Byte { + Byte::new_unchecked(self.0.slice(3..4)) + } + pub fn f4(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(4..6)) + } + pub fn as_reader<'r>(&'r self) -> StructEReader<'r> { + StructEReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructE { + type Builder = StructEBuilder; + const NAME: &'static str = "StructE"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructE(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 { + StructEReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructEReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructEReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructEReader<'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 StructEReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructEReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructEReader<'r> { + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 2, 1, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[1..3]) + } + pub fn f3(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[3..4]) + } + pub fn f4(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[4..6]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructEReader<'r> { + type Entity = StructE; + const NAME: &'static str = "StructEReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructEReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructEBuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte2, + pub(crate) f3: Byte, + pub(crate) f4: Byte2, +} +impl StructEBuilder { + pub const TOTAL_SIZE: usize = 6; + pub const FIELD_SIZES: [usize; 4] = [1, 2, 1, 2]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte2) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte2) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructEBuilder { + type Entity = StructE; + const NAME: &'static str = "StructEBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructE::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructF(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructF { + 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 StructF { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructF { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructF { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructF::new_unchecked(v) + } +} +impl StructF { + const DEFAULT_VALUE: [u8; 5] = [0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 5; + pub const FIELD_SIZES: [usize; 3] = [1, 3, 1]; + pub const FIELD_COUNT: usize = 3; + pub fn f1(&self) -> Byte { + Byte::new_unchecked(self.0.slice(0..1)) + } + pub fn f2(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(1..4)) + } + pub fn f3(&self) -> Byte { + Byte::new_unchecked(self.0.slice(4..5)) + } + pub fn as_reader<'r>(&'r self) -> StructFReader<'r> { + StructFReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructF { + type Builder = StructFBuilder; + const NAME: &'static str = "StructF"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructF(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 { + StructFReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructFReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + } +} +#[derive(Clone, Copy)] +pub struct StructFReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructFReader<'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 StructFReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructFReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, " }}") + } +} +impl<'r> StructFReader<'r> { + pub const TOTAL_SIZE: usize = 5; + pub const FIELD_SIZES: [usize; 3] = [1, 3, 1]; + pub const FIELD_COUNT: usize = 3; + pub fn f1(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[0..1]) + } + pub fn f2(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[1..4]) + } + pub fn f3(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[4..5]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructFReader<'r> { + type Entity = StructF; + const NAME: &'static str = "StructFReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructFReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructFBuilder { + pub(crate) f1: Byte, + pub(crate) f2: Byte3, + pub(crate) f3: Byte, +} +impl StructFBuilder { + pub const TOTAL_SIZE: usize = 5; + pub const FIELD_SIZES: [usize; 3] = [1, 3, 1]; + pub const FIELD_COUNT: usize = 3; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte3) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte) -> Self { + self.f3 = v; + self + } +} +impl molecule::prelude::Builder for StructFBuilder { + type Entity = StructF; + const NAME: &'static str = "StructFBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.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)); + StructF::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructG(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructG { + 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 StructG { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructG { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructG { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructG::new_unchecked(v) + } +} +impl StructG { + const DEFAULT_VALUE: [u8; 10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(0..3)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(3..4)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(4..6)) + } + pub fn f4(&self) -> Word2 { + Word2::new_unchecked(self.0.slice(6..10)) + } + pub fn as_reader<'r>(&'r self) -> StructGReader<'r> { + StructGReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructG { + type Builder = StructGBuilder; + const NAME: &'static str = "StructG"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructG(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 { + StructGReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructGReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructGReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructGReader<'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 StructGReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructGReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructGReader<'r> { + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[0..3]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[3..4]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn f4(&self) -> Word2Reader<'r> { + Word2Reader::new_unchecked(&self.as_slice()[6..10]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructGReader<'r> { + type Entity = StructG; + const NAME: &'static str = "StructGReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructGReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructGBuilder { + pub(crate) f1: Byte3, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Word2, +} +impl StructGBuilder { + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte3) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Word2) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructGBuilder { + type Entity = StructG; + const NAME: &'static str = "StructGBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructG::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructH(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructH { + 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 StructH { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructH { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructH { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructH::new_unchecked(v) + } +} +impl StructH { + const DEFAULT_VALUE: [u8; 10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(0..3)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(3..4)) + } + pub fn f3(&self) -> Byte2 { + Byte2::new_unchecked(self.0.slice(4..6)) + } + pub fn f4(&self) -> Byte4 { + Byte4::new_unchecked(self.0.slice(6..10)) + } + pub fn as_reader<'r>(&'r self) -> StructHReader<'r> { + StructHReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructH { + type Builder = StructHBuilder; + const NAME: &'static str = "StructH"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructH(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 { + StructHReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructHReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct StructHReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructHReader<'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 StructHReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructHReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, " }}") + } +} +impl<'r> StructHReader<'r> { + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[0..3]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[3..4]) + } + pub fn f3(&self) -> Byte2Reader<'r> { + Byte2Reader::new_unchecked(&self.as_slice()[4..6]) + } + pub fn f4(&self) -> Byte4Reader<'r> { + Byte4Reader::new_unchecked(&self.as_slice()[6..10]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructHReader<'r> { + type Entity = StructH; + const NAME: &'static str = "StructHReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructHReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructHBuilder { + pub(crate) f1: Byte3, + pub(crate) f2: Byte, + pub(crate) f3: Byte2, + pub(crate) f4: Byte4, +} +impl StructHBuilder { + pub const TOTAL_SIZE: usize = 10; + pub const FIELD_SIZES: [usize; 4] = [3, 1, 2, 4]; + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte3) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte2) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte4) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for StructHBuilder { + type Entity = StructH; + const NAME: &'static str = "StructHBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + StructH::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructI(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructI { + 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 StructI { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructI { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructI { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructI::new_unchecked(v) + } +} +impl StructI { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 4; + pub const FIELD_SIZES: [usize; 2] = [3, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> Byte3 { + Byte3::new_unchecked(self.0.slice(0..3)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(3..4)) + } + pub fn as_reader<'r>(&'r self) -> StructIReader<'r> { + StructIReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructI { + type Builder = StructIBuilder; + const NAME: &'static str = "StructI"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructI(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 { + StructIReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructIReader::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().f1(self.f1()).f2(self.f2()) + } +} +#[derive(Clone, Copy)] +pub struct StructIReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructIReader<'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 StructIReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructIReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl<'r> StructIReader<'r> { + pub const TOTAL_SIZE: usize = 4; + pub const FIELD_SIZES: [usize; 2] = [3, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> Byte3Reader<'r> { + Byte3Reader::new_unchecked(&self.as_slice()[0..3]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[3..4]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructIReader<'r> { + type Entity = StructI; + const NAME: &'static str = "StructIReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructIReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructIBuilder { + pub(crate) f1: Byte3, + pub(crate) f2: Byte, +} +impl StructIBuilder { + pub const TOTAL_SIZE: usize = 4; + pub const FIELD_SIZES: [usize; 2] = [3, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(mut self, v: Byte3) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } +} +impl molecule::prelude::Builder for StructIBuilder { + type Entity = StructI; + const NAME: &'static str = "StructIBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.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)); + StructI::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructJ(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructJ { + 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 StructJ { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructJ { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructJ { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructJ::new_unchecked(v) + } +} +impl StructJ { + const DEFAULT_VALUE: [u8; 7] = [0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 2] = [6, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> Byte6 { + Byte6::new_unchecked(self.0.slice(0..6)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(6..7)) + } + pub fn as_reader<'r>(&'r self) -> StructJReader<'r> { + StructJReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructJ { + type Builder = StructJBuilder; + const NAME: &'static str = "StructJ"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructJ(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 { + StructJReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructJReader::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().f1(self.f1()).f2(self.f2()) + } +} +#[derive(Clone, Copy)] +pub struct StructJReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructJReader<'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 StructJReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructJReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl<'r> StructJReader<'r> { + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 2] = [6, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> Byte6Reader<'r> { + Byte6Reader::new_unchecked(&self.as_slice()[0..6]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[6..7]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructJReader<'r> { + type Entity = StructJ; + const NAME: &'static str = "StructJReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructJReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructJBuilder { + pub(crate) f1: Byte6, + pub(crate) f2: Byte, +} +impl StructJBuilder { + pub const TOTAL_SIZE: usize = 7; + pub const FIELD_SIZES: [usize; 2] = [6, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(mut self, v: Byte6) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } +} +impl molecule::prelude::Builder for StructJBuilder { + type Entity = StructJ; + const NAME: &'static str = "StructJBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.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)); + StructJ::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructIx3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructIx3 { + 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 StructIx3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructIx3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl ::core::default::Default for StructIx3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructIx3::new_unchecked(v) + } +} +impl StructIx3 { + const DEFAULT_VALUE: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 4; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> StructI { + StructI::new_unchecked(self.0.slice(0..4)) + } + pub fn nth1(&self) -> StructI { + StructI::new_unchecked(self.0.slice(4..8)) + } + pub fn nth2(&self) -> StructI { + StructI::new_unchecked(self.0.slice(8..12)) + } + pub fn as_reader<'r>(&'r self) -> StructIx3Reader<'r> { + StructIx3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructIx3 { + type Builder = StructIx3Builder; + const NAME: &'static str = "StructIx3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructIx3(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 { + StructIx3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructIx3Reader::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()]) + } +} +#[derive(Clone, Copy)] +pub struct StructIx3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructIx3Reader<'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 StructIx3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructIx3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + write!(f, "{}", self.nth0())?; + write!(f, ", {}", self.nth1())?; + write!(f, ", {}", self.nth2())?; + write!(f, "]") + } +} +impl<'r> StructIx3Reader<'r> { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 4; + pub const ITEM_COUNT: usize = 3; + pub fn nth0(&self) -> StructIReader<'r> { + StructIReader::new_unchecked(&self.as_slice()[0..4]) + } + pub fn nth1(&self) -> StructIReader<'r> { + StructIReader::new_unchecked(&self.as_slice()[4..8]) + } + pub fn nth2(&self) -> StructIReader<'r> { + StructIReader::new_unchecked(&self.as_slice()[8..12]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructIx3Reader<'r> { + type Entity = StructIx3; + const NAME: &'static str = "StructIx3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructIx3Reader(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(()) + } +} +#[derive(Clone)] +pub struct StructIx3Builder(pub(crate) [StructI; 3]); +impl ::core::fmt::Debug for StructIx3Builder { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:?})", Self::NAME, &self.0[..]) + } +} +impl ::core::default::Default for StructIx3Builder { + fn default() -> Self { + StructIx3Builder([StructI::default(), StructI::default(), StructI::default()]) + } +} +impl StructIx3Builder { + pub const TOTAL_SIZE: usize = 12; + pub const ITEM_SIZE: usize = 4; + pub const ITEM_COUNT: usize = 3; + pub fn set(mut self, v: [StructI; 3]) -> Self { + self.0 = v; + self + } + pub fn nth0(mut self, v: StructI) -> Self { + self.0[0] = v; + self + } + pub fn nth1(mut self, v: StructI) -> Self { + self.0[1] = v; + self + } + pub fn nth2(mut self, v: StructI) -> Self { + self.0[2] = v; + self + } +} +impl molecule::prelude::Builder for StructIx3Builder { + type Entity = StructIx3; + const NAME: &'static str = "StructIx3Builder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn 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())?; + 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)); + StructIx3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructO(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructO { + 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 StructO { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructO { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructO { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructO::new_unchecked(v) + } +} +impl StructO { + const DEFAULT_VALUE: [u8; 13] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 13; + pub const FIELD_SIZES: [usize; 2] = [12, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> StructIx3 { + StructIx3::new_unchecked(self.0.slice(0..12)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(12..13)) + } + pub fn as_reader<'r>(&'r self) -> StructOReader<'r> { + StructOReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructO { + type Builder = StructOBuilder; + const NAME: &'static str = "StructO"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructO(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 { + StructOReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructOReader::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().f1(self.f1()).f2(self.f2()) + } +} +#[derive(Clone, Copy)] +pub struct StructOReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructOReader<'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 StructOReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructOReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl<'r> StructOReader<'r> { + pub const TOTAL_SIZE: usize = 13; + pub const FIELD_SIZES: [usize; 2] = [12, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> StructIx3Reader<'r> { + StructIx3Reader::new_unchecked(&self.as_slice()[0..12]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[12..13]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructOReader<'r> { + type Entity = StructO; + const NAME: &'static str = "StructOReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructOReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructOBuilder { + pub(crate) f1: StructIx3, + pub(crate) f2: Byte, +} +impl StructOBuilder { + pub const TOTAL_SIZE: usize = 13; + pub const FIELD_SIZES: [usize; 2] = [12, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(mut self, v: StructIx3) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } +} +impl molecule::prelude::Builder for StructOBuilder { + type Entity = StructO; + const NAME: &'static str = "StructOBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.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)); + StructO::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructP(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructP { + 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 StructP { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructP { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl ::core::default::Default for StructP { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructP::new_unchecked(v) + } +} +impl StructP { + const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 2] = [7, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> StructJ { + StructJ::new_unchecked(self.0.slice(0..7)) + } + pub fn f2(&self) -> Byte { + Byte::new_unchecked(self.0.slice(7..8)) + } + pub fn as_reader<'r>(&'r self) -> StructPReader<'r> { + StructPReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructP { + type Builder = StructPBuilder; + const NAME: &'static str = "StructP"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructP(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 { + StructPReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructPReader::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().f1(self.f1()).f2(self.f2()) + } +} +#[derive(Clone, Copy)] +pub struct StructPReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructPReader<'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 StructPReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructPReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, " }}") + } +} +impl<'r> StructPReader<'r> { + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 2] = [7, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(&self) -> StructJReader<'r> { + StructJReader::new_unchecked(&self.as_slice()[0..7]) + } + pub fn f2(&self) -> ByteReader<'r> { + ByteReader::new_unchecked(&self.as_slice()[7..8]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructPReader<'r> { + type Entity = StructP; + const NAME: &'static str = "StructPReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructPReader(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(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructPBuilder { + pub(crate) f1: StructJ, + pub(crate) f2: Byte, +} +impl StructPBuilder { + pub const TOTAL_SIZE: usize = 8; + pub const FIELD_SIZES: [usize; 2] = [7, 1]; + pub const FIELD_COUNT: usize = 2; + pub fn f1(mut self, v: StructJ) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte) -> Self { + self.f2 = v; + self + } +} +impl molecule::prelude::Builder for StructPBuilder { + type Entity = StructP; + const NAME: &'static str = "StructPBuilder"; + fn expected_length(&self) -> usize { + Self::TOTAL_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.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)); + StructP::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 = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Bytes::new_unchecked(v) + } +} +impl Bytes { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + 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 { + 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 { + BytesReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + 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> { + 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(Clone, Debug, Default)] +pub struct BytesBuilder(pub(crate) Vec); +impl BytesBuilder { + pub const ITEM_SIZE: usize = 1; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Byte) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Byte) -> Option { + 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(&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 { + 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 Words(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Words { + 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 Words { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Words { + 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 Words { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Words::new_unchecked(v) + } +} +impl Words { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 2; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Word { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + Word::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> WordsReader<'r> { + WordsReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Words { + type Builder = WordsBuilder; + const NAME: &'static str = "Words"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Words(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 { + WordsReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordsReader::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 WordsReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordsReader<'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 WordsReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordsReader<'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> WordsReader<'r> { + pub const ITEM_SIZE: usize = 2; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordReader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + WordReader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for WordsReader<'r> { + type Entity = Words; + const NAME: &'static str = "WordsReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordsReader(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(Clone, Debug, Default)] +pub struct WordsBuilder(pub(crate) Vec); +impl WordsBuilder { + pub const ITEM_SIZE: usize = 2; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Word) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Word) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for WordsBuilder { + type Entity = Words; + const NAME: &'static str = "WordsBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + Words::new_unchecked(inner.into()) + } +} +pub struct WordsIterator(Words, usize, usize); +impl ::core::iter::Iterator for WordsIterator { + type Item = Word; + fn next(&mut self) -> Option { + 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 WordsIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for Words { + type Item = Word; + type IntoIter = WordsIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + WordsIterator(self, 0, len) + } +} +impl<'r> WordsReader<'r> { + pub fn iter<'t>(&'t self) -> WordsReaderIterator<'t, 'r> { + WordsReaderIterator(&self, 0, self.len()) + } +} +pub struct WordsReaderIterator<'t, 'r>(&'t WordsReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for WordsReaderIterator<'t, 'r> { + type Item = WordReader<'t>; + fn next(&mut self) -> Option { + 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 WordsReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct Byte3Vec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte3Vec { + 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 Byte3Vec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte3Vec { + 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 Byte3Vec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte3Vec::new_unchecked(v) + } +} +impl Byte3Vec { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 3; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Byte3 { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + Byte3::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> Byte3VecReader<'r> { + Byte3VecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte3Vec { + type Builder = Byte3VecBuilder; + const NAME: &'static str = "Byte3Vec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte3Vec(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 { + Byte3VecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte3VecReader::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 Byte3VecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte3VecReader<'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 Byte3VecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte3VecReader<'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> Byte3VecReader<'r> { + pub const ITEM_SIZE: usize = 3; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Byte3Reader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + Byte3Reader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte3VecReader<'r> { + type Entity = Byte3Vec; + const NAME: &'static str = "Byte3VecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte3VecReader(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(Clone, Debug, Default)] +pub struct Byte3VecBuilder(pub(crate) Vec); +impl Byte3VecBuilder { + pub const ITEM_SIZE: usize = 3; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Byte3) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Byte3) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for Byte3VecBuilder { + type Entity = Byte3Vec; + const NAME: &'static str = "Byte3VecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + Byte3Vec::new_unchecked(inner.into()) + } +} +pub struct Byte3VecIterator(Byte3Vec, usize, usize); +impl ::core::iter::Iterator for Byte3VecIterator { + type Item = Byte3; + fn next(&mut self) -> Option { + 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 Byte3VecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for Byte3Vec { + type Item = Byte3; + type IntoIter = Byte3VecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + Byte3VecIterator(self, 0, len) + } +} +impl<'r> Byte3VecReader<'r> { + pub fn iter<'t>(&'t self) -> Byte3VecReaderIterator<'t, 'r> { + Byte3VecReaderIterator(&self, 0, self.len()) + } +} +pub struct Byte3VecReaderIterator<'t, 'r>(&'t Byte3VecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for Byte3VecReaderIterator<'t, 'r> { + type Item = Byte3Reader<'t>; + fn next(&mut self) -> Option { + 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 Byte3VecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct Byte7Vec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Byte7Vec { + 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 Byte7Vec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Byte7Vec { + 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 Byte7Vec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Byte7Vec::new_unchecked(v) + } +} +impl Byte7Vec { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 7; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Byte7 { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + Byte7::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> Byte7VecReader<'r> { + Byte7VecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Byte7Vec { + type Builder = Byte7VecBuilder; + const NAME: &'static str = "Byte7Vec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Byte7Vec(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 { + Byte7VecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Byte7VecReader::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 Byte7VecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Byte7VecReader<'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 Byte7VecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Byte7VecReader<'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> Byte7VecReader<'r> { + pub const ITEM_SIZE: usize = 7; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Byte7Reader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + Byte7Reader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for Byte7VecReader<'r> { + type Entity = Byte7Vec; + const NAME: &'static str = "Byte7VecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Byte7VecReader(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(Clone, Debug, Default)] +pub struct Byte7VecBuilder(pub(crate) Vec); +impl Byte7VecBuilder { + pub const ITEM_SIZE: usize = 7; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Byte7) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Byte7) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for Byte7VecBuilder { + type Entity = Byte7Vec; + const NAME: &'static str = "Byte7VecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + Byte7Vec::new_unchecked(inner.into()) + } +} +pub struct Byte7VecIterator(Byte7Vec, usize, usize); +impl ::core::iter::Iterator for Byte7VecIterator { + type Item = Byte7; + fn next(&mut self) -> Option { + 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 Byte7VecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for Byte7Vec { + type Item = Byte7; + type IntoIter = Byte7VecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + Byte7VecIterator(self, 0, len) + } +} +impl<'r> Byte7VecReader<'r> { + pub fn iter<'t>(&'t self) -> Byte7VecReaderIterator<'t, 'r> { + Byte7VecReaderIterator(&self, 0, self.len()) + } +} +pub struct Byte7VecReaderIterator<'t, 'r>(&'t Byte7VecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for Byte7VecReaderIterator<'t, 'r> { + type Item = Byte7Reader<'t>; + fn next(&mut self) -> Option { + 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 Byte7VecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct StructIVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructIVec { + 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 StructIVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructIVec { + 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 StructIVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructIVec::new_unchecked(v) + } +} +impl StructIVec { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 4; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructI { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructI::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> StructIVecReader<'r> { + StructIVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructIVec { + type Builder = StructIVecBuilder; + const NAME: &'static str = "StructIVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructIVec(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 { + StructIVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructIVecReader::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 StructIVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructIVecReader<'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 StructIVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructIVecReader<'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> StructIVecReader<'r> { + pub const ITEM_SIZE: usize = 4; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructIReader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructIReader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructIVecReader<'r> { + type Entity = StructIVec; + const NAME: &'static str = "StructIVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructIVecReader(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(Clone, Debug, Default)] +pub struct StructIVecBuilder(pub(crate) Vec); +impl StructIVecBuilder { + pub const ITEM_SIZE: usize = 4; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: StructI) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: StructI) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for StructIVecBuilder { + type Entity = StructIVec; + const NAME: &'static str = "StructIVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + StructIVec::new_unchecked(inner.into()) + } +} +pub struct StructIVecIterator(StructIVec, usize, usize); +impl ::core::iter::Iterator for StructIVecIterator { + type Item = StructI; + fn next(&mut self) -> Option { + 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 StructIVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for StructIVec { + type Item = StructI; + type IntoIter = StructIVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + StructIVecIterator(self, 0, len) + } +} +impl<'r> StructIVecReader<'r> { + pub fn iter<'t>(&'t self) -> StructIVecReaderIterator<'t, 'r> { + StructIVecReaderIterator(&self, 0, self.len()) + } +} +pub struct StructIVecReaderIterator<'t, 'r>(&'t StructIVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for StructIVecReaderIterator<'t, 'r> { + type Item = StructIReader<'t>; + fn next(&mut self) -> Option { + 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 StructIVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct StructJVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructJVec { + 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 StructJVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructJVec { + 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 StructJVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructJVec::new_unchecked(v) + } +} +impl StructJVec { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 7; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructJ { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructJ::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> StructJVecReader<'r> { + StructJVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructJVec { + type Builder = StructJVecBuilder; + const NAME: &'static str = "StructJVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructJVec(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 { + StructJVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructJVecReader::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 StructJVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructJVecReader<'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 StructJVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructJVecReader<'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> StructJVecReader<'r> { + pub const ITEM_SIZE: usize = 7; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructJReader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructJReader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructJVecReader<'r> { + type Entity = StructJVec; + const NAME: &'static str = "StructJVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructJVecReader(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(Clone, Debug, Default)] +pub struct StructJVecBuilder(pub(crate) Vec); +impl StructJVecBuilder { + pub const ITEM_SIZE: usize = 7; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: StructJ) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: StructJ) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for StructJVecBuilder { + type Entity = StructJVec; + const NAME: &'static str = "StructJVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + StructJVec::new_unchecked(inner.into()) + } +} +pub struct StructJVecIterator(StructJVec, usize, usize); +impl ::core::iter::Iterator for StructJVecIterator { + type Item = StructJ; + fn next(&mut self) -> Option { + 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 StructJVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for StructJVec { + type Item = StructJ; + type IntoIter = StructJVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + StructJVecIterator(self, 0, len) + } +} +impl<'r> StructJVecReader<'r> { + pub fn iter<'t>(&'t self) -> StructJVecReaderIterator<'t, 'r> { + StructJVecReaderIterator(&self, 0, self.len()) + } +} +pub struct StructJVecReaderIterator<'t, 'r>(&'t StructJVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for StructJVecReaderIterator<'t, 'r> { + type Item = StructJReader<'t>; + fn next(&mut self) -> Option { + 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 StructJVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct StructPVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructPVec { + 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 StructPVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructPVec { + 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 StructPVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructPVec::new_unchecked(v) + } +} +impl StructPVec { + const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0]; + pub const ITEM_SIZE: usize = 8; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructP { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructP::new_unchecked(self.0.slice(start..end)) + } + pub fn as_reader<'r>(&'r self) -> StructPVecReader<'r> { + StructPVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructPVec { + type Builder = StructPVecBuilder; + const NAME: &'static str = "StructPVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructPVec(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 { + StructPVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructPVecReader::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 StructPVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructPVecReader<'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 StructPVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructPVecReader<'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> StructPVecReader<'r> { + pub const ITEM_SIZE: usize = 8; + 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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> StructPReader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + StructPReader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for StructPVecReader<'r> { + type Entity = StructPVec; + const NAME: &'static str = "StructPVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructPVecReader(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(Clone, Debug, Default)] +pub struct StructPVecBuilder(pub(crate) Vec); +impl StructPVecBuilder { + pub const ITEM_SIZE: usize = 8; + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: StructP) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: StructP) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for StructPVecBuilder { + type Entity = StructPVec; + const NAME: &'static str = "StructPVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + fn 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)); + StructPVec::new_unchecked(inner.into()) + } +} +pub struct StructPVecIterator(StructPVec, usize, usize); +impl ::core::iter::Iterator for StructPVecIterator { + type Item = StructP; + fn next(&mut self) -> Option { + 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 StructPVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for StructPVec { + type Item = StructP; + type IntoIter = StructPVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + StructPVecIterator(self, 0, len) + } +} +impl<'r> StructPVecReader<'r> { + pub fn iter<'t>(&'t self) -> StructPVecReaderIterator<'t, 'r> { + StructPVecReaderIterator(&self, 0, self.len()) + } +} +pub struct StructPVecReaderIterator<'t, 'r>(&'t StructPVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for StructPVecReaderIterator<'t, 'r> { + type Item = StructPReader<'t>; + fn next(&mut self) -> Option { + 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 StructPVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[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 = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + BytesVec::new_unchecked(v) + } +} +impl BytesVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + 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 { + BytesVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + 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> { + 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 = 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(Clone, Debug, Default)] +pub struct BytesVecBuilder(pub(crate) Vec); +impl BytesVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Bytes) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Bytes) -> Option { + 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::() + } + fn 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 { + 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 { + 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 WordsVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordsVec { + 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 WordsVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordsVec { + 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 WordsVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordsVec::new_unchecked(v) + } +} +impl WordsVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> Words { + 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 { + Words::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; + Words::new_unchecked(self.0.slice(start..end)) + } + } + pub fn as_reader<'r>(&'r self) -> WordsVecReader<'r> { + WordsVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordsVec { + type Builder = WordsVecBuilder; + const NAME: &'static str = "WordsVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordsVec(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 { + WordsVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordsVecReader::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 WordsVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordsVecReader<'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 WordsVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordsVecReader<'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> WordsVecReader<'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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordsReader<'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 { + WordsReader::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; + WordsReader::new_unchecked(&self.as_slice()[start..end]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordsVecReader<'r> { + type Entity = WordsVec; + const NAME: &'static str = "WordsVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordsVecReader(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 = 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]; + WordsReader::verify(&slice[start..end], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordsVecBuilder(pub(crate) Vec); +impl WordsVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: Words) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: Words) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for WordsVecBuilder { + type Entity = WordsVec; + const NAME: &'static str = "WordsVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (self.0.len() + 1) + + self + .0 + .iter() + .map(|inner| inner.as_slice().len()) + .sum::() + } + fn 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)); + WordsVec::new_unchecked(inner.into()) + } +} +pub struct WordsVecIterator(WordsVec, usize, usize); +impl ::core::iter::Iterator for WordsVecIterator { + type Item = Words; + fn next(&mut self) -> Option { + 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 WordsVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for WordsVec { + type Item = Words; + type IntoIter = WordsVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + WordsVecIterator(self, 0, len) + } +} +impl<'r> WordsVecReader<'r> { + pub fn iter<'t>(&'t self) -> WordsVecReaderIterator<'t, 'r> { + WordsVecReaderIterator(&self, 0, self.len()) + } +} +pub struct WordsVecReaderIterator<'t, 'r>(&'t WordsVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for WordsVecReaderIterator<'t, 'r> { + type Item = WordsReader<'t>; + fn next(&mut self) -> Option { + 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 WordsVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct Table0(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table0 { + 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 Table0 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table0 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ".. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table0 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table0::new_unchecked(v) + } +} +impl Table0 { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + pub const FIELD_COUNT: usize = 0; + 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 as_reader<'r>(&'r self) -> Table0Reader<'r> { + Table0Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table0 { + type Builder = Table0Builder; + const NAME: &'static str = "Table0"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table0(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 { + Table0Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table0Reader::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() + } +} +#[derive(Clone, Copy)] +pub struct Table0Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table0Reader<'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 Table0Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table0Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ".. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table0Reader<'r> { + pub const FIELD_COUNT: usize = 0; + 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() + } +} +impl<'r> molecule::prelude::Reader<'r> for Table0Reader<'r> { + type Entity = Table0; + const NAME: &'static str = "Table0Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table0Reader(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 && !compatible { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, !0); + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table0Builder {} +impl Table0Builder { + pub const FIELD_COUNT: usize = 0; +} +impl molecule::prelude::Builder for Table0Builder { + type Entity = Table0; + const NAME: &'static str = "Table0Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number( + molecule::NUMBER_SIZE as molecule::Number, + ))?; + 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)); + Table0::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table1(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table1 { + 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 Table1 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table1 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table1 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table1::new_unchecked(v) + } +} +impl Table1 { + const DEFAULT_VALUE: [u8; 9] = [9, 0, 0, 0, 8, 0, 0, 0, 0]; + pub const FIELD_COUNT: usize = 1; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } else { + Byte::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> Table1Reader<'r> { + Table1Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table1 { + type Builder = Table1Builder; + const NAME: &'static str = "Table1"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table1(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 { + Table1Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table1Reader::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().f1(self.f1()) + } +} +#[derive(Clone, Copy)] +pub struct Table1Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table1Reader<'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 Table1Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table1Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table1Reader<'r> { + pub const FIELD_COUNT: usize = 1; + 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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } else { + ByteReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table1Reader<'r> { + type Entity = Table1; + const NAME: &'static str = "Table1Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table1Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table1Builder { + pub(crate) f1: Byte, +} +impl Table1Builder { + pub const FIELD_COUNT: usize = 1; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } +} +impl molecule::prelude::Builder for Table1Builder { + type Entity = Table1; + const NAME: &'static str = "Table1Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.f1.as_slice().len() + } + fn 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.f1.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.f1.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)); + Table1::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table2(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table2 { + 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 Table2 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table2 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table2 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table2::new_unchecked(v) + } +} +impl Table2 { + const DEFAULT_VALUE: [u8; 17] = [17, 0, 0, 0, 12, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0]; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Word2 { + 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; + Word2::new_unchecked(self.0.slice(start..end)) + } else { + Word2::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> Table2Reader<'r> { + Table2Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table2 { + type Builder = Table2Builder; + const NAME: &'static str = "Table2"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table2(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 { + Table2Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table2Reader::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().f1(self.f1()).f2(self.f2()) + } +} +#[derive(Clone, Copy)] +pub struct Table2Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table2Reader<'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 Table2Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table2Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table2Reader<'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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Word2Reader<'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; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } else { + Word2Reader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table2Reader<'r> { + type Entity = Table2; + const NAME: &'static str = "Table2Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table2Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Word2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table2Builder { + pub(crate) f1: Byte, + pub(crate) f2: Word2, +} +impl Table2Builder { + pub const FIELD_COUNT: usize = 2; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Word2) -> Self { + self.f2 = v; + self + } +} +impl molecule::prelude::Builder for Table2Builder { + type Entity = Table2; + const NAME: &'static str = "Table2Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.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.f1.as_slice())?; + writer.write_all(self.f2.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)); + Table2::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table3(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table3 { + 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 Table3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table3 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table3 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table3::new_unchecked(v) + } +} +impl Table3 { + const DEFAULT_VALUE: [u8; 27] = [ + 27, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> StructA { + 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; + StructA::new_unchecked(self.0.slice(start..end)) + } else { + StructA::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> Table3Reader<'r> { + Table3Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table3 { + type Builder = Table3Builder; + const NAME: &'static str = "Table3"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table3(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 { + Table3Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table3Reader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + } +} +#[derive(Clone, Copy)] +pub struct Table3Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table3Reader<'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 Table3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table3Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table3Reader<'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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> StructAReader<'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; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } else { + StructAReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table3Reader<'r> { + type Entity = Table3; + const NAME: &'static str = "Table3Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table3Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Word2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + StructAReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table3Builder { + pub(crate) f1: Byte, + pub(crate) f2: Word2, + pub(crate) f3: StructA, +} +impl Table3Builder { + pub const FIELD_COUNT: usize = 3; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Word2) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: StructA) -> Self { + self.f3 = v; + self + } +} +impl molecule::prelude::Builder for Table3Builder { + type Entity = Table3; + const NAME: &'static str = "Table3Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.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.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.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)); + Table3::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table4(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table4 { + 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 Table4 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table4 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table4 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table4::new_unchecked(v) + } +} +impl Table4 { + const DEFAULT_VALUE: [u8; 35] = [ + 35, 0, 0, 0, 20, 0, 0, 0, 21, 0, 0, 0, 25, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ]; + pub const FIELD_COUNT: usize = 4; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> StructA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructA::new_unchecked(self.0.slice(start..end)) + } + pub fn f4(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[20..]) 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) -> Table4Reader<'r> { + Table4Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table4 { + type Builder = Table4Builder; + const NAME: &'static str = "Table4"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table4(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 { + Table4Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table4Reader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + } +} +#[derive(Clone, Copy)] +pub struct Table4Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table4Reader<'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 Table4Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table4Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table4Reader<'r> { + pub const FIELD_COUNT: usize = 4; + 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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> StructAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f4(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[20..]) 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 Table4Reader<'r> { + type Entity = Table4; + const NAME: &'static str = "Table4Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table4Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Word2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + StructAReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + BytesReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table4Builder { + pub(crate) f1: Byte, + pub(crate) f2: Word2, + pub(crate) f3: StructA, + pub(crate) f4: Bytes, +} +impl Table4Builder { + pub const FIELD_COUNT: usize = 4; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Word2) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: StructA) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Bytes) -> Self { + self.f4 = v; + self + } +} +impl molecule::prelude::Builder for Table4Builder { + type Entity = Table4; + const NAME: &'static str = "Table4Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + + self.f4.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.as_slice().len(); + offsets.push(total_size); + total_size += self.f4.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.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.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)); + Table4::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table5(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table5 { + 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 Table5 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table5 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table5 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table5::new_unchecked(v) + } +} +impl Table5 { + const DEFAULT_VALUE: [u8; 43] = [ + 43, 0, 0, 0, 24, 0, 0, 0, 25, 0, 0, 0, 29, 0, 0, 0, 35, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, + ]; + pub const FIELD_COUNT: usize = 5; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> StructA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructA::new_unchecked(self.0.slice(start..end)) + } + pub fn f4(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + pub fn f5(&self) -> BytesVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[24..]) as usize; + BytesVec::new_unchecked(self.0.slice(start..end)) + } else { + BytesVec::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> Table5Reader<'r> { + Table5Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table5 { + type Builder = Table5Builder; + const NAME: &'static str = "Table5"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table5(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 { + Table5Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table5Reader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + .f5(self.f5()) + } +} +#[derive(Clone, Copy)] +pub struct Table5Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table5Reader<'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 Table5Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table5Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table5Reader<'r> { + pub const FIELD_COUNT: usize = 5; + 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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> StructAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f4(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f5(&self) -> BytesVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[24..]) as usize; + BytesVecReader::new_unchecked(&self.as_slice()[start..end]) + } else { + BytesVecReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table5Reader<'r> { + type Entity = Table5; + const NAME: &'static str = "Table5Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table5Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Word2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + StructAReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + BytesReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + BytesVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table5Builder { + pub(crate) f1: Byte, + pub(crate) f2: Word2, + pub(crate) f3: StructA, + pub(crate) f4: Bytes, + pub(crate) f5: BytesVec, +} +impl Table5Builder { + pub const FIELD_COUNT: usize = 5; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Word2) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: StructA) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Bytes) -> Self { + self.f4 = v; + self + } + pub fn f5(mut self, v: BytesVec) -> Self { + self.f5 = v; + self + } +} +impl molecule::prelude::Builder for Table5Builder { + type Entity = Table5; + const NAME: &'static str = "Table5Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + + self.f4.as_slice().len() + + self.f5.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.as_slice().len(); + offsets.push(total_size); + total_size += self.f4.as_slice().len(); + offsets.push(total_size); + total_size += self.f5.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.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.as_slice())?; + writer.write_all(self.f5.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)); + Table5::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table6(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table6 { + 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 Table6 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table6 { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for Table6 { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table6::new_unchecked(v) + } +} +impl Table6 { + const DEFAULT_VALUE: [u8; 90] = [ + 90, 0, 0, 0, 28, 0, 0, 0, 29, 0, 0, 0, 33, 0, 0, 0, 39, 0, 0, 0, 43, 0, 0, 0, 47, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 43, 0, 0, 0, 24, 0, 0, 0, 25, 0, + 0, 0, 29, 0, 0, 0, 35, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, + ]; + pub const FIELD_COUNT: usize = 6; + 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 f1(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> StructA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructA::new_unchecked(self.0.slice(start..end)) + } + pub fn f4(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + pub fn f5(&self) -> BytesVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + BytesVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f6(&self) -> Table5 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[28..]) as usize; + Table5::new_unchecked(self.0.slice(start..end)) + } else { + Table5::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> Table6Reader<'r> { + Table6Reader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table6 { + type Builder = Table6Builder; + const NAME: &'static str = "Table6"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table6(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 { + Table6Reader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table6Reader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + .f5(self.f5()) + .f6(self.f6()) + } +} +#[derive(Clone, Copy)] +pub struct Table6Reader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table6Reader<'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 Table6Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table6Reader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> Table6Reader<'r> { + pub const FIELD_COUNT: usize = 6; + 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 f1(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> StructAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f4(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f5(&self) -> BytesVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + BytesVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f6(&self) -> Table5Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[28..]) as usize; + Table5Reader::new_unchecked(&self.as_slice()[start..end]) + } else { + Table5Reader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table6Reader<'r> { + type Entity = Table6; + const NAME: &'static str = "Table6Reader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table6Reader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Word2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + StructAReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + BytesReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + BytesVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + Table5Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table6Builder { + pub(crate) f1: Byte, + pub(crate) f2: Word2, + pub(crate) f3: StructA, + pub(crate) f4: Bytes, + pub(crate) f5: BytesVec, + pub(crate) f6: Table5, +} +impl Table6Builder { + pub const FIELD_COUNT: usize = 6; + pub fn f1(mut self, v: Byte) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Word2) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: StructA) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Bytes) -> Self { + self.f4 = v; + self + } + pub fn f5(mut self, v: BytesVec) -> Self { + self.f5 = v; + self + } + pub fn f6(mut self, v: Table5) -> Self { + self.f6 = v; + self + } +} +impl molecule::prelude::Builder for Table6Builder { + type Entity = Table6; + const NAME: &'static str = "Table6Builder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + + self.f4.as_slice().len() + + self.f5.as_slice().len() + + self.f6.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.as_slice().len(); + offsets.push(total_size); + total_size += self.f4.as_slice().len(); + offsets.push(total_size); + total_size += self.f5.as_slice().len(); + offsets.push(total_size); + total_size += self.f6.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.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.as_slice())?; + writer.write_all(self.f5.as_slice())?; + writer.write_all(self.f6.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)); + Table6::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct ByteOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for ByteOpt { + 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 ByteOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for ByteOpt { + 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 ByteOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + ByteOpt::new_unchecked(v) + } +} +impl ByteOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Byte::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> ByteOptReader<'r> { + ByteOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for ByteOpt { + type Builder = ByteOptBuilder; + const NAME: &'static str = "ByteOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + ByteOpt(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 { + ByteOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ByteOptReader::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 ByteOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for ByteOptReader<'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 ByteOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for ByteOptReader<'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> ByteOptReader<'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> { + if self.is_none() { + None + } else { + Some(ByteReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for ByteOptReader<'r> { + type Entity = ByteOpt; + const NAME: &'static str = "ByteOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + ByteOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + ByteReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct ByteOptBuilder(pub(crate) Option); +impl ByteOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for ByteOptBuilder { + type Entity = ByteOpt; + const NAME: &'static str = "ByteOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + ByteOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct WordOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordOpt { + 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 WordOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordOpt { + 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 WordOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordOpt::new_unchecked(v) + } +} +impl WordOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Word::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> WordOptReader<'r> { + WordOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordOpt { + type Builder = WordOptBuilder; + const NAME: &'static str = "WordOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordOpt(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 { + WordOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordOptReader::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 WordOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordOptReader<'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 WordOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordOptReader<'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> WordOptReader<'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> { + if self.is_none() { + None + } else { + Some(WordReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordOptReader<'r> { + type Entity = WordOpt; + const NAME: &'static str = "WordOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + WordReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordOptBuilder(pub(crate) Option); +impl WordOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for WordOptBuilder { + type Entity = WordOpt; + const NAME: &'static str = "WordOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + WordOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructAOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructAOpt { + 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 StructAOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructAOpt { + 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 StructAOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructAOpt::new_unchecked(v) + } +} +impl StructAOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(StructA::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> StructAOptReader<'r> { + StructAOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructAOpt { + type Builder = StructAOptBuilder; + const NAME: &'static str = "StructAOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructAOpt(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 { + StructAOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructAOptReader::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 StructAOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructAOptReader<'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 StructAOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructAOptReader<'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> StructAOptReader<'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> { + if self.is_none() { + None + } else { + Some(StructAReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for StructAOptReader<'r> { + type Entity = StructAOpt; + const NAME: &'static str = "StructAOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructAOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + StructAReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructAOptBuilder(pub(crate) Option); +impl StructAOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for StructAOptBuilder { + type Entity = StructAOpt; + const NAME: &'static str = "StructAOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + StructAOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct StructPOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for StructPOpt { + 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 StructPOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for StructPOpt { + 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 StructPOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + StructPOpt::new_unchecked(v) + } +} +impl StructPOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(StructP::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> StructPOptReader<'r> { + StructPOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for StructPOpt { + type Builder = StructPOptBuilder; + const NAME: &'static str = "StructPOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + StructPOpt(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 { + StructPOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + StructPOptReader::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 StructPOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for StructPOptReader<'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 StructPOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for StructPOptReader<'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> StructPOptReader<'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> { + if self.is_none() { + None + } else { + Some(StructPReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for StructPOptReader<'r> { + type Entity = StructPOpt; + const NAME: &'static str = "StructPOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + StructPOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + StructPReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct StructPOptBuilder(pub(crate) Option); +impl StructPOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for StructPOptBuilder { + type Entity = StructPOpt; + const NAME: &'static str = "StructPOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + StructPOpt::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 = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + BytesOpt::new_unchecked(v) + } +} +impl BytesOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + 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 { + BytesOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + 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> { + 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(Clone, Debug, Default)] +pub struct BytesOptBuilder(pub(crate) Option); +impl BytesOptBuilder { + pub fn set(mut self, v: Option) -> 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(&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 WordsOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordsOpt { + 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 WordsOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordsOpt { + 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 WordsOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordsOpt::new_unchecked(v) + } +} +impl WordsOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Words::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> WordsOptReader<'r> { + WordsOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordsOpt { + type Builder = WordsOptBuilder; + const NAME: &'static str = "WordsOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordsOpt(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 { + WordsOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordsOptReader::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 WordsOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordsOptReader<'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 WordsOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordsOptReader<'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> WordsOptReader<'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> { + if self.is_none() { + None + } else { + Some(WordsReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordsOptReader<'r> { + type Entity = WordsOpt; + const NAME: &'static str = "WordsOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordsOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + WordsReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordsOptBuilder(pub(crate) Option); +impl WordsOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for WordsOptBuilder { + type Entity = WordsOpt; + const NAME: &'static str = "WordsOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + WordsOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct BytesVecOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for BytesVecOpt { + 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 BytesVecOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for BytesVecOpt { + 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 BytesVecOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + BytesVecOpt::new_unchecked(v) + } +} +impl BytesVecOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(BytesVec::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> BytesVecOptReader<'r> { + BytesVecOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for BytesVecOpt { + type Builder = BytesVecOptBuilder; + const NAME: &'static str = "BytesVecOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + BytesVecOpt(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 { + BytesVecOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + BytesVecOptReader::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 BytesVecOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for BytesVecOptReader<'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 BytesVecOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for BytesVecOptReader<'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> BytesVecOptReader<'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> { + if self.is_none() { + None + } else { + Some(BytesVecReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for BytesVecOptReader<'r> { + type Entity = BytesVecOpt; + const NAME: &'static str = "BytesVecOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + BytesVecOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + BytesVecReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct BytesVecOptBuilder(pub(crate) Option); +impl BytesVecOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for BytesVecOptBuilder { + type Entity = BytesVecOpt; + const NAME: &'static str = "BytesVecOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + BytesVecOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct WordsVecOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordsVecOpt { + 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 WordsVecOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordsVecOpt { + 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 WordsVecOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordsVecOpt::new_unchecked(v) + } +} +impl WordsVecOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(WordsVec::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> WordsVecOptReader<'r> { + WordsVecOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordsVecOpt { + type Builder = WordsVecOptBuilder; + const NAME: &'static str = "WordsVecOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordsVecOpt(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 { + WordsVecOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordsVecOptReader::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 WordsVecOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordsVecOptReader<'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 WordsVecOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordsVecOptReader<'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> WordsVecOptReader<'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> { + if self.is_none() { + None + } else { + Some(WordsVecReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordsVecOptReader<'r> { + type Entity = WordsVecOpt; + const NAME: &'static str = "WordsVecOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordsVecOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + WordsVecReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordsVecOptBuilder(pub(crate) Option); +impl WordsVecOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for WordsVecOptBuilder { + type Entity = WordsVecOpt; + const NAME: &'static str = "WordsVecOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + WordsVecOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table0Opt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table0Opt { + 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 Table0Opt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table0Opt { + 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 Table0Opt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table0Opt::new_unchecked(v) + } +} +impl Table0Opt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Table0::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> Table0OptReader<'r> { + Table0OptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table0Opt { + type Builder = Table0OptBuilder; + const NAME: &'static str = "Table0Opt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table0Opt(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 { + Table0OptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table0OptReader::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 Table0OptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table0OptReader<'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 Table0OptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table0OptReader<'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> Table0OptReader<'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> { + if self.is_none() { + None + } else { + Some(Table0Reader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table0OptReader<'r> { + type Entity = Table0Opt; + const NAME: &'static str = "Table0OptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table0OptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + Table0Reader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table0OptBuilder(pub(crate) Option); +impl Table0OptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for Table0OptBuilder { + type Entity = Table0Opt; + const NAME: &'static str = "Table0OptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + Table0Opt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table6Opt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table6Opt { + 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 Table6Opt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table6Opt { + 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 Table6Opt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table6Opt::new_unchecked(v) + } +} +impl Table6Opt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Table6::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> Table6OptReader<'r> { + Table6OptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table6Opt { + type Builder = Table6OptBuilder; + const NAME: &'static str = "Table6Opt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table6Opt(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 { + Table6OptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table6OptReader::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 Table6OptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table6OptReader<'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 Table6OptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table6OptReader<'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> Table6OptReader<'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> { + if self.is_none() { + None + } else { + Some(Table6Reader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table6OptReader<'r> { + type Entity = Table6Opt; + const NAME: &'static str = "Table6OptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table6OptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + Table6Reader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table6OptBuilder(pub(crate) Option); +impl Table6OptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for Table6OptBuilder { + type Entity = Table6Opt; + const NAME: &'static str = "Table6OptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + Table6Opt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct Table6OptOpt(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for Table6OptOpt { + 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 Table6OptOpt { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for Table6OptOpt { + 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 Table6OptOpt { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + Table6OptOpt::new_unchecked(v) + } +} +impl Table6OptOpt { + const DEFAULT_VALUE: [u8; 0] = []; + 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 { + if self.is_none() { + None + } else { + Some(Table6Opt::new_unchecked(self.0.clone())) + } + } + pub fn as_reader<'r>(&'r self) -> Table6OptOptReader<'r> { + Table6OptOptReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for Table6OptOpt { + type Builder = Table6OptOptBuilder; + const NAME: &'static str = "Table6OptOpt"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + Table6OptOpt(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 { + Table6OptOptReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + Table6OptOptReader::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 Table6OptOptReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for Table6OptOptReader<'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 Table6OptOptReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for Table6OptOptReader<'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> Table6OptOptReader<'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> { + if self.is_none() { + None + } else { + Some(Table6OptReader::new_unchecked(self.as_slice())) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for Table6OptOptReader<'r> { + type Entity = Table6OptOpt; + const NAME: &'static str = "Table6OptOptReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + Table6OptOptReader(slice) + } + fn as_slice(&self) -> &'r [u8] { + self.0 + } + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + if !slice.is_empty() { + Table6OptReader::verify(&slice[..], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct Table6OptOptBuilder(pub(crate) Option); +impl Table6OptOptBuilder { + pub fn set(mut self, v: Option) -> Self { + self.0 = v; + self + } +} +impl molecule::prelude::Builder for Table6OptOptBuilder { + type Entity = Table6OptOpt; + const NAME: &'static str = "Table6OptOptBuilder"; + fn expected_length(&self) -> usize { + self.0 + .as_ref() + .map(|ref inner| inner.as_slice().len()) + .unwrap_or(0) + } + fn 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)); + Table6OptOpt::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct ByteOptVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for ByteOptVec { + 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 ByteOptVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for ByteOptVec { + 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 ByteOptVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + ByteOptVec::new_unchecked(v) + } +} +impl ByteOptVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> ByteOpt { + 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 { + ByteOpt::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; + ByteOpt::new_unchecked(self.0.slice(start..end)) + } + } + pub fn as_reader<'r>(&'r self) -> ByteOptVecReader<'r> { + ByteOptVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for ByteOptVec { + type Builder = ByteOptVecBuilder; + const NAME: &'static str = "ByteOptVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + ByteOptVec(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 { + ByteOptVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ByteOptVecReader::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 ByteOptVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for ByteOptVecReader<'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 ByteOptVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for ByteOptVecReader<'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> ByteOptVecReader<'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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> ByteOptReader<'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 { + ByteOptReader::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; + ByteOptReader::new_unchecked(&self.as_slice()[start..end]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for ByteOptVecReader<'r> { + type Entity = ByteOptVec; + const NAME: &'static str = "ByteOptVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + ByteOptVecReader(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 = 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]; + ByteOptReader::verify(&slice[start..end], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct ByteOptVecBuilder(pub(crate) Vec); +impl ByteOptVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: ByteOpt) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: ByteOpt) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for ByteOptVecBuilder { + type Entity = ByteOptVec; + const NAME: &'static str = "ByteOptVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (self.0.len() + 1) + + self + .0 + .iter() + .map(|inner| inner.as_slice().len()) + .sum::() + } + fn 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)); + ByteOptVec::new_unchecked(inner.into()) + } +} +pub struct ByteOptVecIterator(ByteOptVec, usize, usize); +impl ::core::iter::Iterator for ByteOptVecIterator { + type Item = ByteOpt; + fn next(&mut self) -> Option { + 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 ByteOptVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for ByteOptVec { + type Item = ByteOpt; + type IntoIter = ByteOptVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + ByteOptVecIterator(self, 0, len) + } +} +impl<'r> ByteOptVecReader<'r> { + pub fn iter<'t>(&'t self) -> ByteOptVecReaderIterator<'t, 'r> { + ByteOptVecReaderIterator(&self, 0, self.len()) + } +} +pub struct ByteOptVecReaderIterator<'t, 'r>(&'t ByteOptVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for ByteOptVecReaderIterator<'t, 'r> { + type Item = ByteOptReader<'t>; + fn next(&mut self) -> Option { + 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 ByteOptVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct WordOptVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordOptVec { + 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 WordOptVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordOptVec { + 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 WordOptVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordOptVec::new_unchecked(v) + } +} +impl WordOptVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordOpt { + 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 { + WordOpt::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; + WordOpt::new_unchecked(self.0.slice(start..end)) + } + } + pub fn as_reader<'r>(&'r self) -> WordOptVecReader<'r> { + WordOptVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordOptVec { + type Builder = WordOptVecBuilder; + const NAME: &'static str = "WordOptVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordOptVec(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 { + WordOptVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordOptVecReader::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 WordOptVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordOptVecReader<'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 WordOptVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordOptVecReader<'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> WordOptVecReader<'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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordOptReader<'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 { + WordOptReader::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; + WordOptReader::new_unchecked(&self.as_slice()[start..end]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordOptVecReader<'r> { + type Entity = WordOptVec; + const NAME: &'static str = "WordOptVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordOptVecReader(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 = 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]; + WordOptReader::verify(&slice[start..end], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordOptVecBuilder(pub(crate) Vec); +impl WordOptVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: WordOpt) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: WordOpt) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for WordOptVecBuilder { + type Entity = WordOptVec; + const NAME: &'static str = "WordOptVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (self.0.len() + 1) + + self + .0 + .iter() + .map(|inner| inner.as_slice().len()) + .sum::() + } + fn 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)); + WordOptVec::new_unchecked(inner.into()) + } +} +pub struct WordOptVecIterator(WordOptVec, usize, usize); +impl ::core::iter::Iterator for WordOptVecIterator { + type Item = WordOpt; + fn next(&mut self) -> Option { + 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 WordOptVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for WordOptVec { + type Item = WordOpt; + type IntoIter = WordOptVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + WordOptVecIterator(self, 0, len) + } +} +impl<'r> WordOptVecReader<'r> { + pub fn iter<'t>(&'t self) -> WordOptVecReaderIterator<'t, 'r> { + WordOptVecReaderIterator(&self, 0, self.len()) + } +} +pub struct WordOptVecReaderIterator<'t, 'r>(&'t WordOptVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for WordOptVecReaderIterator<'t, 'r> { + type Item = WordOptReader<'t>; + fn next(&mut self) -> Option { + 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 WordOptVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct WordsOptVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for WordsOptVec { + 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 WordsOptVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for WordsOptVec { + 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 WordsOptVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + WordsOptVec::new_unchecked(v) + } +} +impl WordsOptVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordsOpt { + 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 { + WordsOpt::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; + WordsOpt::new_unchecked(self.0.slice(start..end)) + } + } + pub fn as_reader<'r>(&'r self) -> WordsOptVecReader<'r> { + WordsOptVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for WordsOptVec { + type Builder = WordsOptVecBuilder; + const NAME: &'static str = "WordsOptVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + WordsOptVec(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 { + WordsOptVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + WordsOptVecReader::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 WordsOptVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for WordsOptVecReader<'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 WordsOptVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for WordsOptVecReader<'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> WordsOptVecReader<'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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> WordsOptReader<'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 { + WordsOptReader::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; + WordsOptReader::new_unchecked(&self.as_slice()[start..end]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for WordsOptVecReader<'r> { + type Entity = WordsOptVec; + const NAME: &'static str = "WordsOptVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + WordsOptVecReader(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 = 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]; + WordsOptReader::verify(&slice[start..end], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct WordsOptVecBuilder(pub(crate) Vec); +impl WordsOptVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: WordsOpt) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: WordsOpt) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for WordsOptVecBuilder { + type Entity = WordsOptVec; + const NAME: &'static str = "WordsOptVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (self.0.len() + 1) + + self + .0 + .iter() + .map(|inner| inner.as_slice().len()) + .sum::() + } + fn 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)); + WordsOptVec::new_unchecked(inner.into()) + } +} +pub struct WordsOptVecIterator(WordsOptVec, usize, usize); +impl ::core::iter::Iterator for WordsOptVecIterator { + type Item = WordsOpt; + fn next(&mut self) -> Option { + 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 WordsOptVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for WordsOptVec { + type Item = WordsOpt; + type IntoIter = WordsOptVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + WordsOptVecIterator(self, 0, len) + } +} +impl<'r> WordsOptVecReader<'r> { + pub fn iter<'t>(&'t self) -> WordsOptVecReaderIterator<'t, 'r> { + WordsOptVecReaderIterator(&self, 0, self.len()) + } +} +pub struct WordsOptVecReaderIterator<'t, 'r>(&'t WordsOptVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for WordsOptVecReaderIterator<'t, 'r> { + type Item = WordsOptReader<'t>; + fn next(&mut self) -> Option { + 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 WordsOptVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct BytesOptVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for BytesOptVec { + 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 BytesOptVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for BytesOptVec { + 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 BytesOptVec { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + BytesOptVec::new_unchecked(v) + } +} +impl BytesOptVec { + const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0]; + 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 { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> BytesOpt { + 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 { + BytesOpt::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; + BytesOpt::new_unchecked(self.0.slice(start..end)) + } + } + pub fn as_reader<'r>(&'r self) -> BytesOptVecReader<'r> { + BytesOptVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for BytesOptVec { + type Builder = BytesOptVecBuilder; + const NAME: &'static str = "BytesOptVec"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + BytesOptVec(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 { + BytesOptVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + BytesOptVecReader::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 BytesOptVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for BytesOptVecReader<'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 BytesOptVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for BytesOptVecReader<'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> BytesOptVecReader<'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> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + pub fn get_unchecked(&self, idx: usize) -> BytesOptReader<'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 { + BytesOptReader::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; + BytesOptReader::new_unchecked(&self.as_slice()[start..end]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for BytesOptVecReader<'r> { + type Entity = BytesOptVec; + const NAME: &'static str = "BytesOptVecReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + BytesOptVecReader(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 = 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]; + BytesOptReader::verify(&slice[start..end], compatible)?; + } + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct BytesOptVecBuilder(pub(crate) Vec); +impl BytesOptVecBuilder { + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + pub fn push(mut self, v: BytesOpt) -> Self { + self.0.push(v); + self + } + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + pub fn replace(&mut self, index: usize, v: BytesOpt) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for BytesOptVecBuilder { + type Entity = BytesOptVec; + const NAME: &'static str = "BytesOptVecBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (self.0.len() + 1) + + self + .0 + .iter() + .map(|inner| inner.as_slice().len()) + .sum::() + } + fn 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)); + BytesOptVec::new_unchecked(inner.into()) + } +} +pub struct BytesOptVecIterator(BytesOptVec, usize, usize); +impl ::core::iter::Iterator for BytesOptVecIterator { + type Item = BytesOpt; + fn next(&mut self) -> Option { + 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 BytesOptVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for BytesOptVec { + type Item = BytesOpt; + type IntoIter = BytesOptVecIterator; + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + BytesOptVecIterator(self, 0, len) + } +} +impl<'r> BytesOptVecReader<'r> { + pub fn iter<'t>(&'t self) -> BytesOptVecReaderIterator<'t, 'r> { + BytesOptVecReaderIterator(&self, 0, self.len()) + } +} +pub struct BytesOptVecReaderIterator<'t, 'r>(&'t BytesOptVecReader<'r>, usize, usize); +impl<'t: 'r, 'r> ::core::iter::Iterator for BytesOptVecReaderIterator<'t, 'r> { + type Item = BytesOptReader<'t>; + fn next(&mut self) -> Option { + 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 BytesOptVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} +#[derive(Clone)] +pub struct UnionA(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for UnionA { + 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 UnionA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for UnionA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl ::core::default::Default for UnionA { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + UnionA::new_unchecked(v) + } +} +impl UnionA { + const DEFAULT_VALUE: [u8; 5] = [0, 0, 0, 0, 0]; + pub const ITEMS_COUNT: usize = 8; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionAUnion { + let inner = self.0.slice(molecule::NUMBER_SIZE..); + match self.item_id() { + 0 => Byte::new_unchecked(inner).into(), + 1 => Word::new_unchecked(inner).into(), + 2 => StructA::new_unchecked(inner).into(), + 3 => Bytes::new_unchecked(inner).into(), + 4 => Words::new_unchecked(inner).into(), + 5 => Table0::new_unchecked(inner).into(), + 6 => Table6::new_unchecked(inner).into(), + 7 => Table6Opt::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } + pub fn as_reader<'r>(&'r self) -> UnionAReader<'r> { + UnionAReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for UnionA { + type Builder = UnionABuilder; + const NAME: &'static str = "UnionA"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + UnionA(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 { + UnionAReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + UnionAReader::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_enum()) + } +} +#[derive(Clone, Copy)] +pub struct UnionAReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for UnionAReader<'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 UnionAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for UnionAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl<'r> UnionAReader<'r> { + pub const ITEMS_COUNT: usize = 8; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionAUnionReader<'r> { + let inner = &self.as_slice()[molecule::NUMBER_SIZE..]; + match self.item_id() { + 0 => ByteReader::new_unchecked(inner).into(), + 1 => WordReader::new_unchecked(inner).into(), + 2 => StructAReader::new_unchecked(inner).into(), + 3 => BytesReader::new_unchecked(inner).into(), + 4 => WordsReader::new_unchecked(inner).into(), + 5 => Table0Reader::new_unchecked(inner).into(), + 6 => Table6Reader::new_unchecked(inner).into(), + 7 => Table6OptReader::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } +} +impl<'r> molecule::prelude::Reader<'r> for UnionAReader<'r> { + type Entity = UnionA; + const NAME: &'static str = "UnionAReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + UnionAReader(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_id = molecule::unpack_number(slice); + let inner_slice = &slice[molecule::NUMBER_SIZE..]; + match item_id { + 0 => ByteReader::verify(inner_slice, compatible), + 1 => WordReader::verify(inner_slice, compatible), + 2 => StructAReader::verify(inner_slice, compatible), + 3 => BytesReader::verify(inner_slice, compatible), + 4 => WordsReader::verify(inner_slice, compatible), + 5 => Table0Reader::verify(inner_slice, compatible), + 6 => Table6Reader::verify(inner_slice, compatible), + 7 => Table6OptReader::verify(inner_slice, compatible), + _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id), + }?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct UnionABuilder(pub(crate) UnionAUnion); +impl UnionABuilder { + pub const ITEMS_COUNT: usize = 8; + pub fn set(mut self, v: I) -> Self + where + I: ::core::convert::Into, + { + self.0 = v.into(); + self + } +} +impl molecule::prelude::Builder for UnionABuilder { + type Entity = UnionA; + const NAME: &'static str = "UnionABuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + self.0.as_slice().len() + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number(self.0.item_id()))?; + writer.write_all(self.0.as_slice()) + } + 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)); + UnionA::new_unchecked(inner.into()) + } +} +#[derive(Debug, Clone)] +pub enum UnionAUnion { + Byte(Byte), + Word(Word), + StructA(StructA), + Bytes(Bytes), + Words(Words), + Table0(Table0), + Table6(Table6), + Table6Opt(Table6Opt), +} +#[derive(Debug, Clone, Copy)] +pub enum UnionAUnionReader<'r> { + Byte(ByteReader<'r>), + Word(WordReader<'r>), + StructA(StructAReader<'r>), + Bytes(BytesReader<'r>), + Words(WordsReader<'r>), + Table0(Table0Reader<'r>), + Table6(Table6Reader<'r>), + Table6Opt(Table6OptReader<'r>), +} +impl ::core::default::Default for UnionAUnion { + fn default() -> Self { + UnionAUnion::Byte(::core::default::Default::default()) + } +} +impl ::core::fmt::Display for UnionAUnion { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionAUnion::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + UnionAUnion::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionAUnion::StructA(ref item) => { + write!(f, "{}::{}({})", Self::NAME, StructA::NAME, item) + } + UnionAUnion::Bytes(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Bytes::NAME, item) + } + UnionAUnion::Words(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Words::NAME, item) + } + UnionAUnion::Table0(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table0::NAME, item) + } + UnionAUnion::Table6(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table6::NAME, item) + } + UnionAUnion::Table6Opt(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table6Opt::NAME, item) + } + } + } +} +impl<'r> ::core::fmt::Display for UnionAUnionReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionAUnionReader::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + UnionAUnionReader::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionAUnionReader::StructA(ref item) => { + write!(f, "{}::{}({})", Self::NAME, StructA::NAME, item) + } + UnionAUnionReader::Bytes(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Bytes::NAME, item) + } + UnionAUnionReader::Words(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Words::NAME, item) + } + UnionAUnionReader::Table0(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table0::NAME, item) + } + UnionAUnionReader::Table6(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table6::NAME, item) + } + UnionAUnionReader::Table6Opt(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Table6Opt::NAME, item) + } + } + } +} +impl UnionAUnion { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionAUnion::Byte(ref item) => write!(f, "{}", item), + UnionAUnion::Word(ref item) => write!(f, "{}", item), + UnionAUnion::StructA(ref item) => write!(f, "{}", item), + UnionAUnion::Bytes(ref item) => write!(f, "{}", item), + UnionAUnion::Words(ref item) => write!(f, "{}", item), + UnionAUnion::Table0(ref item) => write!(f, "{}", item), + UnionAUnion::Table6(ref item) => write!(f, "{}", item), + UnionAUnion::Table6Opt(ref item) => write!(f, "{}", item), + } + } +} +impl<'r> UnionAUnionReader<'r> { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionAUnionReader::Byte(ref item) => write!(f, "{}", item), + UnionAUnionReader::Word(ref item) => write!(f, "{}", item), + UnionAUnionReader::StructA(ref item) => write!(f, "{}", item), + UnionAUnionReader::Bytes(ref item) => write!(f, "{}", item), + UnionAUnionReader::Words(ref item) => write!(f, "{}", item), + UnionAUnionReader::Table0(ref item) => write!(f, "{}", item), + UnionAUnionReader::Table6(ref item) => write!(f, "{}", item), + UnionAUnionReader::Table6Opt(ref item) => write!(f, "{}", item), + } + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Byte) -> Self { + UnionAUnion::Byte(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Word) -> Self { + UnionAUnion::Word(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: StructA) -> Self { + UnionAUnion::StructA(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Bytes) -> Self { + UnionAUnion::Bytes(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Words) -> Self { + UnionAUnion::Words(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Table0) -> Self { + UnionAUnion::Table0(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Table6) -> Self { + UnionAUnion::Table6(item) + } +} +impl ::core::convert::From for UnionAUnion { + fn from(item: Table6Opt) -> Self { + UnionAUnion::Table6Opt(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: ByteReader<'r>) -> Self { + UnionAUnionReader::Byte(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: WordReader<'r>) -> Self { + UnionAUnionReader::Word(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: StructAReader<'r>) -> Self { + UnionAUnionReader::StructA(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: BytesReader<'r>) -> Self { + UnionAUnionReader::Bytes(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: WordsReader<'r>) -> Self { + UnionAUnionReader::Words(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: Table0Reader<'r>) -> Self { + UnionAUnionReader::Table0(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: Table6Reader<'r>) -> Self { + UnionAUnionReader::Table6(item) + } +} +impl<'r> ::core::convert::From> for UnionAUnionReader<'r> { + fn from(item: Table6OptReader<'r>) -> Self { + UnionAUnionReader::Table6Opt(item) + } +} +impl UnionAUnion { + pub const NAME: &'static str = "UnionAUnion"; + pub fn as_bytes(&self) -> molecule::bytes::Bytes { + match self { + UnionAUnion::Byte(item) => item.as_bytes(), + UnionAUnion::Word(item) => item.as_bytes(), + UnionAUnion::StructA(item) => item.as_bytes(), + UnionAUnion::Bytes(item) => item.as_bytes(), + UnionAUnion::Words(item) => item.as_bytes(), + UnionAUnion::Table0(item) => item.as_bytes(), + UnionAUnion::Table6(item) => item.as_bytes(), + UnionAUnion::Table6Opt(item) => item.as_bytes(), + } + } + pub fn as_slice(&self) -> &[u8] { + match self { + UnionAUnion::Byte(item) => item.as_slice(), + UnionAUnion::Word(item) => item.as_slice(), + UnionAUnion::StructA(item) => item.as_slice(), + UnionAUnion::Bytes(item) => item.as_slice(), + UnionAUnion::Words(item) => item.as_slice(), + UnionAUnion::Table0(item) => item.as_slice(), + UnionAUnion::Table6(item) => item.as_slice(), + UnionAUnion::Table6Opt(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionAUnion::Byte(_) => 0, + UnionAUnion::Word(_) => 1, + UnionAUnion::StructA(_) => 2, + UnionAUnion::Bytes(_) => 3, + UnionAUnion::Words(_) => 4, + UnionAUnion::Table0(_) => 5, + UnionAUnion::Table6(_) => 6, + UnionAUnion::Table6Opt(_) => 7, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionAUnion::Byte(_) => "Byte", + UnionAUnion::Word(_) => "Word", + UnionAUnion::StructA(_) => "StructA", + UnionAUnion::Bytes(_) => "Bytes", + UnionAUnion::Words(_) => "Words", + UnionAUnion::Table0(_) => "Table0", + UnionAUnion::Table6(_) => "Table6", + UnionAUnion::Table6Opt(_) => "Table6Opt", + } + } + pub fn as_reader<'r>(&'r self) -> UnionAUnionReader<'r> { + match self { + UnionAUnion::Byte(item) => item.as_reader().into(), + UnionAUnion::Word(item) => item.as_reader().into(), + UnionAUnion::StructA(item) => item.as_reader().into(), + UnionAUnion::Bytes(item) => item.as_reader().into(), + UnionAUnion::Words(item) => item.as_reader().into(), + UnionAUnion::Table0(item) => item.as_reader().into(), + UnionAUnion::Table6(item) => item.as_reader().into(), + UnionAUnion::Table6Opt(item) => item.as_reader().into(), + } + } +} +impl<'r> UnionAUnionReader<'r> { + pub const NAME: &'r str = "UnionAUnionReader"; + pub fn as_slice(&self) -> &'r [u8] { + match self { + UnionAUnionReader::Byte(item) => item.as_slice(), + UnionAUnionReader::Word(item) => item.as_slice(), + UnionAUnionReader::StructA(item) => item.as_slice(), + UnionAUnionReader::Bytes(item) => item.as_slice(), + UnionAUnionReader::Words(item) => item.as_slice(), + UnionAUnionReader::Table0(item) => item.as_slice(), + UnionAUnionReader::Table6(item) => item.as_slice(), + UnionAUnionReader::Table6Opt(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionAUnionReader::Byte(_) => 0, + UnionAUnionReader::Word(_) => 1, + UnionAUnionReader::StructA(_) => 2, + UnionAUnionReader::Bytes(_) => 3, + UnionAUnionReader::Words(_) => 4, + UnionAUnionReader::Table0(_) => 5, + UnionAUnionReader::Table6(_) => 6, + UnionAUnionReader::Table6Opt(_) => 7, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionAUnionReader::Byte(_) => "Byte", + UnionAUnionReader::Word(_) => "Word", + UnionAUnionReader::StructA(_) => "StructA", + UnionAUnionReader::Bytes(_) => "Bytes", + UnionAUnionReader::Words(_) => "Words", + UnionAUnionReader::Table0(_) => "Table0", + UnionAUnionReader::Table6(_) => "Table6", + UnionAUnionReader::Table6Opt(_) => "Table6Opt", + } + } +} +#[derive(Clone)] +pub struct UnionB(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for UnionB { + 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 UnionB { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for UnionB { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl ::core::default::Default for UnionB { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + UnionB::new_unchecked(v) + } +} +impl UnionB { + const DEFAULT_VALUE: [u8; 5] = [2, 0, 0, 0, 0]; + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionBUnion { + let inner = self.0.slice(molecule::NUMBER_SIZE..); + match self.item_id() { + 2 => Byte::new_unchecked(inner).into(), + 4 => Word::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } + pub fn as_reader<'r>(&'r self) -> UnionBReader<'r> { + UnionBReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for UnionB { + type Builder = UnionBBuilder; + const NAME: &'static str = "UnionB"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + UnionB(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 { + UnionBReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + UnionBReader::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_enum()) + } +} +#[derive(Clone, Copy)] +pub struct UnionBReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for UnionBReader<'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 UnionBReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for UnionBReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl<'r> UnionBReader<'r> { + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionBUnionReader<'r> { + let inner = &self.as_slice()[molecule::NUMBER_SIZE..]; + match self.item_id() { + 2 => ByteReader::new_unchecked(inner).into(), + 4 => WordReader::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } +} +impl<'r> molecule::prelude::Reader<'r> for UnionBReader<'r> { + type Entity = UnionB; + const NAME: &'static str = "UnionBReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + UnionBReader(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_id = molecule::unpack_number(slice); + let inner_slice = &slice[molecule::NUMBER_SIZE..]; + match item_id { + 2 => ByteReader::verify(inner_slice, compatible), + 4 => WordReader::verify(inner_slice, compatible), + _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id), + }?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct UnionBBuilder(pub(crate) UnionBUnion); +impl UnionBBuilder { + pub const ITEMS_COUNT: usize = 2; + pub fn set(mut self, v: I) -> Self + where + I: ::core::convert::Into, + { + self.0 = v.into(); + self + } +} +impl molecule::prelude::Builder for UnionBBuilder { + type Entity = UnionB; + const NAME: &'static str = "UnionBBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + self.0.as_slice().len() + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number(self.0.item_id()))?; + writer.write_all(self.0.as_slice()) + } + 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)); + UnionB::new_unchecked(inner.into()) + } +} +#[derive(Debug, Clone)] +pub enum UnionBUnion { + Byte(Byte), + Word(Word), +} +#[derive(Debug, Clone, Copy)] +pub enum UnionBUnionReader<'r> { + Byte(ByteReader<'r>), + Word(WordReader<'r>), +} +impl ::core::default::Default for UnionBUnion { + fn default() -> Self { + UnionBUnion::Byte(::core::default::Default::default()) + } +} +impl ::core::fmt::Display for UnionBUnion { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionBUnion::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + UnionBUnion::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + } + } +} +impl<'r> ::core::fmt::Display for UnionBUnionReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionBUnionReader::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + UnionBUnionReader::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + } + } +} +impl UnionBUnion { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionBUnion::Byte(ref item) => write!(f, "{}", item), + UnionBUnion::Word(ref item) => write!(f, "{}", item), + } + } +} +impl<'r> UnionBUnionReader<'r> { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionBUnionReader::Byte(ref item) => write!(f, "{}", item), + UnionBUnionReader::Word(ref item) => write!(f, "{}", item), + } + } +} +impl ::core::convert::From for UnionBUnion { + fn from(item: Byte) -> Self { + UnionBUnion::Byte(item) + } +} +impl ::core::convert::From for UnionBUnion { + fn from(item: Word) -> Self { + UnionBUnion::Word(item) + } +} +impl<'r> ::core::convert::From> for UnionBUnionReader<'r> { + fn from(item: ByteReader<'r>) -> Self { + UnionBUnionReader::Byte(item) + } +} +impl<'r> ::core::convert::From> for UnionBUnionReader<'r> { + fn from(item: WordReader<'r>) -> Self { + UnionBUnionReader::Word(item) + } +} +impl UnionBUnion { + pub const NAME: &'static str = "UnionBUnion"; + pub fn as_bytes(&self) -> molecule::bytes::Bytes { + match self { + UnionBUnion::Byte(item) => item.as_bytes(), + UnionBUnion::Word(item) => item.as_bytes(), + } + } + pub fn as_slice(&self) -> &[u8] { + match self { + UnionBUnion::Byte(item) => item.as_slice(), + UnionBUnion::Word(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionBUnion::Byte(_) => 2, + UnionBUnion::Word(_) => 4, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionBUnion::Byte(_) => "Byte", + UnionBUnion::Word(_) => "Word", + } + } + pub fn as_reader<'r>(&'r self) -> UnionBUnionReader<'r> { + match self { + UnionBUnion::Byte(item) => item.as_reader().into(), + UnionBUnion::Word(item) => item.as_reader().into(), + } + } +} +impl<'r> UnionBUnionReader<'r> { + pub const NAME: &'r str = "UnionBUnionReader"; + pub fn as_slice(&self) -> &'r [u8] { + match self { + UnionBUnionReader::Byte(item) => item.as_slice(), + UnionBUnionReader::Word(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionBUnionReader::Byte(_) => 2, + UnionBUnionReader::Word(_) => 4, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionBUnionReader::Byte(_) => "Byte", + UnionBUnionReader::Word(_) => "Word", + } + } +} +#[derive(Clone)] +pub struct UnionC(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for UnionC { + 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 UnionC { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for UnionC { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl ::core::default::Default for UnionC { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + UnionC::new_unchecked(v) + } +} +impl UnionC { + const DEFAULT_VALUE: [u8; 6] = [0, 0, 0, 0, 0, 0]; + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionCUnion { + let inner = self.0.slice(molecule::NUMBER_SIZE..); + match self.item_id() { + 0 => Word::new_unchecked(inner).into(), + 1 => Byte::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } + pub fn as_reader<'r>(&'r self) -> UnionCReader<'r> { + UnionCReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for UnionC { + type Builder = UnionCBuilder; + const NAME: &'static str = "UnionC"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + UnionC(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 { + UnionCReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + UnionCReader::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_enum()) + } +} +#[derive(Clone, Copy)] +pub struct UnionCReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for UnionCReader<'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 UnionCReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for UnionCReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl<'r> UnionCReader<'r> { + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionCUnionReader<'r> { + let inner = &self.as_slice()[molecule::NUMBER_SIZE..]; + match self.item_id() { + 0 => WordReader::new_unchecked(inner).into(), + 1 => ByteReader::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } +} +impl<'r> molecule::prelude::Reader<'r> for UnionCReader<'r> { + type Entity = UnionC; + const NAME: &'static str = "UnionCReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + UnionCReader(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_id = molecule::unpack_number(slice); + let inner_slice = &slice[molecule::NUMBER_SIZE..]; + match item_id { + 0 => WordReader::verify(inner_slice, compatible), + 1 => ByteReader::verify(inner_slice, compatible), + _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id), + }?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct UnionCBuilder(pub(crate) UnionCUnion); +impl UnionCBuilder { + pub const ITEMS_COUNT: usize = 2; + pub fn set(mut self, v: I) -> Self + where + I: ::core::convert::Into, + { + self.0 = v.into(); + self + } +} +impl molecule::prelude::Builder for UnionCBuilder { + type Entity = UnionC; + const NAME: &'static str = "UnionCBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + self.0.as_slice().len() + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number(self.0.item_id()))?; + writer.write_all(self.0.as_slice()) + } + 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)); + UnionC::new_unchecked(inner.into()) + } +} +#[derive(Debug, Clone)] +pub enum UnionCUnion { + Word(Word), + Byte(Byte), +} +#[derive(Debug, Clone, Copy)] +pub enum UnionCUnionReader<'r> { + Word(WordReader<'r>), + Byte(ByteReader<'r>), +} +impl ::core::default::Default for UnionCUnion { + fn default() -> Self { + UnionCUnion::Word(::core::default::Default::default()) + } +} +impl ::core::fmt::Display for UnionCUnion { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionCUnion::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionCUnion::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + } + } +} +impl<'r> ::core::fmt::Display for UnionCUnionReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionCUnionReader::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionCUnionReader::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + } + } +} +impl UnionCUnion { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionCUnion::Word(ref item) => write!(f, "{}", item), + UnionCUnion::Byte(ref item) => write!(f, "{}", item), + } + } +} +impl<'r> UnionCUnionReader<'r> { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionCUnionReader::Word(ref item) => write!(f, "{}", item), + UnionCUnionReader::Byte(ref item) => write!(f, "{}", item), + } + } +} +impl ::core::convert::From for UnionCUnion { + fn from(item: Word) -> Self { + UnionCUnion::Word(item) + } +} +impl ::core::convert::From for UnionCUnion { + fn from(item: Byte) -> Self { + UnionCUnion::Byte(item) + } +} +impl<'r> ::core::convert::From> for UnionCUnionReader<'r> { + fn from(item: WordReader<'r>) -> Self { + UnionCUnionReader::Word(item) + } +} +impl<'r> ::core::convert::From> for UnionCUnionReader<'r> { + fn from(item: ByteReader<'r>) -> Self { + UnionCUnionReader::Byte(item) + } +} +impl UnionCUnion { + pub const NAME: &'static str = "UnionCUnion"; + pub fn as_bytes(&self) -> molecule::bytes::Bytes { + match self { + UnionCUnion::Word(item) => item.as_bytes(), + UnionCUnion::Byte(item) => item.as_bytes(), + } + } + pub fn as_slice(&self) -> &[u8] { + match self { + UnionCUnion::Word(item) => item.as_slice(), + UnionCUnion::Byte(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionCUnion::Word(_) => 0, + UnionCUnion::Byte(_) => 1, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionCUnion::Word(_) => "Word", + UnionCUnion::Byte(_) => "Byte", + } + } + pub fn as_reader<'r>(&'r self) -> UnionCUnionReader<'r> { + match self { + UnionCUnion::Word(item) => item.as_reader().into(), + UnionCUnion::Byte(item) => item.as_reader().into(), + } + } +} +impl<'r> UnionCUnionReader<'r> { + pub const NAME: &'r str = "UnionCUnionReader"; + pub fn as_slice(&self) -> &'r [u8] { + match self { + UnionCUnionReader::Word(item) => item.as_slice(), + UnionCUnionReader::Byte(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionCUnionReader::Word(_) => 0, + UnionCUnionReader::Byte(_) => 1, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionCUnionReader::Word(_) => "Word", + UnionCUnionReader::Byte(_) => "Byte", + } + } +} +#[derive(Clone)] +pub struct UnionD(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for UnionD { + 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 UnionD { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for UnionD { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl ::core::default::Default for UnionD { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + UnionD::new_unchecked(v) + } +} +impl UnionD { + const DEFAULT_VALUE: [u8; 6] = [2, 0, 0, 0, 0, 0]; + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionDUnion { + let inner = self.0.slice(molecule::NUMBER_SIZE..); + match self.item_id() { + 2 => Word::new_unchecked(inner).into(), + 4 => Byte::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } + pub fn as_reader<'r>(&'r self) -> UnionDReader<'r> { + UnionDReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for UnionD { + type Builder = UnionDBuilder; + const NAME: &'static str = "UnionD"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + UnionD(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 { + UnionDReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + UnionDReader::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_enum()) + } +} +#[derive(Clone, Copy)] +pub struct UnionDReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for UnionDReader<'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 UnionDReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for UnionDReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}(", Self::NAME)?; + self.to_enum().display_inner(f)?; + write!(f, ")") + } +} +impl<'r> UnionDReader<'r> { + pub const ITEMS_COUNT: usize = 2; + pub fn item_id(&self) -> molecule::Number { + molecule::unpack_number(self.as_slice()) + } + pub fn to_enum(&self) -> UnionDUnionReader<'r> { + let inner = &self.as_slice()[molecule::NUMBER_SIZE..]; + match self.item_id() { + 2 => WordReader::new_unchecked(inner).into(), + 4 => ByteReader::new_unchecked(inner).into(), + _ => panic!("{}: invalid data", Self::NAME), + } + } +} +impl<'r> molecule::prelude::Reader<'r> for UnionDReader<'r> { + type Entity = UnionD; + const NAME: &'static str = "UnionDReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + UnionDReader(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_id = molecule::unpack_number(slice); + let inner_slice = &slice[molecule::NUMBER_SIZE..]; + match item_id { + 2 => WordReader::verify(inner_slice, compatible), + 4 => ByteReader::verify(inner_slice, compatible), + _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id), + }?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct UnionDBuilder(pub(crate) UnionDUnion); +impl UnionDBuilder { + pub const ITEMS_COUNT: usize = 2; + pub fn set(mut self, v: I) -> Self + where + I: ::core::convert::Into, + { + self.0 = v.into(); + self + } +} +impl molecule::prelude::Builder for UnionDBuilder { + type Entity = UnionD; + const NAME: &'static str = "UnionDBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + self.0.as_slice().len() + } + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number(self.0.item_id()))?; + writer.write_all(self.0.as_slice()) + } + 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)); + UnionD::new_unchecked(inner.into()) + } +} +#[derive(Debug, Clone)] +pub enum UnionDUnion { + Word(Word), + Byte(Byte), +} +#[derive(Debug, Clone, Copy)] +pub enum UnionDUnionReader<'r> { + Word(WordReader<'r>), + Byte(ByteReader<'r>), +} +impl ::core::default::Default for UnionDUnion { + fn default() -> Self { + UnionDUnion::Word(::core::default::Default::default()) + } +} +impl ::core::fmt::Display for UnionDUnion { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionDUnion::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionDUnion::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + } + } +} +impl<'r> ::core::fmt::Display for UnionDUnionReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionDUnionReader::Word(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Word::NAME, item) + } + UnionDUnionReader::Byte(ref item) => { + write!(f, "{}::{}({})", Self::NAME, Byte::NAME, item) + } + } + } +} +impl UnionDUnion { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionDUnion::Word(ref item) => write!(f, "{}", item), + UnionDUnion::Byte(ref item) => write!(f, "{}", item), + } + } +} +impl<'r> UnionDUnionReader<'r> { + pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UnionDUnionReader::Word(ref item) => write!(f, "{}", item), + UnionDUnionReader::Byte(ref item) => write!(f, "{}", item), + } + } +} +impl ::core::convert::From for UnionDUnion { + fn from(item: Word) -> Self { + UnionDUnion::Word(item) + } +} +impl ::core::convert::From for UnionDUnion { + fn from(item: Byte) -> Self { + UnionDUnion::Byte(item) + } +} +impl<'r> ::core::convert::From> for UnionDUnionReader<'r> { + fn from(item: WordReader<'r>) -> Self { + UnionDUnionReader::Word(item) + } +} +impl<'r> ::core::convert::From> for UnionDUnionReader<'r> { + fn from(item: ByteReader<'r>) -> Self { + UnionDUnionReader::Byte(item) + } +} +impl UnionDUnion { + pub const NAME: &'static str = "UnionDUnion"; + pub fn as_bytes(&self) -> molecule::bytes::Bytes { + match self { + UnionDUnion::Word(item) => item.as_bytes(), + UnionDUnion::Byte(item) => item.as_bytes(), + } + } + pub fn as_slice(&self) -> &[u8] { + match self { + UnionDUnion::Word(item) => item.as_slice(), + UnionDUnion::Byte(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionDUnion::Word(_) => 2, + UnionDUnion::Byte(_) => 4, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionDUnion::Word(_) => "Word", + UnionDUnion::Byte(_) => "Byte", + } + } + pub fn as_reader<'r>(&'r self) -> UnionDUnionReader<'r> { + match self { + UnionDUnion::Word(item) => item.as_reader().into(), + UnionDUnion::Byte(item) => item.as_reader().into(), + } + } +} +impl<'r> UnionDUnionReader<'r> { + pub const NAME: &'r str = "UnionDUnionReader"; + pub fn as_slice(&self) -> &'r [u8] { + match self { + UnionDUnionReader::Word(item) => item.as_slice(), + UnionDUnionReader::Byte(item) => item.as_slice(), + } + } + pub fn item_id(&self) -> molecule::Number { + match self { + UnionDUnionReader::Word(_) => 2, + UnionDUnionReader::Byte(_) => 4, + } + } + pub fn item_name(&self) -> &str { + match self { + UnionDUnionReader::Word(_) => "Word", + UnionDUnionReader::Byte(_) => "Byte", + } + } +} +#[derive(Clone)] +pub struct TableA(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for TableA { + 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 TableA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for TableA { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + write!(f, ", {}: {}", "f7", self.f7())?; + write!(f, ", {}: {}", "f8", self.f8())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for TableA { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + TableA::new_unchecked(v) + } +} +impl TableA { + const DEFAULT_VALUE: [u8; 69] = [ + 69, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 46, 0, 0, 0, 50, 0, 0, 0, 54, 0, 0, 0, 63, 0, 0, 0, + 63, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 9, 0, 0, 0, + 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + pub const FIELD_COUNT: usize = 8; + 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 f1(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> StructA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + StructA::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + pub fn f4(&self) -> BytesVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + BytesVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f5(&self) -> Table1 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + Table1::new_unchecked(self.0.slice(start..end)) + } + pub fn f6(&self) -> BytesOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + BytesOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f7(&self) -> UnionA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + UnionA::new_unchecked(self.0.slice(start..end)) + } + pub fn f8(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[36..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } else { + Byte::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> TableAReader<'r> { + TableAReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for TableA { + type Builder = TableABuilder; + const NAME: &'static str = "TableA"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + TableA(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 { + TableAReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + TableAReader::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() + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + .f5(self.f5()) + .f6(self.f6()) + .f7(self.f7()) + .f8(self.f8()) + } +} +#[derive(Clone, Copy)] +pub struct TableAReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for TableAReader<'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 TableAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for TableAReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + write!(f, ", {}: {}", "f7", self.f7())?; + write!(f, ", {}: {}", "f8", self.f8())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> TableAReader<'r> { + pub const FIELD_COUNT: usize = 8; + 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 f1(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> StructAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f4(&self) -> BytesVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + BytesVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f5(&self) -> Table1Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + Table1Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f6(&self) -> BytesOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + BytesOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f7(&self) -> UnionAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + UnionAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f8(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[36..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } else { + ByteReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for TableAReader<'r> { + type Entity = TableA; + const NAME: &'static str = "TableAReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + TableAReader(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 * 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 = 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); + } + Word2Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + StructAReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + BytesReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + BytesVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + Table1Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + BytesOptReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + UnionAReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; + ByteReader::verify(&slice[offsets[7]..offsets[8]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct TableABuilder { + pub(crate) f1: Word2, + pub(crate) f2: StructA, + pub(crate) f3: Bytes, + pub(crate) f4: BytesVec, + pub(crate) f5: Table1, + pub(crate) f6: BytesOpt, + pub(crate) f7: UnionA, + pub(crate) f8: Byte, +} +impl TableABuilder { + pub const FIELD_COUNT: usize = 8; + pub fn f1(mut self, v: Word2) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: StructA) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Bytes) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: BytesVec) -> Self { + self.f4 = v; + self + } + pub fn f5(mut self, v: Table1) -> Self { + self.f5 = v; + self + } + pub fn f6(mut self, v: BytesOpt) -> Self { + self.f6 = v; + self + } + pub fn f7(mut self, v: UnionA) -> Self { + self.f7 = v; + self + } + pub fn f8(mut self, v: Byte) -> Self { + self.f8 = v; + self + } +} +impl molecule::prelude::Builder for TableABuilder { + type Entity = TableA; + const NAME: &'static str = "TableABuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + + self.f4.as_slice().len() + + self.f5.as_slice().len() + + self.f6.as_slice().len() + + self.f7.as_slice().len() + + self.f8.as_slice().len() + } + fn 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.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.as_slice().len(); + offsets.push(total_size); + total_size += self.f4.as_slice().len(); + offsets.push(total_size); + total_size += self.f5.as_slice().len(); + offsets.push(total_size); + total_size += self.f6.as_slice().len(); + offsets.push(total_size); + total_size += self.f7.as_slice().len(); + offsets.push(total_size); + total_size += self.f8.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.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.as_slice())?; + writer.write_all(self.f5.as_slice())?; + writer.write_all(self.f6.as_slice())?; + writer.write_all(self.f7.as_slice())?; + writer.write_all(self.f8.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)); + TableA::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct AllInOne(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for AllInOne { + 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 AllInOne { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for AllInOne { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f0", self.f0())?; + write!(f, ", {}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + write!(f, ", {}: {}", "f7", self.f7())?; + write!(f, ", {}: {}", "f8", self.f8())?; + write!(f, ", {}: {}", "f9", self.f9())?; + write!(f, ", {}: {}", "f10", self.f10())?; + write!(f, ", {}: {}", "f11", self.f11())?; + write!(f, ", {}: {}", "f12", self.f12())?; + write!(f, ", {}: {}", "f13", self.f13())?; + write!(f, ", {}: {}", "f14", self.f14())?; + write!(f, ", {}: {}", "f15", self.f15())?; + write!(f, ", {}: {}", "f16", self.f16())?; + write!(f, ", {}: {}", "f17", self.f17())?; + write!(f, ", {}: {}", "f18", self.f18())?; + write!(f, ", {}: {}", "f19", self.f19())?; + write!(f, ", {}: {}", "f20", self.f20())?; + write!(f, ", {}: {}", "f21", self.f21())?; + write!(f, ", {}: {}", "f22", self.f22())?; + write!(f, ", {}: {}", "f23", self.f23())?; + write!(f, ", {}: {}", "f24", self.f24())?; + write!(f, ", {}: {}", "f25", self.f25())?; + write!(f, ", {}: {}", "f26", self.f26())?; + write!(f, ", {}: {}", "f27", self.f27())?; + write!(f, ", {}: {}", "f28", self.f28())?; + write!(f, ", {}: {}", "f29", self.f29())?; + write!(f, ", {}: {}", "f30", self.f30())?; + write!(f, ", {}: {}", "f31", self.f31())?; + write!(f, ", {}: {}", "f32", self.f32())?; + write!(f, ", {}: {}", "f33", self.f33())?; + write!(f, ", {}: {}", "f34", self.f34())?; + write!(f, ", {}: {}", "f35", self.f35())?; + write!(f, ", {}: {}", "f36", self.f36())?; + write!(f, ", {}: {}", "f37", self.f37())?; + write!(f, ", {}: {}", "f38", self.f38())?; + write!(f, ", {}: {}", "f39", self.f39())?; + write!(f, ", {}: {}", "f40", self.f40())?; + write!(f, ", {}: {}", "f41", self.f41())?; + write!(f, ", {}: {}", "f42", self.f42())?; + write!(f, ", {}: {}", "f43", self.f43())?; + write!(f, ", {}: {}", "f44", self.f44())?; + write!(f, ", {}: {}", "f45", self.f45())?; + write!(f, ", {}: {}", "f46", self.f46())?; + write!(f, ", {}: {}", "f47", self.f47())?; + write!(f, ", {}: {}", "f48", self.f48())?; + write!(f, ", {}: {}", "f49", self.f49())?; + write!(f, ", {}: {}", "f50", self.f50())?; + write!(f, ", {}: {}", "f51", self.f51())?; + write!(f, ", {}: {}", "f52", self.f52())?; + write!(f, ", {}: {}", "f53", self.f53())?; + write!(f, ", {}: {}", "f54", self.f54())?; + write!(f, ", {}: {}", "f55", self.f55())?; + write!(f, ", {}: {}", "f56", self.f56())?; + write!(f, ", {}: {}", "f57", self.f57())?; + write!(f, ", {}: {}", "f58", self.f58())?; + write!(f, ", {}: {}", "f59", self.f59())?; + write!(f, ", {}: {}", "f60", self.f60())?; + write!(f, ", {}: {}", "f61", self.f61())?; + write!(f, ", {}: {}", "f62", self.f62())?; + write!(f, ", {}: {}", "f63", self.f63())?; + write!(f, ", {}: {}", "f64", self.f64())?; + write!(f, ", {}: {}", "f65", self.f65())?; + write!(f, ", {}: {}", "f66", self.f66())?; + write!(f, ", {}: {}", "f67", self.f67())?; + write!(f, ", {}: {}", "f68", self.f68())?; + write!(f, ", {}: {}", "f69", self.f69())?; + write!(f, ", {}: {}", "f70", self.f70())?; + write!(f, ", {}: {}", "f71", self.f71())?; + write!(f, ", {}: {}", "f72", self.f72())?; + write!(f, ", {}: {}", "f73", self.f73())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for AllInOne { + fn default() -> Self { + let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE); + AllInOne::new_unchecked(v) + } +} +impl AllInOne { + const DEFAULT_VALUE: [u8; 1036] = [ + 12, 4, 0, 0, 44, 1, 0, 0, 45, 1, 0, 0, 47, 1, 0, 0, 50, 1, 0, 0, 54, 1, 0, 0, 59, 1, 0, 0, + 65, 1, 0, 0, 72, 1, 0, 0, 80, 1, 0, 0, 89, 1, 0, 0, 99, 1, 0, 0, 110, 1, 0, 0, 122, 1, 0, + 0, 135, 1, 0, 0, 149, 1, 0, 0, 164, 1, 0, 0, 180, 1, 0, 0, 182, 1, 0, 0, 186, 1, 0, 0, 192, + 1, 0, 0, 200, 1, 0, 0, 210, 1, 0, 0, 222, 1, 0, 0, 236, 1, 0, 0, 252, 1, 0, 0, 5, 2, 0, 0, + 20, 2, 0, 0, 41, 2, 0, 0, 68, 2, 0, 0, 74, 2, 0, 0, 81, 2, 0, 0, 89, 2, 0, 0, 98, 2, 0, 0, + 104, 2, 0, 0, 109, 2, 0, 0, 119, 2, 0, 0, 129, 2, 0, 0, 133, 2, 0, 0, 140, 2, 0, 0, 152, 2, + 0, 0, 165, 2, 0, 0, 173, 2, 0, 0, 177, 2, 0, 0, 181, 2, 0, 0, 185, 2, 0, 0, 189, 2, 0, 0, + 193, 2, 0, 0, 197, 2, 0, 0, 201, 2, 0, 0, 205, 2, 0, 0, 209, 2, 0, 0, 213, 2, 0, 0, 222, 2, + 0, 0, 239, 2, 0, 0, 10, 3, 0, 0, 45, 3, 0, 0, 88, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, + 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, + 0, 178, 3, 0, 0, 178, 3, 0, 0, 178, 3, 0, 0, 182, 3, 0, 0, 186, 3, 0, 0, 190, 3, 0, 0, 194, + 3, 0, 0, 199, 3, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, + 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 9, 0, 0, 0, 8, 0, 0, 0, 0, 17, 0, 0, 0, 12, 0, 0, 0, + 13, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 20, 0, 0, 0, 21, 0, 0, 0, 25, 0, 0, 0, 31, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 24, 0, 0, 0, 25, 0, 0, 0, 29, 0, 0, 0, + 35, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 90, 0, + 0, 0, 28, 0, 0, 0, 29, 0, 0, 0, 33, 0, 0, 0, 39, 0, 0, 0, 43, 0, 0, 0, 47, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 43, 0, 0, 0, 24, 0, 0, 0, 25, 0, 0, 0, + 29, 0, 0, 0, 35, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, + 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0, 36, 0, 0, + 0, 40, 0, 0, 0, 46, 0, 0, 0, 50, 0, 0, 0, 54, 0, 0, 0, 63, 0, 0, 0, 63, 0, 0, 0, 68, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 9, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ]; + pub const FIELD_COUNT: usize = 74; + 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 f0(&self) -> Byte { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + Byte::new_unchecked(self.0.slice(start..end)) + } + pub fn f1(&self) -> Byte2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Byte2::new_unchecked(self.0.slice(start..end)) + } + pub fn f2(&self) -> Byte3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + Byte3::new_unchecked(self.0.slice(start..end)) + } + pub fn f3(&self) -> Byte4 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + Byte4::new_unchecked(self.0.slice(start..end)) + } + pub fn f4(&self) -> Byte5 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + Byte5::new_unchecked(self.0.slice(start..end)) + } + pub fn f5(&self) -> Byte6 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + Byte6::new_unchecked(self.0.slice(start..end)) + } + pub fn f6(&self) -> Byte7 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + Byte7::new_unchecked(self.0.slice(start..end)) + } + pub fn f7(&self) -> Byte8 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + let end = molecule::unpack_number(&slice[36..]) as usize; + Byte8::new_unchecked(self.0.slice(start..end)) + } + pub fn f8(&self) -> Byte9 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[40..]) as usize; + Byte9::new_unchecked(self.0.slice(start..end)) + } + pub fn f9(&self) -> Byte10 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[40..]) as usize; + let end = molecule::unpack_number(&slice[44..]) as usize; + Byte10::new_unchecked(self.0.slice(start..end)) + } + pub fn f10(&self) -> Byte11 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[44..]) as usize; + let end = molecule::unpack_number(&slice[48..]) as usize; + Byte11::new_unchecked(self.0.slice(start..end)) + } + pub fn f11(&self) -> Byte12 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[48..]) as usize; + let end = molecule::unpack_number(&slice[52..]) as usize; + Byte12::new_unchecked(self.0.slice(start..end)) + } + pub fn f12(&self) -> Byte13 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[52..]) as usize; + let end = molecule::unpack_number(&slice[56..]) as usize; + Byte13::new_unchecked(self.0.slice(start..end)) + } + pub fn f13(&self) -> Byte14 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[56..]) as usize; + let end = molecule::unpack_number(&slice[60..]) as usize; + Byte14::new_unchecked(self.0.slice(start..end)) + } + pub fn f14(&self) -> Byte15 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[60..]) as usize; + let end = molecule::unpack_number(&slice[64..]) as usize; + Byte15::new_unchecked(self.0.slice(start..end)) + } + pub fn f15(&self) -> Byte16 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[64..]) as usize; + let end = molecule::unpack_number(&slice[68..]) as usize; + Byte16::new_unchecked(self.0.slice(start..end)) + } + pub fn f16(&self) -> Word { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[68..]) as usize; + let end = molecule::unpack_number(&slice[72..]) as usize; + Word::new_unchecked(self.0.slice(start..end)) + } + pub fn f17(&self) -> Word2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[72..]) as usize; + let end = molecule::unpack_number(&slice[76..]) as usize; + Word2::new_unchecked(self.0.slice(start..end)) + } + pub fn f18(&self) -> Word3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[76..]) as usize; + let end = molecule::unpack_number(&slice[80..]) as usize; + Word3::new_unchecked(self.0.slice(start..end)) + } + pub fn f19(&self) -> Word4 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[80..]) as usize; + let end = molecule::unpack_number(&slice[84..]) as usize; + Word4::new_unchecked(self.0.slice(start..end)) + } + pub fn f20(&self) -> Word5 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[84..]) as usize; + let end = molecule::unpack_number(&slice[88..]) as usize; + Word5::new_unchecked(self.0.slice(start..end)) + } + pub fn f21(&self) -> Word6 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[88..]) as usize; + let end = molecule::unpack_number(&slice[92..]) as usize; + Word6::new_unchecked(self.0.slice(start..end)) + } + pub fn f22(&self) -> Word7 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[92..]) as usize; + let end = molecule::unpack_number(&slice[96..]) as usize; + Word7::new_unchecked(self.0.slice(start..end)) + } + pub fn f23(&self) -> Word8 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[96..]) as usize; + let end = molecule::unpack_number(&slice[100..]) as usize; + Word8::new_unchecked(self.0.slice(start..end)) + } + pub fn f24(&self) -> Byte3x3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[100..]) as usize; + let end = molecule::unpack_number(&slice[104..]) as usize; + Byte3x3::new_unchecked(self.0.slice(start..end)) + } + pub fn f25(&self) -> Byte5x3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[104..]) as usize; + let end = molecule::unpack_number(&slice[108..]) as usize; + Byte5x3::new_unchecked(self.0.slice(start..end)) + } + pub fn f26(&self) -> Byte7x3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[108..]) as usize; + let end = molecule::unpack_number(&slice[112..]) as usize; + Byte7x3::new_unchecked(self.0.slice(start..end)) + } + pub fn f27(&self) -> Byte9x3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[112..]) as usize; + let end = molecule::unpack_number(&slice[116..]) as usize; + Byte9x3::new_unchecked(self.0.slice(start..end)) + } + pub fn f28(&self) -> StructA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[116..]) as usize; + let end = molecule::unpack_number(&slice[120..]) as usize; + StructA::new_unchecked(self.0.slice(start..end)) + } + pub fn f29(&self) -> StructB { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[120..]) as usize; + let end = molecule::unpack_number(&slice[124..]) as usize; + StructB::new_unchecked(self.0.slice(start..end)) + } + pub fn f30(&self) -> StructC { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[124..]) as usize; + let end = molecule::unpack_number(&slice[128..]) as usize; + StructC::new_unchecked(self.0.slice(start..end)) + } + pub fn f31(&self) -> StructD { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[128..]) as usize; + let end = molecule::unpack_number(&slice[132..]) as usize; + StructD::new_unchecked(self.0.slice(start..end)) + } + pub fn f32(&self) -> StructE { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[132..]) as usize; + let end = molecule::unpack_number(&slice[136..]) as usize; + StructE::new_unchecked(self.0.slice(start..end)) + } + pub fn f33(&self) -> StructF { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[136..]) as usize; + let end = molecule::unpack_number(&slice[140..]) as usize; + StructF::new_unchecked(self.0.slice(start..end)) + } + pub fn f34(&self) -> StructG { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[140..]) as usize; + let end = molecule::unpack_number(&slice[144..]) as usize; + StructG::new_unchecked(self.0.slice(start..end)) + } + pub fn f35(&self) -> StructH { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[144..]) as usize; + let end = molecule::unpack_number(&slice[148..]) as usize; + StructH::new_unchecked(self.0.slice(start..end)) + } + pub fn f36(&self) -> StructI { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[148..]) as usize; + let end = molecule::unpack_number(&slice[152..]) as usize; + StructI::new_unchecked(self.0.slice(start..end)) + } + pub fn f37(&self) -> StructJ { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[152..]) as usize; + let end = molecule::unpack_number(&slice[156..]) as usize; + StructJ::new_unchecked(self.0.slice(start..end)) + } + pub fn f38(&self) -> StructIx3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[156..]) as usize; + let end = molecule::unpack_number(&slice[160..]) as usize; + StructIx3::new_unchecked(self.0.slice(start..end)) + } + pub fn f39(&self) -> StructO { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[160..]) as usize; + let end = molecule::unpack_number(&slice[164..]) as usize; + StructO::new_unchecked(self.0.slice(start..end)) + } + pub fn f40(&self) -> StructP { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[164..]) as usize; + let end = molecule::unpack_number(&slice[168..]) as usize; + StructP::new_unchecked(self.0.slice(start..end)) + } + pub fn f41(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[168..]) as usize; + let end = molecule::unpack_number(&slice[172..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + pub fn f42(&self) -> Words { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[172..]) as usize; + let end = molecule::unpack_number(&slice[176..]) as usize; + Words::new_unchecked(self.0.slice(start..end)) + } + pub fn f43(&self) -> Byte3Vec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[176..]) as usize; + let end = molecule::unpack_number(&slice[180..]) as usize; + Byte3Vec::new_unchecked(self.0.slice(start..end)) + } + pub fn f44(&self) -> Byte7Vec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[180..]) as usize; + let end = molecule::unpack_number(&slice[184..]) as usize; + Byte7Vec::new_unchecked(self.0.slice(start..end)) + } + pub fn f45(&self) -> StructIVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[184..]) as usize; + let end = molecule::unpack_number(&slice[188..]) as usize; + StructIVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f46(&self) -> StructJVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[188..]) as usize; + let end = molecule::unpack_number(&slice[192..]) as usize; + StructJVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f47(&self) -> StructPVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[192..]) as usize; + let end = molecule::unpack_number(&slice[196..]) as usize; + StructPVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f48(&self) -> BytesVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[196..]) as usize; + let end = molecule::unpack_number(&slice[200..]) as usize; + BytesVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f49(&self) -> WordsVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[200..]) as usize; + let end = molecule::unpack_number(&slice[204..]) as usize; + WordsVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f50(&self) -> Table0 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[204..]) as usize; + let end = molecule::unpack_number(&slice[208..]) as usize; + Table0::new_unchecked(self.0.slice(start..end)) + } + pub fn f51(&self) -> Table1 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[208..]) as usize; + let end = molecule::unpack_number(&slice[212..]) as usize; + Table1::new_unchecked(self.0.slice(start..end)) + } + pub fn f52(&self) -> Table2 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[212..]) as usize; + let end = molecule::unpack_number(&slice[216..]) as usize; + Table2::new_unchecked(self.0.slice(start..end)) + } + pub fn f53(&self) -> Table3 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[216..]) as usize; + let end = molecule::unpack_number(&slice[220..]) as usize; + Table3::new_unchecked(self.0.slice(start..end)) + } + pub fn f54(&self) -> Table4 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[220..]) as usize; + let end = molecule::unpack_number(&slice[224..]) as usize; + Table4::new_unchecked(self.0.slice(start..end)) + } + pub fn f55(&self) -> Table5 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[224..]) as usize; + let end = molecule::unpack_number(&slice[228..]) as usize; + Table5::new_unchecked(self.0.slice(start..end)) + } + pub fn f56(&self) -> Table6 { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[228..]) as usize; + let end = molecule::unpack_number(&slice[232..]) as usize; + Table6::new_unchecked(self.0.slice(start..end)) + } + pub fn f57(&self) -> ByteOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[232..]) as usize; + let end = molecule::unpack_number(&slice[236..]) as usize; + ByteOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f58(&self) -> WordOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[236..]) as usize; + let end = molecule::unpack_number(&slice[240..]) as usize; + WordOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f59(&self) -> StructAOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[240..]) as usize; + let end = molecule::unpack_number(&slice[244..]) as usize; + StructAOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f60(&self) -> StructPOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[244..]) as usize; + let end = molecule::unpack_number(&slice[248..]) as usize; + StructPOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f61(&self) -> BytesOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[248..]) as usize; + let end = molecule::unpack_number(&slice[252..]) as usize; + BytesOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f62(&self) -> WordsOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[252..]) as usize; + let end = molecule::unpack_number(&slice[256..]) as usize; + WordsOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f63(&self) -> BytesVecOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[256..]) as usize; + let end = molecule::unpack_number(&slice[260..]) as usize; + BytesVecOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f64(&self) -> WordsVecOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[260..]) as usize; + let end = molecule::unpack_number(&slice[264..]) as usize; + WordsVecOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f65(&self) -> Table0Opt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[264..]) as usize; + let end = molecule::unpack_number(&slice[268..]) as usize; + Table0Opt::new_unchecked(self.0.slice(start..end)) + } + pub fn f66(&self) -> Table6Opt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[268..]) as usize; + let end = molecule::unpack_number(&slice[272..]) as usize; + Table6Opt::new_unchecked(self.0.slice(start..end)) + } + pub fn f67(&self) -> Table6OptOpt { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[272..]) as usize; + let end = molecule::unpack_number(&slice[276..]) as usize; + Table6OptOpt::new_unchecked(self.0.slice(start..end)) + } + pub fn f68(&self) -> ByteOptVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[276..]) as usize; + let end = molecule::unpack_number(&slice[280..]) as usize; + ByteOptVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f69(&self) -> WordOptVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[280..]) as usize; + let end = molecule::unpack_number(&slice[284..]) as usize; + WordOptVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f70(&self) -> WordsOptVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[284..]) as usize; + let end = molecule::unpack_number(&slice[288..]) as usize; + WordsOptVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f71(&self) -> BytesOptVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[288..]) as usize; + let end = molecule::unpack_number(&slice[292..]) as usize; + BytesOptVec::new_unchecked(self.0.slice(start..end)) + } + pub fn f72(&self) -> UnionA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[292..]) as usize; + let end = molecule::unpack_number(&slice[296..]) as usize; + UnionA::new_unchecked(self.0.slice(start..end)) + } + pub fn f73(&self) -> TableA { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[296..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[300..]) as usize; + TableA::new_unchecked(self.0.slice(start..end)) + } else { + TableA::new_unchecked(self.0.slice(start..)) + } + } + pub fn as_reader<'r>(&'r self) -> AllInOneReader<'r> { + AllInOneReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for AllInOne { + type Builder = AllInOneBuilder; + const NAME: &'static str = "AllInOne"; + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + AllInOne(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 { + AllInOneReader::from_slice(slice).map(|reader| reader.to_entity()) + } + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + AllInOneReader::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() + .f0(self.f0()) + .f1(self.f1()) + .f2(self.f2()) + .f3(self.f3()) + .f4(self.f4()) + .f5(self.f5()) + .f6(self.f6()) + .f7(self.f7()) + .f8(self.f8()) + .f9(self.f9()) + .f10(self.f10()) + .f11(self.f11()) + .f12(self.f12()) + .f13(self.f13()) + .f14(self.f14()) + .f15(self.f15()) + .f16(self.f16()) + .f17(self.f17()) + .f18(self.f18()) + .f19(self.f19()) + .f20(self.f20()) + .f21(self.f21()) + .f22(self.f22()) + .f23(self.f23()) + .f24(self.f24()) + .f25(self.f25()) + .f26(self.f26()) + .f27(self.f27()) + .f28(self.f28()) + .f29(self.f29()) + .f30(self.f30()) + .f31(self.f31()) + .f32(self.f32()) + .f33(self.f33()) + .f34(self.f34()) + .f35(self.f35()) + .f36(self.f36()) + .f37(self.f37()) + .f38(self.f38()) + .f39(self.f39()) + .f40(self.f40()) + .f41(self.f41()) + .f42(self.f42()) + .f43(self.f43()) + .f44(self.f44()) + .f45(self.f45()) + .f46(self.f46()) + .f47(self.f47()) + .f48(self.f48()) + .f49(self.f49()) + .f50(self.f50()) + .f51(self.f51()) + .f52(self.f52()) + .f53(self.f53()) + .f54(self.f54()) + .f55(self.f55()) + .f56(self.f56()) + .f57(self.f57()) + .f58(self.f58()) + .f59(self.f59()) + .f60(self.f60()) + .f61(self.f61()) + .f62(self.f62()) + .f63(self.f63()) + .f64(self.f64()) + .f65(self.f65()) + .f66(self.f66()) + .f67(self.f67()) + .f68(self.f68()) + .f69(self.f69()) + .f70(self.f70()) + .f71(self.f71()) + .f72(self.f72()) + .f73(self.f73()) + } +} +#[derive(Clone, Copy)] +pub struct AllInOneReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for AllInOneReader<'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 AllInOneReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for AllInOneReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "f0", self.f0())?; + write!(f, ", {}: {}", "f1", self.f1())?; + write!(f, ", {}: {}", "f2", self.f2())?; + write!(f, ", {}: {}", "f3", self.f3())?; + write!(f, ", {}: {}", "f4", self.f4())?; + write!(f, ", {}: {}", "f5", self.f5())?; + write!(f, ", {}: {}", "f6", self.f6())?; + write!(f, ", {}: {}", "f7", self.f7())?; + write!(f, ", {}: {}", "f8", self.f8())?; + write!(f, ", {}: {}", "f9", self.f9())?; + write!(f, ", {}: {}", "f10", self.f10())?; + write!(f, ", {}: {}", "f11", self.f11())?; + write!(f, ", {}: {}", "f12", self.f12())?; + write!(f, ", {}: {}", "f13", self.f13())?; + write!(f, ", {}: {}", "f14", self.f14())?; + write!(f, ", {}: {}", "f15", self.f15())?; + write!(f, ", {}: {}", "f16", self.f16())?; + write!(f, ", {}: {}", "f17", self.f17())?; + write!(f, ", {}: {}", "f18", self.f18())?; + write!(f, ", {}: {}", "f19", self.f19())?; + write!(f, ", {}: {}", "f20", self.f20())?; + write!(f, ", {}: {}", "f21", self.f21())?; + write!(f, ", {}: {}", "f22", self.f22())?; + write!(f, ", {}: {}", "f23", self.f23())?; + write!(f, ", {}: {}", "f24", self.f24())?; + write!(f, ", {}: {}", "f25", self.f25())?; + write!(f, ", {}: {}", "f26", self.f26())?; + write!(f, ", {}: {}", "f27", self.f27())?; + write!(f, ", {}: {}", "f28", self.f28())?; + write!(f, ", {}: {}", "f29", self.f29())?; + write!(f, ", {}: {}", "f30", self.f30())?; + write!(f, ", {}: {}", "f31", self.f31())?; + write!(f, ", {}: {}", "f32", self.f32())?; + write!(f, ", {}: {}", "f33", self.f33())?; + write!(f, ", {}: {}", "f34", self.f34())?; + write!(f, ", {}: {}", "f35", self.f35())?; + write!(f, ", {}: {}", "f36", self.f36())?; + write!(f, ", {}: {}", "f37", self.f37())?; + write!(f, ", {}: {}", "f38", self.f38())?; + write!(f, ", {}: {}", "f39", self.f39())?; + write!(f, ", {}: {}", "f40", self.f40())?; + write!(f, ", {}: {}", "f41", self.f41())?; + write!(f, ", {}: {}", "f42", self.f42())?; + write!(f, ", {}: {}", "f43", self.f43())?; + write!(f, ", {}: {}", "f44", self.f44())?; + write!(f, ", {}: {}", "f45", self.f45())?; + write!(f, ", {}: {}", "f46", self.f46())?; + write!(f, ", {}: {}", "f47", self.f47())?; + write!(f, ", {}: {}", "f48", self.f48())?; + write!(f, ", {}: {}", "f49", self.f49())?; + write!(f, ", {}: {}", "f50", self.f50())?; + write!(f, ", {}: {}", "f51", self.f51())?; + write!(f, ", {}: {}", "f52", self.f52())?; + write!(f, ", {}: {}", "f53", self.f53())?; + write!(f, ", {}: {}", "f54", self.f54())?; + write!(f, ", {}: {}", "f55", self.f55())?; + write!(f, ", {}: {}", "f56", self.f56())?; + write!(f, ", {}: {}", "f57", self.f57())?; + write!(f, ", {}: {}", "f58", self.f58())?; + write!(f, ", {}: {}", "f59", self.f59())?; + write!(f, ", {}: {}", "f60", self.f60())?; + write!(f, ", {}: {}", "f61", self.f61())?; + write!(f, ", {}: {}", "f62", self.f62())?; + write!(f, ", {}: {}", "f63", self.f63())?; + write!(f, ", {}: {}", "f64", self.f64())?; + write!(f, ", {}: {}", "f65", self.f65())?; + write!(f, ", {}: {}", "f66", self.f66())?; + write!(f, ", {}: {}", "f67", self.f67())?; + write!(f, ", {}: {}", "f68", self.f68())?; + write!(f, ", {}: {}", "f69", self.f69())?; + write!(f, ", {}: {}", "f70", self.f70())?; + write!(f, ", {}: {}", "f71", self.f71())?; + write!(f, ", {}: {}", "f72", self.f72())?; + write!(f, ", {}: {}", "f73", self.f73())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> AllInOneReader<'r> { + pub const FIELD_COUNT: usize = 74; + 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 f0(&self) -> ByteReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ByteReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f1(&self) -> Byte2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + Byte2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f2(&self) -> Byte3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + Byte3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f3(&self) -> Byte4Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + Byte4Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f4(&self) -> Byte5Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + Byte5Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f5(&self) -> Byte6Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + Byte6Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f6(&self) -> Byte7Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + Byte7Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f7(&self) -> Byte8Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + let end = molecule::unpack_number(&slice[36..]) as usize; + Byte8Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f8(&self) -> Byte9Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[40..]) as usize; + Byte9Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f9(&self) -> Byte10Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[40..]) as usize; + let end = molecule::unpack_number(&slice[44..]) as usize; + Byte10Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f10(&self) -> Byte11Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[44..]) as usize; + let end = molecule::unpack_number(&slice[48..]) as usize; + Byte11Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f11(&self) -> Byte12Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[48..]) as usize; + let end = molecule::unpack_number(&slice[52..]) as usize; + Byte12Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f12(&self) -> Byte13Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[52..]) as usize; + let end = molecule::unpack_number(&slice[56..]) as usize; + Byte13Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f13(&self) -> Byte14Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[56..]) as usize; + let end = molecule::unpack_number(&slice[60..]) as usize; + Byte14Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f14(&self) -> Byte15Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[60..]) as usize; + let end = molecule::unpack_number(&slice[64..]) as usize; + Byte15Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f15(&self) -> Byte16Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[64..]) as usize; + let end = molecule::unpack_number(&slice[68..]) as usize; + Byte16Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f16(&self) -> WordReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[68..]) as usize; + let end = molecule::unpack_number(&slice[72..]) as usize; + WordReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f17(&self) -> Word2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[72..]) as usize; + let end = molecule::unpack_number(&slice[76..]) as usize; + Word2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f18(&self) -> Word3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[76..]) as usize; + let end = molecule::unpack_number(&slice[80..]) as usize; + Word3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f19(&self) -> Word4Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[80..]) as usize; + let end = molecule::unpack_number(&slice[84..]) as usize; + Word4Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f20(&self) -> Word5Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[84..]) as usize; + let end = molecule::unpack_number(&slice[88..]) as usize; + Word5Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f21(&self) -> Word6Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[88..]) as usize; + let end = molecule::unpack_number(&slice[92..]) as usize; + Word6Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f22(&self) -> Word7Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[92..]) as usize; + let end = molecule::unpack_number(&slice[96..]) as usize; + Word7Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f23(&self) -> Word8Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[96..]) as usize; + let end = molecule::unpack_number(&slice[100..]) as usize; + Word8Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f24(&self) -> Byte3x3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[100..]) as usize; + let end = molecule::unpack_number(&slice[104..]) as usize; + Byte3x3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f25(&self) -> Byte5x3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[104..]) as usize; + let end = molecule::unpack_number(&slice[108..]) as usize; + Byte5x3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f26(&self) -> Byte7x3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[108..]) as usize; + let end = molecule::unpack_number(&slice[112..]) as usize; + Byte7x3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f27(&self) -> Byte9x3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[112..]) as usize; + let end = molecule::unpack_number(&slice[116..]) as usize; + Byte9x3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f28(&self) -> StructAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[116..]) as usize; + let end = molecule::unpack_number(&slice[120..]) as usize; + StructAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f29(&self) -> StructBReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[120..]) as usize; + let end = molecule::unpack_number(&slice[124..]) as usize; + StructBReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f30(&self) -> StructCReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[124..]) as usize; + let end = molecule::unpack_number(&slice[128..]) as usize; + StructCReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f31(&self) -> StructDReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[128..]) as usize; + let end = molecule::unpack_number(&slice[132..]) as usize; + StructDReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f32(&self) -> StructEReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[132..]) as usize; + let end = molecule::unpack_number(&slice[136..]) as usize; + StructEReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f33(&self) -> StructFReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[136..]) as usize; + let end = molecule::unpack_number(&slice[140..]) as usize; + StructFReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f34(&self) -> StructGReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[140..]) as usize; + let end = molecule::unpack_number(&slice[144..]) as usize; + StructGReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f35(&self) -> StructHReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[144..]) as usize; + let end = molecule::unpack_number(&slice[148..]) as usize; + StructHReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f36(&self) -> StructIReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[148..]) as usize; + let end = molecule::unpack_number(&slice[152..]) as usize; + StructIReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f37(&self) -> StructJReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[152..]) as usize; + let end = molecule::unpack_number(&slice[156..]) as usize; + StructJReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f38(&self) -> StructIx3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[156..]) as usize; + let end = molecule::unpack_number(&slice[160..]) as usize; + StructIx3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f39(&self) -> StructOReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[160..]) as usize; + let end = molecule::unpack_number(&slice[164..]) as usize; + StructOReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f40(&self) -> StructPReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[164..]) as usize; + let end = molecule::unpack_number(&slice[168..]) as usize; + StructPReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f41(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[168..]) as usize; + let end = molecule::unpack_number(&slice[172..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f42(&self) -> WordsReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[172..]) as usize; + let end = molecule::unpack_number(&slice[176..]) as usize; + WordsReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f43(&self) -> Byte3VecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[176..]) as usize; + let end = molecule::unpack_number(&slice[180..]) as usize; + Byte3VecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f44(&self) -> Byte7VecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[180..]) as usize; + let end = molecule::unpack_number(&slice[184..]) as usize; + Byte7VecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f45(&self) -> StructIVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[184..]) as usize; + let end = molecule::unpack_number(&slice[188..]) as usize; + StructIVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f46(&self) -> StructJVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[188..]) as usize; + let end = molecule::unpack_number(&slice[192..]) as usize; + StructJVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f47(&self) -> StructPVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[192..]) as usize; + let end = molecule::unpack_number(&slice[196..]) as usize; + StructPVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f48(&self) -> BytesVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[196..]) as usize; + let end = molecule::unpack_number(&slice[200..]) as usize; + BytesVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f49(&self) -> WordsVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[200..]) as usize; + let end = molecule::unpack_number(&slice[204..]) as usize; + WordsVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f50(&self) -> Table0Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[204..]) as usize; + let end = molecule::unpack_number(&slice[208..]) as usize; + Table0Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f51(&self) -> Table1Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[208..]) as usize; + let end = molecule::unpack_number(&slice[212..]) as usize; + Table1Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f52(&self) -> Table2Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[212..]) as usize; + let end = molecule::unpack_number(&slice[216..]) as usize; + Table2Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f53(&self) -> Table3Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[216..]) as usize; + let end = molecule::unpack_number(&slice[220..]) as usize; + Table3Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f54(&self) -> Table4Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[220..]) as usize; + let end = molecule::unpack_number(&slice[224..]) as usize; + Table4Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f55(&self) -> Table5Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[224..]) as usize; + let end = molecule::unpack_number(&slice[228..]) as usize; + Table5Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f56(&self) -> Table6Reader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[228..]) as usize; + let end = molecule::unpack_number(&slice[232..]) as usize; + Table6Reader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f57(&self) -> ByteOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[232..]) as usize; + let end = molecule::unpack_number(&slice[236..]) as usize; + ByteOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f58(&self) -> WordOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[236..]) as usize; + let end = molecule::unpack_number(&slice[240..]) as usize; + WordOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f59(&self) -> StructAOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[240..]) as usize; + let end = molecule::unpack_number(&slice[244..]) as usize; + StructAOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f60(&self) -> StructPOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[244..]) as usize; + let end = molecule::unpack_number(&slice[248..]) as usize; + StructPOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f61(&self) -> BytesOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[248..]) as usize; + let end = molecule::unpack_number(&slice[252..]) as usize; + BytesOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f62(&self) -> WordsOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[252..]) as usize; + let end = molecule::unpack_number(&slice[256..]) as usize; + WordsOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f63(&self) -> BytesVecOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[256..]) as usize; + let end = molecule::unpack_number(&slice[260..]) as usize; + BytesVecOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f64(&self) -> WordsVecOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[260..]) as usize; + let end = molecule::unpack_number(&slice[264..]) as usize; + WordsVecOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f65(&self) -> Table0OptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[264..]) as usize; + let end = molecule::unpack_number(&slice[268..]) as usize; + Table0OptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f66(&self) -> Table6OptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[268..]) as usize; + let end = molecule::unpack_number(&slice[272..]) as usize; + Table6OptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f67(&self) -> Table6OptOptReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[272..]) as usize; + let end = molecule::unpack_number(&slice[276..]) as usize; + Table6OptOptReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f68(&self) -> ByteOptVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[276..]) as usize; + let end = molecule::unpack_number(&slice[280..]) as usize; + ByteOptVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f69(&self) -> WordOptVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[280..]) as usize; + let end = molecule::unpack_number(&slice[284..]) as usize; + WordOptVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f70(&self) -> WordsOptVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[284..]) as usize; + let end = molecule::unpack_number(&slice[288..]) as usize; + WordsOptVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f71(&self) -> BytesOptVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[288..]) as usize; + let end = molecule::unpack_number(&slice[292..]) as usize; + BytesOptVecReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f72(&self) -> UnionAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[292..]) as usize; + let end = molecule::unpack_number(&slice[296..]) as usize; + UnionAReader::new_unchecked(&self.as_slice()[start..end]) + } + pub fn f73(&self) -> TableAReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[296..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[300..]) as usize; + TableAReader::new_unchecked(&self.as_slice()[start..end]) + } else { + TableAReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for AllInOneReader<'r> { + type Entity = AllInOne; + const NAME: &'static str = "AllInOneReader"; + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + fn new_unchecked(slice: &'r [u8]) -> Self { + AllInOneReader(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 * 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 = 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); + } + ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + Byte2Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + Byte3Reader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + Byte4Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + Byte5Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + Byte6Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + Byte7Reader::verify(&slice[offsets[6]..offsets[7]], compatible)?; + Byte8Reader::verify(&slice[offsets[7]..offsets[8]], compatible)?; + Byte9Reader::verify(&slice[offsets[8]..offsets[9]], compatible)?; + Byte10Reader::verify(&slice[offsets[9]..offsets[10]], compatible)?; + Byte11Reader::verify(&slice[offsets[10]..offsets[11]], compatible)?; + Byte12Reader::verify(&slice[offsets[11]..offsets[12]], compatible)?; + Byte13Reader::verify(&slice[offsets[12]..offsets[13]], compatible)?; + Byte14Reader::verify(&slice[offsets[13]..offsets[14]], compatible)?; + Byte15Reader::verify(&slice[offsets[14]..offsets[15]], compatible)?; + Byte16Reader::verify(&slice[offsets[15]..offsets[16]], compatible)?; + WordReader::verify(&slice[offsets[16]..offsets[17]], compatible)?; + Word2Reader::verify(&slice[offsets[17]..offsets[18]], compatible)?; + Word3Reader::verify(&slice[offsets[18]..offsets[19]], compatible)?; + Word4Reader::verify(&slice[offsets[19]..offsets[20]], compatible)?; + Word5Reader::verify(&slice[offsets[20]..offsets[21]], compatible)?; + Word6Reader::verify(&slice[offsets[21]..offsets[22]], compatible)?; + Word7Reader::verify(&slice[offsets[22]..offsets[23]], compatible)?; + Word8Reader::verify(&slice[offsets[23]..offsets[24]], compatible)?; + Byte3x3Reader::verify(&slice[offsets[24]..offsets[25]], compatible)?; + Byte5x3Reader::verify(&slice[offsets[25]..offsets[26]], compatible)?; + Byte7x3Reader::verify(&slice[offsets[26]..offsets[27]], compatible)?; + Byte9x3Reader::verify(&slice[offsets[27]..offsets[28]], compatible)?; + StructAReader::verify(&slice[offsets[28]..offsets[29]], compatible)?; + StructBReader::verify(&slice[offsets[29]..offsets[30]], compatible)?; + StructCReader::verify(&slice[offsets[30]..offsets[31]], compatible)?; + StructDReader::verify(&slice[offsets[31]..offsets[32]], compatible)?; + StructEReader::verify(&slice[offsets[32]..offsets[33]], compatible)?; + StructFReader::verify(&slice[offsets[33]..offsets[34]], compatible)?; + StructGReader::verify(&slice[offsets[34]..offsets[35]], compatible)?; + StructHReader::verify(&slice[offsets[35]..offsets[36]], compatible)?; + StructIReader::verify(&slice[offsets[36]..offsets[37]], compatible)?; + StructJReader::verify(&slice[offsets[37]..offsets[38]], compatible)?; + StructIx3Reader::verify(&slice[offsets[38]..offsets[39]], compatible)?; + StructOReader::verify(&slice[offsets[39]..offsets[40]], compatible)?; + StructPReader::verify(&slice[offsets[40]..offsets[41]], compatible)?; + BytesReader::verify(&slice[offsets[41]..offsets[42]], compatible)?; + WordsReader::verify(&slice[offsets[42]..offsets[43]], compatible)?; + Byte3VecReader::verify(&slice[offsets[43]..offsets[44]], compatible)?; + Byte7VecReader::verify(&slice[offsets[44]..offsets[45]], compatible)?; + StructIVecReader::verify(&slice[offsets[45]..offsets[46]], compatible)?; + StructJVecReader::verify(&slice[offsets[46]..offsets[47]], compatible)?; + StructPVecReader::verify(&slice[offsets[47]..offsets[48]], compatible)?; + BytesVecReader::verify(&slice[offsets[48]..offsets[49]], compatible)?; + WordsVecReader::verify(&slice[offsets[49]..offsets[50]], compatible)?; + Table0Reader::verify(&slice[offsets[50]..offsets[51]], compatible)?; + Table1Reader::verify(&slice[offsets[51]..offsets[52]], compatible)?; + Table2Reader::verify(&slice[offsets[52]..offsets[53]], compatible)?; + Table3Reader::verify(&slice[offsets[53]..offsets[54]], compatible)?; + Table4Reader::verify(&slice[offsets[54]..offsets[55]], compatible)?; + Table5Reader::verify(&slice[offsets[55]..offsets[56]], compatible)?; + Table6Reader::verify(&slice[offsets[56]..offsets[57]], compatible)?; + ByteOptReader::verify(&slice[offsets[57]..offsets[58]], compatible)?; + WordOptReader::verify(&slice[offsets[58]..offsets[59]], compatible)?; + StructAOptReader::verify(&slice[offsets[59]..offsets[60]], compatible)?; + StructPOptReader::verify(&slice[offsets[60]..offsets[61]], compatible)?; + BytesOptReader::verify(&slice[offsets[61]..offsets[62]], compatible)?; + WordsOptReader::verify(&slice[offsets[62]..offsets[63]], compatible)?; + BytesVecOptReader::verify(&slice[offsets[63]..offsets[64]], compatible)?; + WordsVecOptReader::verify(&slice[offsets[64]..offsets[65]], compatible)?; + Table0OptReader::verify(&slice[offsets[65]..offsets[66]], compatible)?; + Table6OptReader::verify(&slice[offsets[66]..offsets[67]], compatible)?; + Table6OptOptReader::verify(&slice[offsets[67]..offsets[68]], compatible)?; + ByteOptVecReader::verify(&slice[offsets[68]..offsets[69]], compatible)?; + WordOptVecReader::verify(&slice[offsets[69]..offsets[70]], compatible)?; + WordsOptVecReader::verify(&slice[offsets[70]..offsets[71]], compatible)?; + BytesOptVecReader::verify(&slice[offsets[71]..offsets[72]], compatible)?; + UnionAReader::verify(&slice[offsets[72]..offsets[73]], compatible)?; + TableAReader::verify(&slice[offsets[73]..offsets[74]], compatible)?; + Ok(()) + } +} +#[derive(Clone, Debug, Default)] +pub struct AllInOneBuilder { + pub(crate) f0: Byte, + pub(crate) f1: Byte2, + pub(crate) f2: Byte3, + pub(crate) f3: Byte4, + pub(crate) f4: Byte5, + pub(crate) f5: Byte6, + pub(crate) f6: Byte7, + pub(crate) f7: Byte8, + pub(crate) f8: Byte9, + pub(crate) f9: Byte10, + pub(crate) f10: Byte11, + pub(crate) f11: Byte12, + pub(crate) f12: Byte13, + pub(crate) f13: Byte14, + pub(crate) f14: Byte15, + pub(crate) f15: Byte16, + pub(crate) f16: Word, + pub(crate) f17: Word2, + pub(crate) f18: Word3, + pub(crate) f19: Word4, + pub(crate) f20: Word5, + pub(crate) f21: Word6, + pub(crate) f22: Word7, + pub(crate) f23: Word8, + pub(crate) f24: Byte3x3, + pub(crate) f25: Byte5x3, + pub(crate) f26: Byte7x3, + pub(crate) f27: Byte9x3, + pub(crate) f28: StructA, + pub(crate) f29: StructB, + pub(crate) f30: StructC, + pub(crate) f31: StructD, + pub(crate) f32: StructE, + pub(crate) f33: StructF, + pub(crate) f34: StructG, + pub(crate) f35: StructH, + pub(crate) f36: StructI, + pub(crate) f37: StructJ, + pub(crate) f38: StructIx3, + pub(crate) f39: StructO, + pub(crate) f40: StructP, + pub(crate) f41: Bytes, + pub(crate) f42: Words, + pub(crate) f43: Byte3Vec, + pub(crate) f44: Byte7Vec, + pub(crate) f45: StructIVec, + pub(crate) f46: StructJVec, + pub(crate) f47: StructPVec, + pub(crate) f48: BytesVec, + pub(crate) f49: WordsVec, + pub(crate) f50: Table0, + pub(crate) f51: Table1, + pub(crate) f52: Table2, + pub(crate) f53: Table3, + pub(crate) f54: Table4, + pub(crate) f55: Table5, + pub(crate) f56: Table6, + pub(crate) f57: ByteOpt, + pub(crate) f58: WordOpt, + pub(crate) f59: StructAOpt, + pub(crate) f60: StructPOpt, + pub(crate) f61: BytesOpt, + pub(crate) f62: WordsOpt, + pub(crate) f63: BytesVecOpt, + pub(crate) f64: WordsVecOpt, + pub(crate) f65: Table0Opt, + pub(crate) f66: Table6Opt, + pub(crate) f67: Table6OptOpt, + pub(crate) f68: ByteOptVec, + pub(crate) f69: WordOptVec, + pub(crate) f70: WordsOptVec, + pub(crate) f71: BytesOptVec, + pub(crate) f72: UnionA, + pub(crate) f73: TableA, +} +impl AllInOneBuilder { + pub const FIELD_COUNT: usize = 74; + pub fn f0(mut self, v: Byte) -> Self { + self.f0 = v; + self + } + pub fn f1(mut self, v: Byte2) -> Self { + self.f1 = v; + self + } + pub fn f2(mut self, v: Byte3) -> Self { + self.f2 = v; + self + } + pub fn f3(mut self, v: Byte4) -> Self { + self.f3 = v; + self + } + pub fn f4(mut self, v: Byte5) -> Self { + self.f4 = v; + self + } + pub fn f5(mut self, v: Byte6) -> Self { + self.f5 = v; + self + } + pub fn f6(mut self, v: Byte7) -> Self { + self.f6 = v; + self + } + pub fn f7(mut self, v: Byte8) -> Self { + self.f7 = v; + self + } + pub fn f8(mut self, v: Byte9) -> Self { + self.f8 = v; + self + } + pub fn f9(mut self, v: Byte10) -> Self { + self.f9 = v; + self + } + pub fn f10(mut self, v: Byte11) -> Self { + self.f10 = v; + self + } + pub fn f11(mut self, v: Byte12) -> Self { + self.f11 = v; + self + } + pub fn f12(mut self, v: Byte13) -> Self { + self.f12 = v; + self + } + pub fn f13(mut self, v: Byte14) -> Self { + self.f13 = v; + self + } + pub fn f14(mut self, v: Byte15) -> Self { + self.f14 = v; + self + } + pub fn f15(mut self, v: Byte16) -> Self { + self.f15 = v; + self + } + pub fn f16(mut self, v: Word) -> Self { + self.f16 = v; + self + } + pub fn f17(mut self, v: Word2) -> Self { + self.f17 = v; + self + } + pub fn f18(mut self, v: Word3) -> Self { + self.f18 = v; + self + } + pub fn f19(mut self, v: Word4) -> Self { + self.f19 = v; + self + } + pub fn f20(mut self, v: Word5) -> Self { + self.f20 = v; + self + } + pub fn f21(mut self, v: Word6) -> Self { + self.f21 = v; + self + } + pub fn f22(mut self, v: Word7) -> Self { + self.f22 = v; + self + } + pub fn f23(mut self, v: Word8) -> Self { + self.f23 = v; + self + } + pub fn f24(mut self, v: Byte3x3) -> Self { + self.f24 = v; + self + } + pub fn f25(mut self, v: Byte5x3) -> Self { + self.f25 = v; + self + } + pub fn f26(mut self, v: Byte7x3) -> Self { + self.f26 = v; + self + } + pub fn f27(mut self, v: Byte9x3) -> Self { + self.f27 = v; + self + } + pub fn f28(mut self, v: StructA) -> Self { + self.f28 = v; + self + } + pub fn f29(mut self, v: StructB) -> Self { + self.f29 = v; + self + } + pub fn f30(mut self, v: StructC) -> Self { + self.f30 = v; + self + } + pub fn f31(mut self, v: StructD) -> Self { + self.f31 = v; + self + } + pub fn f32(mut self, v: StructE) -> Self { + self.f32 = v; + self + } + pub fn f33(mut self, v: StructF) -> Self { + self.f33 = v; + self + } + pub fn f34(mut self, v: StructG) -> Self { + self.f34 = v; + self + } + pub fn f35(mut self, v: StructH) -> Self { + self.f35 = v; + self + } + pub fn f36(mut self, v: StructI) -> Self { + self.f36 = v; + self + } + pub fn f37(mut self, v: StructJ) -> Self { + self.f37 = v; + self + } + pub fn f38(mut self, v: StructIx3) -> Self { + self.f38 = v; + self + } + pub fn f39(mut self, v: StructO) -> Self { + self.f39 = v; + self + } + pub fn f40(mut self, v: StructP) -> Self { + self.f40 = v; + self + } + pub fn f41(mut self, v: Bytes) -> Self { + self.f41 = v; + self + } + pub fn f42(mut self, v: Words) -> Self { + self.f42 = v; + self + } + pub fn f43(mut self, v: Byte3Vec) -> Self { + self.f43 = v; + self + } + pub fn f44(mut self, v: Byte7Vec) -> Self { + self.f44 = v; + self + } + pub fn f45(mut self, v: StructIVec) -> Self { + self.f45 = v; + self + } + pub fn f46(mut self, v: StructJVec) -> Self { + self.f46 = v; + self + } + pub fn f47(mut self, v: StructPVec) -> Self { + self.f47 = v; + self + } + pub fn f48(mut self, v: BytesVec) -> Self { + self.f48 = v; + self + } + pub fn f49(mut self, v: WordsVec) -> Self { + self.f49 = v; + self + } + pub fn f50(mut self, v: Table0) -> Self { + self.f50 = v; + self + } + pub fn f51(mut self, v: Table1) -> Self { + self.f51 = v; + self + } + pub fn f52(mut self, v: Table2) -> Self { + self.f52 = v; + self + } + pub fn f53(mut self, v: Table3) -> Self { + self.f53 = v; + self + } + pub fn f54(mut self, v: Table4) -> Self { + self.f54 = v; + self + } + pub fn f55(mut self, v: Table5) -> Self { + self.f55 = v; + self + } + pub fn f56(mut self, v: Table6) -> Self { + self.f56 = v; + self + } + pub fn f57(mut self, v: ByteOpt) -> Self { + self.f57 = v; + self + } + pub fn f58(mut self, v: WordOpt) -> Self { + self.f58 = v; + self + } + pub fn f59(mut self, v: StructAOpt) -> Self { + self.f59 = v; + self + } + pub fn f60(mut self, v: StructPOpt) -> Self { + self.f60 = v; + self + } + pub fn f61(mut self, v: BytesOpt) -> Self { + self.f61 = v; + self + } + pub fn f62(mut self, v: WordsOpt) -> Self { + self.f62 = v; + self + } + pub fn f63(mut self, v: BytesVecOpt) -> Self { + self.f63 = v; + self + } + pub fn f64(mut self, v: WordsVecOpt) -> Self { + self.f64 = v; + self + } + pub fn f65(mut self, v: Table0Opt) -> Self { + self.f65 = v; + self + } + pub fn f66(mut self, v: Table6Opt) -> Self { + self.f66 = v; + self + } + pub fn f67(mut self, v: Table6OptOpt) -> Self { + self.f67 = v; + self + } + pub fn f68(mut self, v: ByteOptVec) -> Self { + self.f68 = v; + self + } + pub fn f69(mut self, v: WordOptVec) -> Self { + self.f69 = v; + self + } + pub fn f70(mut self, v: WordsOptVec) -> Self { + self.f70 = v; + self + } + pub fn f71(mut self, v: BytesOptVec) -> Self { + self.f71 = v; + self + } + pub fn f72(mut self, v: UnionA) -> Self { + self.f72 = v; + self + } + pub fn f73(mut self, v: TableA) -> Self { + self.f73 = v; + self + } +} +impl molecule::prelude::Builder for AllInOneBuilder { + type Entity = AllInOne; + const NAME: &'static str = "AllInOneBuilder"; + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.f0.as_slice().len() + + self.f1.as_slice().len() + + self.f2.as_slice().len() + + self.f3.as_slice().len() + + self.f4.as_slice().len() + + self.f5.as_slice().len() + + self.f6.as_slice().len() + + self.f7.as_slice().len() + + self.f8.as_slice().len() + + self.f9.as_slice().len() + + self.f10.as_slice().len() + + self.f11.as_slice().len() + + self.f12.as_slice().len() + + self.f13.as_slice().len() + + self.f14.as_slice().len() + + self.f15.as_slice().len() + + self.f16.as_slice().len() + + self.f17.as_slice().len() + + self.f18.as_slice().len() + + self.f19.as_slice().len() + + self.f20.as_slice().len() + + self.f21.as_slice().len() + + self.f22.as_slice().len() + + self.f23.as_slice().len() + + self.f24.as_slice().len() + + self.f25.as_slice().len() + + self.f26.as_slice().len() + + self.f27.as_slice().len() + + self.f28.as_slice().len() + + self.f29.as_slice().len() + + self.f30.as_slice().len() + + self.f31.as_slice().len() + + self.f32.as_slice().len() + + self.f33.as_slice().len() + + self.f34.as_slice().len() + + self.f35.as_slice().len() + + self.f36.as_slice().len() + + self.f37.as_slice().len() + + self.f38.as_slice().len() + + self.f39.as_slice().len() + + self.f40.as_slice().len() + + self.f41.as_slice().len() + + self.f42.as_slice().len() + + self.f43.as_slice().len() + + self.f44.as_slice().len() + + self.f45.as_slice().len() + + self.f46.as_slice().len() + + self.f47.as_slice().len() + + self.f48.as_slice().len() + + self.f49.as_slice().len() + + self.f50.as_slice().len() + + self.f51.as_slice().len() + + self.f52.as_slice().len() + + self.f53.as_slice().len() + + self.f54.as_slice().len() + + self.f55.as_slice().len() + + self.f56.as_slice().len() + + self.f57.as_slice().len() + + self.f58.as_slice().len() + + self.f59.as_slice().len() + + self.f60.as_slice().len() + + self.f61.as_slice().len() + + self.f62.as_slice().len() + + self.f63.as_slice().len() + + self.f64.as_slice().len() + + self.f65.as_slice().len() + + self.f66.as_slice().len() + + self.f67.as_slice().len() + + self.f68.as_slice().len() + + self.f69.as_slice().len() + + self.f70.as_slice().len() + + self.f71.as_slice().len() + + self.f72.as_slice().len() + + self.f73.as_slice().len() + } + fn 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.f0.as_slice().len(); + offsets.push(total_size); + total_size += self.f1.as_slice().len(); + offsets.push(total_size); + total_size += self.f2.as_slice().len(); + offsets.push(total_size); + total_size += self.f3.as_slice().len(); + offsets.push(total_size); + total_size += self.f4.as_slice().len(); + offsets.push(total_size); + total_size += self.f5.as_slice().len(); + offsets.push(total_size); + total_size += self.f6.as_slice().len(); + offsets.push(total_size); + total_size += self.f7.as_slice().len(); + offsets.push(total_size); + total_size += self.f8.as_slice().len(); + offsets.push(total_size); + total_size += self.f9.as_slice().len(); + offsets.push(total_size); + total_size += self.f10.as_slice().len(); + offsets.push(total_size); + total_size += self.f11.as_slice().len(); + offsets.push(total_size); + total_size += self.f12.as_slice().len(); + offsets.push(total_size); + total_size += self.f13.as_slice().len(); + offsets.push(total_size); + total_size += self.f14.as_slice().len(); + offsets.push(total_size); + total_size += self.f15.as_slice().len(); + offsets.push(total_size); + total_size += self.f16.as_slice().len(); + offsets.push(total_size); + total_size += self.f17.as_slice().len(); + offsets.push(total_size); + total_size += self.f18.as_slice().len(); + offsets.push(total_size); + total_size += self.f19.as_slice().len(); + offsets.push(total_size); + total_size += self.f20.as_slice().len(); + offsets.push(total_size); + total_size += self.f21.as_slice().len(); + offsets.push(total_size); + total_size += self.f22.as_slice().len(); + offsets.push(total_size); + total_size += self.f23.as_slice().len(); + offsets.push(total_size); + total_size += self.f24.as_slice().len(); + offsets.push(total_size); + total_size += self.f25.as_slice().len(); + offsets.push(total_size); + total_size += self.f26.as_slice().len(); + offsets.push(total_size); + total_size += self.f27.as_slice().len(); + offsets.push(total_size); + total_size += self.f28.as_slice().len(); + offsets.push(total_size); + total_size += self.f29.as_slice().len(); + offsets.push(total_size); + total_size += self.f30.as_slice().len(); + offsets.push(total_size); + total_size += self.f31.as_slice().len(); + offsets.push(total_size); + total_size += self.f32.as_slice().len(); + offsets.push(total_size); + total_size += self.f33.as_slice().len(); + offsets.push(total_size); + total_size += self.f34.as_slice().len(); + offsets.push(total_size); + total_size += self.f35.as_slice().len(); + offsets.push(total_size); + total_size += self.f36.as_slice().len(); + offsets.push(total_size); + total_size += self.f37.as_slice().len(); + offsets.push(total_size); + total_size += self.f38.as_slice().len(); + offsets.push(total_size); + total_size += self.f39.as_slice().len(); + offsets.push(total_size); + total_size += self.f40.as_slice().len(); + offsets.push(total_size); + total_size += self.f41.as_slice().len(); + offsets.push(total_size); + total_size += self.f42.as_slice().len(); + offsets.push(total_size); + total_size += self.f43.as_slice().len(); + offsets.push(total_size); + total_size += self.f44.as_slice().len(); + offsets.push(total_size); + total_size += self.f45.as_slice().len(); + offsets.push(total_size); + total_size += self.f46.as_slice().len(); + offsets.push(total_size); + total_size += self.f47.as_slice().len(); + offsets.push(total_size); + total_size += self.f48.as_slice().len(); + offsets.push(total_size); + total_size += self.f49.as_slice().len(); + offsets.push(total_size); + total_size += self.f50.as_slice().len(); + offsets.push(total_size); + total_size += self.f51.as_slice().len(); + offsets.push(total_size); + total_size += self.f52.as_slice().len(); + offsets.push(total_size); + total_size += self.f53.as_slice().len(); + offsets.push(total_size); + total_size += self.f54.as_slice().len(); + offsets.push(total_size); + total_size += self.f55.as_slice().len(); + offsets.push(total_size); + total_size += self.f56.as_slice().len(); + offsets.push(total_size); + total_size += self.f57.as_slice().len(); + offsets.push(total_size); + total_size += self.f58.as_slice().len(); + offsets.push(total_size); + total_size += self.f59.as_slice().len(); + offsets.push(total_size); + total_size += self.f60.as_slice().len(); + offsets.push(total_size); + total_size += self.f61.as_slice().len(); + offsets.push(total_size); + total_size += self.f62.as_slice().len(); + offsets.push(total_size); + total_size += self.f63.as_slice().len(); + offsets.push(total_size); + total_size += self.f64.as_slice().len(); + offsets.push(total_size); + total_size += self.f65.as_slice().len(); + offsets.push(total_size); + total_size += self.f66.as_slice().len(); + offsets.push(total_size); + total_size += self.f67.as_slice().len(); + offsets.push(total_size); + total_size += self.f68.as_slice().len(); + offsets.push(total_size); + total_size += self.f69.as_slice().len(); + offsets.push(total_size); + total_size += self.f70.as_slice().len(); + offsets.push(total_size); + total_size += self.f71.as_slice().len(); + offsets.push(total_size); + total_size += self.f72.as_slice().len(); + offsets.push(total_size); + total_size += self.f73.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.f0.as_slice())?; + writer.write_all(self.f1.as_slice())?; + writer.write_all(self.f2.as_slice())?; + writer.write_all(self.f3.as_slice())?; + writer.write_all(self.f4.as_slice())?; + writer.write_all(self.f5.as_slice())?; + writer.write_all(self.f6.as_slice())?; + writer.write_all(self.f7.as_slice())?; + writer.write_all(self.f8.as_slice())?; + writer.write_all(self.f9.as_slice())?; + writer.write_all(self.f10.as_slice())?; + writer.write_all(self.f11.as_slice())?; + writer.write_all(self.f12.as_slice())?; + writer.write_all(self.f13.as_slice())?; + writer.write_all(self.f14.as_slice())?; + writer.write_all(self.f15.as_slice())?; + writer.write_all(self.f16.as_slice())?; + writer.write_all(self.f17.as_slice())?; + writer.write_all(self.f18.as_slice())?; + writer.write_all(self.f19.as_slice())?; + writer.write_all(self.f20.as_slice())?; + writer.write_all(self.f21.as_slice())?; + writer.write_all(self.f22.as_slice())?; + writer.write_all(self.f23.as_slice())?; + writer.write_all(self.f24.as_slice())?; + writer.write_all(self.f25.as_slice())?; + writer.write_all(self.f26.as_slice())?; + writer.write_all(self.f27.as_slice())?; + writer.write_all(self.f28.as_slice())?; + writer.write_all(self.f29.as_slice())?; + writer.write_all(self.f30.as_slice())?; + writer.write_all(self.f31.as_slice())?; + writer.write_all(self.f32.as_slice())?; + writer.write_all(self.f33.as_slice())?; + writer.write_all(self.f34.as_slice())?; + writer.write_all(self.f35.as_slice())?; + writer.write_all(self.f36.as_slice())?; + writer.write_all(self.f37.as_slice())?; + writer.write_all(self.f38.as_slice())?; + writer.write_all(self.f39.as_slice())?; + writer.write_all(self.f40.as_slice())?; + writer.write_all(self.f41.as_slice())?; + writer.write_all(self.f42.as_slice())?; + writer.write_all(self.f43.as_slice())?; + writer.write_all(self.f44.as_slice())?; + writer.write_all(self.f45.as_slice())?; + writer.write_all(self.f46.as_slice())?; + writer.write_all(self.f47.as_slice())?; + writer.write_all(self.f48.as_slice())?; + writer.write_all(self.f49.as_slice())?; + writer.write_all(self.f50.as_slice())?; + writer.write_all(self.f51.as_slice())?; + writer.write_all(self.f52.as_slice())?; + writer.write_all(self.f53.as_slice())?; + writer.write_all(self.f54.as_slice())?; + writer.write_all(self.f55.as_slice())?; + writer.write_all(self.f56.as_slice())?; + writer.write_all(self.f57.as_slice())?; + writer.write_all(self.f58.as_slice())?; + writer.write_all(self.f59.as_slice())?; + writer.write_all(self.f60.as_slice())?; + writer.write_all(self.f61.as_slice())?; + writer.write_all(self.f62.as_slice())?; + writer.write_all(self.f63.as_slice())?; + writer.write_all(self.f64.as_slice())?; + writer.write_all(self.f65.as_slice())?; + writer.write_all(self.f66.as_slice())?; + writer.write_all(self.f67.as_slice())?; + writer.write_all(self.f68.as_slice())?; + writer.write_all(self.f69.as_slice())?; + writer.write_all(self.f70.as_slice())?; + writer.write_all(self.f71.as_slice())?; + writer.write_all(self.f72.as_slice())?; + writer.write_all(self.f73.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)); + AllInOne::new_unchecked(inner.into()) + } +} diff --git a/examples/lazy-reader-tests/src/types.rs b/examples/lazy-reader-tests/src/types_api2.rs similarity index 99% rename from examples/lazy-reader-tests/src/types.rs rename to examples/lazy-reader-tests/src/types_api2.rs index 75a93be..82bb49c 100644 --- a/examples/lazy-reader-tests/src/types.rs +++ b/examples/lazy-reader-tests/src/types_api2.rs @@ -1,4 +1,3 @@ - #![allow(dead_code)] #![allow(unused_imports)] extern crate alloc; @@ -19,12 +18,14 @@ impl Byte2 { 2 } } + impl Byte2 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte3 { pub cursor: Cursor, } @@ -38,12 +39,14 @@ impl Byte3 { 3 } } + impl Byte3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte4 { pub cursor: Cursor, } @@ -57,12 +60,14 @@ impl Byte4 { 4 } } + impl Byte4 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte5 { pub cursor: Cursor, } @@ -76,12 +81,14 @@ impl Byte5 { 5 } } + impl Byte5 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte6 { pub cursor: Cursor, } @@ -95,12 +102,14 @@ impl Byte6 { 6 } } + impl Byte6 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte7 { pub cursor: Cursor, } @@ -114,12 +123,14 @@ impl Byte7 { 7 } } + impl Byte7 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte8 { pub cursor: Cursor, } @@ -133,12 +144,14 @@ impl Byte8 { 8 } } + impl Byte8 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte9 { pub cursor: Cursor, } @@ -152,12 +165,14 @@ impl Byte9 { 9 } } + impl Byte9 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte10 { pub cursor: Cursor, } @@ -171,12 +186,14 @@ impl Byte10 { 10 } } + impl Byte10 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte11 { pub cursor: Cursor, } @@ -190,12 +207,14 @@ impl Byte11 { 11 } } + impl Byte11 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte12 { pub cursor: Cursor, } @@ -209,12 +228,14 @@ impl Byte12 { 12 } } + impl Byte12 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte13 { pub cursor: Cursor, } @@ -228,12 +249,14 @@ impl Byte13 { 13 } } + impl Byte13 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte14 { pub cursor: Cursor, } @@ -247,12 +270,14 @@ impl Byte14 { 14 } } + impl Byte14 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte15 { pub cursor: Cursor, } @@ -266,12 +291,14 @@ impl Byte15 { 15 } } + impl Byte15 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Byte16 { pub cursor: Cursor, } @@ -285,12 +312,14 @@ impl Byte16 { 16 } } + impl Byte16 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Word { pub cursor: Cursor, } @@ -304,12 +333,14 @@ impl Word { 2 } } + impl Word { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(1 * index, 1)?; cur.try_into() } } + pub struct Word2 { pub cursor: Cursor, } @@ -323,12 +354,14 @@ impl Word2 { 2 } } + impl Word2 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word3 { pub cursor: Cursor, } @@ -342,12 +375,14 @@ impl Word3 { 3 } } + impl Word3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word4 { pub cursor: Cursor, } @@ -361,12 +396,14 @@ impl Word4 { 4 } } + impl Word4 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word5 { pub cursor: Cursor, } @@ -380,12 +417,14 @@ impl Word5 { 5 } } + impl Word5 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word6 { pub cursor: Cursor, } @@ -399,12 +438,14 @@ impl Word6 { 6 } } + impl Word6 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word7 { pub cursor: Cursor, } @@ -418,12 +459,14 @@ impl Word7 { 7 } } + impl Word7 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Word8 { pub cursor: Cursor, } @@ -437,12 +480,14 @@ impl Word8 { 8 } } + impl Word8 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(2 * index, 2)?; Ok(cur) } } + pub struct Byte3x3 { pub cursor: Cursor, } @@ -456,12 +501,14 @@ impl Byte3x3 { 3 } } + impl Byte3x3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(3 * index, 3)?; Ok(cur) } } + pub struct Byte5x3 { pub cursor: Cursor, } @@ -475,12 +522,14 @@ impl Byte5x3 { 3 } } + impl Byte5x3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(5 * index, 5)?; Ok(cur) } } + pub struct Byte7x3 { pub cursor: Cursor, } @@ -494,12 +543,14 @@ impl Byte7x3 { 3 } } + impl Byte7x3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(7 * index, 7)?; Ok(cur) } } + pub struct Byte9x3 { pub cursor: Cursor, } @@ -513,12 +564,14 @@ impl Byte9x3 { 3 } } + impl Byte9x3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(9 * index, 9)?; Ok(cur) } } + pub struct StructA { pub cursor: Cursor, } @@ -527,6 +580,7 @@ impl From for StructA { StructA { cursor } } } + impl StructA { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -554,6 +608,7 @@ impl StructA { Ok(cur) } } + pub struct StructB { pub cursor: Cursor, } @@ -562,6 +617,7 @@ impl From for StructB { StructB { cursor } } } + impl StructB { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -589,6 +645,7 @@ impl StructB { Ok(cur) } } + pub struct StructC { pub cursor: Cursor, } @@ -597,6 +654,7 @@ impl From for StructC { StructC { cursor } } } + impl StructC { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -624,6 +682,7 @@ impl StructC { Ok(cur) } } + pub struct StructD { pub cursor: Cursor, } @@ -632,6 +691,7 @@ impl From for StructD { StructD { cursor } } } + impl StructD { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -659,6 +719,7 @@ impl StructD { Ok(cur) } } + pub struct StructE { pub cursor: Cursor, } @@ -667,6 +728,7 @@ impl From for StructE { StructE { cursor } } } + impl StructE { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -694,6 +756,7 @@ impl StructE { Ok(cur) } } + pub struct StructF { pub cursor: Cursor, } @@ -702,6 +765,7 @@ impl From for StructF { StructF { cursor } } } + impl StructF { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 1)?; @@ -722,6 +786,7 @@ impl StructF { cur.try_into() } } + pub struct StructG { pub cursor: Cursor, } @@ -730,6 +795,7 @@ impl From for StructG { StructG { cursor } } } + impl StructG { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 3)?; @@ -757,6 +823,7 @@ impl StructG { Ok(cur.into()) } } + pub struct StructH { pub cursor: Cursor, } @@ -765,6 +832,7 @@ impl From for StructH { StructH { cursor } } } + impl StructH { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 3)?; @@ -792,6 +860,7 @@ impl StructH { Ok(cur) } } + pub struct StructI { pub cursor: Cursor, } @@ -800,6 +869,7 @@ impl From for StructI { StructI { cursor } } } + impl StructI { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 3)?; @@ -813,6 +883,7 @@ impl StructI { cur.try_into() } } + pub struct StructJ { pub cursor: Cursor, } @@ -821,6 +892,7 @@ impl From for StructJ { StructJ { cursor } } } + impl StructJ { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 6)?; @@ -834,6 +906,7 @@ impl StructJ { cur.try_into() } } + pub struct StructIx3 { pub cursor: Cursor, } @@ -847,12 +920,14 @@ impl StructIx3 { 3 } } + impl StructIx3 { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.slice_by_offset(4 * index, 4)?; Ok(cur.into()) } } + pub struct StructO { pub cursor: Cursor, } @@ -861,6 +936,7 @@ impl From for StructO { StructO { cursor } } } + impl StructO { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 12)?; @@ -874,6 +950,7 @@ impl StructO { cur.try_into() } } + pub struct StructP { pub cursor: Cursor, } @@ -882,6 +959,7 @@ impl From for StructP { StructP { cursor } } } + impl StructP { pub fn f1(&self) -> Result { let cur = self.cursor.slice_by_offset(0, 7)?; @@ -895,6 +973,7 @@ impl StructP { cur.try_into() } } + pub struct Bytes { pub cursor: Cursor, } @@ -908,12 +987,14 @@ impl Bytes { self.cursor.fixvec_length() } } + impl Bytes { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(1, index)?; cur.try_into() } } + pub struct Words { pub cursor: Cursor, } @@ -927,12 +1008,14 @@ impl Words { self.cursor.fixvec_length() } } + impl Words { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(2, index)?; Ok(cur) } } + pub struct Byte3Vec { pub cursor: Cursor, } @@ -946,12 +1029,14 @@ impl Byte3Vec { self.cursor.fixvec_length() } } + impl Byte3Vec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(3, index)?; Ok(cur) } } + pub struct Byte7Vec { pub cursor: Cursor, } @@ -965,12 +1050,14 @@ impl Byte7Vec { self.cursor.fixvec_length() } } + impl Byte7Vec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(7, index)?; Ok(cur) } } + pub struct StructIVec { pub cursor: Cursor, } @@ -984,12 +1071,14 @@ impl StructIVec { self.cursor.fixvec_length() } } + impl StructIVec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(4, index)?; Ok(cur.into()) } } + pub struct StructJVec { pub cursor: Cursor, } @@ -1003,12 +1092,14 @@ impl StructJVec { self.cursor.fixvec_length() } } + impl StructJVec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(7, index)?; Ok(cur.into()) } } + pub struct StructPVec { pub cursor: Cursor, } @@ -1022,12 +1113,14 @@ impl StructPVec { self.cursor.fixvec_length() } } + impl StructPVec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.fixvec_slice_by_index(8, index)?; Ok(cur.into()) } } + pub struct BytesVec { pub cursor: Cursor, } @@ -1041,12 +1134,14 @@ impl BytesVec { self.cursor.dynvec_length() } } + impl BytesVec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.dynvec_slice_by_index(index)?; cur.convert_to_rawbytes() } } + pub struct WordsVec { pub cursor: Cursor, } @@ -1060,12 +1155,14 @@ impl WordsVec { self.cursor.dynvec_length() } } + impl WordsVec { pub fn get(&self, index: usize) -> Result { let cur = self.cursor.dynvec_slice_by_index(index)?; Ok(cur.into()) } } + pub struct Table0 { pub cursor: Cursor, } @@ -1082,12 +1179,14 @@ impl From for Table1 { Table1 { cursor } } } + impl Table1 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; cur.try_into() } } + pub struct Table2 { pub cursor: Cursor, } @@ -1096,6 +1195,7 @@ impl From for Table2 { Table2 { cursor } } } + impl Table2 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1109,6 +1209,7 @@ impl Table2 { Ok(cur.into()) } } + pub struct Table3 { pub cursor: Cursor, } @@ -1117,6 +1218,7 @@ impl From for Table3 { Table3 { cursor } } } + impl Table3 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1137,6 +1239,7 @@ impl Table3 { Ok(cur.into()) } } + pub struct Table4 { pub cursor: Cursor, } @@ -1145,6 +1248,7 @@ impl From for Table4 { Table4 { cursor } } } + impl Table4 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1172,6 +1276,7 @@ impl Table4 { cur.convert_to_rawbytes() } } + pub struct Table5 { pub cursor: Cursor, } @@ -1180,6 +1285,7 @@ impl From for Table5 { Table5 { cursor } } } + impl Table5 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1214,6 +1320,7 @@ impl Table5 { Ok(cur.into()) } } + pub struct Table6 { pub cursor: Cursor, } @@ -1222,6 +1329,7 @@ impl From for Table6 { Table6 { cursor } } } + impl Table6 { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1263,6 +1371,7 @@ impl Table6 { Ok(cur.into()) } } + pub struct ByteOpt { pub cursor: Cursor, } @@ -1364,6 +1473,7 @@ impl ByteOptVec { self.cursor.dynvec_length() } } + impl ByteOptVec { pub fn get(&self, index: usize) -> Result, Error> { let cur = self.cursor.dynvec_slice_by_index(index)?; @@ -1374,6 +1484,7 @@ impl ByteOptVec { } } } + pub struct WordOptVec { pub cursor: Cursor, } @@ -1387,6 +1498,7 @@ impl WordOptVec { self.cursor.dynvec_length() } } + impl WordOptVec { pub fn get(&self, index: usize) -> Result, Error> { let cur = self.cursor.dynvec_slice_by_index(index)?; @@ -1397,6 +1509,7 @@ impl WordOptVec { } } } + pub struct WordsOptVec { pub cursor: Cursor, } @@ -1410,6 +1523,7 @@ impl WordsOptVec { self.cursor.dynvec_length() } } + impl WordsOptVec { pub fn get(&self, index: usize) -> Result, Error> { let cur = self.cursor.dynvec_slice_by_index(index)?; @@ -1420,6 +1534,7 @@ impl WordsOptVec { } } } + pub struct BytesOptVec { pub cursor: Cursor, } @@ -1433,6 +1548,7 @@ impl BytesOptVec { self.cursor.dynvec_length() } } + impl BytesOptVec { pub fn get(&self, index: usize) -> Result, Error> { let cur = self.cursor.dynvec_slice_by_index(index)?; @@ -1444,6 +1560,7 @@ impl BytesOptVec { } } } + pub struct UnionA { pub cursor: Cursor, } @@ -1610,6 +1727,7 @@ impl From for TableA { TableA { cursor } } } + impl TableA { pub fn f1(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; @@ -1670,6 +1788,7 @@ impl TableA { cur.try_into() } } + pub struct AllInOne { pub cursor: Cursor, } @@ -1678,6 +1797,7 @@ impl From for AllInOne { AllInOne { cursor } } } + impl AllInOne { pub fn f0(&self) -> Result { let cur = self.cursor.table_slice_by_index(0)?; diff --git a/examples/lazy-reader-tests/src/types_api2_mol2.rs b/examples/lazy-reader-tests/src/types_api2_mol2.rs new file mode 100644 index 0000000..a46f673 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_api2_mol2.rs @@ -0,0 +1,795 @@ +use super::TypesCheckErr; +use crate::types_api; +use crate::types_api2::*; + +pub trait Mol2Vec { + type RetType; + fn mol_len(&self) -> Result; + fn mol_get(&self, index: usize) -> Result; +} +impl Mol2Vec for Vec { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self[index]) + } +} +impl Mol2Vec for Byte2 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte3 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte4 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte5 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte6 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte7 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte8 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte9 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte10 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte11 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte12 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte13 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte14 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte15 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Byte16 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Word { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for StructIx3 { + type RetType = StructI; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Bytes { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for StructIVec { + type RetType = StructI; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for StructJVec { + type RetType = StructJ; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for StructPVec { + type RetType = StructP; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?) + } +} +impl Mol2Vec for Word2 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word3 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word4 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word5 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word6 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word7 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Word8 { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte3x3 { + type RetType = Byte3; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte5x3 { + type RetType = Byte5; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte7x3 { + type RetType = Byte7; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte9x3 { + type RetType = Byte9; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Words { + type RetType = Word; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte3Vec { + type RetType = Byte3; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for Byte7Vec { + type RetType = Byte7; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} +impl Mol2Vec for BytesVec { + type RetType = Vec; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index)?.try_into()?) + } +} +impl Mol2Vec for WordsVec { + type RetType = Words; + fn mol_len(&self) -> Result { + Ok(self.len()?) + } + fn mol_get(&self, index: usize) -> Result { + Ok(Self::RetType::from(self.get(index)?)) + } +} + +impl Mol2Vec for types_api::Byte2 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte3 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte4 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte5 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte6 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte7 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte8 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte9 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte10 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte11 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte12 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte13 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte14 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte15 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Byte16 { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Word { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.raw_data().len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.raw_data().get(index).unwrap().clone()) + } +} +impl Mol2Vec for types_api::Word2 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(2) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word3 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word4 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(4) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + 3 => self.nth3(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word5 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(5) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + 3 => self.nth3(), + 4 => self.nth4(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word6 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(6) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + 3 => self.nth3(), + 4 => self.nth4(), + 5 => self.nth5(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word7 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(7) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + 3 => self.nth3(), + 4 => self.nth4(), + 5 => self.nth5(), + 6 => self.nth6(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Word8 { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(8) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + 3 => self.nth3(), + 4 => self.nth4(), + 5 => self.nth5(), + 6 => self.nth6(), + 7 => self.nth7(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Byte3x3 { + type RetType = types_api::Byte3; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Byte5x3 { + type RetType = types_api::Byte5; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Byte7x3 { + type RetType = types_api::Byte7; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Byte9x3 { + type RetType = types_api::Byte9; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::StructIx3 { + type RetType = types_api::StructI; + fn mol_len(&self) -> Result { + Ok(3) + } + fn mol_get(&self, index: usize) -> Result { + Ok(match index { + 0 => self.nth0(), + 1 => self.nth1(), + 2 => self.nth2(), + _ => panic!("out of bound"), + }) + } +} +impl Mol2Vec for types_api::Bytes { + type RetType = u8; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap().into()) + } +} +impl Mol2Vec for types_api::Words { + type RetType = types_api::Word; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::Byte3Vec { + type RetType = types_api::Byte3; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::Byte7Vec { + type RetType = types_api::Byte7; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::StructIVec { + type RetType = types_api::StructI; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::StructJVec { + type RetType = types_api::StructJ; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::StructPVec { + type RetType = types_api::StructP; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::BytesVec { + type RetType = types_api::Bytes; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::WordsVec { + type RetType = types_api::Words; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::ByteOptVec { + type RetType = types_api::ByteOpt; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::WordOptVec { + type RetType = types_api::WordOpt; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::WordsOptVec { + type RetType = types_api::WordsOpt; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} +impl Mol2Vec for types_api::BytesOptVec { + type RetType = types_api::BytesOpt; + fn mol_len(&self) -> Result { + Ok(self.len()) + } + fn mol_get(&self, index: usize) -> Result { + Ok(self.get(index).unwrap()) + } +} diff --git a/examples/lazy-reader-tests/src/types_array.rs b/examples/lazy-reader-tests/src/types_array.rs new file mode 100644 index 0000000..000ec39 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_array.rs @@ -0,0 +1,367 @@ +use super::{BaseTypes, ResCheckErr, TypesCheckErr, TypesConfig}; +use crate::{types_api, types_api2}; +use molecule::prelude::{Builder, Byte, Entity}; +use rand::{rngs::ThreadRng, thread_rng}; + +#[derive(Clone, Copy)] +pub struct TypesArray { + pub d: [T; N], +} + +impl BaseTypes for TypesArray { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + let mut buf = [T::new_rng(rng, config); N]; + + for i in 0..N { + buf[i] = T::new_rng(rng, config); + } + + Self { d: buf } + } +} +impl TypesArray { + pub fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + let mut d = Vec::new(); + for _ in 0..N { + d.push(T::new_rng(rng, config)); + } + + Self { + d: d.try_into().ok().unwrap(), + } + } +} + +impl Default for TypesArray { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} + +impl TypesArray { + pub fn to_mol(&self) -> Byte { + self.d[0].into() + } + + pub fn check(&self, d: &u8) -> ResCheckErr { + TypesCheckErr::check_1_data(d, &self.d[0]) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte2 { + types_api::Byte2::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn to_mol2(&self) -> types_api::Word { + types_api::Word::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte2) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } + pub fn check2(&self, d: &types_api2::Word) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte3 { + types_api::Byte3::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte3) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte4 { + types_api::Byte4::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte4) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte5 { + types_api::Byte5::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte5) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte6 { + types_api::Byte6::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte6) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte7 { + types_api::Byte7::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte7) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte8 { + types_api::Byte8::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte8) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte9 { + types_api::Byte9::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte9) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte10 { + types_api::Byte10::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte10) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte11 { + types_api::Byte11::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte11) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte12 { + types_api::Byte12::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte12) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte13 { + types_api::Byte13::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte13) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte14 { + types_api::Byte14::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte14) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte15 { + types_api::Byte15::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte15) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Byte16 { + types_api::Byte16::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + pub fn check(&self, d: &types_api2::Byte16) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +pub type TypesArrayWord = TypesArray; +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word2 { + types_api::Word2::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word2) -> ResCheckErr { + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word3 { + types_api::Word3::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word4 { + types_api::Word4::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word4) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word5 { + types_api::Word5::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word5) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word6 { + types_api::Word6::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word6) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word7 { + types_api::Word7::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word7) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray { + pub fn to_mol(&self) -> types_api::Word8 { + types_api::Word8::new_builder() + .set(self.d.clone().map(|f| f.to_mol2())) + .build() + } + pub fn check(&self, d: &types_api2::Word8) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray, 3> { + pub fn to_mol(&self) -> types_api::Byte3x3 { + types_api::Byte3x3::new_builder() + .set(self.d.clone().map(|f| f.to_mol())) + .build() + } + pub fn check(&self, d: &types_api2::Byte3x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray, 3> { + pub fn to_mol(&self) -> types_api::Byte5x3 { + types_api::Byte5x3::new_builder() + .set(self.d.clone().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &types_api2::Byte5x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray, 3> { + pub fn to_mol(&self) -> types_api::Byte7x3 { + types_api::Byte7x3::new_builder() + .set(self.d.clone().map(|f| f.to_mol())) + .build() + } + pub fn check(&self, d: &types_api2::Byte7x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesArray, 3> { + pub fn to_mol(&self) -> types_api::Byte9x3 { + types_api::Byte9x3::new_builder() + .set(self.d.clone().map(|f| f.to_mol())) + .build() + } + pub fn check(&self, d: &types_api2::Byte9x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} diff --git a/examples/lazy-reader-tests/src/types_moleculec_check.rs b/examples/lazy-reader-tests/src/types_moleculec_check.rs new file mode 100644 index 0000000..6849a72 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_moleculec_check.rs @@ -0,0 +1,680 @@ +use crate::{types_api, types_api2, Mol2Vec, ResCheckErr, TypesCheckErr}; +use molecule::prelude::Byte; + +pub fn check_mol(d1: &types_api::AllInOne, d2: &types_api2::AllInOne) -> ResCheckErr { + f0(&d1.f0(), &d2.f0()?.into())?; + f1(&d1.f1(), &d2.f1()?.into())?; + f2(&d1.f2(), &d2.f2()?.into())?; + f3(&d1.f3(), &d2.f3()?.into())?; + f4(&d1.f4(), &d2.f4()?.into())?; + f5(&d1.f5(), &d2.f5()?.into())?; + f6(&d1.f6(), &d2.f6()?.into())?; + f7(&d1.f7(), &d2.f7()?.into())?; + f8(&d1.f8(), &d2.f8()?.into())?; + f9(&d1.f9(), &d2.f9()?.into())?; + f10(&d1.f10(), &d2.f10()?.into())?; + f11(&d1.f11(), &d2.f11()?.into())?; + f12(&d1.f12(), &d2.f12()?.into())?; + f13(&d1.f13(), &d2.f13()?.into())?; + f14(&d1.f14(), &d2.f14()?.into())?; + f15(&d1.f15(), &d2.f15()?.into())?; + + f16(&d1.f16(), &d2.f16()?.into())?; + f17(&d1.f17(), &d2.f17()?.into())?; + f18(&d1.f18(), &d2.f18()?.into())?; + f19(&d1.f19(), &d2.f19()?.into())?; + f20(&d1.f20(), &d2.f20()?.into())?; + f21(&d1.f21(), &d2.f21()?.into())?; + f22(&d1.f22(), &d2.f22()?.into())?; + f23(&d1.f23(), &d2.f23()?.into())?; + + f24(&d1.f24(), &d2.f24()?.into())?; + f25(&d1.f25(), &d2.f25()?.into())?; + f26(&d1.f26(), &d2.f26()?.into())?; + f27(&d1.f27(), &d2.f27()?.into())?; + + f28(&d1.f28(), &d2.f28()?.into())?; + f29(&d1.f29(), &d2.f29()?.into())?; + f30(&d1.f30(), &d2.f30()?.into())?; + f31(&d1.f31(), &d2.f31()?.into())?; + f32(&d1.f32(), &d2.f32()?.into())?; + f33(&d1.f33(), &d2.f33()?.into())?; + f34(&d1.f34(), &d2.f34()?.into())?; + f35(&d1.f35(), &d2.f35()?.into())?; + f36(&d1.f36(), &d2.f36()?.into())?; + f37(&d1.f37(), &d2.f37()?.into())?; + f38(&d1.f38(), &d2.f38()?.into())?; + f39(&d1.f39(), &d2.f39()?.into())?; + f40(&d1.f40(), &d2.f40()?.into())?; + + f41(&d1.f41(), &d2.f41()?.try_into().unwrap())?; + f42(&d1.f42(), &d2.f42()?.into())?; + f43(&d1.f43(), &d2.f43()?.into())?; + f44(&d1.f44(), &d2.f44()?.into())?; + f45(&d1.f45(), &d2.f45()?.into())?; + f46(&d1.f46(), &d2.f46()?.into())?; + f47(&d1.f47(), &d2.f47()?.into())?; + f48(&d1.f48(), &d2.f48()?.into())?; + f49(&d1.f49(), &d2.f49()?.into())?; + + f50(&d1.f50(), &d2.f50()?.into())?; + f51(&d1.f51(), &d2.f51()?.into())?; + f52(&d1.f52(), &d2.f52()?.into())?; + f53(&d1.f53(), &d2.f53()?.into())?; + f54(&d1.f54(), &d2.f54()?.into())?; + f55(&d1.f55(), &d2.f55()?.into())?; + f56(&d1.f56(), &d2.f56()?.into())?; + + f57(&d1.f57().to_opt(), &d2.f57()?)?; + f58(&d1.f58().to_opt(), &d2.f58()?.map(|f| f.into()))?; + f59(&d1.f59().to_opt(), &d2.f59()?)?; + f60(&d1.f60().to_opt(), &d2.f60()?)?; + f61( + &d1.f61().to_opt(), + &d2.f61()?.map(|f| f.try_into().unwrap()), + )?; + f62(&d1.f62().to_opt(), &d2.f62()?)?; + f63(&d1.f63().to_opt(), &d2.f63()?)?; + f64(&d1.f64().to_opt(), &d2.f64()?)?; + f65(&d1.f65().to_opt(), &d2.f65()?)?; + f66(&d1.f66().to_opt(), &d2.f66()?)?; + f67(&d1.f67().to_opt().map(|f| f.to_opt()), &d2.f67()?)?; + + f68(&d1.f68(), &d2.f68()?)?; + f69(&d1.f69(), &d2.f69()?)?; + f70(&d1.f70(), &d2.f70()?)?; + f71(&d1.f71(), &d2.f71()?)?; + + f72(&d1.f72(), &d2.f72()?)?; + f73(&d1.f73(), &d2.f73()?)?; + + Ok(()) +} + +fn f0(d1: &Byte, d2: &Byte) -> ResCheckErr { + TypesCheckErr::check_1_data(d1, d2) +} +fn f1(d1: &types_api::Byte2, d2: &types_api2::Byte2) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f2(d1: &types_api::Byte3, d2: &types_api2::Byte3) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f3(d1: &types_api::Byte4, d2: &types_api2::Byte4) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f4(d1: &types_api::Byte5, d2: &types_api2::Byte5) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f5(d1: &types_api::Byte6, d2: &types_api2::Byte6) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f6(d1: &types_api::Byte7, d2: &types_api2::Byte7) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f7(d1: &types_api::Byte8, d2: &types_api2::Byte8) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f8(d1: &types_api::Byte9, d2: &types_api2::Byte9) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f9(d1: &types_api::Byte10, d2: &types_api2::Byte10) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f10(d1: &types_api::Byte11, d2: &types_api2::Byte11) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f11(d1: &types_api::Byte12, d2: &types_api2::Byte12) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f12(d1: &types_api::Byte13, d2: &types_api2::Byte13) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f13(d1: &types_api::Byte14, d2: &types_api2::Byte14) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f14(d1: &types_api::Byte15, d2: &types_api2::Byte15) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f15(d1: &types_api::Byte16, d2: &types_api2::Byte16) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f16(d1: &types_api::Word, d2: &types_api2::Word) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f17(d1: &types_api::Word2, d2: &types_api2::Word2) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f18(d1: &types_api::Word3, d2: &types_api2::Word3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f19(d1: &types_api::Word4, d2: &types_api2::Word4) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f20(d1: &types_api::Word5, d2: &types_api2::Word5) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f21(d1: &types_api::Word6, d2: &types_api2::Word6) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f22(d1: &types_api::Word7, d2: &types_api2::Word7) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f23(d1: &types_api::Word8, d2: &types_api2::Word8) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f24(d1: &types_api::Byte3x3, d2: &types_api2::Byte3x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f25(d1: &types_api::Byte5x3, d2: &types_api2::Byte5x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f26(d1: &types_api::Byte7x3, d2: &types_api2::Byte7x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f27(d1: &types_api::Byte9x3, d2: &types_api2::Byte9x3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f28(d1: &types_api::StructA, d2: &types_api2::StructA) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f1(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f29(d1: &types_api::StructB, d2: &types_api2::StructB) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f2(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f30(d1: &types_api::StructC, d2: &types_api2::StructC) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f3(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f31(d1: &types_api::StructD, d2: &types_api2::StructD) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f4(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f32(d1: &types_api::StructE, d2: &types_api2::StructE) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f1(&d1.f2(), &d2.f2()?.into())?; + f0(&d1.f3(), &d2.f3()?.into())?; + f1(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f33(d1: &types_api::StructF, d2: &types_api2::StructF) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f2(&d1.f2(), &d2.f2()?.into())?; + f0(&d1.f3(), &d2.f3()?.into())?; + + Ok(()) +} +fn f34(d1: &types_api::StructG, d2: &types_api2::StructG) -> ResCheckErr { + f2(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f17(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f35(d1: &types_api::StructH, d2: &types_api2::StructH) -> ResCheckErr { + f2(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + f1(&d1.f3(), &d2.f3()?.into())?; + f3(&d1.f4(), &d2.f4()?.into())?; + + Ok(()) +} +fn f36(d1: &types_api::StructI, d2: &types_api2::StructI) -> ResCheckErr { + f2(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + + Ok(()) +} +fn f37(d1: &types_api::StructJ, d2: &types_api2::StructJ) -> ResCheckErr { + f5(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + + Ok(()) +} +fn f38(d1: &types_api::StructIx3, d2: &types_api2::StructIx3) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; + for i in 0..d1.mol_len()? { + f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + + Ok(()) +} +fn f39(d1: &types_api::StructO, d2: &types_api2::StructO) -> ResCheckErr { + f38(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + + Ok(()) +} +fn f40(d1: &types_api::StructP, d2: &types_api2::StructP) -> ResCheckErr { + f37(&d1.f1(), &d2.f1()?.into())?; + f0(&d1.f2(), &d2.f2()?.into())?; + + Ok(()) +} +fn f41(d1: &types_api::Bytes, d2: &Vec) -> ResCheckErr { + TypesCheckErr::check_mol_data(d1, d2) +} +fn f42(d1: &types_api::Words, d2: &types_api2::Words) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f43(d1: &types_api::Byte3Vec, d2: &types_api2::Byte3Vec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f44(d1: &types_api::Byte7Vec, d2: &types_api2::Byte7Vec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f45(d1: &types_api::StructIVec, d2: &types_api2::StructIVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f46(d1: &types_api::StructJVec, d2: &types_api2::StructJVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + f37(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f47(d1: &types_api::StructPVec, d2: &types_api2::StructPVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + f40(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f48(d1: &types_api::BytesVec, d2: &types_api2::BytesVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + f41(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f49(d1: &types_api::WordsVec, d2: &types_api2::WordsVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + f42(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + } + Ok(()) +} +fn f50(_d1: &types_api::Table0, _d2: &types_api2::Table0) -> ResCheckErr { + Ok(()) +} +fn f51(d1: &types_api::Table1, d2: &types_api2::Table1) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + Ok(()) +} +fn f52(d1: &types_api::Table2, d2: &types_api2::Table2) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f17(&d1.f2(), &d2.f2()?.into())?; + Ok(()) +} +fn f53(d1: &types_api::Table3, d2: &types_api2::Table3) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f17(&d1.f2(), &d2.f2()?.into())?; + f28(&d1.f3(), &d2.f3()?.into())?; + Ok(()) +} +fn f54(d1: &types_api::Table4, d2: &types_api2::Table4) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f17(&d1.f2(), &d2.f2()?.into())?; + f28(&d1.f3(), &d2.f3()?.into())?; + f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; + Ok(()) +} +fn f55(d1: &types_api::Table5, d2: &types_api2::Table5) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f17(&d1.f2(), &d2.f2()?.into())?; + f28(&d1.f3(), &d2.f3()?.into())?; + f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; + f48(&d1.f5(), &d2.f5()?.into())?; + Ok(()) +} +fn f56(d1: &types_api::Table6, d2: &types_api2::Table6) -> ResCheckErr { + f0(&d1.f1(), &d2.f1()?.into())?; + f17(&d1.f2(), &d2.f2()?.into())?; + f28(&d1.f3(), &d2.f3()?.into())?; + f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; + f48(&d1.f5(), &d2.f5()?.into())?; + f55(&d1.f6(), &d2.f6()?.into())?; + Ok(()) +} +fn f57(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + TypesCheckErr::check_1_data(d1.as_ref().unwrap(), &d2.as_ref().unwrap().clone().into())?; + + Ok(()) +} +fn f58(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f16(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f59(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f28(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f60(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f40(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f61(d1: &Option, d2: &Option>) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f41(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f62(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f42(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f63(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f48(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f64(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f49(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f65(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f50(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f66(d1: &Option, d2: &Option) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f56(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f67( + d1: &Option>, + d2: &Option>, +) -> ResCheckErr { + if d1.is_some() != d2.is_some() { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + d1.is_some(), + d2.is_some() + ))); + } + if d1.is_none() { + return Ok(()); + } + + f66(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + + Ok(()) +} +fn f68(d1: &types_api::ByteOptVec, d2: &types_api2::ByteOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + let dd1 = d1.mol_get(i)?.to_opt(); + let dd2 = d2.get(i)?; + f57(&dd1, &dd2)?; + } + Ok(()) +} +fn f69(d1: &types_api::WordOptVec, d2: &types_api2::WordOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + let dd1 = d1.mol_get(i)?.to_opt(); + let dd2 = d2.get(i)?.map(|f| f.into()); + f58(&dd1, &dd2)?; + } + Ok(()) +} +fn f70(d1: &types_api::WordsOptVec, d2: &types_api2::WordsOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + let dd1 = d1.mol_get(i)?.to_opt(); + let dd2 = d2.get(i)?.map(|f| f.into()); + f62(&dd1, &dd2)?; + } + Ok(()) +} +fn f71(d1: &types_api::BytesOptVec, d2: &types_api2::BytesOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; + for i in 0..d1.mol_len()? { + let dd1 = d1.mol_get(i)?.to_opt(); + let dd2 = d2.get(i)?.map(|f| f.try_into().unwrap()); + f61(&dd1, &dd2)?; + } + Ok(()) +} +fn f72(d1: &types_api::UnionA, d2: &types_api2::UnionA) -> ResCheckErr { + match d1.to_enum() { + types_api::UnionAUnion::Byte(v) => { + let v2 = d2.as_byte()?; + TypesCheckErr::check_1_data(&v, &v2.into())?; + } + types_api::UnionAUnion::Word(v) => { + let v2 = d2.as_word()?; + f16(&v, &v2.into())?; + } + types_api::UnionAUnion::StructA(v) => { + let v2 = d2.as_structa()?; + f28(&v, &v2)?; + } + types_api::UnionAUnion::Bytes(v) => { + let v2 = d2.as_bytes()?; + f41(&v, &v2.try_into().unwrap())?; + } + types_api::UnionAUnion::Words(v) => { + let v2 = d2.as_words()?; + f42(&v, &v2)?; + } + types_api::UnionAUnion::Table0(v) => { + let v2 = d2.as_table0()?; + f50(&v, &v2)?; + } + types_api::UnionAUnion::Table6(v) => { + let v2 = d2.as_table6()?; + f56(&v, &v2)?; + } + types_api::UnionAUnion::Table6Opt(v) => { + let v2 = d2.as_table6opt()?; + f66(&v.to_opt(), &v2)?; + } + }; + + Ok(()) +} +fn f73(d1: &types_api::TableA, d2: &types_api2::TableA) -> ResCheckErr { + f17(&d1.f1(), &d2.f1()?.into())?; + f28(&d1.f2(), &d2.f2()?.into())?; + f41(&d1.f3(), &d2.f3()?.try_into().unwrap())?; + f48(&d1.f4(), &d2.f4()?)?; + f51(&d1.f5(), &d2.f5()?)?; + f61(&d1.f6().to_opt(), &d2.f6()?.map(|f| f.try_into().unwrap()))?; + f72(&d1.f7(), &d2.f7()?)?; + Ok(()) +} diff --git a/examples/lazy-reader-tests/src/types_option.rs b/examples/lazy-reader-tests/src/types_option.rs new file mode 100644 index 0000000..0e13491 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_option.rs @@ -0,0 +1,217 @@ +use super::{ + BaseTypes, ResCheckErr, TypesArrayWord, TypesCheckErr, TypesConfig, TypesStructA, TypesStructP, + TypesTable0, TypesTable6, TypesVec, +}; +use crate::{types_api, types_api2}; +use molecule::lazy_reader::Cursor; +use molecule::prelude::{Builder, Entity}; +use rand::{rngs::ThreadRng, thread_rng, Rng}; + +pub struct TypesOption { + d: Option, +} +impl BaseTypes for TypesOption { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + let fill = match config.option_fill { + super::OptionFillType::FillRand => rng.gen(), + super::OptionFillType::FillSome => true, + super::OptionFillType::FillNone => false, + }; + if fill { + Self { + d: Some(T::new_rng(rng, config)), + } + } else { + Self { d: None } + } + } +} +impl Default for TypesOption { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} + +impl TypesOption { + pub fn to_mol(&self) -> types_api::ByteOpt { + types_api::ByteOpt::new_builder() + .set(self.d.map(|f| f.into())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + TypesCheckErr::check_1_data(d.as_ref().unwrap(), self.d.as_ref().unwrap()) + } +} +impl TypesOption { + pub fn to_mol(&self) -> types_api::WordOpt { + types_api::WordOpt::new_builder() + .set(self.d.map(|f| f.to_mol2())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d + .as_ref() + .unwrap() + .check2(&d.as_ref().unwrap().clone().into()) + } +} +impl TypesOption { + pub fn to_mol(&self) -> types_api::StructAOpt { + types_api::StructAOpt::new_builder() + .set(self.d.map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption { + pub fn to_mol(&self) -> types_api::StructPOpt { + types_api::StructPOpt::new_builder() + .set(self.d.map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption> { + pub fn to_mol(&self) -> types_api::BytesOpt { + types_api::BytesOpt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d + .as_ref() + .unwrap() + .check(&d.as_ref().unwrap().clone().try_into().unwrap()) + } +} +impl TypesOption> { + pub fn to_mol(&self) -> types_api::WordsOpt { + types_api::WordsOpt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(&d.as_ref().unwrap()) + } +} +impl TypesOption>> { + pub fn to_mol(&self) -> types_api::BytesVecOpt { + types_api::BytesVecOpt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption>> { + pub fn to_mol(&self) -> types_api::WordsVecOpt { + types_api::WordsVecOpt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption { + pub fn to_mol(&self) -> types_api::Table0Opt { + types_api::Table0Opt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption { + pub fn to_mol(&self) -> types_api::Table6Opt { + types_api::Table6Opt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option) -> ResCheckErr { + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} +impl TypesOption> { + pub fn to_mol(&self) -> types_api::Table6OptOpt { + types_api::Table6OptOpt::new_builder() + .set(self.d.as_ref().map(|f| f.to_mol())) + .build() + } + + pub fn check(&self, d: &Option>) -> ResCheckErr { + let f1_flag = d.is_some() && d.as_ref().is_none(); + let f2_flag = self.d.is_some() && self.d.as_ref().is_none(); + if f1_flag != f2_flag { + return Err(TypesCheckErr::Opt(format!( + "different option: {:?} {:?}", + f1_flag, f2_flag + ))); + } + if !f1_flag { + return Ok(()); + } + + TypesCheckErr::check_option(d, &self.d)?; + if d.is_none() { + return Ok(()); + } + self.d.as_ref().unwrap().check(d.as_ref().unwrap()) + } +} diff --git a/examples/lazy-reader-tests/src/types_struct.rs b/examples/lazy-reader-tests/src/types_struct.rs new file mode 100644 index 0000000..5c02eef --- /dev/null +++ b/examples/lazy-reader-tests/src/types_struct.rs @@ -0,0 +1,282 @@ +use super::*; +use crate::{types_api, types_api2}; +use molecule::prelude::{Builder, Entity}; +use rand::rngs::ThreadRng; + +#[derive(Clone, Copy)] +pub struct TypesStructBytes { + pub f1: T1, + pub f2: T2, + pub f3: T3, + pub f4: T4, +} + +impl BaseTypes + for TypesStructBytes +{ + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: T1::new_rng(rng, config), + f2: T2::new_rng(rng, config), + f3: T3::new_rng(rng, config), + f4: T4::new_rng(rng, config), + } + } +} + +impl Default + for TypesStructBytes +{ + fn default() -> Self { + let mut rng = rand::thread_rng(); + let config = TypesConfig::default(); + Self { + f1: T1::new_rng(&mut rng, &config), + f2: T2::new_rng(&mut rng, &config), + f3: T3::new_rng(&mut rng, &config), + f4: T4::new_rng(&mut rng, &config), + } + } +} + +pub type TypesStructA = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructA { + pub fn to_mol(&self) -> types_api::StructA { + types_api::StructA::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructA) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} +pub type TypesStructB = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructB { + pub fn to_mol(&self) -> types_api::StructB { + types_api::StructB::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructB) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructC = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructC { + pub fn to_mol(&self) -> types_api::StructC { + types_api::StructC::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructC) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructD = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructD { + pub fn to_mol(&self) -> types_api::StructD { + types_api::StructD::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructD) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructE = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructE { + pub fn to_mol(&self) -> types_api::StructE { + types_api::StructE::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructE) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructF = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructF { + pub fn to_mol(&self) -> types_api::StructF { + types_api::StructF::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructF) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + Ok(()) + } +} + +pub type TypesStructG = TypesStructBytes< + TypesArray, + TypesArray, + TypesArray, + TypesArray, +>; +impl TypesStructG { + pub fn to_mol(&self) -> types_api::StructG { + types_api::StructG::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructG) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructH = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructH { + pub fn to_mol(&self) -> types_api::StructH { + types_api::StructH::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructH) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + self.f3.check(&d.f3()?.into())?; + self.f4.check(&d.f4()?.into())?; + Ok(()) + } +} + +pub type TypesStructI = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructI { + pub fn to_mol(&self) -> types_api::StructI { + types_api::StructI::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructI) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + Ok(()) + } +} + +pub type TypesStructJ = + TypesStructBytes, TypesArray, TypesArray, TypesArray>; +impl TypesStructJ { + pub fn to_mol(&self) -> types_api::StructJ { + types_api::StructJ::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructJ) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + Ok(()) + } +} + +pub type TypesStructIx3 = TypesArray; +impl TypesStructIx3 { + pub fn to_mol(&self) -> types_api::StructIx3 { + types_api::StructIx3::new_builder() + .set(self.d.clone().map(|f| f.to_mol())) + .build() + } + pub fn check(&self, d: &types_api2::StructIx3) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len(), self.d.len())?; + for i in 0..d.len() { + let dd = d.get(i)?; + self.d[i].check(&dd)?; + } + Ok(()) + } +} + +pub type TypesStructO = + TypesStructBytes, TypesArray, TypesArray>; +impl TypesStructO { + pub fn to_mol(&self) -> types_api::StructO { + types_api::StructO::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructO) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + Ok(()) + } +} + +pub type TypesStructP = + TypesStructBytes, TypesArray, TypesArray>; +impl TypesStructP { + pub fn to_mol(&self) -> types_api::StructP { + types_api::StructP::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::StructP) -> ResCheckErr { + self.f1.check(&d.f1()?.into())?; + self.f2.check(&d.f2()?.into())?; + Ok(()) + } +} diff --git a/examples/lazy-reader-tests/src/types_table.rs b/examples/lazy-reader-tests/src/types_table.rs new file mode 100644 index 0000000..619cc8a --- /dev/null +++ b/examples/lazy-reader-tests/src/types_table.rs @@ -0,0 +1,302 @@ +use super::{ + BaseTypes, ResCheckErr, TypesArray, TypesArrayWord, TypesConfig, TypesOption, TypesStructA, + TypesUnionA, TypesVec, +}; +use crate::{types_api, types_api2}; +use molecule::prelude::{Builder, Entity}; +use rand::{rngs::ThreadRng, thread_rng}; + +pub struct TypesTable0 {} +impl BaseTypes for TypesTable0 { + fn new_rng(_rng: &mut ThreadRng, _config: &TypesConfig) -> Self { + Self {} + } +} +impl Default for TypesTable0 { + fn default() -> Self { + Self {} + } +} +impl TypesTable0 { + pub fn to_mol(&self) -> types_api::Table0 { + types_api::Table0::new_builder().build() + } + pub fn check(&self, _d: &types_api2::Table0) -> ResCheckErr { + // TODO + Ok(()) + } +} + +pub struct TypesTable1 { + f1: TypesArray, +} +impl BaseTypes for TypesTable1 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + } + } +} +impl Default for TypesTable1 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable1 { + pub fn to_mol(&self) -> types_api::Table1 { + types_api::Table1::new_builder() + .f1(self.f1.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table1) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + Ok(()) + } +} + +pub struct TypesTable2 { + f1: TypesArray, + f2: TypesArray, +} +impl BaseTypes for TypesTable2 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesArray::new_rng(rng, config), + } + } +} +impl Default for TypesTable2 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable2 { + pub fn to_mol(&self) -> types_api::Table2 { + types_api::Table2::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table2) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + Ok(()) + } +} + +pub struct TypesTable3 { + f1: TypesArray, + f2: TypesArray, + f3: TypesStructA, +} +impl BaseTypes for TypesTable3 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesArray::new_rng(rng, config), + f3: TypesStructA::new_rng(rng, config), + } + } +} +impl Default for TypesTable3 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable3 { + pub fn to_mol(&self) -> types_api::Table3 { + types_api::Table3::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table3) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + self.f3.check(&d.f3()?)?; + Ok(()) + } +} + +pub struct TypesTable4 { + f1: TypesArray, + f2: TypesArray, + f3: TypesStructA, + f4: TypesVec, +} +impl BaseTypes for TypesTable4 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesArray::new_rng(rng, config), + f3: TypesStructA::new_rng(rng, config), + f4: TypesVec::new_rng(rng, config), + } + } +} +impl Default for TypesTable4 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable4 { + pub fn to_mol(&self) -> types_api::Table4 { + types_api::Table4::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table4) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + self.f3.check(&d.f3()?)?; + self.f4.check(&d.f4()?.try_into().unwrap())?; + Ok(()) + } +} + +pub struct TypesTable5 { + f1: TypesArray, + f2: TypesArray, + f3: TypesStructA, + f4: TypesVec, + f5: TypesVec>, +} +impl BaseTypes for TypesTable5 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesArray::new_rng(rng, config), + f3: TypesStructA::new_rng(rng, config), + f4: TypesVec::new_rng(rng, config), + f5: TypesVec::new_rng(rng, config), + } + } +} +impl Default for TypesTable5 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable5 { + pub fn to_mol(&self) -> types_api::Table5 { + types_api::Table5::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .f5(self.f5.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table5) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + self.f3.check(&d.f3()?)?; + self.f4.check(&d.f4()?.try_into().unwrap())?; + self.f5.check(&d.f5()?.try_into().unwrap())?; + Ok(()) + } +} + +pub struct TypesTable6 { + f1: TypesArray, + f2: TypesArray, + f3: TypesStructA, + f4: TypesVec, + f5: TypesVec>, + f6: TypesTable5, +} +impl BaseTypes for TypesTable6 { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesArray::new_rng(rng, config), + f3: TypesStructA::new_rng(rng, config), + f4: TypesVec::new_rng(rng, config), + f5: TypesVec::new_rng(rng, config), + f6: TypesTable5::new_rng(rng, config), + } + } +} +impl Default for TypesTable6 { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTable6 { + pub fn to_mol(&self) -> types_api::Table6 { + types_api::Table6::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .f5(self.f5.to_mol()) + .f6(self.f6.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::Table6) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + self.f3.check(&d.f3()?)?; + self.f4.check(&d.f4()?.try_into().unwrap())?; + self.f5.check(&d.f5()?.try_into().unwrap())?; + self.f6.check(&d.f6()?.try_into().unwrap())?; + Ok(()) + } +} +pub struct TypesTableA { + f1: TypesArray, + f2: TypesStructA, + f3: TypesVec, + f4: TypesVec>, + f5: TypesTable1, + f6: TypesOption>, + f7: TypesUnionA, + f8: TypesArray, +} +impl BaseTypes for TypesTableA { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + Self { + f1: TypesArray::new_rng(rng, config), + f2: TypesStructA::new_rng(rng, config), + f3: TypesVec::new_rng(rng, config), + f4: TypesVec::new_rng(rng, config), + f5: TypesTable1::new_rng(rng, config), + f6: TypesOption::new_rng(rng, config), + f7: TypesUnionA::new_rng(rng, config), + f8: TypesArray::new_rng(rng, config), + } + } +} +impl Default for TypesTableA { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTableA { + pub fn to_mol(&self) -> types_api::TableA { + types_api::TableA::new_builder() + .f1(self.f1.to_mol()) + .f2(self.f2.to_mol()) + .f3(self.f3.to_mol()) + .f4(self.f4.to_mol()) + .f5(self.f5.to_mol()) + .f6(self.f6.to_mol()) + .f7(self.f7.to_mol()) + .f8(self.f8.to_mol()) + .build() + } + pub fn check(&self, d: &types_api2::TableA) -> ResCheckErr { + self.f1.check(&d.f1()?)?; + self.f2.check(&d.f2()?)?; + self.f3.check(&d.f3()?.try_into().unwrap())?; + self.f4.check(&d.f4()?.try_into().unwrap())?; + self.f5.check(&d.f5()?.try_into().unwrap())?; + self.f6.check(&d.f6()?.try_into().unwrap())?; + Ok(()) + } +} diff --git a/examples/lazy-reader-tests/src/types_vec.rs b/examples/lazy-reader-tests/src/types_vec.rs new file mode 100644 index 0000000..b9a3c46 --- /dev/null +++ b/examples/lazy-reader-tests/src/types_vec.rs @@ -0,0 +1,218 @@ +use super::*; +use crate::{types_api, types_api2}; +use molecule::prelude::{Builder, Entity}; +use rand::{rngs::ThreadRng, thread_rng, Rng}; + +pub struct TypesVec { + pub d: Vec, +} + +impl BaseTypes for TypesVec { + fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { + let mut d = Vec::new(); + + let size = if config.large_vec { + rng.gen_range(128..1024) + } else { + rng.gen_range(1..128) + }; + for _i in 0..size { + d.push(T::new_rng(rng, config)); + } + + Self { d } + } +} +impl Default for TypesVec { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} + +impl TypesVec { + pub fn to_mol(&self) -> types_api::Bytes { + types_api::Bytes::new_builder() + .set(self.d.iter().map(|f| f.clone().into()).collect()) + .build() + } + pub fn check(&self, d: &Vec) -> ResCheckErr { + TypesCheckErr::check_data(d, &self.d) + } +} +impl TypesVec { + pub fn to_mol(&self) -> types_api::Words { + types_api::Words::new_builder() + .set(self.d.iter().map(|f| f.to_mol2()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::Words) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::Byte3Vec { + types_api::Byte3Vec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::Byte3Vec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::Byte7Vec { + types_api::Byte7Vec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::Byte7Vec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec { + pub fn to_mol(&self) -> types_api::StructIVec { + types_api::StructIVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::StructIVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?)?; + } + Ok(()) + } +} +impl TypesVec { + pub fn to_mol(&self) -> types_api::StructJVec { + types_api::StructJVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::StructJVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?)?; + } + Ok(()) + } +} +impl TypesVec { + pub fn to_mol(&self) -> types_api::StructPVec { + types_api::StructPVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::StructPVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?)?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::BytesVec { + types_api::BytesVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::BytesVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.try_into().unwrap())?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::WordsVec { + types_api::WordsVec::new_builder() + .set( + self.d + .iter() + .map(|f| { + types_api::Words::new_builder() + .set(f.d.iter().map(|ff| ff.to_mol2()).collect()) + .build() + }) + .collect(), + ) + .build() + } + pub fn check(&self, d: &types_api2::WordsVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::ByteOptVec { + types_api::ByteOptVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::ByteOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec> { + pub fn to_mol(&self) -> types_api::WordOptVec { + types_api::WordOptVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::WordOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec>> { + pub fn to_mol(&self) -> types_api::WordsOptVec { + types_api::WordsOptVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::WordsOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +} +impl TypesVec>> { + pub fn to_mol(&self) -> types_api::BytesOptVec { + types_api::BytesOptVec::new_builder() + .set(self.d.iter().map(|f| f.to_mol()).collect()) + .build() + } + pub fn check(&self, d: &types_api2::BytesOptVec) -> ResCheckErr { + TypesCheckErr::check_lenght(d.len()?, self.d.len())?; + for i in 0..d.len()? { + self.d[i].check(&d.get(i)?.into())?; + } + Ok(()) + } +}