diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8050d2295..e7c797aee 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,7 +17,7 @@ jobs: complete: if: always() - needs: [generate, fmt, readme, prepare, build, test, publish-dry-run] + needs: [generate, fmt, readme, prepare, build, test, fuzz-corpus, publish-dry-run] runs-on: ubuntu-latest steps: - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') @@ -140,6 +140,22 @@ jobs: - run: cargo version - run: cargo test ${{ matrix.feature-args }} + fuzz-corpus: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: stellar/actions/rust-cache@main + - uses: stellar/binaries@v55 + with: + name: cargo-fuzz + version: 0.13.1 + - run: rustup install nightly + - run: rustup default nightly + - name: Run fuzz corpus + run: make fuzz + - name: Check no diffs exist + run: git add -N . && git diff HEAD --exit-code + publish-dry-run: if: github.event_name == 'push' || startsWith(github.head_ref, 'release/') strategy: diff --git a/Cargo.toml b/Cargo.toml index 5a5f4d8d7..ed33256d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ sha2 = { version = "0.10.9", optional = true } [dev-dependencies] serde_json = "1.0.89" bytes-lit = "0.0.5" +rand = "0.9.0" [features] default = ["std"] @@ -52,6 +53,7 @@ ms_close_time = [] # Features available without any new dependencies. type_enum = [] +const = [] # Features dependent on optional dependencies. base64 = ["std", "dep:base64"] diff --git a/Makefile b/Makefile index 616d9969f..f09faed09 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: all test build doc install readme fuzz fuzz-reduce watch generate generate-files clean fmt publish + export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic CARGO_HACK_ARGS=--feature-powerset --exclude-features default --group-features base64,serde,arbitrary,hex,rand @@ -27,6 +29,16 @@ readme: | jq -r '"# stellar-xdr\n\n" + .index[.root|tostring].docs' \ > README.md +# Run the fuzz corpus. +# Leak detection is disabled because the fuzzer tests the const impls that +# contain &'static data and so their Arbitrary impls explicitly leak. +fuzz: + ASAN_OPTIONS=detect_leaks=0 cargo +nightly fuzz run spec-entry -- -rss_limit_mb=0 -max_len=10240 -runs=0 + +# Shrinks each corpus to the smallest set of inputs with the same coverage. +fuzz-reduce: + ASAN_OPTIONS=detect_leaks=0 cargo +nightly fuzz cmin spec-entry -- -rss_limit_mb=0 + watch: cargo watch --clear --watch-when-idle --shell '$(MAKE)' diff --git a/README.md b/README.md index ea7137efd..0e01eb87c 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,13 @@ only necessary to use utility functions that depend on serde_json. 6. `hex` – Enables support for hex in string representations of some types. Automatically enabled when serde is enabled. 7. `schemars` – Enables support for JSON Schema generation. (Experimental) +8. `const` – Enables the `const` module, containing a form of every type +that can be constructed and encoded to XDR in a const context. Types that +own heap data have a borrowing counterpart in the module that wraps +`&'static` slices instead; the rest are re-exports of the owned types. +Every type in the module has `const_xdr_len` and `const_to_xdr` methods, +so XDR can be encoded at compile time into a fixed-size array. Requires no +additional dependencies and works without std or alloc. (Experimental) Features marked experimental may disappear at anytime, see breaking changes at anytime, or and may be minimal implementations instead of complete. diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 000000000..735ae0d23 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +artifacts +coverage diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock new file mode 100644 index 000000000..540578856 --- /dev/null +++ b/fuzz/Cargo.lock @@ -0,0 +1,351 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cc" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crate-git-revision" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c521bf1f43d31ed2f73441775ed31935d77901cb3451e44b38a1c1612fcbaf98" +dependencies = [ + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "crate-git-revision" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54851b5b3f24621804b1cded2820975623c205e3055d2d44031cdb1237339ac8" +dependencies = [ + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "escape-bytes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfcf67fea2815c2fc3b90873fae90957be12ff417335dfadc7f52927feb03b2" + +[[package]] +name = "ethnum" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40404c3f5f511ec4da6fe866ddf6a717c309fdbb69fbbad7b0f3edab8f2e835f" + +[[package]] +name = "find-msvc-tools" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libfuzzer-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2" +dependencies = [ + "arbitrary", + "cc", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "stellar-strkey" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee1832fb50c651ad10f734aaf5d31ca5acdfb197a6ecda64d93fcdb8885af913" +dependencies = [ + "crate-git-revision 0.0.6", + "data-encoding", +] + +[[package]] +name = "stellar-xdr" +version = "28.0.0" +dependencies = [ + "arbitrary", + "crate-git-revision 0.0.9", + "escape-bytes", + "ethnum", + "hex", + "sha2", + "stellar-strkey", +] + +[[package]] +name = "stellar-xdr-fuzz" +version = "0.0.0" +dependencies = [ + "arbitrary", + "libfuzzer-sys", + "stellar-xdr", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 000000000..537bd85f3 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "stellar-xdr-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +# Its own workspace root, so the fuzz targets are not built as part of the +# parent package, which does not require nightly. +[workspace] + +[dependencies] +arbitrary = { version = "1.1.3", features = ["derive"] } +libfuzzer-sys = "0.4" +stellar-xdr = { path = "..", features = ["const", "arbitrary"] } + +[[bin]] +name = "spec-entry" +path = "fuzz_targets/spec-entry.rs" +test = false +doc = false +bench = false diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 000000000..afb0b3273 --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,28 @@ +# Fuzz targets + +Differential fuzzing of the const XDR encoder against the owned one. + +Each target builds a value in both the owned and the const form from the same +input bytes, then asserts the two encoders produce identical XDR. The +`Arbitrary` impls of the types the const form substitutes — `VecM` for `Vec`, +`BytesM` and `StringM` for `Vec`, a `&'static` reference for a `Box` — +consume input bytes exactly as the owned ones do, so one input yields the same +value in both forms with no conversion between them. + +| Target | Type | +| --- | --- | +| `spec-entry` | `ScSpecEntry` | + +## Running + +``` +ASAN_OPTIONS=detect_leaks=0 cargo +nightly fuzz run spec-entry -- -rss_limit_mb=0 +``` + +Both options are required rather than optional. Const types hold `&'static` +data, so their `Arbitrary` impls leak every value they build: without them the +run ends in a LeakSanitizer report or an out-of-memory abort that says nothing +about the encoders. Memory grows by roughly 10MB/s at 25k exec/s, so run +bounded campaigns (`-runs=N` or `-max_total_time=N`) and restart, rather than +leaving a target running indefinitely. The corpus carries across restarts in +`fuzz/corpus//`. diff --git a/fuzz/corpus/spec-entry/098d722a0c4216cec31f5c0141a2a55d74180bf5 b/fuzz/corpus/spec-entry/098d722a0c4216cec31f5c0141a2a55d74180bf5 new file mode 100644 index 000000000..687d51daa Binary files /dev/null and b/fuzz/corpus/spec-entry/098d722a0c4216cec31f5c0141a2a55d74180bf5 differ diff --git a/fuzz/corpus/spec-entry/0d2725f3a3b236c88f53fe0c271440a2abe5e871 b/fuzz/corpus/spec-entry/0d2725f3a3b236c88f53fe0c271440a2abe5e871 new file mode 100644 index 000000000..ffc43d5f4 --- /dev/null +++ b/fuzz/corpus/spec-entry/0d2725f3a3b236c88f53fe0c271440a2abe5e871 @@ -0,0 +1,3 @@ + + +¾&' \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/0f7acf620bd6744d47d896303becd50631377aae b/fuzz/corpus/spec-entry/0f7acf620bd6744d47d896303becd50631377aae new file mode 100644 index 000000000..391539721 Binary files /dev/null and b/fuzz/corpus/spec-entry/0f7acf620bd6744d47d896303becd50631377aae differ diff --git a/fuzz/corpus/spec-entry/123ab60e3d82467db9f85c271afcbf624fe30682 b/fuzz/corpus/spec-entry/123ab60e3d82467db9f85c271afcbf624fe30682 new file mode 100644 index 000000000..6e09a5c53 --- /dev/null +++ b/fuzz/corpus/spec-entry/123ab60e3d82467db9f85c271afcbf624fe30682 @@ -0,0 +1 @@ +NŒ!ZÅ_³G£­•–ÚÜÿ¨H¤O’% \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/145138ad092e96519156adfea0256f5dc0acefc5 b/fuzz/corpus/spec-entry/145138ad092e96519156adfea0256f5dc0acefc5 new file mode 100644 index 000000000..9af4722fd --- /dev/null +++ b/fuzz/corpus/spec-entry/145138ad092e96519156adfea0256f5dc0acefc5 @@ -0,0 +1 @@ +0:UUUUU@õ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/17631b3afd33b71126fbc7fd2496240588000e94 b/fuzz/corpus/spec-entry/17631b3afd33b71126fbc7fd2496240588000e94 new file mode 100644 index 000000000..8e52f5f4f Binary files /dev/null and b/fuzz/corpus/spec-entry/17631b3afd33b71126fbc7fd2496240588000e94 differ diff --git a/fuzz/corpus/spec-entry/18d9a6a5b9ca7c062159b7a2e0866adebd567b9c b/fuzz/corpus/spec-entry/18d9a6a5b9ca7c062159b7a2e0866adebd567b9c new file mode 100644 index 000000000..66c9cf5b3 --- /dev/null +++ b/fuzz/corpus/spec-entry/18d9a6a5b9ca7c062159b7a2e0866adebd567b9c @@ -0,0 +1,6 @@ + +€ +JJz”5-éèèÚà + +õõÙ +€ØŸŸŸŸŸ¢ŸŸ^GGŸÿ Ÿþÿ?1- \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/2180ced167490cedb5d83972dbbcf0aa99f0e7c3 b/fuzz/corpus/spec-entry/2180ced167490cedb5d83972dbbcf0aa99f0e7c3 new file mode 100644 index 000000000..c9a84a3cf Binary files /dev/null and b/fuzz/corpus/spec-entry/2180ced167490cedb5d83972dbbcf0aa99f0e7c3 differ diff --git a/fuzz/corpus/spec-entry/2e71af3e4908f69b5e96d411d9c2919af5a175a7 b/fuzz/corpus/spec-entry/2e71af3e4908f69b5e96d411d9c2919af5a175a7 new file mode 100644 index 000000000..9f7f4799e --- /dev/null +++ b/fuzz/corpus/spec-entry/2e71af3e4908f69b5e96d411d9c2919af5a175a7 @@ -0,0 +1 @@ +õú€€€ÎÁ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/448fe04e6ca271b9f325c7dcca0ec33d6ecc6fbe b/fuzz/corpus/spec-entry/448fe04e6ca271b9f325c7dcca0ec33d6ecc6fbe new file mode 100644 index 000000000..b88cfdc1a Binary files /dev/null and b/fuzz/corpus/spec-entry/448fe04e6ca271b9f325c7dcca0ec33d6ecc6fbe differ diff --git a/fuzz/corpus/spec-entry/49387cc5927cd4d1d229597f1eb7b88e5477d630 b/fuzz/corpus/spec-entry/49387cc5927cd4d1d229597f1eb7b88e5477d630 new file mode 100644 index 000000000..ca7e6bcdb --- /dev/null +++ b/fuzz/corpus/spec-entry/49387cc5927cd4d1d229597f1eb7b88e5477d630 @@ -0,0 +1,5 @@ + + +* + +0í€í€0€--«€èðéèèèÿÿ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/4b79d73704b5bd9da173c0935e384ffd134f3f03 b/fuzz/corpus/spec-entry/4b79d73704b5bd9da173c0935e384ffd134f3f03 new file mode 100644 index 000000000..acf97764a Binary files /dev/null and b/fuzz/corpus/spec-entry/4b79d73704b5bd9da173c0935e384ffd134f3f03 differ diff --git a/fuzz/corpus/spec-entry/5bc92340cdbc45f9d30d95aa1da462acea2f183b b/fuzz/corpus/spec-entry/5bc92340cdbc45f9d30d95aa1da462acea2f183b new file mode 100644 index 000000000..485401f9f Binary files /dev/null and b/fuzz/corpus/spec-entry/5bc92340cdbc45f9d30d95aa1da462acea2f183b differ diff --git a/fuzz/corpus/spec-entry/6526b87a58cdc585f70f6f35263a905d643f8c16 b/fuzz/corpus/spec-entry/6526b87a58cdc585f70f6f35263a905d643f8c16 new file mode 100644 index 000000000..1dfcadd0b --- /dev/null +++ b/fuzz/corpus/spec-entry/6526b87a58cdc585f70f6f35263a905d643f8c16 @@ -0,0 +1 @@ +õuúÁ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/6724ae20469024dec0737c8eac70ef9994308d86 b/fuzz/corpus/spec-entry/6724ae20469024dec0737c8eac70ef9994308d86 new file mode 100644 index 000000000..e47875d9d Binary files /dev/null and b/fuzz/corpus/spec-entry/6724ae20469024dec0737c8eac70ef9994308d86 differ diff --git a/fuzz/corpus/spec-entry/67a16e7ccd2c86c1f5a4e5c920b4560b7bd524ae b/fuzz/corpus/spec-entry/67a16e7ccd2c86c1f5a4e5c920b4560b7bd524ae new file mode 100644 index 000000000..41eba9a63 Binary files /dev/null and b/fuzz/corpus/spec-entry/67a16e7ccd2c86c1f5a4e5c920b4560b7bd524ae differ diff --git a/fuzz/corpus/spec-entry/6afed13433083943e0507ea61017a77694f804cf b/fuzz/corpus/spec-entry/6afed13433083943e0507ea61017a77694f804cf new file mode 100644 index 000000000..e4471cd81 Binary files /dev/null and b/fuzz/corpus/spec-entry/6afed13433083943e0507ea61017a77694f804cf differ diff --git a/fuzz/corpus/spec-entry/707973c40a4dd7715cbbb35e7d84339ed7ded43e b/fuzz/corpus/spec-entry/707973c40a4dd7715cbbb35e7d84339ed7ded43e new file mode 100644 index 000000000..43507194c Binary files /dev/null and b/fuzz/corpus/spec-entry/707973c40a4dd7715cbbb35e7d84339ed7ded43e differ diff --git a/fuzz/corpus/spec-entry/7149123e685624e34649e6848f9e30818e3ade50 b/fuzz/corpus/spec-entry/7149123e685624e34649e6848f9e30818e3ade50 new file mode 100644 index 000000000..f360142de Binary files /dev/null and b/fuzz/corpus/spec-entry/7149123e685624e34649e6848f9e30818e3ade50 differ diff --git a/fuzz/corpus/spec-entry/786c6d61ddcc9f5d4e639631522101b2353bf8a1 b/fuzz/corpus/spec-entry/786c6d61ddcc9f5d4e639631522101b2353bf8a1 new file mode 100644 index 000000000..d13f19431 Binary files /dev/null and b/fuzz/corpus/spec-entry/786c6d61ddcc9f5d4e639631522101b2353bf8a1 differ diff --git a/fuzz/corpus/spec-entry/78ed6da57bdfe0319aa8fe0be86b3053c5931f99 b/fuzz/corpus/spec-entry/78ed6da57bdfe0319aa8fe0be86b3053c5931f99 new file mode 100644 index 000000000..2f1ac2189 Binary files /dev/null and b/fuzz/corpus/spec-entry/78ed6da57bdfe0319aa8fe0be86b3053c5931f99 differ diff --git a/fuzz/corpus/spec-entry/7a54d2e457b87d8c67aa7a674897b1dcc10be05d b/fuzz/corpus/spec-entry/7a54d2e457b87d8c67aa7a674897b1dcc10be05d new file mode 100644 index 000000000..c38166555 Binary files /dev/null and b/fuzz/corpus/spec-entry/7a54d2e457b87d8c67aa7a674897b1dcc10be05d differ diff --git a/fuzz/corpus/spec-entry/7b2a68827647ef5138fef817ac3477bfe15bda01 b/fuzz/corpus/spec-entry/7b2a68827647ef5138fef817ac3477bfe15bda01 new file mode 100644 index 000000000..dc9224a44 Binary files /dev/null and b/fuzz/corpus/spec-entry/7b2a68827647ef5138fef817ac3477bfe15bda01 differ diff --git a/fuzz/corpus/spec-entry/8277bad33662ae395381aa143808da412c27f3a5 b/fuzz/corpus/spec-entry/8277bad33662ae395381aa143808da412c27f3a5 new file mode 100644 index 000000000..2641760b8 Binary files /dev/null and b/fuzz/corpus/spec-entry/8277bad33662ae395381aa143808da412c27f3a5 differ diff --git a/fuzz/corpus/spec-entry/867336765db3d59f5e3699900e5b89758b3f58a4 b/fuzz/corpus/spec-entry/867336765db3d59f5e3699900e5b89758b3f58a4 new file mode 100644 index 000000000..09e2c5521 --- /dev/null +++ b/fuzz/corpus/spec-entry/867336765db3d59f5e3699900e5b89758b3f58a4 @@ -0,0 +1,4 @@ + + + +€J€0? \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/89d025c1277e6eabdede6c9667cbdfce0209e7dc b/fuzz/corpus/spec-entry/89d025c1277e6eabdede6c9667cbdfce0209e7dc new file mode 100644 index 000000000..a2b363392 Binary files /dev/null and b/fuzz/corpus/spec-entry/89d025c1277e6eabdede6c9667cbdfce0209e7dc differ diff --git a/fuzz/corpus/spec-entry/8b8b5abcfab471b0c0b5e3578e3003795f589516 b/fuzz/corpus/spec-entry/8b8b5abcfab471b0c0b5e3578e3003795f589516 new file mode 100644 index 000000000..f8590cfa7 --- /dev/null +++ b/fuzz/corpus/spec-entry/8b8b5abcfab471b0c0b5e3578e3003795f589516 @@ -0,0 +1 @@ +šxîÙ£J\f„>º!„3/Óê[ɈJfÿ ‡º˜¼�"ùÏåûÉ»d§Õˆ©Ì¬ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/8d86a60bafa293b1af1177e4e800ea2c0bcf1687 b/fuzz/corpus/spec-entry/8d86a60bafa293b1af1177e4e800ea2c0bcf1687 new file mode 100644 index 000000000..6874d8031 --- /dev/null +++ b/fuzz/corpus/spec-entry/8d86a60bafa293b1af1177e4e800ea2c0bcf1687 @@ -0,0 +1 @@ +õ......Á \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/99688351018b9fe430513977c33e1c0c9b2092f3 b/fuzz/corpus/spec-entry/99688351018b9fe430513977c33e1c0c9b2092f3 new file mode 100644 index 000000000..be3f91c94 Binary files /dev/null and b/fuzz/corpus/spec-entry/99688351018b9fe430513977c33e1c0c9b2092f3 differ diff --git a/fuzz/corpus/spec-entry/9dfae95f6a745fb08949affd9dcf3cce3ba6cfdb b/fuzz/corpus/spec-entry/9dfae95f6a745fb08949affd9dcf3cce3ba6cfdb new file mode 100644 index 000000000..5ea73872e --- /dev/null +++ b/fuzz/corpus/spec-entry/9dfae95f6a745fb08949affd9dcf3cce3ba6cfdb @@ -0,0 +1 @@ +.c|ñn'Ê÷2¢:Ö‘éºÔ¿)0gW¬±6 \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/a928790baa93ddc5e0b1fb2a2af32f10385cbb77 b/fuzz/corpus/spec-entry/a928790baa93ddc5e0b1fb2a2af32f10385cbb77 new file mode 100644 index 000000000..216ca18a0 --- /dev/null +++ b/fuzz/corpus/spec-entry/a928790baa93ddc5e0b1fb2a2af32f10385cbb77 @@ -0,0 +1,6 @@ +$1 +“J +öõJ +öõÿÿÿöüÿÿÿÿuJ +öõJ +öõ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/aae40b75b2102f35c53f376bcf209c1c46884c8e b/fuzz/corpus/spec-entry/aae40b75b2102f35c53f376bcf209c1c46884c8e new file mode 100644 index 000000000..cad226201 Binary files /dev/null and b/fuzz/corpus/spec-entry/aae40b75b2102f35c53f376bcf209c1c46884c8e differ diff --git a/fuzz/corpus/spec-entry/ad140a446e955b5c80ad8f46b430c12921038711 b/fuzz/corpus/spec-entry/ad140a446e955b5c80ad8f46b430c12921038711 new file mode 100644 index 000000000..c8c50f642 Binary files /dev/null and b/fuzz/corpus/spec-entry/ad140a446e955b5c80ad8f46b430c12921038711 differ diff --git a/fuzz/corpus/spec-entry/adbbe9d8047e0b54f9f9074b3cb4a5bd46b9e923 b/fuzz/corpus/spec-entry/adbbe9d8047e0b54f9f9074b3cb4a5bd46b9e923 new file mode 100644 index 000000000..9013d61ee --- /dev/null +++ b/fuzz/corpus/spec-entry/adbbe9d8047e0b54f9f9074b3cb4a5bd46b9e923 @@ -0,0 +1,4 @@ + + +% +H€í€0-«€í \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/b0c7c5b1739498071ec6c5b451ea85e858be65dc b/fuzz/corpus/spec-entry/b0c7c5b1739498071ec6c5b451ea85e858be65dc new file mode 100644 index 000000000..1563fc4d4 Binary files /dev/null and b/fuzz/corpus/spec-entry/b0c7c5b1739498071ec6c5b451ea85e858be65dc differ diff --git a/fuzz/corpus/spec-entry/b10ad453dfcbf6398f7bc62c61148642477d1fcb b/fuzz/corpus/spec-entry/b10ad453dfcbf6398f7bc62c61148642477d1fcb new file mode 100644 index 000000000..b6148227b Binary files /dev/null and b/fuzz/corpus/spec-entry/b10ad453dfcbf6398f7bc62c61148642477d1fcb differ diff --git a/fuzz/corpus/spec-entry/b19f25d0bdc96cf488f967b9806e4298eff3d8ba b/fuzz/corpus/spec-entry/b19f25d0bdc96cf488f967b9806e4298eff3d8ba new file mode 100644 index 000000000..d0a2cb887 Binary files /dev/null and b/fuzz/corpus/spec-entry/b19f25d0bdc96cf488f967b9806e4298eff3d8ba differ diff --git a/fuzz/corpus/spec-entry/c50b8763bcc70b6c47455940b337475f1354634e b/fuzz/corpus/spec-entry/c50b8763bcc70b6c47455940b337475f1354634e new file mode 100644 index 000000000..ead227ff1 Binary files /dev/null and b/fuzz/corpus/spec-entry/c50b8763bcc70b6c47455940b337475f1354634e differ diff --git a/fuzz/corpus/spec-entry/c8cfae4c1ac67da1679472220fc7a41a0be724e8 b/fuzz/corpus/spec-entry/c8cfae4c1ac67da1679472220fc7a41a0be724e8 new file mode 100644 index 000000000..cabca9b73 Binary files /dev/null and b/fuzz/corpus/spec-entry/c8cfae4c1ac67da1679472220fc7a41a0be724e8 differ diff --git a/fuzz/corpus/spec-entry/cd785e976eb70e272c61259ad13bb6fcf5e0e396 b/fuzz/corpus/spec-entry/cd785e976eb70e272c61259ad13bb6fcf5e0e396 new file mode 100644 index 000000000..f1ee0138b --- /dev/null +++ b/fuzz/corpus/spec-entry/cd785e976eb70e272c61259ad13bb6fcf5e0e396 @@ -0,0 +1,3 @@ +: +:¾& +õ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/cf43074ae55a269d1524fb9b564f748f277cd60a b/fuzz/corpus/spec-entry/cf43074ae55a269d1524fb9b564f748f277cd60a new file mode 100644 index 000000000..12ae5e035 Binary files /dev/null and b/fuzz/corpus/spec-entry/cf43074ae55a269d1524fb9b564f748f277cd60a differ diff --git a/fuzz/corpus/spec-entry/d4b9400703ae2c959edbdce8117e709805e853f3 b/fuzz/corpus/spec-entry/d4b9400703ae2c959edbdce8117e709805e853f3 new file mode 100644 index 000000000..b3df640d4 Binary files /dev/null and b/fuzz/corpus/spec-entry/d4b9400703ae2c959edbdce8117e709805e853f3 differ diff --git a/fuzz/corpus/spec-entry/dcc99a72f3905d9f3ed7cb2bbd9a6b6d8106099b b/fuzz/corpus/spec-entry/dcc99a72f3905d9f3ed7cb2bbd9a6b6d8106099b new file mode 100644 index 000000000..d15c57369 --- /dev/null +++ b/fuzz/corpus/spec-entry/dcc99a72f3905d9f3ed7cb2bbd9a6b6d8106099b @@ -0,0 +1 @@ +'õ5n \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/dfbd2ba8a034396283af1115030fa7eb4fdbceb0 b/fuzz/corpus/spec-entry/dfbd2ba8a034396283af1115030fa7eb4fdbceb0 new file mode 100644 index 000000000..c41a464e1 Binary files /dev/null and b/fuzz/corpus/spec-entry/dfbd2ba8a034396283af1115030fa7eb4fdbceb0 differ diff --git a/fuzz/corpus/spec-entry/e1bfaf4146ab5229cde6f3ad0de561182f131ab3 b/fuzz/corpus/spec-entry/e1bfaf4146ab5229cde6f3ad0de561182f131ab3 new file mode 100644 index 000000000..e714da9c3 --- /dev/null +++ b/fuzz/corpus/spec-entry/e1bfaf4146ab5229cde6f3ad0de561182f131ab3 @@ -0,0 +1,3 @@ + + +?+ \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/e583a089a9d87a3d8072f93f27b73e1ab7b984b6 b/fuzz/corpus/spec-entry/e583a089a9d87a3d8072f93f27b73e1ab7b984b6 new file mode 100644 index 000000000..6d1e3e73d Binary files /dev/null and b/fuzz/corpus/spec-entry/e583a089a9d87a3d8072f93f27b73e1ab7b984b6 differ diff --git a/fuzz/corpus/spec-entry/e905770a91e2eed40a879984dad79c8c306bce6c b/fuzz/corpus/spec-entry/e905770a91e2eed40a879984dad79c8c306bce6c new file mode 100644 index 000000000..937afe077 --- /dev/null +++ b/fuzz/corpus/spec-entry/e905770a91e2eed40a879984dad79c8c306bce6c @@ -0,0 +1,5 @@ + + +* + +ÿÿÿÿÿÿÿ-ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿBÿÿÿÿÿÿÿ`퀀0éèèèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ`퀀è \ No newline at end of file diff --git a/fuzz/corpus/spec-entry/ec700fe315cf7e3010987f1d957d40dd5965a22b b/fuzz/corpus/spec-entry/ec700fe315cf7e3010987f1d957d40dd5965a22b new file mode 100644 index 000000000..333de6897 Binary files /dev/null and b/fuzz/corpus/spec-entry/ec700fe315cf7e3010987f1d957d40dd5965a22b differ diff --git a/fuzz/fuzz_targets/spec-entry.rs b/fuzz/fuzz_targets/spec-entry.rs new file mode 100644 index 000000000..4c03c0e1f --- /dev/null +++ b/fuzz/fuzz_targets/spec-entry.rs @@ -0,0 +1,11 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + stellar_xdr_fuzz::assert_same_encoding!( + ScSpecEntry, + write_type_sc_spec_entry, + data, + ); +}); diff --git a/fuzz/src/lib.rs b/fuzz/src/lib.rs new file mode 100644 index 000000000..b36b8d30b --- /dev/null +++ b/fuzz/src/lib.rs @@ -0,0 +1,67 @@ +//! Shared harness for the differential fuzz targets. + +/// Builds a value in both the owned and the const form from the same input +/// bytes, and asserts the two encoders agree. +/// +/// The const form of a type mirrors the owned form field for field, and the +/// `Arbitrary` impls of the types the const form substitutes — `VecM` for +/// `Vec`, `BytesM` and `StringM` for `Vec`, a `&'static` reference for a +/// `Box` — consume input bytes exactly as the owned ones do. Driving both +/// derives from the same input therefore yields the same value in both forms, +/// with no conversion between them, and the two encoders must agree. +/// +/// `$write` is the [`ConstWriter`](stellar_xdr::r#const::ConstWriter) method +/// for `$type`, which is what a const context reaches for; going through it +/// rather than `const_to_xdr` keeps the buffer sizeable at runtime. +#[macro_export] +macro_rules! assert_same_encoding { + ($type:ident, $write:ident, $data:expr $(,)?) => {{ + use arbitrary::{Arbitrary, Unstructured}; + use stellar_xdr::{Limits, WriteXdr}; + + let data: &[u8] = $data; + let owned = stellar_xdr::$type::arbitrary(&mut Unstructured::new(data)); + let konst = stellar_xdr::r#const::$type::arbitrary(&mut Unstructured::new(data)); + + match (owned, konst) { + (Ok(owned), Ok(konst)) => { + let owned_xdr = owned.to_xdr(Limits::none()).unwrap(); + + let konst_xdr_len = konst.const_xdr_len(); + let mut konst_xdr = vec![0u8; konst.const_xdr_len()]; + let mut w = stellar_xdr::r#const::ConstWriter::new(&mut konst_xdr); + w.$write(&konst); + assert_eq!( + w.len(), + konst_xdr_len, + "{} const_xdr_len disagrees with what the writer wrote", + stringify!($type), + ); + assert_eq!( + konst_xdr, + owned_xdr, + "{} encodings differ", + stringify!($type), + ); + } + // Both forms read the same bytes, so input that runs out, or that + // no value can be built from, stops both. There is nothing to + // compare, and it is the common case for a short input rather than + // a failure, but the two must agree on why they stopped. + (Err(owned_err), Err(konst_err)) => assert_eq!( + owned_err, + konst_err, + "{} failed to build in both forms but for different reasons", + stringify!($type), + ), + (Ok(_), Err(e)) => panic!( + "{} built in the owned form but not the const form: {e}", + stringify!($type), + ), + (Err(e), Ok(_)) => panic!( + "{} built in the const form but not the owned form: {e}", + stringify!($type), + ), + } + }}; +} diff --git a/src/cli/generate/arbitrary.rs b/src/cli/generate/arbitrary.rs index f1ae96019..134281a1b 100644 --- a/src/cli/generate/arbitrary.rs +++ b/src/cli/generate/arbitrary.rs @@ -1,7 +1,9 @@ use arbitrary::Unstructured; use clap::{Args, ValueEnum}; use std::{ - io::{stdout, Write}, + ffi::{OsStr, OsString}, + fs, + io::{stdin, stdout, Read, Write}, str::FromStr, }; @@ -48,6 +50,13 @@ pub struct Cmd { /// up. #[arg(long, default_value_t = 20_000)] pub hint_attempts: u64, + + /// Drive generation with the bytes in this file, or stdin if '-', instead + /// of with fresh randomness. Bytes are consumed the same way the fuzz + /// targets consume them, so a fuzz corpus entry piped in here produces the + /// value that entry stands for. + #[arg(long, conflicts_with = "hint")] + pub entropy: Option, } #[derive(Default, Clone, Copy, Debug, Eq, Hash, PartialEq, ValueEnum)] @@ -120,8 +129,25 @@ impl Cmd { Ok(crate::Type::arbitrary(type_, &mut u)?) } + /// Read the bytes that drive generation, from a file or from stdin if the + /// path is `-`. + fn read_entropy(path: &OsStr) -> Result, Error> { + if path == "-" { + let mut bytes = Vec::new(); + stdin().read_to_end(&mut bytes)?; + Ok(bytes) + } else { + Ok(fs::read(path)?) + } + } + /// Generate an arbitrary value of the given type. /// + /// If `entropy` is configured the value is built from those bytes rather + /// than from randomness, which makes the output a function of the input + /// alone. Hints are meaningless there — the bytes decide the value — and + /// the two flags conflict. + /// /// If any `hint`s are configured, values are generated repeatedly (up to /// `hint_attempts` times) until one whose JSON representation contains all /// of the hints is found. In that case the matching value's compact JSON, @@ -133,6 +159,11 @@ impl Cmd { /// rather than fatal: it is skipped and the search continues with fresh /// randomness, so a single bad draw doesn't abort the whole search. fn generate(&self, type_: crate::TypeVariant) -> Result<(crate::Type, Option), Error> { + if let Some(path) = &self.entropy { + let bytes = Self::read_entropy(path)?; + let mut u = Unstructured::new(&bytes); + return Ok((crate::Type::arbitrary(type_, &mut u)?, None)); + } if self.hint.is_empty() { return Ok((Self::generate_one(type_)?, None)); } @@ -158,6 +189,30 @@ impl Cmd { mod tests { use super::*; + /// The same bytes must always produce the same value, otherwise piping a + /// corpus entry in wouldn't show what that entry stands for. + #[test] + fn entropy_is_deterministic() { + let file = std::env::temp_dir().join("stellar-xdr-arbitrary-entropy"); + fs::write(&file, (0u8..=255).collect::>()).unwrap(); + let cmd = Cmd { + r#type: "TimeBounds".to_string(), + output_format: OutputFormat::Json, + hint: vec![], + hint_attempts: 1, + entropy: Some(file.clone().into_os_string()), + }; + let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); + let (first, json) = cmd.generate(type_).unwrap(); + assert!(json.is_none()); + let (second, _) = cmd.generate(type_).unwrap(); + assert_eq!( + serde_json::to_string(&first).unwrap(), + serde_json::to_string(&second).unwrap(), + ); + fs::remove_file(&file).unwrap(); + } + #[test] fn hint_matches() { let cmd = Cmd { @@ -165,6 +220,7 @@ mod tests { output_format: OutputFormat::Json, hint: vec!["min_time".into()], hint_attempts: 1000, + entropy: None, }; let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); let (v, json) = cmd.generate(type_).unwrap(); @@ -180,6 +236,7 @@ mod tests { output_format: OutputFormat::Json, hint: vec!["min_time".into(), "max_time".into()], hint_attempts: 1000, + entropy: None, }; let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); let (_v, json) = cmd.generate(type_).unwrap(); @@ -195,6 +252,7 @@ mod tests { output_format: OutputFormat::Json, hint: vec!["zzz_does_not_exist_xyzzy".into()], hint_attempts: 5, + entropy: None, }; let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); assert!(matches!( @@ -210,6 +268,7 @@ mod tests { output_format: OutputFormat::Json, hint: vec!["min_time".into(), "zzz_does_not_exist_xyzzy".into()], hint_attempts: 5, + entropy: None, }; let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); assert!(matches!( @@ -225,6 +284,7 @@ mod tests { output_format: OutputFormat::Json, hint: vec![], hint_attempts: 1, + entropy: None, }; let type_ = crate::TypeVariant::from_str("TimeBounds").unwrap(); let (_v, json) = cmd.generate(type_).unwrap(); diff --git a/src/generated.rs b/src/generated.rs index cd6a826ac..f4cae3cf3 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -243,6 +243,33 @@ impl fmt::Display for Error { } } +/// The error returned by the borrowing `Const` types' `try_from_slice` and +/// `try_from_str` constructors when the input length exceeds the type's `MAX`. +/// +/// Unlike [`Error`] it is `Copy` and free of any destructor, so a +/// `Result<_, ErrorLengthExceedsMax>` can be matched in a const context (a +/// `Result<_, Error>` cannot, because `Error` owns fields that have +/// destructors). It converts into [`Error::LengthExceedsMax`] via [`From`], so +/// runtime callers can still propagate it with `?`. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct ErrorLengthExceedsMax; + +impl From for Error { + #[must_use] + fn from(_: ErrorLengthExceedsMax) -> Self { + Error::LengthExceedsMax + } +} + +impl fmt::Display for ErrorLengthExceedsMax { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "xdr value max length exceeded") + } +} + +#[cfg(feature = "std")] +impl error::Error for ErrorLengthExceedsMax {} + impl From for Error { fn from(_: TryFromSliceError) -> Error { Error::LengthMismatch @@ -503,7 +530,7 @@ impl Iterator for ReadXdrIter { Err(e) => return Some(Err(Error::Io(e))), // If there is data in the buf available for reading, continue. Ok([..]) => (), - }; + } // Read the buf into the type. let r = self.reader.with_limited_depth(|dlr| S::read_xdr(dlr)); match r { @@ -747,8 +774,8 @@ pub trait WriteXdr { /// `Pad_len` returns the number of bytes to pad an XDR value of the given /// length to make the final serialized size a multiple of 4. -#[cfg(feature = "std")] -fn pad_len(len: usize) -> usize { +#[cfg(any(feature = "std", feature = "const"))] +const fn pad_len(len: usize) -> usize { (4 - (len % 4)) % 4 } @@ -1022,16 +1049,57 @@ impl WriteXdr for [T; N] { serde_with::serde_as, derive(serde::Serialize, serde::Deserialize) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct VecM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct VecM(Vec) where T: 'static; +/// `MAX` as a length, saturating where `usize` is narrower than `u32`. +/// +/// Shared with the const types' `Arbitrary` impls, which must truncate exactly +/// as these do for the two forms to hold the same value. +#[cfg(feature = "arbitrary")] +pub(crate) const fn arbitrary_max_len(max: u32) -> usize { + if max as u64 > usize::MAX as u64 { + usize::MAX + } else { + max as usize + } +} + +/// The length limit is an invariant of the type, and a derived impl would +/// produce values outside it, because `MAX` lives in a const parameter the +/// derive cannot see. +/// +/// `Vec`'s own impl reads a continuation byte before each element, so capping +/// the iterator stops at `MAX` without reading, and then discarding, the +/// elements past it. +#[cfg(feature = "arbitrary")] +impl<'a, T: Arbitrary<'a>, const MAX: u32> Arbitrary<'a> for VecM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl Deref for VecM { type Target = Vec; @@ -1559,14 +1627,36 @@ impl WriteXdr for VecM { feature = "serde", derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct BytesM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct BytesM(Vec); +/// Length limited to `MAX`, as for [`VecM`]. +#[cfg(feature = "arbitrary")] +impl<'a, const MAX: u32> Arbitrary<'a> for BytesM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl core::fmt::Display for BytesM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] @@ -1974,14 +2064,37 @@ impl WriteXdr for BytesM { feature = "serde", derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); +/// Length limited to `MAX`, as for [`VecM`]. The type holds +/// arbitrary bytes rather than UTF-8, so truncating cannot split a character. +#[cfg(feature = "arbitrary")] +impl<'a, const MAX: u32> Arbitrary<'a> for StringM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] @@ -5626,3 +5739,6 @@ pub use test_next_type::*; mod type_enum; #[allow(unused_imports)] pub use type_enum::*; + +#[cfg(feature = "const")] +pub mod r#const; diff --git a/src/generated/const.rs b/src/generated/const.rs new file mode 100644 index 000000000..e4218b0a2 --- /dev/null +++ b/src/generated/const.rs @@ -0,0 +1,2502 @@ +//! Const-evaluable forms of the generated XDR types. +//! +//! Every type in the parent module has a name here. A type that owns heap data +//! has a borrowing equivalent of its own, holding `&'static` data so it can be +//! built in a const context; every other type is an alias to the owned type, +//! which const evaluation can already hold. So a value of any type can be +//! written as `const`, and encoded to XDR at compile time with the type's +//! `const_xdr_len` and `const_to_xdr`. +//! +//! The names are those of the parent module, without a suffix: `const::Memo` is +//! the const form of [`super::Memo`]. Types that cannot be built in a const +//! context (`Vec`, `String`, `Box`) are replaced by [`VecM`], [`BytesM`], +//! [`StringM`], and `&'static` references respectively. + +use core::{ops::Deref, slice}; + +use super::{pad_len, Error, ErrorLengthExceedsMax}; + +#[cfg(feature = "arbitrary")] +use arbitrary::Arbitrary; + +/// `padding` returns the zero bytes that pad an XDR value of the given length +/// out to a multiple of 4. The padding is never more than 3 bytes, so it is a +/// prefix of a single static. +const fn padding(len: usize) -> &'static [u8] { + const PADDING: [u8; 3] = [0; 3]; + PADDING.split_at(pad_len(len)).0 +} + +/// `ConstWriter` serializes XDR into a fixed byte buffer using only const +/// operations. +/// +/// It is the const-evaluable counterpart to [`super::WriteXdr::write_xdr`], +/// producing +/// the same bytes. Unlike the streaming path it enforces no depth or length +/// limits: a const value is fixed at compile time, so there is no untrusted +/// input to bound. +/// +/// The writers below are the primitives. Every type defined in the XDR files +/// additionally has a generated `write_type_{type}` method on `ConstWriter` +/// that serializes one value of that type, taking the type as this module +/// defines it; a type that appears wrapped gets `write_type_option_{type}` and +/// `write_type_vec_{type}` alongside. The `type_` distinguishes them from these primitives, so a +/// wrapper over a primitive is named `write_option_u32` rather than +/// `write_type_option_u32`. +/// +/// Keeping the encoders on the writer, rather than as inherent methods on each +/// generated type, leaves each type with only a thin `const_xdr_len` and +/// `const_to_xdr` pair that wraps its writer method. Each generated method is +/// emitted into the file of the type it serializes, so the two stay together. +/// +/// Serialization is infallible. The only way it can fail is a value whose +/// length does not fit the `u32` XDR length prefix, which panics; in a const +/// context that is a compile-time error. +/// +/// Bytes are only stored while the running length is within the buffer; bytes +/// past the end of the buffer are counted but not written. This allows the +/// exact encoded length to be measured by serializing into an empty buffer and +/// reading [`ConstWriter::len`], then serializing again into a buffer of that +/// size. +pub struct ConstWriter<'a> { + buf: &'a mut [u8], + len: usize, +} + +impl<'a> ConstWriter<'a> { + /// Constructs a new `ConstWriter` that serializes into `buf`. + #[must_use] + pub const fn new(buf: &'a mut [u8]) -> Self { + ConstWriter { buf, len: 0 } + } + + /// Returns the number of bytes serialized so far, which equals the total + /// encoded length once serialization completes (even if it exceeded the + /// buffer). + #[must_use] + pub const fn len(&self) -> usize { + self.len + } + + /// Returns true while nothing has been serialized yet. + #[must_use] + pub const fn is_empty(&self) -> bool { + self.len == 0 + } + + /// Writes `data` into the buffer, advancing the length. Bytes beyond the + /// end of the buffer are counted but not stored. + const fn write_bytes(&mut self, data: &[u8]) { + let mut i = 0; + while i < data.len() { + if self.len < self.buf.len() { + self.buf[self.len] = data[i]; + } + self.len += 1; + i += 1; + } + } + + /// Serializes an `i32`, mirroring `::write_xdr`. + pub const fn write_i32(&mut self, v: i32) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `u32`, mirroring `::write_xdr`. + pub const fn write_u32(&mut self, v: u32) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes an `i64`, mirroring `::write_xdr`. + pub const fn write_i64(&mut self, v: i64) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `u64`, mirroring `::write_xdr`. + pub const fn write_u64(&mut self, v: u64) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `bool`, mirroring `::write_xdr`. + pub const fn write_bool(&mut self, v: bool) { + let i = if v { 1u32 } else { 0u32 }; + self.write_u32(i); + } + + /// Serializes a fixed-length opaque array with trailing padding, mirroring + /// `<[u8; N] as WriteXdr>::write_xdr`. + pub const fn write_fixed_opaque(&mut self, data: &[u8]) { + self.write_bytes(data); + self.write_bytes(padding(data.len())); + } + + /// Serializes a `u32` length prefix from a `usize`, mirroring the + /// `len.try_into()` and `len.write_xdr(w)` of the variable-length + /// `WriteXdr` implementations. + /// + /// ### Panics + /// + /// If `len` does not fit in a `u32`. In a const context that is a + /// compile-time error. + #[allow(clippy::cast_possible_truncation)] + pub const fn write_len(&mut self, len: usize) { + assert!(len <= u32::MAX as usize, "xdr value max length exceeded"); + self.write_u32(len as u32); + } + + /// Serializes a variable-length opaque byte sequence: a `u32` length + /// prefix, the bytes, then trailing padding. Mirrors ` as + /// WriteXdr>::write_xdr`, `::write_xdr`, and `::write_xdr`, which XDR encodes identically. + pub const fn write_var_opaque(&mut self, data: &[u8]) { + let n = data.len(); + self.write_len(n); + self.write_bytes(data); + self.write_bytes(padding(n)); + } + + // The `Option` and `VecM` serializers below are the ones whose inner type + // is a builtin scalar. They are written by hand, beside the scalar + // serializers they call, because they have no generated type to sit with: + // the generator emits a wrapper into the file of the type it wraps, and a + // scalar has no file. Wrappers over `opaque`, `string` and defined types + // are still generated. + + /// Serializes an optional `i32`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_i32(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_i32(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `u32`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_u32(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_u32(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `i64`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_i64(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_i64(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `u64`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_u64(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_u64(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `bool`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_bool(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_bool(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes a variable-length array of `i32`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_i32(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_i32(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `u32`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_u32(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_u32(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `i64`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_i64(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_i64(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `u64`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_u64(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_u64(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `bool`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_bool(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_bool(s[i]); + i += 1; + } + } +} + +/// A borrowing equivalent of [`super::VecM`] that wraps a slice instead of owning a +/// `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays, without heap allocation. +#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct VecM(&'static [T]); + +// Copy and Clone are implemented manually because the derived impls would +// require `T: Copy`/`T: Clone`, and the wrapped `&[T]` is copyable for any +// `T`. +impl Copy for VecM {} + +#[allow(clippy::expl_impl_clone_on_copy)] +impl Clone for VecM { + fn clone(&self) -> Self { + *self + } +} + +impl Deref for VecM { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for VecM { + fn default() -> Self { + Self(&[]) + } +} + +impl VecM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `VecM` from the given slice, erroring if the length of + /// the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [T]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `VecM` from the given slice, panicking if the length of + /// the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [T]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [T] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn iter(&self) -> slice::Iter<'static, T> { + self.0.iter() + } +} + +impl core::iter::IntoIterator for &VecM { + type Item = &'static T; + type IntoIter = slice::Iter<'static, T>; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl TryFrom<&'static [T]> for VecM { + type Error = Error; + + fn try_from(v: &'static [T]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +/// A borrowing equivalent of [`super::BytesM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct BytesM(&'static [u8]); + +impl core::fmt::Display for BytesM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in self.0 { + write!(f, "{b:02x}")?; + } + Ok(()) + } +} + +impl core::fmt::Debug for BytesM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "BytesM(")?; + for b in self.0 { + write!(f, "{b:02x}")?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for BytesM { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for BytesM { + fn default() -> Self { + Self(&[]) + } +} + +impl BytesM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `BytesM` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `BytesM` from the given slice, panicking if the length + /// of the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [u8]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl TryFrom<&'static [u8]> for BytesM { + type Error = Error; + + fn try_from(v: &'static [u8]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +/// A borrowing equivalent of [`super::StringM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays or string literals, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StringM(&'static [u8]); + +impl core::fmt::Display for StringM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + Ok(()) + } +} + +impl core::fmt::Debug for StringM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "StringM(")?; + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for StringM { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for StringM { + fn default() -> Self { + Self(&[]) + } +} + +impl StringM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `StringM` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `StringM` from the given slice, panicking if the length + /// of the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [u8]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + /// Constructs a `StringM` from the UTF-8 bytes of the given str, + /// erroring if the length of the str exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the str exceeds `MAX`. + pub const fn try_from_str(s: &'static str) -> Result { + Self::try_from_slice(s.as_bytes()) + } + + /// Constructs a `StringM` from the UTF-8 bytes of the given str, + /// panicking if the length of the str exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length str is a compile-time + /// error. Prefer [`Self::try_from_str`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the str exceeds `MAX`. + #[must_use] + pub const fn try_from_str_or_panic(s: &'static str) -> Self { + Self::try_from_slice_or_panic(s.as_bytes()) + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl TryFrom<&'static [u8]> for StringM { + type Error = Error; + + fn try_from(v: &'static [u8]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +impl TryFrom<&'static str> for StringM { + type Error = Error; + + fn try_from(s: &'static str) -> Result { + Ok(Self::try_from_str(s)?) + } +} + +/// `Arbitrary` support for the const types, mirroring the owned types byte for +/// byte. +/// +/// Each impl below delegates to the `Arbitrary` impl of the owned field the +/// const type replaces — `VecM` to `Vec`, `BytesM` and `StringM` to +/// `Vec`, a `&'static T` recursive reference to `Box` — and then leaks +/// the result to obtain the `'static` data the const types hold. Consuming the +/// same bytes in the same order as the owned type is what makes a matched pair +/// possible: driving [`arbitrary::Arbitrary`] for an owned type and for its +/// const counterpart from the same input produces the same value in both +/// forms, without any conversion between them. +/// +/// Leaking is why this is behind the `arbitrary` feature, which exists for +/// fuzzing and testing: every value built this way holds its memory for the +/// life of the process. A bounded number of values, as in a test or a fuzz +/// target that caps its iterations, is fine; an unbounded fuzzing run grows +/// without limit. +#[cfg(feature = "arbitrary")] +mod arbitrary_impls { + use super::{BytesM, StringM, VecM}; + use crate::generated::arbitrary_max_len; + use arbitrary::{Arbitrary, Result, Unstructured}; + + /// Builds an arbitrary `T` behind a `&'static` reference, mirroring + /// `Box`, for the recursive references the const types hold in place of + /// a `Box`. + /// + /// Named in the generated types by `#[arbitrary(with = ...)]`. + /// + /// ### Errors + /// + /// If the underlying `T` cannot be built from the remaining input. + pub fn arbitrary_ref<'a, T: Arbitrary<'a> + 'static>( + u: &mut Unstructured<'a>, + ) -> Result<&'static T> { + Ok(Box::leak(Box::new(T::arbitrary(u)?))) + } + + /// The [`arbitrary_ref`] equivalent for an optional recursive reference, + /// mirroring `Option>`. + /// + /// ### Errors + /// + /// If the underlying value cannot be built from the remaining input. + pub fn arbitrary_option_ref<'a, T: Arbitrary<'a> + 'static>( + u: &mut Unstructured<'a>, + ) -> Result> { + Ok(match Option::::arbitrary(u)? { + Some(v) => Some(Box::leak(Box::new(v))), + None => None, + }) + } + + impl<'a, T: Arbitrary<'a> + 'static, const MAX: u32> Arbitrary<'a> for VecM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + // Capped at MAX, and consuming the same bytes as the owned + // type's impl does, so both forms hold the same value. + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // The leak is required because the type holds a static lifetime + // reference to a slice. Even if the ref was not static but some + // other lifetime, the API does not provide any way to pass in an + // arena or similar memory management component to own the + // underlying memory. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } + + impl<'a, const MAX: u32> Arbitrary<'a> for BytesM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // Leaked for the same reason as VecM above. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } + + impl<'a, const MAX: u32> Arbitrary<'a> for StringM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // Leaked for the same reason as VecM above. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } +} + +#[cfg(feature = "arbitrary")] +pub use arbitrary_impls::{arbitrary_option_ref, arbitrary_ref}; + +mod value; +#[allow(unused_imports)] +pub use value::*; +mod scp_ballot; +#[allow(unused_imports)] +pub use scp_ballot::*; +mod scp_statement_type; +pub use super::ScpStatementType; +#[allow(unused_imports)] +pub use scp_statement_type::*; +mod scp_nomination; +#[allow(unused_imports)] +pub use scp_nomination::*; +mod scp_statement_prepare; +#[allow(unused_imports)] +pub use scp_statement_prepare::*; +mod scp_statement_confirm; +#[allow(unused_imports)] +pub use scp_statement_confirm::*; +mod scp_statement_externalize; +#[allow(unused_imports)] +pub use scp_statement_externalize::*; +mod scp_statement_pledges; +#[allow(unused_imports)] +pub use scp_statement_pledges::*; +mod scp_statement; +#[allow(unused_imports)] +pub use scp_statement::*; +mod scp_envelope; +#[allow(unused_imports)] +pub use scp_envelope::*; +mod scp_quorum_set; +#[allow(unused_imports)] +pub use scp_quorum_set::*; +mod encoded_ledger_key; +#[allow(unused_imports)] +pub use encoded_ledger_key::*; +mod config_setting_contract_execution_lanes_v0; +pub use super::ConfigSettingContractExecutionLanesV0; +#[allow(unused_imports)] +pub use config_setting_contract_execution_lanes_v0::*; +mod config_setting_contract_compute_v0; +pub use super::ConfigSettingContractComputeV0; +#[allow(unused_imports)] +pub use config_setting_contract_compute_v0::*; +mod config_setting_contract_parallel_compute_v0; +pub use super::ConfigSettingContractParallelComputeV0; +#[allow(unused_imports)] +pub use config_setting_contract_parallel_compute_v0::*; +mod config_setting_contract_ledger_cost_v0; +pub use super::ConfigSettingContractLedgerCostV0; +#[allow(unused_imports)] +pub use config_setting_contract_ledger_cost_v0::*; +mod config_setting_contract_ledger_cost_ext_v0; +pub use super::ConfigSettingContractLedgerCostExtV0; +#[allow(unused_imports)] +pub use config_setting_contract_ledger_cost_ext_v0::*; +mod config_setting_contract_historical_data_v0; +pub use super::ConfigSettingContractHistoricalDataV0; +#[allow(unused_imports)] +pub use config_setting_contract_historical_data_v0::*; +mod config_setting_contract_events_v0; +pub use super::ConfigSettingContractEventsV0; +#[allow(unused_imports)] +pub use config_setting_contract_events_v0::*; +mod config_setting_contract_bandwidth_v0; +pub use super::ConfigSettingContractBandwidthV0; +#[allow(unused_imports)] +pub use config_setting_contract_bandwidth_v0::*; +mod contract_cost_type; +pub use super::ContractCostType; +#[allow(unused_imports)] +pub use contract_cost_type::*; +mod contract_cost_param_entry; +pub use super::ContractCostParamEntry; +#[allow(unused_imports)] +pub use contract_cost_param_entry::*; +mod state_archival_settings; +pub use super::StateArchivalSettings; +#[allow(unused_imports)] +pub use state_archival_settings::*; +mod eviction_iterator; +pub use super::EvictionIterator; +#[allow(unused_imports)] +pub use eviction_iterator::*; +mod config_setting_scp_timing; +pub use super::ConfigSettingScpTiming; +#[allow(unused_imports)] +pub use config_setting_scp_timing::*; +mod frozen_ledger_keys; +#[allow(unused_imports)] +pub use frozen_ledger_keys::*; +mod frozen_ledger_keys_delta; +#[allow(unused_imports)] +pub use frozen_ledger_keys_delta::*; +mod freeze_bypass_txs; +#[allow(unused_imports)] +pub use freeze_bypass_txs::*; +mod freeze_bypass_txs_delta; +pub use super::CONTRACT_COST_COUNT_LIMIT; +#[allow(unused_imports)] +pub use freeze_bypass_txs_delta::*; +mod contract_cost_params; +#[allow(unused_imports)] +pub use contract_cost_params::*; +mod config_setting_id; +pub use super::ConfigSettingId; +#[allow(unused_imports)] +pub use config_setting_id::*; +mod config_setting_entry; +#[allow(unused_imports)] +pub use config_setting_entry::*; +mod sc_env_meta_kind; +pub use super::ScEnvMetaKind; +#[allow(unused_imports)] +pub use sc_env_meta_kind::*; +mod sc_env_meta_entry_interface_version; +pub use super::ScEnvMetaEntryInterfaceVersion; +#[allow(unused_imports)] +pub use sc_env_meta_entry_interface_version::*; +mod sc_env_meta_entry; +pub use super::ScEnvMetaEntry; +#[allow(unused_imports)] +pub use sc_env_meta_entry::*; +mod sc_meta_v0; +#[allow(unused_imports)] +pub use sc_meta_v0::*; +mod sc_meta_kind; +pub use super::ScMetaKind; +#[allow(unused_imports)] +pub use sc_meta_kind::*; +mod sc_meta_entry; +pub use super::SC_SPEC_DOC_LIMIT; +pub use super::SC_SPEC_TYPE_NAME_LIMIT; +#[allow(unused_imports)] +pub use sc_meta_entry::*; +mod sc_spec_type; +pub use super::ScSpecType; +#[allow(unused_imports)] +pub use sc_spec_type::*; +mod sc_spec_type_option; +#[allow(unused_imports)] +pub use sc_spec_type_option::*; +mod sc_spec_type_result; +#[allow(unused_imports)] +pub use sc_spec_type_result::*; +mod sc_spec_type_vec; +#[allow(unused_imports)] +pub use sc_spec_type_vec::*; +mod sc_spec_type_map; +#[allow(unused_imports)] +pub use sc_spec_type_map::*; +mod sc_spec_type_tuple; +#[allow(unused_imports)] +pub use sc_spec_type_tuple::*; +mod sc_spec_type_bytes_n; +pub use super::ScSpecTypeBytesN; +#[allow(unused_imports)] +pub use sc_spec_type_bytes_n::*; +mod sc_spec_type_udt; +#[allow(unused_imports)] +pub use sc_spec_type_udt::*; +mod sc_spec_type_def; +#[allow(unused_imports)] +pub use sc_spec_type_def::*; +mod sc_spec_udt_struct_field_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_struct_field_v0::*; +mod sc_spec_udt_struct_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_struct_v0::*; +mod sc_spec_udt_union_case_void_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_union_case_void_v0::*; +mod sc_spec_udt_union_case_tuple_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_union_case_tuple_v0::*; +mod sc_spec_udt_union_case_v0_kind; +pub use super::ScSpecUdtUnionCaseV0Kind; +#[allow(unused_imports)] +pub use sc_spec_udt_union_case_v0_kind::*; +mod sc_spec_udt_union_case_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_union_case_v0::*; +mod sc_spec_udt_union_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_union_v0::*; +mod sc_spec_udt_enum_case_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_enum_case_v0::*; +mod sc_spec_udt_enum_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_enum_v0::*; +mod sc_spec_udt_error_enum_case_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_error_enum_case_v0::*; +mod sc_spec_udt_error_enum_v0; +#[allow(unused_imports)] +pub use sc_spec_udt_error_enum_v0::*; +mod sc_spec_function_input_v0; +#[allow(unused_imports)] +pub use sc_spec_function_input_v0::*; +mod sc_spec_function_v0; +#[allow(unused_imports)] +pub use sc_spec_function_v0::*; +mod sc_spec_event_param_location_v0; +pub use super::ScSpecEventParamLocationV0; +#[allow(unused_imports)] +pub use sc_spec_event_param_location_v0::*; +mod sc_spec_event_param_v0; +#[allow(unused_imports)] +pub use sc_spec_event_param_v0::*; +mod sc_spec_event_data_format; +pub use super::ScSpecEventDataFormat; +#[allow(unused_imports)] +pub use sc_spec_event_data_format::*; +mod sc_spec_event_v0; +#[allow(unused_imports)] +pub use sc_spec_event_v0::*; +mod sc_spec_entry_kind; +pub use super::ScSpecEntryKind; +#[allow(unused_imports)] +pub use sc_spec_entry_kind::*; +mod sc_spec_entry; +#[allow(unused_imports)] +pub use sc_spec_entry::*; +mod sc_bytes; +#[allow(unused_imports)] +pub use sc_bytes::*; +mod sc_string; +pub use super::SCSYMBOL_LIMIT; +#[allow(unused_imports)] +pub use sc_string::*; +mod sc_symbol; +#[allow(unused_imports)] +pub use sc_symbol::*; +mod sc_val_type; +pub use super::ScValType; +#[allow(unused_imports)] +pub use sc_val_type::*; +mod sc_error_type; +pub use super::ScErrorType; +#[allow(unused_imports)] +pub use sc_error_type::*; +mod sc_error_code; +pub use super::ScErrorCode; +#[allow(unused_imports)] +pub use sc_error_code::*; +mod sc_error; +pub use super::ScError; +#[allow(unused_imports)] +pub use sc_error::*; +mod u_int128_parts; +pub use super::UInt128Parts; +#[allow(unused_imports)] +pub use u_int128_parts::*; +mod int128_parts; +pub use super::Int128Parts; +#[allow(unused_imports)] +pub use int128_parts::*; +mod u_int256_parts; +pub use super::UInt256Parts; +#[allow(unused_imports)] +pub use u_int256_parts::*; +mod int256_parts; +pub use super::Int256Parts; +#[allow(unused_imports)] +pub use int256_parts::*; +mod contract_executable_type; +pub use super::ContractExecutableType; +#[allow(unused_imports)] +pub use contract_executable_type::*; +mod sc_address_type; +pub use super::ScAddressType; +#[allow(unused_imports)] +pub use sc_address_type::*; +mod muxed_ed25519_account; +pub use super::MuxedEd25519Account; +#[allow(unused_imports)] +pub use muxed_ed25519_account::*; +mod muxed_contract; +#[cfg(feature = "cap_0084_muxed_contract")] +pub use super::MuxedContract; +#[allow(unused_imports)] +pub use muxed_contract::*; +mod sc_address; +pub use super::ScAddress; +#[allow(unused_imports)] +pub use sc_address::*; +mod contract_executable_external_ref; +#[allow(unused_imports)] +pub use contract_executable_external_ref::*; +mod contract_executable; +#[allow(unused_imports)] +pub use contract_executable::*; +mod sc_vec; +#[allow(unused_imports)] +pub use sc_vec::*; +mod sc_map; +#[allow(unused_imports)] +pub use sc_map::*; +mod sc_nonce_key; +pub use super::ScNonceKey; +#[allow(unused_imports)] +pub use sc_nonce_key::*; +mod sc_contract_instance; +#[allow(unused_imports)] +pub use sc_contract_instance::*; +mod sc_val; +#[allow(unused_imports)] +pub use sc_val::*; +mod sc_map_entry; +#[allow(unused_imports)] +pub use sc_map_entry::*; +mod ledger_close_meta_batch; +#[allow(unused_imports)] +pub use ledger_close_meta_batch::*; +mod stored_transaction_set; +#[allow(unused_imports)] +pub use stored_transaction_set::*; +mod stored_debug_transaction_set; +#[allow(unused_imports)] +pub use stored_debug_transaction_set::*; +mod persisted_scp_state_v0; +#[allow(unused_imports)] +pub use persisted_scp_state_v0::*; +mod persisted_scp_state_v1; +#[allow(unused_imports)] +pub use persisted_scp_state_v1::*; +mod persisted_scp_state; +#[allow(unused_imports)] +pub use persisted_scp_state::*; +mod thresholds; +pub use super::Thresholds; +#[allow(unused_imports)] +pub use thresholds::*; +mod string32; +#[allow(unused_imports)] +pub use string32::*; +mod string64; +#[allow(unused_imports)] +pub use string64::*; +mod sequence_number; +pub use super::SequenceNumber; +#[allow(unused_imports)] +pub use sequence_number::*; +mod data_value; +#[allow(unused_imports)] +pub use data_value::*; +mod asset_code4; +pub use super::AssetCode4; +#[allow(unused_imports)] +pub use asset_code4::*; +mod asset_code12; +pub use super::AssetCode12; +#[allow(unused_imports)] +pub use asset_code12::*; +mod asset_type; +pub use super::AssetType; +#[allow(unused_imports)] +pub use asset_type::*; +mod asset_code; +pub use super::AssetCode; +#[allow(unused_imports)] +pub use asset_code::*; +mod alpha_num4; +pub use super::AlphaNum4; +#[allow(unused_imports)] +pub use alpha_num4::*; +mod alpha_num12; +pub use super::AlphaNum12; +#[allow(unused_imports)] +pub use alpha_num12::*; +mod asset; +pub use super::Asset; +#[allow(unused_imports)] +pub use asset::*; +mod price; +pub use super::Price; +#[allow(unused_imports)] +pub use price::*; +mod liabilities; +pub use super::Liabilities; +#[allow(unused_imports)] +pub use liabilities::*; +mod threshold_indexes; +pub use super::ThresholdIndexes; +#[allow(unused_imports)] +pub use threshold_indexes::*; +mod ledger_entry_type; +pub use super::LedgerEntryType; +#[allow(unused_imports)] +pub use ledger_entry_type::*; +mod signer; +#[allow(unused_imports)] +pub use signer::*; +mod account_flags; +pub use super::AccountFlags; +pub use super::MASK_ACCOUNT_FLAGS; +pub use super::MASK_ACCOUNT_FLAGS_V17; +pub use super::MAX_SIGNERS; +#[allow(unused_imports)] +pub use account_flags::*; +mod sponsorship_descriptor; +pub use super::SponsorshipDescriptor; +#[allow(unused_imports)] +pub use sponsorship_descriptor::*; +mod account_entry_extension_v3; +pub use super::AccountEntryExtensionV3; +#[allow(unused_imports)] +pub use account_entry_extension_v3::*; +mod account_entry_extension_v2_ext; +pub use super::AccountEntryExtensionV2Ext; +#[allow(unused_imports)] +pub use account_entry_extension_v2_ext::*; +mod account_entry_extension_v2; +#[allow(unused_imports)] +pub use account_entry_extension_v2::*; +mod account_entry_extension_v1_ext; +#[allow(unused_imports)] +pub use account_entry_extension_v1_ext::*; +mod account_entry_extension_v1; +#[allow(unused_imports)] +pub use account_entry_extension_v1::*; +mod account_entry_ext; +#[allow(unused_imports)] +pub use account_entry_ext::*; +mod account_entry; +#[allow(unused_imports)] +pub use account_entry::*; +mod trust_line_flags; +pub use super::TrustLineFlags; +pub use super::MASK_TRUSTLINE_FLAGS; +pub use super::MASK_TRUSTLINE_FLAGS_V13; +pub use super::MASK_TRUSTLINE_FLAGS_V17; +#[allow(unused_imports)] +pub use trust_line_flags::*; +mod liquidity_pool_type; +pub use super::LiquidityPoolType; +#[allow(unused_imports)] +pub use liquidity_pool_type::*; +mod trust_line_asset; +pub use super::TrustLineAsset; +#[allow(unused_imports)] +pub use trust_line_asset::*; +mod trust_line_entry_extension_v2_ext; +pub use super::TrustLineEntryExtensionV2Ext; +#[allow(unused_imports)] +pub use trust_line_entry_extension_v2_ext::*; +mod trust_line_entry_extension_v2; +pub use super::TrustLineEntryExtensionV2; +#[allow(unused_imports)] +pub use trust_line_entry_extension_v2::*; +mod trust_line_entry_v1_ext; +pub use super::TrustLineEntryV1Ext; +#[allow(unused_imports)] +pub use trust_line_entry_v1_ext::*; +mod trust_line_entry_v1; +pub use super::TrustLineEntryV1; +#[allow(unused_imports)] +pub use trust_line_entry_v1::*; +mod trust_line_entry_ext; +pub use super::TrustLineEntryExt; +#[allow(unused_imports)] +pub use trust_line_entry_ext::*; +mod trust_line_entry; +pub use super::TrustLineEntry; +#[allow(unused_imports)] +pub use trust_line_entry::*; +mod offer_entry_flags; +pub use super::OfferEntryFlags; +pub use super::MASK_OFFERENTRY_FLAGS; +#[allow(unused_imports)] +pub use offer_entry_flags::*; +mod offer_entry_ext; +pub use super::OfferEntryExt; +#[allow(unused_imports)] +pub use offer_entry_ext::*; +mod offer_entry; +pub use super::OfferEntry; +#[allow(unused_imports)] +pub use offer_entry::*; +mod data_entry_ext; +pub use super::DataEntryExt; +#[allow(unused_imports)] +pub use data_entry_ext::*; +mod data_entry; +#[allow(unused_imports)] +pub use data_entry::*; +mod claim_predicate_type; +pub use super::ClaimPredicateType; +#[allow(unused_imports)] +pub use claim_predicate_type::*; +mod claim_predicate; +#[allow(unused_imports)] +pub use claim_predicate::*; +mod claimant_type; +pub use super::ClaimantType; +#[allow(unused_imports)] +pub use claimant_type::*; +mod claimant_v0; +#[allow(unused_imports)] +pub use claimant_v0::*; +mod claimant; +#[allow(unused_imports)] +pub use claimant::*; +mod claimable_balance_flags; +pub use super::ClaimableBalanceFlags; +pub use super::MASK_CLAIMABLE_BALANCE_FLAGS; +#[allow(unused_imports)] +pub use claimable_balance_flags::*; +mod claimable_balance_entry_extension_v1_ext; +pub use super::ClaimableBalanceEntryExtensionV1Ext; +#[allow(unused_imports)] +pub use claimable_balance_entry_extension_v1_ext::*; +mod claimable_balance_entry_extension_v1; +pub use super::ClaimableBalanceEntryExtensionV1; +#[allow(unused_imports)] +pub use claimable_balance_entry_extension_v1::*; +mod claimable_balance_entry_ext; +pub use super::ClaimableBalanceEntryExt; +#[allow(unused_imports)] +pub use claimable_balance_entry_ext::*; +mod claimable_balance_entry; +#[allow(unused_imports)] +pub use claimable_balance_entry::*; +mod liquidity_pool_constant_product_parameters; +pub use super::LiquidityPoolConstantProductParameters; +#[allow(unused_imports)] +pub use liquidity_pool_constant_product_parameters::*; +mod liquidity_pool_entry_constant_product; +pub use super::LiquidityPoolEntryConstantProduct; +#[allow(unused_imports)] +pub use liquidity_pool_entry_constant_product::*; +mod liquidity_pool_entry_body; +pub use super::LiquidityPoolEntryBody; +#[allow(unused_imports)] +pub use liquidity_pool_entry_body::*; +mod liquidity_pool_entry; +pub use super::LiquidityPoolEntry; +#[allow(unused_imports)] +pub use liquidity_pool_entry::*; +mod contract_data_durability; +pub use super::ContractDataDurability; +#[allow(unused_imports)] +pub use contract_data_durability::*; +mod contract_data_entry; +#[allow(unused_imports)] +pub use contract_data_entry::*; +mod contract_code_cost_inputs; +pub use super::ContractCodeCostInputs; +#[allow(unused_imports)] +pub use contract_code_cost_inputs::*; +mod contract_code_entry_v1; +pub use super::ContractCodeEntryV1; +#[allow(unused_imports)] +pub use contract_code_entry_v1::*; +mod contract_code_entry_ext; +pub use super::ContractCodeEntryExt; +#[allow(unused_imports)] +pub use contract_code_entry_ext::*; +mod contract_code_entry; +#[allow(unused_imports)] +pub use contract_code_entry::*; +mod ttl_entry; +pub use super::TtlEntry; +#[allow(unused_imports)] +pub use ttl_entry::*; +mod ledger_entry_extension_v1_ext; +pub use super::LedgerEntryExtensionV1Ext; +#[allow(unused_imports)] +pub use ledger_entry_extension_v1_ext::*; +mod ledger_entry_extension_v1; +pub use super::LedgerEntryExtensionV1; +#[allow(unused_imports)] +pub use ledger_entry_extension_v1::*; +mod ledger_entry_data; +#[allow(unused_imports)] +pub use ledger_entry_data::*; +mod ledger_entry_ext; +pub use super::LedgerEntryExt; +#[allow(unused_imports)] +pub use ledger_entry_ext::*; +mod ledger_entry; +#[allow(unused_imports)] +pub use ledger_entry::*; +mod ledger_key_account; +pub use super::LedgerKeyAccount; +#[allow(unused_imports)] +pub use ledger_key_account::*; +mod ledger_key_trust_line; +pub use super::LedgerKeyTrustLine; +#[allow(unused_imports)] +pub use ledger_key_trust_line::*; +mod ledger_key_offer; +pub use super::LedgerKeyOffer; +#[allow(unused_imports)] +pub use ledger_key_offer::*; +mod ledger_key_data; +#[allow(unused_imports)] +pub use ledger_key_data::*; +mod ledger_key_claimable_balance; +pub use super::LedgerKeyClaimableBalance; +#[allow(unused_imports)] +pub use ledger_key_claimable_balance::*; +mod ledger_key_liquidity_pool; +pub use super::LedgerKeyLiquidityPool; +#[allow(unused_imports)] +pub use ledger_key_liquidity_pool::*; +mod ledger_key_contract_data; +#[allow(unused_imports)] +pub use ledger_key_contract_data::*; +mod ledger_key_contract_code; +pub use super::LedgerKeyContractCode; +#[allow(unused_imports)] +pub use ledger_key_contract_code::*; +mod ledger_key_config_setting; +pub use super::LedgerKeyConfigSetting; +#[allow(unused_imports)] +pub use ledger_key_config_setting::*; +mod ledger_key_ttl; +pub use super::LedgerKeyTtl; +#[allow(unused_imports)] +pub use ledger_key_ttl::*; +mod ledger_key; +#[allow(unused_imports)] +pub use ledger_key::*; +mod envelope_type; +pub use super::EnvelopeType; +#[allow(unused_imports)] +pub use envelope_type::*; +mod bucket_list_type; +pub use super::BucketListType; +#[allow(unused_imports)] +pub use bucket_list_type::*; +mod bucket_entry_type; +pub use super::BucketEntryType; +#[allow(unused_imports)] +pub use bucket_entry_type::*; +mod hot_archive_bucket_entry_type; +pub use super::HotArchiveBucketEntryType; +#[allow(unused_imports)] +pub use hot_archive_bucket_entry_type::*; +mod bucket_metadata_ext; +pub use super::BucketMetadataExt; +#[allow(unused_imports)] +pub use bucket_metadata_ext::*; +mod bucket_metadata; +pub use super::BucketMetadata; +#[allow(unused_imports)] +pub use bucket_metadata::*; +mod bucket_entry; +#[allow(unused_imports)] +pub use bucket_entry::*; +mod hot_archive_bucket_entry; +#[allow(unused_imports)] +pub use hot_archive_bucket_entry::*; +mod upgrade_type; +#[allow(unused_imports)] +pub use upgrade_type::*; +mod stellar_value_type; +pub use super::StellarValueType; +#[allow(unused_imports)] +pub use stellar_value_type::*; +mod ledger_close_value_signature; +#[allow(unused_imports)] +pub use ledger_close_value_signature::*; +mod stellar_value_proposed_value; +#[allow(unused_imports)] +pub use stellar_value_proposed_value::*; +mod stellar_value_signed_ms_value; +#[allow(unused_imports)] +pub use stellar_value_signed_ms_value::*; +mod stellar_value_proposed_ms_value; +#[allow(unused_imports)] +pub use stellar_value_proposed_ms_value::*; +mod stellar_value_ext; +#[allow(unused_imports)] +pub use stellar_value_ext::*; +mod stellar_value; +pub use super::MASK_LEDGER_HEADER_FLAGS; +#[allow(unused_imports)] +pub use stellar_value::*; +mod ledger_header_flags; +pub use super::LedgerHeaderFlags; +#[allow(unused_imports)] +pub use ledger_header_flags::*; +mod ledger_header_extension_v1_ext; +pub use super::LedgerHeaderExtensionV1Ext; +#[allow(unused_imports)] +pub use ledger_header_extension_v1_ext::*; +mod ledger_header_extension_v1; +pub use super::LedgerHeaderExtensionV1; +#[allow(unused_imports)] +pub use ledger_header_extension_v1::*; +mod ledger_header_ext; +pub use super::LedgerHeaderExt; +#[allow(unused_imports)] +pub use ledger_header_ext::*; +mod ledger_header; +#[allow(unused_imports)] +pub use ledger_header::*; +mod ledger_upgrade_type; +pub use super::LedgerUpgradeType; +#[allow(unused_imports)] +pub use ledger_upgrade_type::*; +mod config_upgrade_set_key; +pub use super::ConfigUpgradeSetKey; +#[allow(unused_imports)] +pub use config_upgrade_set_key::*; +mod ledger_upgrade; +pub use super::LedgerUpgrade; +#[allow(unused_imports)] +pub use ledger_upgrade::*; +mod config_upgrade_set; +#[allow(unused_imports)] +pub use config_upgrade_set::*; +mod tx_set_component_type; +pub use super::TxSetComponentType; +#[allow(unused_imports)] +pub use tx_set_component_type::*; +mod dependent_tx_cluster; +#[allow(unused_imports)] +pub use dependent_tx_cluster::*; +mod parallel_tx_execution_stage; +#[allow(unused_imports)] +pub use parallel_tx_execution_stage::*; +mod parallel_txs_component; +#[allow(unused_imports)] +pub use parallel_txs_component::*; +mod tx_set_component_txs_maybe_discounted_fee; +#[allow(unused_imports)] +pub use tx_set_component_txs_maybe_discounted_fee::*; +mod tx_set_component; +#[allow(unused_imports)] +pub use tx_set_component::*; +mod transaction_phase; +#[allow(unused_imports)] +pub use transaction_phase::*; +mod transaction_set; +#[allow(unused_imports)] +pub use transaction_set::*; +mod transaction_set_v1; +#[allow(unused_imports)] +pub use transaction_set_v1::*; +mod generalized_transaction_set; +#[allow(unused_imports)] +pub use generalized_transaction_set::*; +mod transaction_result_pair; +#[allow(unused_imports)] +pub use transaction_result_pair::*; +mod transaction_result_set; +#[allow(unused_imports)] +pub use transaction_result_set::*; +mod transaction_history_entry_ext; +#[allow(unused_imports)] +pub use transaction_history_entry_ext::*; +mod transaction_history_entry; +#[allow(unused_imports)] +pub use transaction_history_entry::*; +mod transaction_history_result_entry_ext; +pub use super::TransactionHistoryResultEntryExt; +#[allow(unused_imports)] +pub use transaction_history_result_entry_ext::*; +mod transaction_history_result_entry; +#[allow(unused_imports)] +pub use transaction_history_result_entry::*; +mod ledger_header_history_entry_ext; +pub use super::LedgerHeaderHistoryEntryExt; +#[allow(unused_imports)] +pub use ledger_header_history_entry_ext::*; +mod ledger_header_history_entry; +#[allow(unused_imports)] +pub use ledger_header_history_entry::*; +mod ledger_scp_messages; +#[allow(unused_imports)] +pub use ledger_scp_messages::*; +mod scp_history_entry_v0; +#[allow(unused_imports)] +pub use scp_history_entry_v0::*; +mod scp_history_entry; +#[allow(unused_imports)] +pub use scp_history_entry::*; +mod ledger_entry_change_type; +pub use super::LedgerEntryChangeType; +#[allow(unused_imports)] +pub use ledger_entry_change_type::*; +mod ledger_entry_change; +#[allow(unused_imports)] +pub use ledger_entry_change::*; +mod ledger_entry_changes; +#[allow(unused_imports)] +pub use ledger_entry_changes::*; +mod operation_meta; +#[allow(unused_imports)] +pub use operation_meta::*; +mod transaction_meta_v1; +#[allow(unused_imports)] +pub use transaction_meta_v1::*; +mod transaction_meta_v2; +#[allow(unused_imports)] +pub use transaction_meta_v2::*; +mod contract_event_type; +pub use super::ContractEventType; +#[allow(unused_imports)] +pub use contract_event_type::*; +mod contract_event_v0; +#[allow(unused_imports)] +pub use contract_event_v0::*; +mod contract_event_body; +#[allow(unused_imports)] +pub use contract_event_body::*; +mod contract_event; +#[allow(unused_imports)] +pub use contract_event::*; +mod diagnostic_event; +#[allow(unused_imports)] +pub use diagnostic_event::*; +mod soroban_transaction_meta_ext_v1; +pub use super::SorobanTransactionMetaExtV1; +#[allow(unused_imports)] +pub use soroban_transaction_meta_ext_v1::*; +mod soroban_transaction_meta_ext; +pub use super::SorobanTransactionMetaExt; +#[allow(unused_imports)] +pub use soroban_transaction_meta_ext::*; +mod soroban_transaction_meta; +#[allow(unused_imports)] +pub use soroban_transaction_meta::*; +mod transaction_meta_v3; +#[allow(unused_imports)] +pub use transaction_meta_v3::*; +mod operation_meta_v2; +#[allow(unused_imports)] +pub use operation_meta_v2::*; +mod soroban_transaction_meta_v2; +#[allow(unused_imports)] +pub use soroban_transaction_meta_v2::*; +mod transaction_event_stage; +pub use super::TransactionEventStage; +#[allow(unused_imports)] +pub use transaction_event_stage::*; +mod transaction_event; +#[allow(unused_imports)] +pub use transaction_event::*; +mod transaction_meta_v4; +#[allow(unused_imports)] +pub use transaction_meta_v4::*; +mod invoke_host_function_success_pre_image; +#[allow(unused_imports)] +pub use invoke_host_function_success_pre_image::*; +mod transaction_meta; +#[allow(unused_imports)] +pub use transaction_meta::*; +mod transaction_result_meta; +#[allow(unused_imports)] +pub use transaction_result_meta::*; +mod transaction_result_meta_v1; +#[allow(unused_imports)] +pub use transaction_result_meta_v1::*; +mod upgrade_entry_meta; +#[allow(unused_imports)] +pub use upgrade_entry_meta::*; +mod ledger_close_meta_v0; +#[allow(unused_imports)] +pub use ledger_close_meta_v0::*; +mod ledger_close_meta_ext_v1; +pub use super::LedgerCloseMetaExtV1; +#[allow(unused_imports)] +pub use ledger_close_meta_ext_v1::*; +mod ledger_close_meta_ext; +pub use super::LedgerCloseMetaExt; +#[allow(unused_imports)] +pub use ledger_close_meta_ext::*; +mod ledger_close_meta_v1; +#[allow(unused_imports)] +pub use ledger_close_meta_v1::*; +mod ledger_close_meta_v2; +#[allow(unused_imports)] +pub use ledger_close_meta_v2::*; +mod ledger_close_meta; +#[allow(unused_imports)] +pub use ledger_close_meta::*; +mod error_code; +pub use super::ErrorCode; +#[allow(unused_imports)] +pub use error_code::*; +mod s_error; +#[allow(unused_imports)] +pub use s_error::*; +mod send_more; +pub use super::SendMore; +#[allow(unused_imports)] +pub use send_more::*; +mod send_more_extended; +pub use super::SendMoreExtended; +#[allow(unused_imports)] +pub use send_more_extended::*; +mod auth_cert; +#[allow(unused_imports)] +pub use auth_cert::*; +mod hello; +pub use super::AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED; +#[allow(unused_imports)] +pub use hello::*; +mod auth; +pub use super::Auth; +#[allow(unused_imports)] +pub use auth::*; +mod ip_addr_type; +pub use super::IpAddrType; +#[allow(unused_imports)] +pub use ip_addr_type::*; +mod peer_address_ip; +pub use super::PeerAddressIp; +#[allow(unused_imports)] +pub use peer_address_ip::*; +mod peer_address; +pub use super::PeerAddress; +#[allow(unused_imports)] +pub use peer_address::*; +mod message_type; +pub use super::MessageType; +#[allow(unused_imports)] +pub use message_type::*; +mod dont_have; +pub use super::DontHave; +#[allow(unused_imports)] +pub use dont_have::*; +mod survey_message_command_type; +pub use super::SurveyMessageCommandType; +#[allow(unused_imports)] +pub use survey_message_command_type::*; +mod survey_message_response_type; +pub use super::SurveyMessageResponseType; +#[allow(unused_imports)] +pub use survey_message_response_type::*; +mod time_sliced_survey_start_collecting_message; +pub use super::TimeSlicedSurveyStartCollectingMessage; +#[allow(unused_imports)] +pub use time_sliced_survey_start_collecting_message::*; +mod signed_time_sliced_survey_start_collecting_message; +#[allow(unused_imports)] +pub use signed_time_sliced_survey_start_collecting_message::*; +mod time_sliced_survey_stop_collecting_message; +pub use super::TimeSlicedSurveyStopCollectingMessage; +#[allow(unused_imports)] +pub use time_sliced_survey_stop_collecting_message::*; +mod signed_time_sliced_survey_stop_collecting_message; +#[allow(unused_imports)] +pub use signed_time_sliced_survey_stop_collecting_message::*; +mod survey_request_message; +pub use super::SurveyRequestMessage; +#[allow(unused_imports)] +pub use survey_request_message::*; +mod time_sliced_survey_request_message; +pub use super::TimeSlicedSurveyRequestMessage; +#[allow(unused_imports)] +pub use time_sliced_survey_request_message::*; +mod signed_time_sliced_survey_request_message; +#[allow(unused_imports)] +pub use signed_time_sliced_survey_request_message::*; +mod encrypted_body; +#[allow(unused_imports)] +pub use encrypted_body::*; +mod survey_response_message; +#[allow(unused_imports)] +pub use survey_response_message::*; +mod time_sliced_survey_response_message; +#[allow(unused_imports)] +pub use time_sliced_survey_response_message::*; +mod signed_time_sliced_survey_response_message; +#[allow(unused_imports)] +pub use signed_time_sliced_survey_response_message::*; +mod peer_stats; +#[allow(unused_imports)] +pub use peer_stats::*; +mod time_sliced_node_data; +pub use super::TimeSlicedNodeData; +#[allow(unused_imports)] +pub use time_sliced_node_data::*; +mod time_sliced_peer_data; +#[allow(unused_imports)] +pub use time_sliced_peer_data::*; +mod time_sliced_peer_data_list; +#[allow(unused_imports)] +pub use time_sliced_peer_data_list::*; +mod topology_response_body_v2; +#[allow(unused_imports)] +pub use topology_response_body_v2::*; +mod survey_response_body; +pub use super::TX_ADVERT_VECTOR_MAX_SIZE; +#[allow(unused_imports)] +pub use survey_response_body::*; +mod tx_advert_vector; +#[allow(unused_imports)] +pub use tx_advert_vector::*; +mod flood_advert; +pub use super::TX_DEMAND_VECTOR_MAX_SIZE; +#[allow(unused_imports)] +pub use flood_advert::*; +mod tx_demand_vector; +#[allow(unused_imports)] +pub use tx_demand_vector::*; +mod flood_demand; +#[allow(unused_imports)] +pub use flood_demand::*; +mod stellar_message; +#[allow(unused_imports)] +pub use stellar_message::*; +mod authenticated_message_v0; +#[allow(unused_imports)] +pub use authenticated_message_v0::*; +mod authenticated_message; +pub use super::MAX_OPS_PER_TX; +#[allow(unused_imports)] +pub use authenticated_message::*; +mod liquidity_pool_parameters; +pub use super::LiquidityPoolParameters; +#[allow(unused_imports)] +pub use liquidity_pool_parameters::*; +mod muxed_account_med25519; +pub use super::MuxedAccountMed25519; +#[allow(unused_imports)] +pub use muxed_account_med25519::*; +mod muxed_account; +pub use super::MuxedAccount; +#[allow(unused_imports)] +pub use muxed_account::*; +mod decorated_signature; +#[allow(unused_imports)] +pub use decorated_signature::*; +mod operation_type; +pub use super::OperationType; +#[allow(unused_imports)] +pub use operation_type::*; +mod create_account_op; +pub use super::CreateAccountOp; +#[allow(unused_imports)] +pub use create_account_op::*; +mod payment_op; +pub use super::PaymentOp; +#[allow(unused_imports)] +pub use payment_op::*; +mod path_payment_strict_receive_op; +#[allow(unused_imports)] +pub use path_payment_strict_receive_op::*; +mod path_payment_strict_send_op; +#[allow(unused_imports)] +pub use path_payment_strict_send_op::*; +mod manage_sell_offer_op; +pub use super::ManageSellOfferOp; +#[allow(unused_imports)] +pub use manage_sell_offer_op::*; +mod manage_buy_offer_op; +pub use super::ManageBuyOfferOp; +#[allow(unused_imports)] +pub use manage_buy_offer_op::*; +mod create_passive_sell_offer_op; +pub use super::CreatePassiveSellOfferOp; +#[allow(unused_imports)] +pub use create_passive_sell_offer_op::*; +mod set_options_op; +#[allow(unused_imports)] +pub use set_options_op::*; +mod change_trust_asset; +pub use super::ChangeTrustAsset; +#[allow(unused_imports)] +pub use change_trust_asset::*; +mod change_trust_op; +pub use super::ChangeTrustOp; +#[allow(unused_imports)] +pub use change_trust_op::*; +mod allow_trust_op; +pub use super::AllowTrustOp; +#[allow(unused_imports)] +pub use allow_trust_op::*; +mod manage_data_op; +#[allow(unused_imports)] +pub use manage_data_op::*; +mod bump_sequence_op; +pub use super::BumpSequenceOp; +#[allow(unused_imports)] +pub use bump_sequence_op::*; +mod create_claimable_balance_op; +#[allow(unused_imports)] +pub use create_claimable_balance_op::*; +mod claim_claimable_balance_op; +pub use super::ClaimClaimableBalanceOp; +#[allow(unused_imports)] +pub use claim_claimable_balance_op::*; +mod begin_sponsoring_future_reserves_op; +pub use super::BeginSponsoringFutureReservesOp; +#[allow(unused_imports)] +pub use begin_sponsoring_future_reserves_op::*; +mod revoke_sponsorship_type; +pub use super::RevokeSponsorshipType; +#[allow(unused_imports)] +pub use revoke_sponsorship_type::*; +mod revoke_sponsorship_op_signer; +#[allow(unused_imports)] +pub use revoke_sponsorship_op_signer::*; +mod revoke_sponsorship_op; +#[allow(unused_imports)] +pub use revoke_sponsorship_op::*; +mod clawback_op; +pub use super::ClawbackOp; +#[allow(unused_imports)] +pub use clawback_op::*; +mod clawback_claimable_balance_op; +pub use super::ClawbackClaimableBalanceOp; +#[allow(unused_imports)] +pub use clawback_claimable_balance_op::*; +mod set_trust_line_flags_op; +pub use super::SetTrustLineFlagsOp; +pub use super::LIQUIDITY_POOL_FEE_V18; +#[allow(unused_imports)] +pub use set_trust_line_flags_op::*; +mod liquidity_pool_deposit_op; +pub use super::LiquidityPoolDepositOp; +#[allow(unused_imports)] +pub use liquidity_pool_deposit_op::*; +mod liquidity_pool_withdraw_op; +pub use super::LiquidityPoolWithdrawOp; +#[allow(unused_imports)] +pub use liquidity_pool_withdraw_op::*; +mod host_function_type; +pub use super::HostFunctionType; +#[allow(unused_imports)] +pub use host_function_type::*; +mod contract_id_preimage_type; +pub use super::ContractIdPreimageType; +#[allow(unused_imports)] +pub use contract_id_preimage_type::*; +mod contract_id_preimage_from_address; +pub use super::ContractIdPreimageFromAddress; +#[allow(unused_imports)] +pub use contract_id_preimage_from_address::*; +mod contract_id_preimage; +pub use super::ContractIdPreimage; +#[allow(unused_imports)] +pub use contract_id_preimage::*; +mod create_contract_args; +#[allow(unused_imports)] +pub use create_contract_args::*; +mod create_contract_args_v2; +#[allow(unused_imports)] +pub use create_contract_args_v2::*; +mod invoke_contract_args; +#[allow(unused_imports)] +pub use invoke_contract_args::*; +mod host_function; +#[allow(unused_imports)] +pub use host_function::*; +mod soroban_authorized_function_type; +pub use super::SorobanAuthorizedFunctionType; +#[allow(unused_imports)] +pub use soroban_authorized_function_type::*; +mod soroban_authorized_function; +#[allow(unused_imports)] +pub use soroban_authorized_function::*; +mod soroban_authorized_invocation; +#[allow(unused_imports)] +pub use soroban_authorized_invocation::*; +mod soroban_address_credentials; +#[allow(unused_imports)] +pub use soroban_address_credentials::*; +mod soroban_delegate_signature; +#[allow(unused_imports)] +pub use soroban_delegate_signature::*; +mod soroban_address_credentials_with_delegates; +#[allow(unused_imports)] +pub use soroban_address_credentials_with_delegates::*; +mod soroban_credentials_type; +pub use super::SorobanCredentialsType; +#[allow(unused_imports)] +pub use soroban_credentials_type::*; +mod soroban_credentials; +#[allow(unused_imports)] +pub use soroban_credentials::*; +mod soroban_authorization_entry; +#[allow(unused_imports)] +pub use soroban_authorization_entry::*; +mod soroban_authorization_entries; +#[allow(unused_imports)] +pub use soroban_authorization_entries::*; +mod invoke_host_function_op; +#[allow(unused_imports)] +pub use invoke_host_function_op::*; +mod extend_footprint_ttl_op; +pub use super::ExtendFootprintTtlOp; +#[allow(unused_imports)] +pub use extend_footprint_ttl_op::*; +mod restore_footprint_op; +pub use super::RestoreFootprintOp; +#[allow(unused_imports)] +pub use restore_footprint_op::*; +mod operation_body; +#[allow(unused_imports)] +pub use operation_body::*; +mod operation; +#[allow(unused_imports)] +pub use operation::*; +mod hash_id_preimage_operation_id; +pub use super::HashIdPreimageOperationId; +#[allow(unused_imports)] +pub use hash_id_preimage_operation_id::*; +mod hash_id_preimage_revoke_id; +pub use super::HashIdPreimageRevokeId; +#[allow(unused_imports)] +pub use hash_id_preimage_revoke_id::*; +mod hash_id_preimage_contract_id; +pub use super::HashIdPreimageContractId; +#[allow(unused_imports)] +pub use hash_id_preimage_contract_id::*; +mod hash_id_preimage_soroban_authorization; +#[allow(unused_imports)] +pub use hash_id_preimage_soroban_authorization::*; +mod hash_id_preimage_soroban_authorization_with_address; +#[allow(unused_imports)] +pub use hash_id_preimage_soroban_authorization_with_address::*; +mod hash_id_preimage; +#[allow(unused_imports)] +pub use hash_id_preimage::*; +mod memo_type; +pub use super::MemoType; +#[allow(unused_imports)] +pub use memo_type::*; +mod memo; +#[allow(unused_imports)] +pub use memo::*; +mod time_bounds; +pub use super::TimeBounds; +#[allow(unused_imports)] +pub use time_bounds::*; +mod ledger_bounds; +pub use super::LedgerBounds; +#[allow(unused_imports)] +pub use ledger_bounds::*; +mod preconditions_v2; +#[allow(unused_imports)] +pub use preconditions_v2::*; +mod precondition_type; +pub use super::PreconditionType; +#[allow(unused_imports)] +pub use precondition_type::*; +mod preconditions; +#[allow(unused_imports)] +pub use preconditions::*; +mod ledger_footprint; +#[allow(unused_imports)] +pub use ledger_footprint::*; +mod soroban_resources; +#[allow(unused_imports)] +pub use soroban_resources::*; +mod soroban_resources_ext_v0; +#[allow(unused_imports)] +pub use soroban_resources_ext_v0::*; +mod soroban_transaction_data_ext; +#[allow(unused_imports)] +pub use soroban_transaction_data_ext::*; +mod soroban_transaction_data; +#[allow(unused_imports)] +pub use soroban_transaction_data::*; +mod transaction_v0_ext; +pub use super::TransactionV0Ext; +#[allow(unused_imports)] +pub use transaction_v0_ext::*; +mod transaction_v0; +#[allow(unused_imports)] +pub use transaction_v0::*; +mod transaction_v0_envelope; +#[allow(unused_imports)] +pub use transaction_v0_envelope::*; +mod transaction_ext; +#[allow(unused_imports)] +pub use transaction_ext::*; +mod transaction; +#[allow(unused_imports)] +pub use transaction::*; +mod transaction_v1_envelope; +#[allow(unused_imports)] +pub use transaction_v1_envelope::*; +mod fee_bump_transaction_inner_tx; +#[allow(unused_imports)] +pub use fee_bump_transaction_inner_tx::*; +mod fee_bump_transaction_ext; +pub use super::FeeBumpTransactionExt; +#[allow(unused_imports)] +pub use fee_bump_transaction_ext::*; +mod fee_bump_transaction; +#[allow(unused_imports)] +pub use fee_bump_transaction::*; +mod fee_bump_transaction_envelope; +#[allow(unused_imports)] +pub use fee_bump_transaction_envelope::*; +mod transaction_envelope; +#[allow(unused_imports)] +pub use transaction_envelope::*; +mod transaction_signature_payload_tagged_transaction; +#[allow(unused_imports)] +pub use transaction_signature_payload_tagged_transaction::*; +mod transaction_signature_payload; +#[allow(unused_imports)] +pub use transaction_signature_payload::*; +mod claim_atom_type; +pub use super::ClaimAtomType; +#[allow(unused_imports)] +pub use claim_atom_type::*; +mod claim_offer_atom_v0; +pub use super::ClaimOfferAtomV0; +#[allow(unused_imports)] +pub use claim_offer_atom_v0::*; +mod claim_offer_atom; +pub use super::ClaimOfferAtom; +#[allow(unused_imports)] +pub use claim_offer_atom::*; +mod claim_liquidity_atom; +pub use super::ClaimLiquidityAtom; +#[allow(unused_imports)] +pub use claim_liquidity_atom::*; +mod claim_atom; +pub use super::ClaimAtom; +#[allow(unused_imports)] +pub use claim_atom::*; +mod create_account_result_code; +pub use super::CreateAccountResultCode; +#[allow(unused_imports)] +pub use create_account_result_code::*; +mod create_account_result; +pub use super::CreateAccountResult; +#[allow(unused_imports)] +pub use create_account_result::*; +mod payment_result_code; +pub use super::PaymentResultCode; +#[allow(unused_imports)] +pub use payment_result_code::*; +mod payment_result; +pub use super::PaymentResult; +#[allow(unused_imports)] +pub use payment_result::*; +mod path_payment_strict_receive_result_code; +pub use super::PathPaymentStrictReceiveResultCode; +#[allow(unused_imports)] +pub use path_payment_strict_receive_result_code::*; +mod simple_payment_result; +pub use super::SimplePaymentResult; +#[allow(unused_imports)] +pub use simple_payment_result::*; +mod path_payment_strict_receive_result_success; +#[allow(unused_imports)] +pub use path_payment_strict_receive_result_success::*; +mod path_payment_strict_receive_result; +#[allow(unused_imports)] +pub use path_payment_strict_receive_result::*; +mod path_payment_strict_send_result_code; +pub use super::PathPaymentStrictSendResultCode; +#[allow(unused_imports)] +pub use path_payment_strict_send_result_code::*; +mod path_payment_strict_send_result_success; +#[allow(unused_imports)] +pub use path_payment_strict_send_result_success::*; +mod path_payment_strict_send_result; +#[allow(unused_imports)] +pub use path_payment_strict_send_result::*; +mod manage_sell_offer_result_code; +pub use super::ManageSellOfferResultCode; +#[allow(unused_imports)] +pub use manage_sell_offer_result_code::*; +mod manage_offer_effect; +pub use super::ManageOfferEffect; +#[allow(unused_imports)] +pub use manage_offer_effect::*; +mod manage_offer_success_result_offer; +pub use super::ManageOfferSuccessResultOffer; +#[allow(unused_imports)] +pub use manage_offer_success_result_offer::*; +mod manage_offer_success_result; +#[allow(unused_imports)] +pub use manage_offer_success_result::*; +mod manage_sell_offer_result; +#[allow(unused_imports)] +pub use manage_sell_offer_result::*; +mod manage_buy_offer_result_code; +pub use super::ManageBuyOfferResultCode; +#[allow(unused_imports)] +pub use manage_buy_offer_result_code::*; +mod manage_buy_offer_result; +#[allow(unused_imports)] +pub use manage_buy_offer_result::*; +mod set_options_result_code; +pub use super::SetOptionsResultCode; +#[allow(unused_imports)] +pub use set_options_result_code::*; +mod set_options_result; +pub use super::SetOptionsResult; +#[allow(unused_imports)] +pub use set_options_result::*; +mod change_trust_result_code; +pub use super::ChangeTrustResultCode; +#[allow(unused_imports)] +pub use change_trust_result_code::*; +mod change_trust_result; +pub use super::ChangeTrustResult; +#[allow(unused_imports)] +pub use change_trust_result::*; +mod allow_trust_result_code; +pub use super::AllowTrustResultCode; +#[allow(unused_imports)] +pub use allow_trust_result_code::*; +mod allow_trust_result; +pub use super::AllowTrustResult; +#[allow(unused_imports)] +pub use allow_trust_result::*; +mod account_merge_result_code; +pub use super::AccountMergeResultCode; +#[allow(unused_imports)] +pub use account_merge_result_code::*; +mod account_merge_result; +pub use super::AccountMergeResult; +#[allow(unused_imports)] +pub use account_merge_result::*; +mod inflation_result_code; +pub use super::InflationResultCode; +#[allow(unused_imports)] +pub use inflation_result_code::*; +mod inflation_payout; +pub use super::InflationPayout; +#[allow(unused_imports)] +pub use inflation_payout::*; +mod inflation_result; +#[allow(unused_imports)] +pub use inflation_result::*; +mod manage_data_result_code; +pub use super::ManageDataResultCode; +#[allow(unused_imports)] +pub use manage_data_result_code::*; +mod manage_data_result; +pub use super::ManageDataResult; +#[allow(unused_imports)] +pub use manage_data_result::*; +mod bump_sequence_result_code; +pub use super::BumpSequenceResultCode; +#[allow(unused_imports)] +pub use bump_sequence_result_code::*; +mod bump_sequence_result; +pub use super::BumpSequenceResult; +#[allow(unused_imports)] +pub use bump_sequence_result::*; +mod create_claimable_balance_result_code; +pub use super::CreateClaimableBalanceResultCode; +#[allow(unused_imports)] +pub use create_claimable_balance_result_code::*; +mod create_claimable_balance_result; +pub use super::CreateClaimableBalanceResult; +#[allow(unused_imports)] +pub use create_claimable_balance_result::*; +mod claim_claimable_balance_result_code; +pub use super::ClaimClaimableBalanceResultCode; +#[allow(unused_imports)] +pub use claim_claimable_balance_result_code::*; +mod claim_claimable_balance_result; +pub use super::ClaimClaimableBalanceResult; +#[allow(unused_imports)] +pub use claim_claimable_balance_result::*; +mod begin_sponsoring_future_reserves_result_code; +pub use super::BeginSponsoringFutureReservesResultCode; +#[allow(unused_imports)] +pub use begin_sponsoring_future_reserves_result_code::*; +mod begin_sponsoring_future_reserves_result; +pub use super::BeginSponsoringFutureReservesResult; +#[allow(unused_imports)] +pub use begin_sponsoring_future_reserves_result::*; +mod end_sponsoring_future_reserves_result_code; +pub use super::EndSponsoringFutureReservesResultCode; +#[allow(unused_imports)] +pub use end_sponsoring_future_reserves_result_code::*; +mod end_sponsoring_future_reserves_result; +pub use super::EndSponsoringFutureReservesResult; +#[allow(unused_imports)] +pub use end_sponsoring_future_reserves_result::*; +mod revoke_sponsorship_result_code; +pub use super::RevokeSponsorshipResultCode; +#[allow(unused_imports)] +pub use revoke_sponsorship_result_code::*; +mod revoke_sponsorship_result; +pub use super::RevokeSponsorshipResult; +#[allow(unused_imports)] +pub use revoke_sponsorship_result::*; +mod clawback_result_code; +pub use super::ClawbackResultCode; +#[allow(unused_imports)] +pub use clawback_result_code::*; +mod clawback_result; +pub use super::ClawbackResult; +#[allow(unused_imports)] +pub use clawback_result::*; +mod clawback_claimable_balance_result_code; +pub use super::ClawbackClaimableBalanceResultCode; +#[allow(unused_imports)] +pub use clawback_claimable_balance_result_code::*; +mod clawback_claimable_balance_result; +pub use super::ClawbackClaimableBalanceResult; +#[allow(unused_imports)] +pub use clawback_claimable_balance_result::*; +mod set_trust_line_flags_result_code; +pub use super::SetTrustLineFlagsResultCode; +#[allow(unused_imports)] +pub use set_trust_line_flags_result_code::*; +mod set_trust_line_flags_result; +pub use super::SetTrustLineFlagsResult; +#[allow(unused_imports)] +pub use set_trust_line_flags_result::*; +mod liquidity_pool_deposit_result_code; +pub use super::LiquidityPoolDepositResultCode; +#[allow(unused_imports)] +pub use liquidity_pool_deposit_result_code::*; +mod liquidity_pool_deposit_result; +pub use super::LiquidityPoolDepositResult; +#[allow(unused_imports)] +pub use liquidity_pool_deposit_result::*; +mod liquidity_pool_withdraw_result_code; +pub use super::LiquidityPoolWithdrawResultCode; +#[allow(unused_imports)] +pub use liquidity_pool_withdraw_result_code::*; +mod liquidity_pool_withdraw_result; +pub use super::LiquidityPoolWithdrawResult; +#[allow(unused_imports)] +pub use liquidity_pool_withdraw_result::*; +mod invoke_host_function_result_code; +pub use super::InvokeHostFunctionResultCode; +#[allow(unused_imports)] +pub use invoke_host_function_result_code::*; +mod invoke_host_function_result; +pub use super::InvokeHostFunctionResult; +#[allow(unused_imports)] +pub use invoke_host_function_result::*; +mod extend_footprint_ttl_result_code; +pub use super::ExtendFootprintTtlResultCode; +#[allow(unused_imports)] +pub use extend_footprint_ttl_result_code::*; +mod extend_footprint_ttl_result; +pub use super::ExtendFootprintTtlResult; +#[allow(unused_imports)] +pub use extend_footprint_ttl_result::*; +mod restore_footprint_result_code; +pub use super::RestoreFootprintResultCode; +#[allow(unused_imports)] +pub use restore_footprint_result_code::*; +mod restore_footprint_result; +pub use super::RestoreFootprintResult; +#[allow(unused_imports)] +pub use restore_footprint_result::*; +mod operation_result_code; +pub use super::OperationResultCode; +#[allow(unused_imports)] +pub use operation_result_code::*; +mod operation_result_tr; +#[allow(unused_imports)] +pub use operation_result_tr::*; +mod operation_result; +#[allow(unused_imports)] +pub use operation_result::*; +mod transaction_result_code; +pub use super::TransactionResultCode; +#[allow(unused_imports)] +pub use transaction_result_code::*; +mod inner_transaction_result_result; +#[allow(unused_imports)] +pub use inner_transaction_result_result::*; +mod inner_transaction_result_ext; +pub use super::InnerTransactionResultExt; +#[allow(unused_imports)] +pub use inner_transaction_result_ext::*; +mod inner_transaction_result; +#[allow(unused_imports)] +pub use inner_transaction_result::*; +mod inner_transaction_result_pair; +#[allow(unused_imports)] +pub use inner_transaction_result_pair::*; +mod transaction_result_result; +#[allow(unused_imports)] +pub use transaction_result_result::*; +mod transaction_result_ext; +pub use super::TransactionResultExt; +#[allow(unused_imports)] +pub use transaction_result_ext::*; +mod transaction_result; +#[allow(unused_imports)] +pub use transaction_result::*; +mod hash; +pub use super::Hash; +#[allow(unused_imports)] +pub use hash::*; +mod uint256; +pub use super::Int32; +pub use super::Int64; +pub use super::Uint256; +pub use super::Uint32; +pub use super::Uint64; +#[allow(unused_imports)] +pub use uint256::*; +mod time_point; +pub use super::TimePoint; +#[allow(unused_imports)] +pub use time_point::*; +mod duration; +pub use super::Duration; +#[allow(unused_imports)] +pub use duration::*; +mod time_point_milliseconds; +#[cfg(feature = "ms_close_time")] +pub use super::TimePointMilliseconds; +#[allow(unused_imports)] +pub use time_point_milliseconds::*; +mod extension_point; +pub use super::ExtensionPoint; +#[allow(unused_imports)] +pub use extension_point::*; +mod crypto_key_type; +pub use super::CryptoKeyType; +#[allow(unused_imports)] +pub use crypto_key_type::*; +mod public_key_type; +pub use super::PublicKeyType; +#[allow(unused_imports)] +pub use public_key_type::*; +mod signer_key_type; +pub use super::SignerKeyType; +#[allow(unused_imports)] +pub use signer_key_type::*; +mod public_key; +pub use super::PublicKey; +#[allow(unused_imports)] +pub use public_key::*; +mod signer_key_ed25519_signed_payload; +#[allow(unused_imports)] +pub use signer_key_ed25519_signed_payload::*; +mod signer_key; +#[allow(unused_imports)] +pub use signer_key::*; +mod signature; +#[allow(unused_imports)] +pub use signature::*; +mod signature_hint; +pub use super::SignatureHint; +#[allow(unused_imports)] +pub use signature_hint::*; +mod node_id; +pub use super::NodeId; +#[allow(unused_imports)] +pub use node_id::*; +mod account_id; +pub use super::AccountId; +#[allow(unused_imports)] +pub use account_id::*; +mod contract_id; +pub use super::ContractId; +#[allow(unused_imports)] +pub use contract_id::*; +mod curve25519_secret; +pub use super::Curve25519Secret; +#[allow(unused_imports)] +pub use curve25519_secret::*; +mod curve25519_public; +pub use super::Curve25519Public; +#[allow(unused_imports)] +pub use curve25519_public::*; +mod hmac_sha256_key; +pub use super::HmacSha256Key; +#[allow(unused_imports)] +pub use hmac_sha256_key::*; +mod hmac_sha256_mac; +pub use super::HmacSha256Mac; +#[allow(unused_imports)] +pub use hmac_sha256_mac::*; +mod short_hash_seed; +pub use super::ShortHashSeed; +#[allow(unused_imports)] +pub use short_hash_seed::*; +mod binary_fuse_filter_type; +pub use super::BinaryFuseFilterType; +#[allow(unused_imports)] +pub use binary_fuse_filter_type::*; +mod serialized_binary_fuse_filter; +#[allow(unused_imports)] +pub use serialized_binary_fuse_filter::*; +mod pool_id; +pub use super::PoolId; +#[allow(unused_imports)] +pub use pool_id::*; +mod claimable_balance_id_type; +pub use super::ClaimableBalanceIdType; +#[allow(unused_imports)] +pub use claimable_balance_id_type::*; +mod claimable_balance_id; +pub use super::ClaimableBalanceId; +#[allow(unused_imports)] +pub use claimable_balance_id::*; +mod test_next_type; +#[cfg(feature = "test_feature")] +pub use super::TestNextType; +#[allow(unused_imports)] +pub use test_next_type::*; diff --git a/src/generated/const/account_entry.rs b/src/generated/const/account_entry.rs new file mode 100644 index 000000000..efca3e981 --- /dev/null +++ b/src/generated/const/account_entry.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AccountEntry is a borrowing equivalent of [`AccountEntry`](super::super::AccountEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct AccountEntry { + pub account_id: AccountId, + pub balance: i64, + pub seq_num: SequenceNumber, + pub num_sub_entries: u32, + pub inflation_dest: Option, + pub flags: u32, + pub home_domain: String32, + pub thresholds: Thresholds, + pub signers: VecM, + pub ext: AccountEntryExt, +} + +impl AccountEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntry`], mirroring `::write_xdr`. + pub const fn write_type_account_entry(&mut self, v: &AccountEntry) { + self.write_type_account_id(&v.account_id); + self.write_i64(v.balance); + self.write_type_sequence_number(&v.seq_num); + self.write_u32(v.num_sub_entries); + self.write_type_option_account_id(&v.inflation_dest); + self.write_u32(v.flags); + self.write_type_string32(&v.home_domain); + self.write_type_thresholds(&v.thresholds); + self.write_type_vec_signer(&v.signers); + self.write_type_account_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/account_entry_ext.rs b/src/generated/const/account_entry_ext.rs new file mode 100644 index 000000000..530a7e538 --- /dev/null +++ b/src/generated/const/account_entry_ext.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AccountEntryExt is a borrowing equivalent of [`AccountEntryExt`](super::super::AccountEntryExt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum AccountEntryExt { + V0, + V1(AccountEntryExtensionV1), +} + +impl AccountEntryExt { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl AccountEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_ext(&mut self, v: &AccountEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + AccountEntryExt::V0 => {} + AccountEntryExt::V1(value) => { + self.write_type_account_entry_extension_v1(value); + } + } + } +} diff --git a/src/generated/const/account_entry_extension_v1.rs b/src/generated/const/account_entry_extension_v1.rs new file mode 100644 index 000000000..abb1b824e --- /dev/null +++ b/src/generated/const/account_entry_extension_v1.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AccountEntryExtensionV1 is a borrowing equivalent of [`AccountEntryExtensionV1`](super::super::AccountEntryExtensionV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct AccountEntryExtensionV1 { + pub liabilities: Liabilities, + pub ext: AccountEntryExtensionV1Ext, +} + +impl AccountEntryExtensionV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_extension_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_extension_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExtensionV1`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_extension_v1(&mut self, v: &AccountEntryExtensionV1) { + self.write_type_liabilities(&v.liabilities); + self.write_type_account_entry_extension_v1_ext(&v.ext); + } +} diff --git a/src/generated/const/account_entry_extension_v1_ext.rs b/src/generated/const/account_entry_extension_v1_ext.rs new file mode 100644 index 000000000..fa01ebf15 --- /dev/null +++ b/src/generated/const/account_entry_extension_v1_ext.rs @@ -0,0 +1,78 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AccountEntryExtensionV1Ext is a borrowing equivalent of [`AccountEntryExtensionV1Ext`](super::super::AccountEntryExtensionV1Ext) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum AccountEntryExtensionV1Ext { + V0, + V2(AccountEntryExtensionV2), +} + +impl AccountEntryExtensionV1Ext { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V2(_) => 2, + } + } +} + +impl AccountEntryExtensionV1Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_extension_v1_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_extension_v1_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExtensionV1Ext`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_extension_v1_ext( + &mut self, + v: &AccountEntryExtensionV1Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + AccountEntryExtensionV1Ext::V0 => {} + AccountEntryExtensionV1Ext::V2(value) => { + self.write_type_account_entry_extension_v2(value); + } + } + } +} diff --git a/src/generated/const/account_entry_extension_v2.rs b/src/generated/const/account_entry_extension_v2.rs new file mode 100644 index 000000000..e9108cee0 --- /dev/null +++ b/src/generated/const/account_entry_extension_v2.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AccountEntryExtensionV2 is a borrowing equivalent of [`AccountEntryExtensionV2`](super::super::AccountEntryExtensionV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct AccountEntryExtensionV2 { + pub num_sponsored: u32, + pub num_sponsoring: u32, + pub signer_sponsoring_i_ds: VecM, + pub ext: AccountEntryExtensionV2Ext, +} + +impl AccountEntryExtensionV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_extension_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_extension_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExtensionV2`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_extension_v2(&mut self, v: &AccountEntryExtensionV2) { + self.write_u32(v.num_sponsored); + self.write_u32(v.num_sponsoring); + self.write_type_vec_sponsorship_descriptor(&v.signer_sponsoring_i_ds); + self.write_type_account_entry_extension_v2_ext(&v.ext); + } +} diff --git a/src/generated/const/account_entry_extension_v2_ext.rs b/src/generated/const/account_entry_extension_v2_ext.rs new file mode 100644 index 000000000..ab9f1d069 --- /dev/null +++ b/src/generated/const/account_entry_extension_v2_ext.rs @@ -0,0 +1,57 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountEntryExtensionV2Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_extension_v2_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_extension_v2_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExtensionV2Ext`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_extension_v2_ext( + &mut self, + v: &AccountEntryExtensionV2Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + AccountEntryExtensionV2Ext::V0 => {} + AccountEntryExtensionV2Ext::V3(value) => { + self.write_type_account_entry_extension_v3(value); + } + } + } +} diff --git a/src/generated/const/account_entry_extension_v3.rs b/src/generated/const/account_entry_extension_v3.rs new file mode 100644 index 000000000..cde7ab6a5 --- /dev/null +++ b/src/generated/const/account_entry_extension_v3.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountEntryExtensionV3 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_entry_extension_v3(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_entry_extension_v3(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountEntryExtensionV3`], mirroring `::write_xdr`. + pub const fn write_type_account_entry_extension_v3(&mut self, v: &AccountEntryExtensionV3) { + self.write_type_extension_point(&v.ext); + self.write_u32(v.seq_ledger); + self.write_type_time_point(&v.seq_time); + } +} diff --git a/src/generated/const/account_flags.rs b/src/generated/const/account_flags.rs new file mode 100644 index 000000000..a065aab7d --- /dev/null +++ b/src/generated/const/account_flags.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountFlags { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_flags(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_flags(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountFlags`], mirroring `::write_xdr`. + pub const fn write_type_account_flags(&mut self, v: &AccountFlags) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/account_id.rs b/src/generated/const/account_id.rs new file mode 100644 index 000000000..6ce970490 --- /dev/null +++ b/src/generated/const/account_id.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountId`], mirroring `::write_xdr`. + pub const fn write_type_account_id(&mut self, v: &AccountId) { + self.write_type_public_key(&v.0); + } + + /// Serializes an optional [`AccountId`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_account_id(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_account_id(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/account_merge_result.rs b/src/generated/const/account_merge_result.rs new file mode 100644 index 000000000..588c261e9 --- /dev/null +++ b/src/generated/const/account_merge_result.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountMergeResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_merge_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_merge_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountMergeResult`], mirroring `::write_xdr`. + pub const fn write_type_account_merge_result(&mut self, v: &AccountMergeResult) { + let d = v.discriminant(); + self.write_type_account_merge_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + AccountMergeResult::Success(value) => { + self.write_i64(*value); + } + AccountMergeResult::Malformed => {} + AccountMergeResult::NoAccount => {} + AccountMergeResult::ImmutableSet => {} + AccountMergeResult::HasSubEntries => {} + AccountMergeResult::SeqnumTooFar => {} + AccountMergeResult::DestFull => {} + AccountMergeResult::IsSponsor => {} + } + } +} diff --git a/src/generated/const/account_merge_result_code.rs b/src/generated/const/account_merge_result_code.rs new file mode 100644 index 000000000..411fac203 --- /dev/null +++ b/src/generated/const/account_merge_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AccountMergeResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_account_merge_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_account_merge_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AccountMergeResultCode`], mirroring `::write_xdr`. + pub const fn write_type_account_merge_result_code(&mut self, v: &AccountMergeResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/allow_trust_op.rs b/src/generated/const/allow_trust_op.rs new file mode 100644 index 000000000..bfd74447f --- /dev/null +++ b/src/generated/const/allow_trust_op.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AllowTrustOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_allow_trust_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_allow_trust_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AllowTrustOp`], mirroring `::write_xdr`. + pub const fn write_type_allow_trust_op(&mut self, v: &AllowTrustOp) { + self.write_type_account_id(&v.trustor); + self.write_type_asset_code(&v.asset); + self.write_u32(v.authorize); + } +} diff --git a/src/generated/const/allow_trust_result.rs b/src/generated/const/allow_trust_result.rs new file mode 100644 index 000000000..deb63081a --- /dev/null +++ b/src/generated/const/allow_trust_result.rs @@ -0,0 +1,57 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AllowTrustResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_allow_trust_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_allow_trust_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AllowTrustResult`], mirroring `::write_xdr`. + pub const fn write_type_allow_trust_result(&mut self, v: &AllowTrustResult) { + let d = v.discriminant(); + self.write_type_allow_trust_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + AllowTrustResult::Success => {} + AllowTrustResult::Malformed => {} + AllowTrustResult::NoTrustLine => {} + AllowTrustResult::TrustNotRequired => {} + AllowTrustResult::CantRevoke => {} + AllowTrustResult::SelfNotAllowed => {} + AllowTrustResult::LowReserve => {} + } + } +} diff --git a/src/generated/const/allow_trust_result_code.rs b/src/generated/const/allow_trust_result_code.rs new file mode 100644 index 000000000..8a67dfa65 --- /dev/null +++ b/src/generated/const/allow_trust_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AllowTrustResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_allow_trust_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_allow_trust_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AllowTrustResultCode`], mirroring `::write_xdr`. + pub const fn write_type_allow_trust_result_code(&mut self, v: &AllowTrustResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/alpha_num12.rs b/src/generated/const/alpha_num12.rs new file mode 100644 index 000000000..379fa75df --- /dev/null +++ b/src/generated/const/alpha_num12.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AlphaNum12 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_alpha_num12(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_alpha_num12(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AlphaNum12`], mirroring `::write_xdr`. + pub const fn write_type_alpha_num12(&mut self, v: &AlphaNum12) { + self.write_type_asset_code12(&v.asset_code); + self.write_type_account_id(&v.issuer); + } +} diff --git a/src/generated/const/alpha_num4.rs b/src/generated/const/alpha_num4.rs new file mode 100644 index 000000000..a64cb946d --- /dev/null +++ b/src/generated/const/alpha_num4.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AlphaNum4 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_alpha_num4(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_alpha_num4(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AlphaNum4`], mirroring `::write_xdr`. + pub const fn write_type_alpha_num4(&mut self, v: &AlphaNum4) { + self.write_type_asset_code4(&v.asset_code); + self.write_type_account_id(&v.issuer); + } +} diff --git a/src/generated/const/asset.rs b/src/generated/const/asset.rs new file mode 100644 index 000000000..642225aab --- /dev/null +++ b/src/generated/const/asset.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Asset { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_asset(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_asset(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Asset`], mirroring `::write_xdr`. + pub const fn write_type_asset(&mut self, v: &Asset) { + let d = v.discriminant(); + self.write_type_asset_type(&d); + #[allow(clippy::match_same_arms)] + match v { + Asset::Native => {} + Asset::CreditAlphanum4(value) => { + self.write_type_alpha_num4(value); + } + Asset::CreditAlphanum12(value) => { + self.write_type_alpha_num12(value); + } + } + } + + /// Serializes a variable-length array of [`Asset`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_asset(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_asset(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/asset_code.rs b/src/generated/const/asset_code.rs new file mode 100644 index 000000000..e1b996ff3 --- /dev/null +++ b/src/generated/const/asset_code.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AssetCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_asset_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_asset_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AssetCode`], mirroring `::write_xdr`. + pub const fn write_type_asset_code(&mut self, v: &AssetCode) { + let d = v.discriminant(); + self.write_type_asset_type(&d); + #[allow(clippy::match_same_arms)] + match v { + AssetCode::CreditAlphanum4(value) => { + self.write_type_asset_code4(value); + } + AssetCode::CreditAlphanum12(value) => { + self.write_type_asset_code12(value); + } + } + } +} diff --git a/src/generated/const/asset_code12.rs b/src/generated/const/asset_code12.rs new file mode 100644 index 000000000..2258323e2 --- /dev/null +++ b/src/generated/const/asset_code12.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AssetCode12 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_asset_code12(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_asset_code12(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AssetCode12`], mirroring `::write_xdr`. + pub const fn write_type_asset_code12(&mut self, v: &AssetCode12) { + self.write_fixed_opaque(&v.0); + } +} diff --git a/src/generated/const/asset_code4.rs b/src/generated/const/asset_code4.rs new file mode 100644 index 000000000..98c5543de --- /dev/null +++ b/src/generated/const/asset_code4.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AssetCode4 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_asset_code4(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_asset_code4(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AssetCode4`], mirroring `::write_xdr`. + pub const fn write_type_asset_code4(&mut self, v: &AssetCode4) { + self.write_fixed_opaque(&v.0); + } +} diff --git a/src/generated/const/asset_type.rs b/src/generated/const/asset_type.rs new file mode 100644 index 000000000..a76dddb29 --- /dev/null +++ b/src/generated/const/asset_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl AssetType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_asset_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_asset_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AssetType`], mirroring `::write_xdr`. + pub const fn write_type_asset_type(&mut self, v: &AssetType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/auth.rs b/src/generated/const/auth.rs new file mode 100644 index 000000000..9c0b732ab --- /dev/null +++ b/src/generated/const/auth.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Auth { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_auth(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_auth(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Auth`], mirroring `::write_xdr`. + pub const fn write_type_auth(&mut self, v: &Auth) { + self.write_i32(v.flags); + } +} diff --git a/src/generated/const/auth_cert.rs b/src/generated/const/auth_cert.rs new file mode 100644 index 000000000..ee60d711a --- /dev/null +++ b/src/generated/const/auth_cert.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AuthCert is a borrowing equivalent of [`AuthCert`](super::super::AuthCert) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct AuthCert { + pub pubkey: Curve25519Public, + pub expiration: u64, + pub sig: Signature, +} + +impl AuthCert { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_auth_cert(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_auth_cert(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AuthCert`], mirroring `::write_xdr`. + pub const fn write_type_auth_cert(&mut self, v: &AuthCert) { + self.write_type_curve25519_public(&v.pubkey); + self.write_u64(v.expiration); + self.write_type_signature(&v.sig); + } +} diff --git a/src/generated/const/authenticated_message.rs b/src/generated/const/authenticated_message.rs new file mode 100644 index 000000000..2bfc30f62 --- /dev/null +++ b/src/generated/const/authenticated_message.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AuthenticatedMessage is a borrowing equivalent of [`AuthenticatedMessage`](super::super::AuthenticatedMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum AuthenticatedMessage { + V0(AuthenticatedMessageV0), +} + +impl AuthenticatedMessage { + #[must_use] + pub const fn discriminant(&self) -> u32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl AuthenticatedMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_authenticated_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_authenticated_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AuthenticatedMessage`], mirroring `::write_xdr`. + pub const fn write_type_authenticated_message(&mut self, v: &AuthenticatedMessage) { + let d = v.discriminant(); + self.write_u32(d); + #[allow(clippy::match_same_arms)] + match v { + AuthenticatedMessage::V0(value) => { + self.write_type_authenticated_message_v0(value); + } + } + } +} diff --git a/src/generated/const/authenticated_message_v0.rs b/src/generated/const/authenticated_message_v0.rs new file mode 100644 index 000000000..f27e9a461 --- /dev/null +++ b/src/generated/const/authenticated_message_v0.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// AuthenticatedMessageV0 is a borrowing equivalent of [`AuthenticatedMessageV0`](super::super::AuthenticatedMessageV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct AuthenticatedMessageV0 { + pub sequence: u64, + pub message: StellarMessage, + pub mac: HmacSha256Mac, +} + +impl AuthenticatedMessageV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_authenticated_message_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_authenticated_message_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`AuthenticatedMessageV0`], mirroring `::write_xdr`. + pub const fn write_type_authenticated_message_v0(&mut self, v: &AuthenticatedMessageV0) { + self.write_u64(v.sequence); + self.write_type_stellar_message(&v.message); + self.write_type_hmac_sha256_mac(&v.mac); + } +} diff --git a/src/generated/const/begin_sponsoring_future_reserves_op.rs b/src/generated/const/begin_sponsoring_future_reserves_op.rs new file mode 100644 index 000000000..c5003183e --- /dev/null +++ b/src/generated/const/begin_sponsoring_future_reserves_op.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BeginSponsoringFutureReservesOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_begin_sponsoring_future_reserves_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_begin_sponsoring_future_reserves_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BeginSponsoringFutureReservesOp`], mirroring `::write_xdr`. + pub const fn write_type_begin_sponsoring_future_reserves_op( + &mut self, + v: &BeginSponsoringFutureReservesOp, + ) { + self.write_type_account_id(&v.sponsored_id); + } +} diff --git a/src/generated/const/begin_sponsoring_future_reserves_result.rs b/src/generated/const/begin_sponsoring_future_reserves_result.rs new file mode 100644 index 000000000..3c5a2d944 --- /dev/null +++ b/src/generated/const/begin_sponsoring_future_reserves_result.rs @@ -0,0 +1,57 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BeginSponsoringFutureReservesResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_begin_sponsoring_future_reserves_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_begin_sponsoring_future_reserves_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BeginSponsoringFutureReservesResult`], mirroring `::write_xdr`. + pub const fn write_type_begin_sponsoring_future_reserves_result( + &mut self, + v: &BeginSponsoringFutureReservesResult, + ) { + let d = v.discriminant(); + self.write_type_begin_sponsoring_future_reserves_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + BeginSponsoringFutureReservesResult::Success => {} + BeginSponsoringFutureReservesResult::Malformed => {} + BeginSponsoringFutureReservesResult::AlreadySponsored => {} + BeginSponsoringFutureReservesResult::Recursive => {} + } + } +} diff --git a/src/generated/const/begin_sponsoring_future_reserves_result_code.rs b/src/generated/const/begin_sponsoring_future_reserves_result_code.rs new file mode 100644 index 000000000..a6f0dfa59 --- /dev/null +++ b/src/generated/const/begin_sponsoring_future_reserves_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BeginSponsoringFutureReservesResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_begin_sponsoring_future_reserves_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_begin_sponsoring_future_reserves_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BeginSponsoringFutureReservesResultCode`], mirroring `::write_xdr`. + pub const fn write_type_begin_sponsoring_future_reserves_result_code( + &mut self, + v: &BeginSponsoringFutureReservesResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/binary_fuse_filter_type.rs b/src/generated/const/binary_fuse_filter_type.rs new file mode 100644 index 000000000..6116b67dc --- /dev/null +++ b/src/generated/const/binary_fuse_filter_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BinaryFuseFilterType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_binary_fuse_filter_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_binary_fuse_filter_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BinaryFuseFilterType`], mirroring `::write_xdr`. + pub const fn write_type_binary_fuse_filter_type(&mut self, v: &BinaryFuseFilterType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/bucket_entry.rs b/src/generated/const/bucket_entry.rs new file mode 100644 index 000000000..4a62680e2 --- /dev/null +++ b/src/generated/const/bucket_entry.rs @@ -0,0 +1,87 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// BucketEntry is a borrowing equivalent of [`BucketEntry`](super::super::BucketEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum BucketEntry { + Liveentry(LedgerEntry), + Initentry(LedgerEntry), + Deadentry(LedgerKey), + Metaentry(BucketMetadata), +} + +impl BucketEntry { + #[must_use] + pub const fn discriminant(&self) -> BucketEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Liveentry(_) => BucketEntryType::Liveentry, + Self::Initentry(_) => BucketEntryType::Initentry, + Self::Deadentry(_) => BucketEntryType::Deadentry, + Self::Metaentry(_) => BucketEntryType::Metaentry, + } + } +} + +impl BucketEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bucket_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bucket_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BucketEntry`], mirroring `::write_xdr`. + pub const fn write_type_bucket_entry(&mut self, v: &BucketEntry) { + let d = v.discriminant(); + self.write_type_bucket_entry_type(&d); + #[allow(clippy::match_same_arms)] + match v { + BucketEntry::Liveentry(value) => { + self.write_type_ledger_entry(value); + } + BucketEntry::Initentry(value) => { + self.write_type_ledger_entry(value); + } + BucketEntry::Deadentry(value) => { + self.write_type_ledger_key(value); + } + BucketEntry::Metaentry(value) => { + self.write_type_bucket_metadata(value); + } + } + } +} diff --git a/src/generated/const/bucket_entry_type.rs b/src/generated/const/bucket_entry_type.rs new file mode 100644 index 000000000..4fdb3267f --- /dev/null +++ b/src/generated/const/bucket_entry_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BucketEntryType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bucket_entry_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bucket_entry_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BucketEntryType`], mirroring `::write_xdr`. + pub const fn write_type_bucket_entry_type(&mut self, v: &BucketEntryType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/bucket_list_type.rs b/src/generated/const/bucket_list_type.rs new file mode 100644 index 000000000..eb772064b --- /dev/null +++ b/src/generated/const/bucket_list_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BucketListType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bucket_list_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bucket_list_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BucketListType`], mirroring `::write_xdr`. + pub const fn write_type_bucket_list_type(&mut self, v: &BucketListType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/bucket_metadata.rs b/src/generated/const/bucket_metadata.rs new file mode 100644 index 000000000..d559e8b27 --- /dev/null +++ b/src/generated/const/bucket_metadata.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BucketMetadata { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bucket_metadata(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bucket_metadata(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BucketMetadata`], mirroring `::write_xdr`. + pub const fn write_type_bucket_metadata(&mut self, v: &BucketMetadata) { + self.write_u32(v.ledger_version); + self.write_type_bucket_metadata_ext(&v.ext); + } +} diff --git a/src/generated/const/bucket_metadata_ext.rs b/src/generated/const/bucket_metadata_ext.rs new file mode 100644 index 000000000..aa439a53c --- /dev/null +++ b/src/generated/const/bucket_metadata_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BucketMetadataExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bucket_metadata_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bucket_metadata_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BucketMetadataExt`], mirroring `::write_xdr`. + pub const fn write_type_bucket_metadata_ext(&mut self, v: &BucketMetadataExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + BucketMetadataExt::V0 => {} + BucketMetadataExt::V1(value) => { + self.write_type_bucket_list_type(value); + } + } + } +} diff --git a/src/generated/const/bump_sequence_op.rs b/src/generated/const/bump_sequence_op.rs new file mode 100644 index 000000000..c5f4f4b3b --- /dev/null +++ b/src/generated/const/bump_sequence_op.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BumpSequenceOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bump_sequence_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bump_sequence_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BumpSequenceOp`], mirroring `::write_xdr`. + pub const fn write_type_bump_sequence_op(&mut self, v: &BumpSequenceOp) { + self.write_type_sequence_number(&v.bump_to); + } +} diff --git a/src/generated/const/bump_sequence_result.rs b/src/generated/const/bump_sequence_result.rs new file mode 100644 index 000000000..6136b27dd --- /dev/null +++ b/src/generated/const/bump_sequence_result.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BumpSequenceResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bump_sequence_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bump_sequence_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BumpSequenceResult`], mirroring `::write_xdr`. + pub const fn write_type_bump_sequence_result(&mut self, v: &BumpSequenceResult) { + let d = v.discriminant(); + self.write_type_bump_sequence_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + BumpSequenceResult::Success => {} + BumpSequenceResult::BadSeq => {} + } + } +} diff --git a/src/generated/const/bump_sequence_result_code.rs b/src/generated/const/bump_sequence_result_code.rs new file mode 100644 index 000000000..c668e7d5d --- /dev/null +++ b/src/generated/const/bump_sequence_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl BumpSequenceResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_bump_sequence_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_bump_sequence_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`BumpSequenceResultCode`], mirroring `::write_xdr`. + pub const fn write_type_bump_sequence_result_code(&mut self, v: &BumpSequenceResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/change_trust_asset.rs b/src/generated/const/change_trust_asset.rs new file mode 100644 index 000000000..a1ca96cdd --- /dev/null +++ b/src/generated/const/change_trust_asset.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ChangeTrustAsset { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_change_trust_asset(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_change_trust_asset(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ChangeTrustAsset`], mirroring `::write_xdr`. + pub const fn write_type_change_trust_asset(&mut self, v: &ChangeTrustAsset) { + let d = v.discriminant(); + self.write_type_asset_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ChangeTrustAsset::Native => {} + ChangeTrustAsset::CreditAlphanum4(value) => { + self.write_type_alpha_num4(value); + } + ChangeTrustAsset::CreditAlphanum12(value) => { + self.write_type_alpha_num12(value); + } + ChangeTrustAsset::PoolShare(value) => { + self.write_type_liquidity_pool_parameters(value); + } + } + } +} diff --git a/src/generated/const/change_trust_op.rs b/src/generated/const/change_trust_op.rs new file mode 100644 index 000000000..94c653da2 --- /dev/null +++ b/src/generated/const/change_trust_op.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ChangeTrustOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_change_trust_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_change_trust_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ChangeTrustOp`], mirroring `::write_xdr`. + pub const fn write_type_change_trust_op(&mut self, v: &ChangeTrustOp) { + self.write_type_change_trust_asset(&v.line); + self.write_i64(v.limit); + } +} diff --git a/src/generated/const/change_trust_result.rs b/src/generated/const/change_trust_result.rs new file mode 100644 index 000000000..cbe6d1335 --- /dev/null +++ b/src/generated/const/change_trust_result.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ChangeTrustResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_change_trust_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_change_trust_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ChangeTrustResult`], mirroring `::write_xdr`. + pub const fn write_type_change_trust_result(&mut self, v: &ChangeTrustResult) { + let d = v.discriminant(); + self.write_type_change_trust_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ChangeTrustResult::Success => {} + ChangeTrustResult::Malformed => {} + ChangeTrustResult::NoIssuer => {} + ChangeTrustResult::InvalidLimit => {} + ChangeTrustResult::LowReserve => {} + ChangeTrustResult::SelfNotAllowed => {} + ChangeTrustResult::TrustLineMissing => {} + ChangeTrustResult::CannotDelete => {} + ChangeTrustResult::NotAuthMaintainLiabilities => {} + } + } +} diff --git a/src/generated/const/change_trust_result_code.rs b/src/generated/const/change_trust_result_code.rs new file mode 100644 index 000000000..64f710f0e --- /dev/null +++ b/src/generated/const/change_trust_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ChangeTrustResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_change_trust_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_change_trust_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ChangeTrustResultCode`], mirroring `::write_xdr`. + pub const fn write_type_change_trust_result_code(&mut self, v: &ChangeTrustResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claim_atom.rs b/src/generated/const/claim_atom.rs new file mode 100644 index 000000000..10566c962 --- /dev/null +++ b/src/generated/const/claim_atom.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimAtom { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_atom(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_atom(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimAtom`], mirroring `::write_xdr`. + pub const fn write_type_claim_atom(&mut self, v: &ClaimAtom) { + let d = v.discriminant(); + self.write_type_claim_atom_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ClaimAtom::V0(value) => { + self.write_type_claim_offer_atom_v0(value); + } + ClaimAtom::OrderBook(value) => { + self.write_type_claim_offer_atom(value); + } + ClaimAtom::LiquidityPool(value) => { + self.write_type_claim_liquidity_atom(value); + } + } + } + + /// Serializes a variable-length array of [`ClaimAtom`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_claim_atom(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_claim_atom(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/claim_atom_type.rs b/src/generated/const/claim_atom_type.rs new file mode 100644 index 000000000..02c5cd1bb --- /dev/null +++ b/src/generated/const/claim_atom_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimAtomType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_atom_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_atom_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimAtomType`], mirroring `::write_xdr`. + pub const fn write_type_claim_atom_type(&mut self, v: &ClaimAtomType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claim_claimable_balance_op.rs b/src/generated/const/claim_claimable_balance_op.rs new file mode 100644 index 000000000..2646afc0e --- /dev/null +++ b/src/generated/const/claim_claimable_balance_op.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimClaimableBalanceOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_claimable_balance_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_claimable_balance_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimClaimableBalanceOp`], mirroring `::write_xdr`. + pub const fn write_type_claim_claimable_balance_op(&mut self, v: &ClaimClaimableBalanceOp) { + self.write_type_claimable_balance_id(&v.balance_id); + } +} diff --git a/src/generated/const/claim_claimable_balance_result.rs b/src/generated/const/claim_claimable_balance_result.rs new file mode 100644 index 000000000..37d3b2d11 --- /dev/null +++ b/src/generated/const/claim_claimable_balance_result.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimClaimableBalanceResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_claimable_balance_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_claimable_balance_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimClaimableBalanceResult`], mirroring `::write_xdr`. + pub const fn write_type_claim_claimable_balance_result( + &mut self, + v: &ClaimClaimableBalanceResult, + ) { + let d = v.discriminant(); + self.write_type_claim_claimable_balance_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ClaimClaimableBalanceResult::Success => {} + ClaimClaimableBalanceResult::DoesNotExist => {} + ClaimClaimableBalanceResult::CannotClaim => {} + ClaimClaimableBalanceResult::LineFull => {} + ClaimClaimableBalanceResult::NoTrust => {} + ClaimClaimableBalanceResult::NotAuthorized => {} + ClaimClaimableBalanceResult::TrustlineFrozen => {} + } + } +} diff --git a/src/generated/const/claim_claimable_balance_result_code.rs b/src/generated/const/claim_claimable_balance_result_code.rs new file mode 100644 index 000000000..7f1943801 --- /dev/null +++ b/src/generated/const/claim_claimable_balance_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimClaimableBalanceResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_claimable_balance_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_claimable_balance_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimClaimableBalanceResultCode`], mirroring `::write_xdr`. + pub const fn write_type_claim_claimable_balance_result_code( + &mut self, + v: &ClaimClaimableBalanceResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claim_liquidity_atom.rs b/src/generated/const/claim_liquidity_atom.rs new file mode 100644 index 000000000..1eb9dfc03 --- /dev/null +++ b/src/generated/const/claim_liquidity_atom.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimLiquidityAtom { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_liquidity_atom(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_liquidity_atom(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimLiquidityAtom`], mirroring `::write_xdr`. + pub const fn write_type_claim_liquidity_atom(&mut self, v: &ClaimLiquidityAtom) { + self.write_type_pool_id(&v.liquidity_pool_id); + self.write_type_asset(&v.asset_sold); + self.write_i64(v.amount_sold); + self.write_type_asset(&v.asset_bought); + self.write_i64(v.amount_bought); + } +} diff --git a/src/generated/const/claim_offer_atom.rs b/src/generated/const/claim_offer_atom.rs new file mode 100644 index 000000000..33e482d48 --- /dev/null +++ b/src/generated/const/claim_offer_atom.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimOfferAtom { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_offer_atom(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_offer_atom(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimOfferAtom`], mirroring `::write_xdr`. + pub const fn write_type_claim_offer_atom(&mut self, v: &ClaimOfferAtom) { + self.write_type_account_id(&v.seller_id); + self.write_i64(v.offer_id); + self.write_type_asset(&v.asset_sold); + self.write_i64(v.amount_sold); + self.write_type_asset(&v.asset_bought); + self.write_i64(v.amount_bought); + } +} diff --git a/src/generated/const/claim_offer_atom_v0.rs b/src/generated/const/claim_offer_atom_v0.rs new file mode 100644 index 000000000..6071ab1aa --- /dev/null +++ b/src/generated/const/claim_offer_atom_v0.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimOfferAtomV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_offer_atom_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_offer_atom_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimOfferAtomV0`], mirroring `::write_xdr`. + pub const fn write_type_claim_offer_atom_v0(&mut self, v: &ClaimOfferAtomV0) { + self.write_type_uint256(&v.seller_ed25519); + self.write_i64(v.offer_id); + self.write_type_asset(&v.asset_sold); + self.write_i64(v.amount_sold); + self.write_type_asset(&v.asset_bought); + self.write_i64(v.amount_bought); + } +} diff --git a/src/generated/const/claim_predicate.rs b/src/generated/const/claim_predicate.rs new file mode 100644 index 000000000..3a461ec74 --- /dev/null +++ b/src/generated/const/claim_predicate.rs @@ -0,0 +1,129 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ClaimPredicate is a borrowing equivalent of [`ClaimPredicate`](super::super::ClaimPredicate) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ClaimPredicate { + Unconditional, + And(VecM), + Or(VecM), + Not( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_option_ref::))] + Option<&'static ClaimPredicate>, + ), + BeforeAbsoluteTime(i64), + BeforeRelativeTime(i64), +} + +impl ClaimPredicate { + #[must_use] + pub const fn discriminant(&self) -> ClaimPredicateType { + #[allow(clippy::match_same_arms)] + match self { + Self::Unconditional => ClaimPredicateType::Unconditional, + Self::And(_) => ClaimPredicateType::And, + Self::Or(_) => ClaimPredicateType::Or, + Self::Not(_) => ClaimPredicateType::Not, + Self::BeforeAbsoluteTime(_) => ClaimPredicateType::BeforeAbsoluteTime, + Self::BeforeRelativeTime(_) => ClaimPredicateType::BeforeRelativeTime, + } + } +} + +impl ClaimPredicate { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_predicate(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_predicate(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimPredicate`], mirroring `::write_xdr`. + pub const fn write_type_claim_predicate(&mut self, v: &ClaimPredicate) { + let d = v.discriminant(); + self.write_type_claim_predicate_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ClaimPredicate::Unconditional => {} + ClaimPredicate::And(value) => { + self.write_type_vec_claim_predicate(value); + } + ClaimPredicate::Or(value) => { + self.write_type_vec_claim_predicate(value); + } + ClaimPredicate::Not(value) => { + self.write_type_option_ref_claim_predicate(*value); + } + ClaimPredicate::BeforeAbsoluteTime(value) => { + self.write_i64(*value); + } + ClaimPredicate::BeforeRelativeTime(value) => { + self.write_i64(*value); + } + } + } + + /// Serializes an optional [`ClaimPredicate`], mirroring `> as WriteXdr>::write_xdr`. + pub const fn write_type_option_ref_claim_predicate( + &mut self, + v: Option<&'static ClaimPredicate>, + ) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_claim_predicate(v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes a variable-length array of [`ClaimPredicate`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_claim_predicate( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_claim_predicate(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/claim_predicate_type.rs b/src/generated/const/claim_predicate_type.rs new file mode 100644 index 000000000..d94248020 --- /dev/null +++ b/src/generated/const/claim_predicate_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimPredicateType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claim_predicate_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claim_predicate_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimPredicateType`], mirroring `::write_xdr`. + pub const fn write_type_claim_predicate_type(&mut self, v: &ClaimPredicateType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claimable_balance_entry.rs b/src/generated/const/claimable_balance_entry.rs new file mode 100644 index 000000000..f821032c9 --- /dev/null +++ b/src/generated/const/claimable_balance_entry.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ClaimableBalanceEntry is a borrowing equivalent of [`ClaimableBalanceEntry`](super::super::ClaimableBalanceEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ClaimableBalanceEntry { + pub balance_id: ClaimableBalanceId, + pub claimants: VecM, + pub asset: Asset, + pub amount: i64, + pub ext: ClaimableBalanceEntryExt, +} + +impl ClaimableBalanceEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceEntry`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_entry(&mut self, v: &ClaimableBalanceEntry) { + self.write_type_claimable_balance_id(&v.balance_id); + self.write_type_vec_claimant(&v.claimants); + self.write_type_asset(&v.asset); + self.write_i64(v.amount); + self.write_type_claimable_balance_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/claimable_balance_entry_ext.rs b/src/generated/const/claimable_balance_entry_ext.rs new file mode 100644 index 000000000..c05de52a4 --- /dev/null +++ b/src/generated/const/claimable_balance_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_entry_ext(&mut self, v: &ClaimableBalanceEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ClaimableBalanceEntryExt::V0 => {} + ClaimableBalanceEntryExt::V1(value) => { + self.write_type_claimable_balance_entry_extension_v1(value); + } + } + } +} diff --git a/src/generated/const/claimable_balance_entry_extension_v1.rs b/src/generated/const/claimable_balance_entry_extension_v1.rs new file mode 100644 index 000000000..333ad68a0 --- /dev/null +++ b/src/generated/const/claimable_balance_entry_extension_v1.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceEntryExtensionV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_entry_extension_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_entry_extension_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceEntryExtensionV1`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_entry_extension_v1( + &mut self, + v: &ClaimableBalanceEntryExtensionV1, + ) { + self.write_type_claimable_balance_entry_extension_v1_ext(&v.ext); + self.write_u32(v.flags); + } +} diff --git a/src/generated/const/claimable_balance_entry_extension_v1_ext.rs b/src/generated/const/claimable_balance_entry_extension_v1_ext.rs new file mode 100644 index 000000000..d2197f333 --- /dev/null +++ b/src/generated/const/claimable_balance_entry_extension_v1_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceEntryExtensionV1Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_entry_extension_v1_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_entry_extension_v1_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceEntryExtensionV1Ext`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_entry_extension_v1_ext( + &mut self, + v: &ClaimableBalanceEntryExtensionV1Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ClaimableBalanceEntryExtensionV1Ext::V0 => {} + } + } +} diff --git a/src/generated/const/claimable_balance_flags.rs b/src/generated/const/claimable_balance_flags.rs new file mode 100644 index 000000000..5ab5100c3 --- /dev/null +++ b/src/generated/const/claimable_balance_flags.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceFlags { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_flags(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_flags(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceFlags`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_flags(&mut self, v: &ClaimableBalanceFlags) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claimable_balance_id.rs b/src/generated/const/claimable_balance_id.rs new file mode 100644 index 000000000..f9caf22e7 --- /dev/null +++ b/src/generated/const/claimable_balance_id.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceId`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_id(&mut self, v: &ClaimableBalanceId) { + let d = v.discriminant(); + self.write_type_claimable_balance_id_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ClaimableBalanceId::ClaimableBalanceIdTypeV0(value) => { + self.write_type_hash(value); + } + } + } +} diff --git a/src/generated/const/claimable_balance_id_type.rs b/src/generated/const/claimable_balance_id_type.rs new file mode 100644 index 000000000..ee8a47dae --- /dev/null +++ b/src/generated/const/claimable_balance_id_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimableBalanceIdType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimable_balance_id_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimable_balance_id_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimableBalanceIdType`], mirroring `::write_xdr`. + pub const fn write_type_claimable_balance_id_type(&mut self, v: &ClaimableBalanceIdType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claimant.rs b/src/generated/const/claimant.rs new file mode 100644 index 000000000..a70ba9670 --- /dev/null +++ b/src/generated/const/claimant.rs @@ -0,0 +1,84 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Claimant is a borrowing equivalent of [`Claimant`](super::super::Claimant) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum Claimant { + ClaimantTypeV0(ClaimantV0), +} + +impl Claimant { + #[must_use] + pub const fn discriminant(&self) -> ClaimantType { + #[allow(clippy::match_same_arms)] + match self { + Self::ClaimantTypeV0(_) => ClaimantType::ClaimantTypeV0, + } + } +} + +impl Claimant { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimant(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimant(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Claimant`], mirroring `::write_xdr`. + pub const fn write_type_claimant(&mut self, v: &Claimant) { + let d = v.discriminant(); + self.write_type_claimant_type(&d); + #[allow(clippy::match_same_arms)] + match v { + Claimant::ClaimantTypeV0(value) => { + self.write_type_claimant_v0(value); + } + } + } + + /// Serializes a variable-length array of [`Claimant`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_claimant(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_claimant(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/claimant_type.rs b/src/generated/const/claimant_type.rs new file mode 100644 index 000000000..a9f2112e5 --- /dev/null +++ b/src/generated/const/claimant_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClaimantType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimant_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimant_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimantType`], mirroring `::write_xdr`. + pub const fn write_type_claimant_type(&mut self, v: &ClaimantType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/claimant_v0.rs b/src/generated/const/claimant_v0.rs new file mode 100644 index 000000000..920321cb2 --- /dev/null +++ b/src/generated/const/claimant_v0.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ClaimantV0 is a borrowing equivalent of [`ClaimantV0`](super::super::ClaimantV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ClaimantV0 { + pub destination: AccountId, + pub predicate: ClaimPredicate, +} + +impl ClaimantV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_claimant_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_claimant_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClaimantV0`], mirroring `::write_xdr`. + pub const fn write_type_claimant_v0(&mut self, v: &ClaimantV0) { + self.write_type_account_id(&v.destination); + self.write_type_claim_predicate(&v.predicate); + } +} diff --git a/src/generated/const/clawback_claimable_balance_op.rs b/src/generated/const/clawback_claimable_balance_op.rs new file mode 100644 index 000000000..6146b0bd9 --- /dev/null +++ b/src/generated/const/clawback_claimable_balance_op.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackClaimableBalanceOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_claimable_balance_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_claimable_balance_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackClaimableBalanceOp`], mirroring `::write_xdr`. + pub const fn write_type_clawback_claimable_balance_op( + &mut self, + v: &ClawbackClaimableBalanceOp, + ) { + self.write_type_claimable_balance_id(&v.balance_id); + } +} diff --git a/src/generated/const/clawback_claimable_balance_result.rs b/src/generated/const/clawback_claimable_balance_result.rs new file mode 100644 index 000000000..b83f13c4b --- /dev/null +++ b/src/generated/const/clawback_claimable_balance_result.rs @@ -0,0 +1,57 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackClaimableBalanceResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_claimable_balance_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_claimable_balance_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackClaimableBalanceResult`], mirroring `::write_xdr`. + pub const fn write_type_clawback_claimable_balance_result( + &mut self, + v: &ClawbackClaimableBalanceResult, + ) { + let d = v.discriminant(); + self.write_type_clawback_claimable_balance_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ClawbackClaimableBalanceResult::Success => {} + ClawbackClaimableBalanceResult::DoesNotExist => {} + ClawbackClaimableBalanceResult::NotIssuer => {} + ClawbackClaimableBalanceResult::NotClawbackEnabled => {} + } + } +} diff --git a/src/generated/const/clawback_claimable_balance_result_code.rs b/src/generated/const/clawback_claimable_balance_result_code.rs new file mode 100644 index 000000000..9a16b61c0 --- /dev/null +++ b/src/generated/const/clawback_claimable_balance_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackClaimableBalanceResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_claimable_balance_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_claimable_balance_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackClaimableBalanceResultCode`], mirroring `::write_xdr`. + pub const fn write_type_clawback_claimable_balance_result_code( + &mut self, + v: &ClawbackClaimableBalanceResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/clawback_op.rs b/src/generated/const/clawback_op.rs new file mode 100644 index 000000000..11f06b835 --- /dev/null +++ b/src/generated/const/clawback_op.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackOp`], mirroring `::write_xdr`. + pub const fn write_type_clawback_op(&mut self, v: &ClawbackOp) { + self.write_type_asset(&v.asset); + self.write_type_muxed_account(&v.from); + self.write_i64(v.amount); + } +} diff --git a/src/generated/const/clawback_result.rs b/src/generated/const/clawback_result.rs new file mode 100644 index 000000000..d9f7083f1 --- /dev/null +++ b/src/generated/const/clawback_result.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackResult`], mirroring `::write_xdr`. + pub const fn write_type_clawback_result(&mut self, v: &ClawbackResult) { + let d = v.discriminant(); + self.write_type_clawback_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ClawbackResult::Success => {} + ClawbackResult::Malformed => {} + ClawbackResult::NotClawbackEnabled => {} + ClawbackResult::NoTrust => {} + ClawbackResult::Underfunded => {} + } + } +} diff --git a/src/generated/const/clawback_result_code.rs b/src/generated/const/clawback_result_code.rs new file mode 100644 index 000000000..d15b4820e --- /dev/null +++ b/src/generated/const/clawback_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ClawbackResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_clawback_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_clawback_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ClawbackResultCode`], mirroring `::write_xdr`. + pub const fn write_type_clawback_result_code(&mut self, v: &ClawbackResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/config_setting_contract_bandwidth_v0.rs b/src/generated/const/config_setting_contract_bandwidth_v0.rs new file mode 100644 index 000000000..9d0bfd5cd --- /dev/null +++ b/src/generated/const/config_setting_contract_bandwidth_v0.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractBandwidthV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_bandwidth_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_bandwidth_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractBandwidthV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_bandwidth_v0( + &mut self, + v: &ConfigSettingContractBandwidthV0, + ) { + self.write_u32(v.ledger_max_txs_size_bytes); + self.write_u32(v.tx_max_size_bytes); + self.write_i64(v.fee_tx_size1_kb); + } +} diff --git a/src/generated/const/config_setting_contract_compute_v0.rs b/src/generated/const/config_setting_contract_compute_v0.rs new file mode 100644 index 000000000..0fe67dd1e --- /dev/null +++ b/src/generated/const/config_setting_contract_compute_v0.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractComputeV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_compute_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_compute_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractComputeV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_compute_v0( + &mut self, + v: &ConfigSettingContractComputeV0, + ) { + self.write_i64(v.ledger_max_instructions); + self.write_i64(v.tx_max_instructions); + self.write_i64(v.fee_rate_per_instructions_increment); + self.write_u32(v.tx_memory_limit); + } +} diff --git a/src/generated/const/config_setting_contract_events_v0.rs b/src/generated/const/config_setting_contract_events_v0.rs new file mode 100644 index 000000000..76f21f83e --- /dev/null +++ b/src/generated/const/config_setting_contract_events_v0.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractEventsV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_events_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_events_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractEventsV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_events_v0( + &mut self, + v: &ConfigSettingContractEventsV0, + ) { + self.write_u32(v.tx_max_contract_events_size_bytes); + self.write_i64(v.fee_contract_events1_kb); + } +} diff --git a/src/generated/const/config_setting_contract_execution_lanes_v0.rs b/src/generated/const/config_setting_contract_execution_lanes_v0.rs new file mode 100644 index 000000000..4cb237806 --- /dev/null +++ b/src/generated/const/config_setting_contract_execution_lanes_v0.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractExecutionLanesV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_execution_lanes_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_execution_lanes_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractExecutionLanesV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_execution_lanes_v0( + &mut self, + v: &ConfigSettingContractExecutionLanesV0, + ) { + self.write_u32(v.ledger_max_tx_count); + } +} diff --git a/src/generated/const/config_setting_contract_historical_data_v0.rs b/src/generated/const/config_setting_contract_historical_data_v0.rs new file mode 100644 index 000000000..063df6ec7 --- /dev/null +++ b/src/generated/const/config_setting_contract_historical_data_v0.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractHistoricalDataV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_historical_data_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_historical_data_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractHistoricalDataV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_historical_data_v0( + &mut self, + v: &ConfigSettingContractHistoricalDataV0, + ) { + self.write_i64(v.fee_historical1_kb); + } +} diff --git a/src/generated/const/config_setting_contract_ledger_cost_ext_v0.rs b/src/generated/const/config_setting_contract_ledger_cost_ext_v0.rs new file mode 100644 index 000000000..3dbb8fe2c --- /dev/null +++ b/src/generated/const/config_setting_contract_ledger_cost_ext_v0.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractLedgerCostExtV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_ledger_cost_ext_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_ledger_cost_ext_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractLedgerCostExtV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_ledger_cost_ext_v0( + &mut self, + v: &ConfigSettingContractLedgerCostExtV0, + ) { + self.write_u32(v.tx_max_footprint_entries); + self.write_i64(v.fee_write1_kb); + } +} diff --git a/src/generated/const/config_setting_contract_ledger_cost_v0.rs b/src/generated/const/config_setting_contract_ledger_cost_v0.rs new file mode 100644 index 000000000..2e3b5f159 --- /dev/null +++ b/src/generated/const/config_setting_contract_ledger_cost_v0.rs @@ -0,0 +1,63 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractLedgerCostV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_ledger_cost_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_ledger_cost_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractLedgerCostV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_ledger_cost_v0( + &mut self, + v: &ConfigSettingContractLedgerCostV0, + ) { + self.write_u32(v.ledger_max_disk_read_entries); + self.write_u32(v.ledger_max_disk_read_bytes); + self.write_u32(v.ledger_max_write_ledger_entries); + self.write_u32(v.ledger_max_write_bytes); + self.write_u32(v.tx_max_disk_read_entries); + self.write_u32(v.tx_max_disk_read_bytes); + self.write_u32(v.tx_max_write_ledger_entries); + self.write_u32(v.tx_max_write_bytes); + self.write_i64(v.fee_disk_read_ledger_entry); + self.write_i64(v.fee_write_ledger_entry); + self.write_i64(v.fee_disk_read1_kb); + self.write_i64(v.soroban_state_target_size_bytes); + self.write_i64(v.rent_fee1_kb_soroban_state_size_low); + self.write_i64(v.rent_fee1_kb_soroban_state_size_high); + self.write_u32(v.soroban_state_rent_fee_growth_factor); + } +} diff --git a/src/generated/const/config_setting_contract_parallel_compute_v0.rs b/src/generated/const/config_setting_contract_parallel_compute_v0.rs new file mode 100644 index 000000000..48641890e --- /dev/null +++ b/src/generated/const/config_setting_contract_parallel_compute_v0.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingContractParallelComputeV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_contract_parallel_compute_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_contract_parallel_compute_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingContractParallelComputeV0`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_contract_parallel_compute_v0( + &mut self, + v: &ConfigSettingContractParallelComputeV0, + ) { + self.write_u32(v.ledger_max_dependent_tx_clusters); + } +} diff --git a/src/generated/const/config_setting_entry.rs b/src/generated/const/config_setting_entry.rs new file mode 100644 index 000000000..e6e6c272e --- /dev/null +++ b/src/generated/const/config_setting_entry.rs @@ -0,0 +1,191 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ConfigSettingEntry is a borrowing equivalent of [`ConfigSettingEntry`](super::super::ConfigSettingEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ConfigSettingEntry { + ContractMaxSizeBytes(u32), + ContractComputeV0(ConfigSettingContractComputeV0), + ContractLedgerCostV0(ConfigSettingContractLedgerCostV0), + ContractHistoricalDataV0(ConfigSettingContractHistoricalDataV0), + ContractEventsV0(ConfigSettingContractEventsV0), + ContractBandwidthV0(ConfigSettingContractBandwidthV0), + ContractCostParamsCpuInstructions(ContractCostParams), + ContractCostParamsMemoryBytes(ContractCostParams), + ContractDataKeySizeBytes(u32), + ContractDataEntrySizeBytes(u32), + StateArchival(StateArchivalSettings), + ContractExecutionLanes(ConfigSettingContractExecutionLanesV0), + LiveSorobanStateSizeWindow(VecM), + EvictionIterator(EvictionIterator), + ContractParallelComputeV0(ConfigSettingContractParallelComputeV0), + ContractLedgerCostExtV0(ConfigSettingContractLedgerCostExtV0), + ScpTiming(ConfigSettingScpTiming), + FrozenLedgerKeys(FrozenLedgerKeys), + FrozenLedgerKeysDelta(FrozenLedgerKeysDelta), + FreezeBypassTxs(FreezeBypassTxs), + FreezeBypassTxsDelta(FreezeBypassTxsDelta), +} + +impl ConfigSettingEntry { + #[must_use] + pub const fn discriminant(&self) -> ConfigSettingId { + #[allow(clippy::match_same_arms)] + match self { + Self::ContractMaxSizeBytes(_) => ConfigSettingId::ContractMaxSizeBytes, + Self::ContractComputeV0(_) => ConfigSettingId::ContractComputeV0, + Self::ContractLedgerCostV0(_) => ConfigSettingId::ContractLedgerCostV0, + Self::ContractHistoricalDataV0(_) => ConfigSettingId::ContractHistoricalDataV0, + Self::ContractEventsV0(_) => ConfigSettingId::ContractEventsV0, + Self::ContractBandwidthV0(_) => ConfigSettingId::ContractBandwidthV0, + Self::ContractCostParamsCpuInstructions(_) => { + ConfigSettingId::ContractCostParamsCpuInstructions + } + Self::ContractCostParamsMemoryBytes(_) => { + ConfigSettingId::ContractCostParamsMemoryBytes + } + Self::ContractDataKeySizeBytes(_) => ConfigSettingId::ContractDataKeySizeBytes, + Self::ContractDataEntrySizeBytes(_) => ConfigSettingId::ContractDataEntrySizeBytes, + Self::StateArchival(_) => ConfigSettingId::StateArchival, + Self::ContractExecutionLanes(_) => ConfigSettingId::ContractExecutionLanes, + Self::LiveSorobanStateSizeWindow(_) => ConfigSettingId::LiveSorobanStateSizeWindow, + Self::EvictionIterator(_) => ConfigSettingId::EvictionIterator, + Self::ContractParallelComputeV0(_) => ConfigSettingId::ContractParallelComputeV0, + Self::ContractLedgerCostExtV0(_) => ConfigSettingId::ContractLedgerCostExtV0, + Self::ScpTiming(_) => ConfigSettingId::ScpTiming, + Self::FrozenLedgerKeys(_) => ConfigSettingId::FrozenLedgerKeys, + Self::FrozenLedgerKeysDelta(_) => ConfigSettingId::FrozenLedgerKeysDelta, + Self::FreezeBypassTxs(_) => ConfigSettingId::FreezeBypassTxs, + Self::FreezeBypassTxsDelta(_) => ConfigSettingId::FreezeBypassTxsDelta, + } + } +} + +impl ConfigSettingEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingEntry`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_entry(&mut self, v: &ConfigSettingEntry) { + let d = v.discriminant(); + self.write_type_config_setting_id(&d); + #[allow(clippy::match_same_arms)] + match v { + ConfigSettingEntry::ContractMaxSizeBytes(value) => { + self.write_u32(*value); + } + ConfigSettingEntry::ContractComputeV0(value) => { + self.write_type_config_setting_contract_compute_v0(value); + } + ConfigSettingEntry::ContractLedgerCostV0(value) => { + self.write_type_config_setting_contract_ledger_cost_v0(value); + } + ConfigSettingEntry::ContractHistoricalDataV0(value) => { + self.write_type_config_setting_contract_historical_data_v0(value); + } + ConfigSettingEntry::ContractEventsV0(value) => { + self.write_type_config_setting_contract_events_v0(value); + } + ConfigSettingEntry::ContractBandwidthV0(value) => { + self.write_type_config_setting_contract_bandwidth_v0(value); + } + ConfigSettingEntry::ContractCostParamsCpuInstructions(value) => { + self.write_type_contract_cost_params(value); + } + ConfigSettingEntry::ContractCostParamsMemoryBytes(value) => { + self.write_type_contract_cost_params(value); + } + ConfigSettingEntry::ContractDataKeySizeBytes(value) => { + self.write_u32(*value); + } + ConfigSettingEntry::ContractDataEntrySizeBytes(value) => { + self.write_u32(*value); + } + ConfigSettingEntry::StateArchival(value) => { + self.write_type_state_archival_settings(value); + } + ConfigSettingEntry::ContractExecutionLanes(value) => { + self.write_type_config_setting_contract_execution_lanes_v0(value); + } + ConfigSettingEntry::LiveSorobanStateSizeWindow(value) => { + self.write_vec_u64(value); + } + ConfigSettingEntry::EvictionIterator(value) => { + self.write_type_eviction_iterator(value); + } + ConfigSettingEntry::ContractParallelComputeV0(value) => { + self.write_type_config_setting_contract_parallel_compute_v0(value); + } + ConfigSettingEntry::ContractLedgerCostExtV0(value) => { + self.write_type_config_setting_contract_ledger_cost_ext_v0(value); + } + ConfigSettingEntry::ScpTiming(value) => { + self.write_type_config_setting_scp_timing(value); + } + ConfigSettingEntry::FrozenLedgerKeys(value) => { + self.write_type_frozen_ledger_keys(value); + } + ConfigSettingEntry::FrozenLedgerKeysDelta(value) => { + self.write_type_frozen_ledger_keys_delta(value); + } + ConfigSettingEntry::FreezeBypassTxs(value) => { + self.write_type_freeze_bypass_txs(value); + } + ConfigSettingEntry::FreezeBypassTxsDelta(value) => { + self.write_type_freeze_bypass_txs_delta(value); + } + } + } + + /// Serializes a variable-length array of [`ConfigSettingEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_config_setting_entry( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_config_setting_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/config_setting_id.rs b/src/generated/const/config_setting_id.rs new file mode 100644 index 000000000..17ef70ed5 --- /dev/null +++ b/src/generated/const/config_setting_id.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingId`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_id(&mut self, v: &ConfigSettingId) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/config_setting_scp_timing.rs b/src/generated/const/config_setting_scp_timing.rs new file mode 100644 index 000000000..44cabc7c9 --- /dev/null +++ b/src/generated/const/config_setting_scp_timing.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigSettingScpTiming { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_setting_scp_timing(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_setting_scp_timing(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigSettingScpTiming`], mirroring `::write_xdr`. + pub const fn write_type_config_setting_scp_timing(&mut self, v: &ConfigSettingScpTiming) { + self.write_u32(v.ledger_target_close_time_milliseconds); + self.write_u32(v.nomination_timeout_initial_milliseconds); + self.write_u32(v.nomination_timeout_increment_milliseconds); + self.write_u32(v.ballot_timeout_initial_milliseconds); + self.write_u32(v.ballot_timeout_increment_milliseconds); + } +} diff --git a/src/generated/const/config_upgrade_set.rs b/src/generated/const/config_upgrade_set.rs new file mode 100644 index 000000000..9c38d313f --- /dev/null +++ b/src/generated/const/config_upgrade_set.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ConfigUpgradeSet is a borrowing equivalent of [`ConfigUpgradeSet`](super::super::ConfigUpgradeSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ConfigUpgradeSet { + pub updated_entry: VecM, +} + +impl ConfigUpgradeSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_upgrade_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_upgrade_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigUpgradeSet`], mirroring `::write_xdr`. + pub const fn write_type_config_upgrade_set(&mut self, v: &ConfigUpgradeSet) { + self.write_type_vec_config_setting_entry(&v.updated_entry); + } +} diff --git a/src/generated/const/config_upgrade_set_key.rs b/src/generated/const/config_upgrade_set_key.rs new file mode 100644 index 000000000..17fa89b93 --- /dev/null +++ b/src/generated/const/config_upgrade_set_key.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ConfigUpgradeSetKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_config_upgrade_set_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_config_upgrade_set_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ConfigUpgradeSetKey`], mirroring `::write_xdr`. + pub const fn write_type_config_upgrade_set_key(&mut self, v: &ConfigUpgradeSetKey) { + self.write_type_contract_id(&v.contract_id); + self.write_type_hash(&v.content_hash); + } +} diff --git a/src/generated/const/contract_code_cost_inputs.rs b/src/generated/const/contract_code_cost_inputs.rs new file mode 100644 index 000000000..54bb3b6fd --- /dev/null +++ b/src/generated/const/contract_code_cost_inputs.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractCodeCostInputs { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_code_cost_inputs(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_code_cost_inputs(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCodeCostInputs`], mirroring `::write_xdr`. + pub const fn write_type_contract_code_cost_inputs(&mut self, v: &ContractCodeCostInputs) { + self.write_type_extension_point(&v.ext); + self.write_u32(v.n_instructions); + self.write_u32(v.n_functions); + self.write_u32(v.n_globals); + self.write_u32(v.n_table_entries); + self.write_u32(v.n_types); + self.write_u32(v.n_data_segments); + self.write_u32(v.n_elem_segments); + self.write_u32(v.n_imports); + self.write_u32(v.n_exports); + self.write_u32(v.n_data_segment_bytes); + } +} diff --git a/src/generated/const/contract_code_entry.rs b/src/generated/const/contract_code_entry.rs new file mode 100644 index 000000000..6fcf6a3a3 --- /dev/null +++ b/src/generated/const/contract_code_entry.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractCodeEntry is a borrowing equivalent of [`ContractCodeEntry`](super::super::ContractCodeEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractCodeEntry { + pub ext: ContractCodeEntryExt, + pub hash: Hash, + pub code: BytesM, +} + +impl ContractCodeEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_code_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_code_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCodeEntry`], mirroring `::write_xdr`. + pub const fn write_type_contract_code_entry(&mut self, v: &ContractCodeEntry) { + self.write_type_contract_code_entry_ext(&v.ext); + self.write_type_hash(&v.hash); + self.write_var_opaque(v.code.as_slice()); + } +} diff --git a/src/generated/const/contract_code_entry_ext.rs b/src/generated/const/contract_code_entry_ext.rs new file mode 100644 index 000000000..678861294 --- /dev/null +++ b/src/generated/const/contract_code_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractCodeEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_code_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_code_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCodeEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_contract_code_entry_ext(&mut self, v: &ContractCodeEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ContractCodeEntryExt::V0 => {} + ContractCodeEntryExt::V1(value) => { + self.write_type_contract_code_entry_v1(value); + } + } + } +} diff --git a/src/generated/const/contract_code_entry_v1.rs b/src/generated/const/contract_code_entry_v1.rs new file mode 100644 index 000000000..58dfce57e --- /dev/null +++ b/src/generated/const/contract_code_entry_v1.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractCodeEntryV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_code_entry_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_code_entry_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCodeEntryV1`], mirroring `::write_xdr`. + pub const fn write_type_contract_code_entry_v1(&mut self, v: &ContractCodeEntryV1) { + self.write_type_extension_point(&v.ext); + self.write_type_contract_code_cost_inputs(&v.cost_inputs); + } +} diff --git a/src/generated/const/contract_cost_param_entry.rs b/src/generated/const/contract_cost_param_entry.rs new file mode 100644 index 000000000..07d0f80cf --- /dev/null +++ b/src/generated/const/contract_cost_param_entry.rs @@ -0,0 +1,63 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractCostParamEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_cost_param_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_cost_param_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCostParamEntry`], mirroring `::write_xdr`. + pub const fn write_type_contract_cost_param_entry(&mut self, v: &ContractCostParamEntry) { + self.write_type_extension_point(&v.ext); + self.write_i64(v.const_term); + self.write_i64(v.linear_term); + } + + /// Serializes a variable-length array of [`ContractCostParamEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_contract_cost_param_entry( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_contract_cost_param_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/contract_cost_params.rs b/src/generated/const/contract_cost_params.rs new file mode 100644 index 000000000..87a3c6c47 --- /dev/null +++ b/src/generated/const/contract_cost_params.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractCostParams is a borrowing equivalent of [`ContractCostParams`](super::super::ContractCostParams) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractCostParams(pub VecM); + +impl ContractCostParams { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_cost_params(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_cost_params(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCostParams`], mirroring `::write_xdr`. + pub const fn write_type_contract_cost_params(&mut self, v: &ContractCostParams) { + self.write_type_vec_contract_cost_param_entry(&v.0); + } +} diff --git a/src/generated/const/contract_cost_type.rs b/src/generated/const/contract_cost_type.rs new file mode 100644 index 000000000..ce9763a8f --- /dev/null +++ b/src/generated/const/contract_cost_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractCostType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_cost_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_cost_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractCostType`], mirroring `::write_xdr`. + pub const fn write_type_contract_cost_type(&mut self, v: &ContractCostType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/contract_data_durability.rs b/src/generated/const/contract_data_durability.rs new file mode 100644 index 000000000..b51c404c6 --- /dev/null +++ b/src/generated/const/contract_data_durability.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractDataDurability { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_data_durability(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_data_durability(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractDataDurability`], mirroring `::write_xdr`. + pub const fn write_type_contract_data_durability(&mut self, v: &ContractDataDurability) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/contract_data_entry.rs b/src/generated/const/contract_data_entry.rs new file mode 100644 index 000000000..6cef43f94 --- /dev/null +++ b/src/generated/const/contract_data_entry.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractDataEntry is a borrowing equivalent of [`ContractDataEntry`](super::super::ContractDataEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractDataEntry { + pub ext: ExtensionPoint, + pub contract: ScAddress, + pub key: ScVal, + pub durability: ContractDataDurability, + pub val: ScVal, +} + +impl ContractDataEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_data_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_data_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractDataEntry`], mirroring `::write_xdr`. + pub const fn write_type_contract_data_entry(&mut self, v: &ContractDataEntry) { + self.write_type_extension_point(&v.ext); + self.write_type_sc_address(&v.contract); + self.write_type_sc_val(&v.key); + self.write_type_contract_data_durability(&v.durability); + self.write_type_sc_val(&v.val); + } +} diff --git a/src/generated/const/contract_event.rs b/src/generated/const/contract_event.rs new file mode 100644 index 000000000..ba2a31d17 --- /dev/null +++ b/src/generated/const/contract_event.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractEvent is a borrowing equivalent of [`ContractEvent`](super::super::ContractEvent) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractEvent { + pub ext: ExtensionPoint, + pub contract_id: Option, + pub type_: ContractEventType, + pub body: ContractEventBody, +} + +impl ContractEvent { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_event(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_event(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractEvent`], mirroring `::write_xdr`. + pub const fn write_type_contract_event(&mut self, v: &ContractEvent) { + self.write_type_extension_point(&v.ext); + self.write_type_option_contract_id(&v.contract_id); + self.write_type_contract_event_type(&v.type_); + self.write_type_contract_event_body(&v.body); + } + + /// Serializes a variable-length array of [`ContractEvent`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_contract_event( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_contract_event(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/contract_event_body.rs b/src/generated/const/contract_event_body.rs new file mode 100644 index 000000000..41ec2255b --- /dev/null +++ b/src/generated/const/contract_event_body.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractEventBody is a borrowing equivalent of [`ContractEventBody`](super::super::ContractEventBody) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ContractEventBody { + V0(ContractEventV0), +} + +impl ContractEventBody { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl ContractEventBody { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_event_body(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_event_body(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractEventBody`], mirroring `::write_xdr`. + pub const fn write_type_contract_event_body(&mut self, v: &ContractEventBody) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ContractEventBody::V0(value) => { + self.write_type_contract_event_v0(value); + } + } + } +} diff --git a/src/generated/const/contract_event_type.rs b/src/generated/const/contract_event_type.rs new file mode 100644 index 000000000..fa2745ec6 --- /dev/null +++ b/src/generated/const/contract_event_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractEventType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_event_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_event_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractEventType`], mirroring `::write_xdr`. + pub const fn write_type_contract_event_type(&mut self, v: &ContractEventType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/contract_event_v0.rs b/src/generated/const/contract_event_v0.rs new file mode 100644 index 000000000..558242cd8 --- /dev/null +++ b/src/generated/const/contract_event_v0.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractEventV0 is a borrowing equivalent of [`ContractEventV0`](super::super::ContractEventV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractEventV0 { + pub topics: VecM, + pub data: ScVal, +} + +impl ContractEventV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_event_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_event_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractEventV0`], mirroring `::write_xdr`. + pub const fn write_type_contract_event_v0(&mut self, v: &ContractEventV0) { + self.write_type_vec_sc_val(&v.topics); + self.write_type_sc_val(&v.data); + } +} diff --git a/src/generated/const/contract_executable.rs b/src/generated/const/contract_executable.rs new file mode 100644 index 000000000..5afecc25f --- /dev/null +++ b/src/generated/const/contract_executable.rs @@ -0,0 +1,80 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractExecutable is a borrowing equivalent of [`ContractExecutable`](super::super::ContractExecutable) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ContractExecutable { + Wasm(Hash), + StellarAsset, + ExternalRef(ContractExecutableExternalRef), +} + +impl ContractExecutable { + #[must_use] + pub const fn discriminant(&self) -> ContractExecutableType { + #[allow(clippy::match_same_arms)] + match self { + Self::Wasm(_) => ContractExecutableType::Wasm, + Self::StellarAsset => ContractExecutableType::StellarAsset, + Self::ExternalRef(_) => ContractExecutableType::ExternalRef, + } + } +} + +impl ContractExecutable { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_executable(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_executable(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractExecutable`], mirroring `::write_xdr`. + pub const fn write_type_contract_executable(&mut self, v: &ContractExecutable) { + let d = v.discriminant(); + self.write_type_contract_executable_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ContractExecutable::Wasm(value) => { + self.write_type_hash(value); + } + ContractExecutable::StellarAsset => {} + ContractExecutable::ExternalRef(value) => { + self.write_type_contract_executable_external_ref(value); + } + } + } +} diff --git a/src/generated/const/contract_executable_external_ref.rs b/src/generated/const/contract_executable_external_ref.rs new file mode 100644 index 000000000..78719124f --- /dev/null +++ b/src/generated/const/contract_executable_external_ref.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ContractExecutableExternalRef is a borrowing equivalent of [`ContractExecutableExternalRef`](super::super::ContractExecutableExternalRef) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ContractExecutableExternalRef { + pub executable_owner: ScAddress, + pub tag: ScString, +} + +impl ContractExecutableExternalRef { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_executable_external_ref(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_executable_external_ref(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractExecutableExternalRef`], mirroring `::write_xdr`. + pub const fn write_type_contract_executable_external_ref( + &mut self, + v: &ContractExecutableExternalRef, + ) { + self.write_type_sc_address(&v.executable_owner); + self.write_type_sc_string(&v.tag); + } +} diff --git a/src/generated/const/contract_executable_type.rs b/src/generated/const/contract_executable_type.rs new file mode 100644 index 000000000..0d3afce07 --- /dev/null +++ b/src/generated/const/contract_executable_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractExecutableType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_executable_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_executable_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractExecutableType`], mirroring `::write_xdr`. + pub const fn write_type_contract_executable_type(&mut self, v: &ContractExecutableType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/contract_id.rs b/src/generated/const/contract_id.rs new file mode 100644 index 000000000..bc0676c2b --- /dev/null +++ b/src/generated/const/contract_id.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractId`], mirroring `::write_xdr`. + pub const fn write_type_contract_id(&mut self, v: &ContractId) { + self.write_type_hash(&v.0); + } + + /// Serializes an optional [`ContractId`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_contract_id(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_contract_id(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/contract_id_preimage.rs b/src/generated/const/contract_id_preimage.rs new file mode 100644 index 000000000..9ba218f51 --- /dev/null +++ b/src/generated/const/contract_id_preimage.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractIdPreimage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_id_preimage(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_id_preimage(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractIdPreimage`], mirroring `::write_xdr`. + pub const fn write_type_contract_id_preimage(&mut self, v: &ContractIdPreimage) { + let d = v.discriminant(); + self.write_type_contract_id_preimage_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ContractIdPreimage::Address(value) => { + self.write_type_contract_id_preimage_from_address(value); + } + ContractIdPreimage::Asset(value) => { + self.write_type_asset(value); + } + } + } +} diff --git a/src/generated/const/contract_id_preimage_from_address.rs b/src/generated/const/contract_id_preimage_from_address.rs new file mode 100644 index 000000000..155fc4bca --- /dev/null +++ b/src/generated/const/contract_id_preimage_from_address.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractIdPreimageFromAddress { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_id_preimage_from_address(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_id_preimage_from_address(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractIdPreimageFromAddress`], mirroring `::write_xdr`. + pub const fn write_type_contract_id_preimage_from_address( + &mut self, + v: &ContractIdPreimageFromAddress, + ) { + self.write_type_sc_address(&v.address); + self.write_type_uint256(&v.salt); + } +} diff --git a/src/generated/const/contract_id_preimage_type.rs b/src/generated/const/contract_id_preimage_type.rs new file mode 100644 index 000000000..081fb42b2 --- /dev/null +++ b/src/generated/const/contract_id_preimage_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ContractIdPreimageType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_contract_id_preimage_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_contract_id_preimage_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ContractIdPreimageType`], mirroring `::write_xdr`. + pub const fn write_type_contract_id_preimage_type(&mut self, v: &ContractIdPreimageType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/create_account_op.rs b/src/generated/const/create_account_op.rs new file mode 100644 index 000000000..276c3b497 --- /dev/null +++ b/src/generated/const/create_account_op.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreateAccountOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_account_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_account_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateAccountOp`], mirroring `::write_xdr`. + pub const fn write_type_create_account_op(&mut self, v: &CreateAccountOp) { + self.write_type_account_id(&v.destination); + self.write_i64(v.starting_balance); + } +} diff --git a/src/generated/const/create_account_result.rs b/src/generated/const/create_account_result.rs new file mode 100644 index 000000000..b1699fc12 --- /dev/null +++ b/src/generated/const/create_account_result.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreateAccountResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_account_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_account_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateAccountResult`], mirroring `::write_xdr`. + pub const fn write_type_create_account_result(&mut self, v: &CreateAccountResult) { + let d = v.discriminant(); + self.write_type_create_account_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + CreateAccountResult::Success => {} + CreateAccountResult::Malformed => {} + CreateAccountResult::Underfunded => {} + CreateAccountResult::LowReserve => {} + CreateAccountResult::AlreadyExist => {} + } + } +} diff --git a/src/generated/const/create_account_result_code.rs b/src/generated/const/create_account_result_code.rs new file mode 100644 index 000000000..9fb03a956 --- /dev/null +++ b/src/generated/const/create_account_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreateAccountResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_account_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_account_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateAccountResultCode`], mirroring `::write_xdr`. + pub const fn write_type_create_account_result_code(&mut self, v: &CreateAccountResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/create_claimable_balance_op.rs b/src/generated/const/create_claimable_balance_op.rs new file mode 100644 index 000000000..84aa92604 --- /dev/null +++ b/src/generated/const/create_claimable_balance_op.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// CreateClaimableBalanceOp is a borrowing equivalent of [`CreateClaimableBalanceOp`](super::super::CreateClaimableBalanceOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct CreateClaimableBalanceOp { + pub asset: Asset, + pub amount: i64, + pub claimants: VecM, +} + +impl CreateClaimableBalanceOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_claimable_balance_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_claimable_balance_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateClaimableBalanceOp`], mirroring `::write_xdr`. + pub const fn write_type_create_claimable_balance_op(&mut self, v: &CreateClaimableBalanceOp) { + self.write_type_asset(&v.asset); + self.write_i64(v.amount); + self.write_type_vec_claimant(&v.claimants); + } +} diff --git a/src/generated/const/create_claimable_balance_result.rs b/src/generated/const/create_claimable_balance_result.rs new file mode 100644 index 000000000..e8d562279 --- /dev/null +++ b/src/generated/const/create_claimable_balance_result.rs @@ -0,0 +1,61 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreateClaimableBalanceResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_claimable_balance_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_claimable_balance_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateClaimableBalanceResult`], mirroring `::write_xdr`. + pub const fn write_type_create_claimable_balance_result( + &mut self, + v: &CreateClaimableBalanceResult, + ) { + let d = v.discriminant(); + self.write_type_create_claimable_balance_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + CreateClaimableBalanceResult::Success(value) => { + self.write_type_claimable_balance_id(value); + } + CreateClaimableBalanceResult::Malformed => {} + CreateClaimableBalanceResult::LowReserve => {} + CreateClaimableBalanceResult::NoTrust => {} + CreateClaimableBalanceResult::NotAuthorized => {} + CreateClaimableBalanceResult::Underfunded => {} + } + } +} diff --git a/src/generated/const/create_claimable_balance_result_code.rs b/src/generated/const/create_claimable_balance_result_code.rs new file mode 100644 index 000000000..aa5d18b1c --- /dev/null +++ b/src/generated/const/create_claimable_balance_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreateClaimableBalanceResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_claimable_balance_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_claimable_balance_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateClaimableBalanceResultCode`], mirroring `::write_xdr`. + pub const fn write_type_create_claimable_balance_result_code( + &mut self, + v: &CreateClaimableBalanceResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/create_contract_args.rs b/src/generated/const/create_contract_args.rs new file mode 100644 index 000000000..ddb61f3b4 --- /dev/null +++ b/src/generated/const/create_contract_args.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// CreateContractArgs is a borrowing equivalent of [`CreateContractArgs`](super::super::CreateContractArgs) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct CreateContractArgs { + pub contract_id_preimage: ContractIdPreimage, + pub executable: ContractExecutable, +} + +impl CreateContractArgs { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_contract_args(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_contract_args(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateContractArgs`], mirroring `::write_xdr`. + pub const fn write_type_create_contract_args(&mut self, v: &CreateContractArgs) { + self.write_type_contract_id_preimage(&v.contract_id_preimage); + self.write_type_contract_executable(&v.executable); + } +} diff --git a/src/generated/const/create_contract_args_v2.rs b/src/generated/const/create_contract_args_v2.rs new file mode 100644 index 000000000..aee9f3ed7 --- /dev/null +++ b/src/generated/const/create_contract_args_v2.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// CreateContractArgsV2 is a borrowing equivalent of [`CreateContractArgsV2`](super::super::CreateContractArgsV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct CreateContractArgsV2 { + pub contract_id_preimage: ContractIdPreimage, + pub executable: ContractExecutable, + pub constructor_args: VecM, +} + +impl CreateContractArgsV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_contract_args_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_contract_args_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreateContractArgsV2`], mirroring `::write_xdr`. + pub const fn write_type_create_contract_args_v2(&mut self, v: &CreateContractArgsV2) { + self.write_type_contract_id_preimage(&v.contract_id_preimage); + self.write_type_contract_executable(&v.executable); + self.write_type_vec_sc_val(&v.constructor_args); + } +} diff --git a/src/generated/const/create_passive_sell_offer_op.rs b/src/generated/const/create_passive_sell_offer_op.rs new file mode 100644 index 000000000..b54a86426 --- /dev/null +++ b/src/generated/const/create_passive_sell_offer_op.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CreatePassiveSellOfferOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_create_passive_sell_offer_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_create_passive_sell_offer_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CreatePassiveSellOfferOp`], mirroring `::write_xdr`. + pub const fn write_type_create_passive_sell_offer_op(&mut self, v: &CreatePassiveSellOfferOp) { + self.write_type_asset(&v.selling); + self.write_type_asset(&v.buying); + self.write_i64(v.amount); + self.write_type_price(&v.price); + } +} diff --git a/src/generated/const/crypto_key_type.rs b/src/generated/const/crypto_key_type.rs new file mode 100644 index 000000000..94ddf3548 --- /dev/null +++ b/src/generated/const/crypto_key_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl CryptoKeyType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_crypto_key_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_crypto_key_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`CryptoKeyType`], mirroring `::write_xdr`. + pub const fn write_type_crypto_key_type(&mut self, v: &CryptoKeyType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/curve25519_public.rs b/src/generated/const/curve25519_public.rs new file mode 100644 index 000000000..555ed49ff --- /dev/null +++ b/src/generated/const/curve25519_public.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Curve25519Public { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_curve25519_public(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_curve25519_public(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Curve25519Public`], mirroring `::write_xdr`. + pub const fn write_type_curve25519_public(&mut self, v: &Curve25519Public) { + self.write_fixed_opaque(&v.key); + } +} diff --git a/src/generated/const/curve25519_secret.rs b/src/generated/const/curve25519_secret.rs new file mode 100644 index 000000000..e7f2a5ee0 --- /dev/null +++ b/src/generated/const/curve25519_secret.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Curve25519Secret { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_curve25519_secret(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_curve25519_secret(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Curve25519Secret`], mirroring `::write_xdr`. + pub const fn write_type_curve25519_secret(&mut self, v: &Curve25519Secret) { + self.write_fixed_opaque(&v.key); + } +} diff --git a/src/generated/const/data_entry.rs b/src/generated/const/data_entry.rs new file mode 100644 index 000000000..fda3d4780 --- /dev/null +++ b/src/generated/const/data_entry.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// DataEntry is a borrowing equivalent of [`DataEntry`](super::super::DataEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct DataEntry { + pub account_id: AccountId, + pub data_name: String64, + pub data_value: DataValue, + pub ext: DataEntryExt, +} + +impl DataEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_data_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_data_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DataEntry`], mirroring `::write_xdr`. + pub const fn write_type_data_entry(&mut self, v: &DataEntry) { + self.write_type_account_id(&v.account_id); + self.write_type_string64(&v.data_name); + self.write_type_data_value(&v.data_value); + self.write_type_data_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/data_entry_ext.rs b/src/generated/const/data_entry_ext.rs new file mode 100644 index 000000000..61c53acf8 --- /dev/null +++ b/src/generated/const/data_entry_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl DataEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_data_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_data_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DataEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_data_entry_ext(&mut self, v: &DataEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + DataEntryExt::V0 => {} + } + } +} diff --git a/src/generated/const/data_value.rs b/src/generated/const/data_value.rs new file mode 100644 index 000000000..b49c4e5ad --- /dev/null +++ b/src/generated/const/data_value.rs @@ -0,0 +1,65 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// DataValue is a borrowing equivalent of [`DataValue`](super::super::DataValue) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct DataValue(pub BytesM<64>); + +impl DataValue { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_data_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_data_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DataValue`], mirroring `::write_xdr`. + pub const fn write_type_data_value(&mut self, v: &DataValue) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes an optional [`DataValue`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_data_value(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_data_value(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/decorated_signature.rs b/src/generated/const/decorated_signature.rs new file mode 100644 index 000000000..fa16e4fa8 --- /dev/null +++ b/src/generated/const/decorated_signature.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// DecoratedSignature is a borrowing equivalent of [`DecoratedSignature`](super::super::DecoratedSignature) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct DecoratedSignature { + pub hint: SignatureHint, + pub signature: Signature, +} + +impl DecoratedSignature { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_decorated_signature(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_decorated_signature(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DecoratedSignature`], mirroring `::write_xdr`. + pub const fn write_type_decorated_signature(&mut self, v: &DecoratedSignature) { + self.write_type_signature_hint(&v.hint); + self.write_type_signature(&v.signature); + } + + /// Serializes a variable-length array of [`DecoratedSignature`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_decorated_signature( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_decorated_signature(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/dependent_tx_cluster.rs b/src/generated/const/dependent_tx_cluster.rs new file mode 100644 index 000000000..117afce2f --- /dev/null +++ b/src/generated/const/dependent_tx_cluster.rs @@ -0,0 +1,67 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// DependentTxCluster is a borrowing equivalent of [`DependentTxCluster`](super::super::DependentTxCluster) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct DependentTxCluster(pub VecM); + +impl DependentTxCluster { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_dependent_tx_cluster(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_dependent_tx_cluster(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DependentTxCluster`], mirroring `::write_xdr`. + pub const fn write_type_dependent_tx_cluster(&mut self, v: &DependentTxCluster) { + self.write_type_vec_transaction_envelope(&v.0); + } + + /// Serializes a variable-length array of [`DependentTxCluster`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_dependent_tx_cluster( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_dependent_tx_cluster(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/diagnostic_event.rs b/src/generated/const/diagnostic_event.rs new file mode 100644 index 000000000..b3d7a5ace --- /dev/null +++ b/src/generated/const/diagnostic_event.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// DiagnosticEvent is a borrowing equivalent of [`DiagnosticEvent`](super::super::DiagnosticEvent) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct DiagnosticEvent { + pub in_successful_contract_call: bool, + pub event: ContractEvent, +} + +impl DiagnosticEvent { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_diagnostic_event(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_diagnostic_event(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DiagnosticEvent`], mirroring `::write_xdr`. + pub const fn write_type_diagnostic_event(&mut self, v: &DiagnosticEvent) { + self.write_bool(v.in_successful_contract_call); + self.write_type_contract_event(&v.event); + } + + /// Serializes a variable-length array of [`DiagnosticEvent`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_diagnostic_event( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_diagnostic_event(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/dont_have.rs b/src/generated/const/dont_have.rs new file mode 100644 index 000000000..e4997f615 --- /dev/null +++ b/src/generated/const/dont_have.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl DontHave { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_dont_have(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_dont_have(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`DontHave`], mirroring `::write_xdr`. + pub const fn write_type_dont_have(&mut self, v: &DontHave) { + self.write_type_message_type(&v.type_); + self.write_type_uint256(&v.req_hash); + } +} diff --git a/src/generated/const/duration.rs b/src/generated/const/duration.rs new file mode 100644 index 000000000..383a47d7a --- /dev/null +++ b/src/generated/const/duration.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Duration { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_duration(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_duration(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Duration`], mirroring `::write_xdr`. + pub const fn write_type_duration(&mut self, v: &Duration) { + self.write_u64(v.0); + } +} diff --git a/src/generated/const/encoded_ledger_key.rs b/src/generated/const/encoded_ledger_key.rs new file mode 100644 index 000000000..fd4482444 --- /dev/null +++ b/src/generated/const/encoded_ledger_key.rs @@ -0,0 +1,67 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// EncodedLedgerKey is a borrowing equivalent of [`EncodedLedgerKey`](super::super::EncodedLedgerKey) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct EncodedLedgerKey(pub BytesM); + +impl EncodedLedgerKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_encoded_ledger_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_encoded_ledger_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EncodedLedgerKey`], mirroring `::write_xdr`. + pub const fn write_type_encoded_ledger_key(&mut self, v: &EncodedLedgerKey) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes a variable-length array of [`EncodedLedgerKey`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_encoded_ledger_key( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_encoded_ledger_key(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/encrypted_body.rs b/src/generated/const/encrypted_body.rs new file mode 100644 index 000000000..f71744607 --- /dev/null +++ b/src/generated/const/encrypted_body.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// EncryptedBody is a borrowing equivalent of [`EncryptedBody`](super::super::EncryptedBody) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct EncryptedBody(pub BytesM<64000>); + +impl EncryptedBody { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_encrypted_body(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_encrypted_body(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EncryptedBody`], mirroring `::write_xdr`. + pub const fn write_type_encrypted_body(&mut self, v: &EncryptedBody) { + self.write_var_opaque(v.0.as_slice()); + } +} diff --git a/src/generated/const/end_sponsoring_future_reserves_result.rs b/src/generated/const/end_sponsoring_future_reserves_result.rs new file mode 100644 index 000000000..98449bd43 --- /dev/null +++ b/src/generated/const/end_sponsoring_future_reserves_result.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl EndSponsoringFutureReservesResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_end_sponsoring_future_reserves_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_end_sponsoring_future_reserves_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EndSponsoringFutureReservesResult`], mirroring `::write_xdr`. + pub const fn write_type_end_sponsoring_future_reserves_result( + &mut self, + v: &EndSponsoringFutureReservesResult, + ) { + let d = v.discriminant(); + self.write_type_end_sponsoring_future_reserves_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + EndSponsoringFutureReservesResult::Success => {} + EndSponsoringFutureReservesResult::NotSponsored => {} + } + } +} diff --git a/src/generated/const/end_sponsoring_future_reserves_result_code.rs b/src/generated/const/end_sponsoring_future_reserves_result_code.rs new file mode 100644 index 000000000..97bb66160 --- /dev/null +++ b/src/generated/const/end_sponsoring_future_reserves_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl EndSponsoringFutureReservesResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_end_sponsoring_future_reserves_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_end_sponsoring_future_reserves_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EndSponsoringFutureReservesResultCode`], mirroring `::write_xdr`. + pub const fn write_type_end_sponsoring_future_reserves_result_code( + &mut self, + v: &EndSponsoringFutureReservesResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/envelope_type.rs b/src/generated/const/envelope_type.rs new file mode 100644 index 000000000..af2b79e77 --- /dev/null +++ b/src/generated/const/envelope_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl EnvelopeType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_envelope_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_envelope_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EnvelopeType`], mirroring `::write_xdr`. + pub const fn write_type_envelope_type(&mut self, v: &EnvelopeType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/error_code.rs b/src/generated/const/error_code.rs new file mode 100644 index 000000000..278d182f9 --- /dev/null +++ b/src/generated/const/error_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ErrorCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_error_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_error_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ErrorCode`], mirroring `::write_xdr`. + pub const fn write_type_error_code(&mut self, v: &ErrorCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/eviction_iterator.rs b/src/generated/const/eviction_iterator.rs new file mode 100644 index 000000000..1d92314ab --- /dev/null +++ b/src/generated/const/eviction_iterator.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl EvictionIterator { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_eviction_iterator(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_eviction_iterator(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`EvictionIterator`], mirroring `::write_xdr`. + pub const fn write_type_eviction_iterator(&mut self, v: &EvictionIterator) { + self.write_u32(v.bucket_list_level); + self.write_bool(v.is_curr_bucket); + self.write_u64(v.bucket_file_offset); + } +} diff --git a/src/generated/const/extend_footprint_ttl_op.rs b/src/generated/const/extend_footprint_ttl_op.rs new file mode 100644 index 000000000..65644fd5d --- /dev/null +++ b/src/generated/const/extend_footprint_ttl_op.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ExtendFootprintTtlOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_extend_footprint_ttl_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_extend_footprint_ttl_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ExtendFootprintTtlOp`], mirroring `::write_xdr`. + pub const fn write_type_extend_footprint_ttl_op(&mut self, v: &ExtendFootprintTtlOp) { + self.write_type_extension_point(&v.ext); + self.write_u32(v.extend_to); + } +} diff --git a/src/generated/const/extend_footprint_ttl_result.rs b/src/generated/const/extend_footprint_ttl_result.rs new file mode 100644 index 000000000..89455d39e --- /dev/null +++ b/src/generated/const/extend_footprint_ttl_result.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ExtendFootprintTtlResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_extend_footprint_ttl_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_extend_footprint_ttl_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ExtendFootprintTtlResult`], mirroring `::write_xdr`. + pub const fn write_type_extend_footprint_ttl_result(&mut self, v: &ExtendFootprintTtlResult) { + let d = v.discriminant(); + self.write_type_extend_footprint_ttl_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ExtendFootprintTtlResult::Success => {} + ExtendFootprintTtlResult::Malformed => {} + ExtendFootprintTtlResult::ResourceLimitExceeded => {} + ExtendFootprintTtlResult::InsufficientRefundableFee => {} + } + } +} diff --git a/src/generated/const/extend_footprint_ttl_result_code.rs b/src/generated/const/extend_footprint_ttl_result_code.rs new file mode 100644 index 000000000..2bd0dd7f1 --- /dev/null +++ b/src/generated/const/extend_footprint_ttl_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ExtendFootprintTtlResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_extend_footprint_ttl_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_extend_footprint_ttl_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ExtendFootprintTtlResultCode`], mirroring `::write_xdr`. + pub const fn write_type_extend_footprint_ttl_result_code( + &mut self, + v: &ExtendFootprintTtlResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/extension_point.rs b/src/generated/const/extension_point.rs new file mode 100644 index 000000000..97b138e18 --- /dev/null +++ b/src/generated/const/extension_point.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ExtensionPoint { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_extension_point(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_extension_point(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ExtensionPoint`], mirroring `::write_xdr`. + pub const fn write_type_extension_point(&mut self, v: &ExtensionPoint) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ExtensionPoint::V0 => {} + } + } +} diff --git a/src/generated/const/fee_bump_transaction.rs b/src/generated/const/fee_bump_transaction.rs new file mode 100644 index 000000000..50fb397d7 --- /dev/null +++ b/src/generated/const/fee_bump_transaction.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FeeBumpTransaction is a borrowing equivalent of [`FeeBumpTransaction`](super::super::FeeBumpTransaction) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FeeBumpTransaction { + pub fee_source: MuxedAccount, + pub fee: i64, + pub inner_tx: FeeBumpTransactionInnerTx, + pub ext: FeeBumpTransactionExt, +} + +impl FeeBumpTransaction { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_fee_bump_transaction(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_fee_bump_transaction(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FeeBumpTransaction`], mirroring `::write_xdr`. + pub const fn write_type_fee_bump_transaction(&mut self, v: &FeeBumpTransaction) { + self.write_type_muxed_account(&v.fee_source); + self.write_i64(v.fee); + self.write_type_fee_bump_transaction_inner_tx(&v.inner_tx); + self.write_type_fee_bump_transaction_ext(&v.ext); + } +} diff --git a/src/generated/const/fee_bump_transaction_envelope.rs b/src/generated/const/fee_bump_transaction_envelope.rs new file mode 100644 index 000000000..24f0eb1b1 --- /dev/null +++ b/src/generated/const/fee_bump_transaction_envelope.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FeeBumpTransactionEnvelope is a borrowing equivalent of [`FeeBumpTransactionEnvelope`](super::super::FeeBumpTransactionEnvelope) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FeeBumpTransactionEnvelope { + pub tx: FeeBumpTransaction, + pub signatures: VecM, +} + +impl FeeBumpTransactionEnvelope { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_fee_bump_transaction_envelope(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_fee_bump_transaction_envelope(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FeeBumpTransactionEnvelope`], mirroring `::write_xdr`. + pub const fn write_type_fee_bump_transaction_envelope( + &mut self, + v: &FeeBumpTransactionEnvelope, + ) { + self.write_type_fee_bump_transaction(&v.tx); + self.write_type_vec_decorated_signature(&v.signatures); + } +} diff --git a/src/generated/const/fee_bump_transaction_ext.rs b/src/generated/const/fee_bump_transaction_ext.rs new file mode 100644 index 000000000..b3472cf3d --- /dev/null +++ b/src/generated/const/fee_bump_transaction_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl FeeBumpTransactionExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_fee_bump_transaction_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_fee_bump_transaction_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FeeBumpTransactionExt`], mirroring `::write_xdr`. + pub const fn write_type_fee_bump_transaction_ext(&mut self, v: &FeeBumpTransactionExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + FeeBumpTransactionExt::V0 => {} + } + } +} diff --git a/src/generated/const/fee_bump_transaction_inner_tx.rs b/src/generated/const/fee_bump_transaction_inner_tx.rs new file mode 100644 index 000000000..897898b43 --- /dev/null +++ b/src/generated/const/fee_bump_transaction_inner_tx.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FeeBumpTransactionInnerTx is a borrowing equivalent of [`FeeBumpTransactionInnerTx`](super::super::FeeBumpTransactionInnerTx) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum FeeBumpTransactionInnerTx { + Tx(TransactionV1Envelope), +} + +impl FeeBumpTransactionInnerTx { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(_) => EnvelopeType::Tx, + } + } +} + +impl FeeBumpTransactionInnerTx { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_fee_bump_transaction_inner_tx(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_fee_bump_transaction_inner_tx(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FeeBumpTransactionInnerTx`], mirroring `::write_xdr`. + pub const fn write_type_fee_bump_transaction_inner_tx( + &mut self, + v: &FeeBumpTransactionInnerTx, + ) { + let d = v.discriminant(); + self.write_type_envelope_type(&d); + #[allow(clippy::match_same_arms)] + match v { + FeeBumpTransactionInnerTx::Tx(value) => { + self.write_type_transaction_v1_envelope(value); + } + } + } +} diff --git a/src/generated/const/flood_advert.rs b/src/generated/const/flood_advert.rs new file mode 100644 index 000000000..5256b5bc7 --- /dev/null +++ b/src/generated/const/flood_advert.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FloodAdvert is a borrowing equivalent of [`FloodAdvert`](super::super::FloodAdvert) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FloodAdvert { + pub tx_hashes: TxAdvertVector, +} + +impl FloodAdvert { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_flood_advert(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_flood_advert(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FloodAdvert`], mirroring `::write_xdr`. + pub const fn write_type_flood_advert(&mut self, v: &FloodAdvert) { + self.write_type_tx_advert_vector(&v.tx_hashes); + } +} diff --git a/src/generated/const/flood_demand.rs b/src/generated/const/flood_demand.rs new file mode 100644 index 000000000..34bb894dd --- /dev/null +++ b/src/generated/const/flood_demand.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FloodDemand is a borrowing equivalent of [`FloodDemand`](super::super::FloodDemand) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FloodDemand { + pub tx_hashes: TxDemandVector, +} + +impl FloodDemand { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_flood_demand(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_flood_demand(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FloodDemand`], mirroring `::write_xdr`. + pub const fn write_type_flood_demand(&mut self, v: &FloodDemand) { + self.write_type_tx_demand_vector(&v.tx_hashes); + } +} diff --git a/src/generated/const/freeze_bypass_txs.rs b/src/generated/const/freeze_bypass_txs.rs new file mode 100644 index 000000000..1698e91b1 --- /dev/null +++ b/src/generated/const/freeze_bypass_txs.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FreezeBypassTxs is a borrowing equivalent of [`FreezeBypassTxs`](super::super::FreezeBypassTxs) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FreezeBypassTxs { + pub tx_hashes: VecM, +} + +impl FreezeBypassTxs { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_freeze_bypass_txs(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_freeze_bypass_txs(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FreezeBypassTxs`], mirroring `::write_xdr`. + pub const fn write_type_freeze_bypass_txs(&mut self, v: &FreezeBypassTxs) { + self.write_type_vec_hash(&v.tx_hashes); + } +} diff --git a/src/generated/const/freeze_bypass_txs_delta.rs b/src/generated/const/freeze_bypass_txs_delta.rs new file mode 100644 index 000000000..f6a23509f --- /dev/null +++ b/src/generated/const/freeze_bypass_txs_delta.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FreezeBypassTxsDelta is a borrowing equivalent of [`FreezeBypassTxsDelta`](super::super::FreezeBypassTxsDelta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FreezeBypassTxsDelta { + pub add_txs: VecM, + pub remove_txs: VecM, +} + +impl FreezeBypassTxsDelta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_freeze_bypass_txs_delta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_freeze_bypass_txs_delta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FreezeBypassTxsDelta`], mirroring `::write_xdr`. + pub const fn write_type_freeze_bypass_txs_delta(&mut self, v: &FreezeBypassTxsDelta) { + self.write_type_vec_hash(&v.add_txs); + self.write_type_vec_hash(&v.remove_txs); + } +} diff --git a/src/generated/const/frozen_ledger_keys.rs b/src/generated/const/frozen_ledger_keys.rs new file mode 100644 index 000000000..7e28d5f5f --- /dev/null +++ b/src/generated/const/frozen_ledger_keys.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FrozenLedgerKeys is a borrowing equivalent of [`FrozenLedgerKeys`](super::super::FrozenLedgerKeys) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FrozenLedgerKeys { + pub keys: VecM, +} + +impl FrozenLedgerKeys { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_frozen_ledger_keys(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_frozen_ledger_keys(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FrozenLedgerKeys`], mirroring `::write_xdr`. + pub const fn write_type_frozen_ledger_keys(&mut self, v: &FrozenLedgerKeys) { + self.write_type_vec_encoded_ledger_key(&v.keys); + } +} diff --git a/src/generated/const/frozen_ledger_keys_delta.rs b/src/generated/const/frozen_ledger_keys_delta.rs new file mode 100644 index 000000000..bb8e3454e --- /dev/null +++ b/src/generated/const/frozen_ledger_keys_delta.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// FrozenLedgerKeysDelta is a borrowing equivalent of [`FrozenLedgerKeysDelta`](super::super::FrozenLedgerKeysDelta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct FrozenLedgerKeysDelta { + pub keys_to_freeze: VecM, + pub keys_to_unfreeze: VecM, +} + +impl FrozenLedgerKeysDelta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_frozen_ledger_keys_delta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_frozen_ledger_keys_delta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`FrozenLedgerKeysDelta`], mirroring `::write_xdr`. + pub const fn write_type_frozen_ledger_keys_delta(&mut self, v: &FrozenLedgerKeysDelta) { + self.write_type_vec_encoded_ledger_key(&v.keys_to_freeze); + self.write_type_vec_encoded_ledger_key(&v.keys_to_unfreeze); + } +} diff --git a/src/generated/const/generalized_transaction_set.rs b/src/generated/const/generalized_transaction_set.rs new file mode 100644 index 000000000..f8fce6fa6 --- /dev/null +++ b/src/generated/const/generalized_transaction_set.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// GeneralizedTransactionSet is a borrowing equivalent of [`GeneralizedTransactionSet`](super::super::GeneralizedTransactionSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum GeneralizedTransactionSet { + V1(TransactionSetV1), +} + +impl GeneralizedTransactionSet { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V1(_) => 1, + } + } +} + +impl GeneralizedTransactionSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_generalized_transaction_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_generalized_transaction_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`GeneralizedTransactionSet`], mirroring `::write_xdr`. + pub const fn write_type_generalized_transaction_set(&mut self, v: &GeneralizedTransactionSet) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + GeneralizedTransactionSet::V1(value) => { + self.write_type_transaction_set_v1(value); + } + } + } +} diff --git a/src/generated/const/hash.rs b/src/generated/const/hash.rs new file mode 100644 index 000000000..600eddf44 --- /dev/null +++ b/src/generated/const/hash.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Hash { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Hash`], mirroring `::write_xdr`. + pub const fn write_type_hash(&mut self, v: &Hash) { + self.write_fixed_opaque(&v.0); + } + + /// Serializes a variable-length array of [`Hash`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_hash(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_hash(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/hash_id_preimage.rs b/src/generated/const/hash_id_preimage.rs new file mode 100644 index 000000000..8a12275ff --- /dev/null +++ b/src/generated/const/hash_id_preimage.rs @@ -0,0 +1,94 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// HashIdPreimage is a borrowing equivalent of [`HashIdPreimage`](super::super::HashIdPreimage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum HashIdPreimage { + OpId(HashIdPreimageOperationId), + PoolRevokeOpId(HashIdPreimageRevokeId), + ContractId(HashIdPreimageContractId), + SorobanAuthorization(HashIdPreimageSorobanAuthorization), + SorobanAuthorizationWithAddress(HashIdPreimageSorobanAuthorizationWithAddress), +} + +impl HashIdPreimage { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::OpId(_) => EnvelopeType::OpId, + Self::PoolRevokeOpId(_) => EnvelopeType::PoolRevokeOpId, + Self::ContractId(_) => EnvelopeType::ContractId, + Self::SorobanAuthorization(_) => EnvelopeType::SorobanAuthorization, + Self::SorobanAuthorizationWithAddress(_) => { + EnvelopeType::SorobanAuthorizationWithAddress + } + } + } +} + +impl HashIdPreimage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimage`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage(&mut self, v: &HashIdPreimage) { + let d = v.discriminant(); + self.write_type_envelope_type(&d); + #[allow(clippy::match_same_arms)] + match v { + HashIdPreimage::OpId(value) => { + self.write_type_hash_id_preimage_operation_id(value); + } + HashIdPreimage::PoolRevokeOpId(value) => { + self.write_type_hash_id_preimage_revoke_id(value); + } + HashIdPreimage::ContractId(value) => { + self.write_type_hash_id_preimage_contract_id(value); + } + HashIdPreimage::SorobanAuthorization(value) => { + self.write_type_hash_id_preimage_soroban_authorization(value); + } + HashIdPreimage::SorobanAuthorizationWithAddress(value) => { + self.write_type_hash_id_preimage_soroban_authorization_with_address(value); + } + } + } +} diff --git a/src/generated/const/hash_id_preimage_contract_id.rs b/src/generated/const/hash_id_preimage_contract_id.rs new file mode 100644 index 000000000..b8b5ca71b --- /dev/null +++ b/src/generated/const/hash_id_preimage_contract_id.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HashIdPreimageContractId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage_contract_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage_contract_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimageContractId`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage_contract_id(&mut self, v: &HashIdPreimageContractId) { + self.write_type_hash(&v.network_id); + self.write_type_contract_id_preimage(&v.contract_id_preimage); + } +} diff --git a/src/generated/const/hash_id_preimage_operation_id.rs b/src/generated/const/hash_id_preimage_operation_id.rs new file mode 100644 index 000000000..764aedbc3 --- /dev/null +++ b/src/generated/const/hash_id_preimage_operation_id.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HashIdPreimageOperationId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage_operation_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage_operation_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimageOperationId`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage_operation_id( + &mut self, + v: &HashIdPreimageOperationId, + ) { + self.write_type_account_id(&v.source_account); + self.write_type_sequence_number(&v.seq_num); + self.write_u32(v.op_num); + } +} diff --git a/src/generated/const/hash_id_preimage_revoke_id.rs b/src/generated/const/hash_id_preimage_revoke_id.rs new file mode 100644 index 000000000..474c3f757 --- /dev/null +++ b/src/generated/const/hash_id_preimage_revoke_id.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HashIdPreimageRevokeId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage_revoke_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage_revoke_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimageRevokeId`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage_revoke_id(&mut self, v: &HashIdPreimageRevokeId) { + self.write_type_account_id(&v.source_account); + self.write_type_sequence_number(&v.seq_num); + self.write_u32(v.op_num); + self.write_type_pool_id(&v.liquidity_pool_id); + self.write_type_asset(&v.asset); + } +} diff --git a/src/generated/const/hash_id_preimage_soroban_authorization.rs b/src/generated/const/hash_id_preimage_soroban_authorization.rs new file mode 100644 index 000000000..e56a36787 --- /dev/null +++ b/src/generated/const/hash_id_preimage_soroban_authorization.rs @@ -0,0 +1,63 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// HashIdPreimageSorobanAuthorization is a borrowing equivalent of [`HashIdPreimageSorobanAuthorization`](super::super::HashIdPreimageSorobanAuthorization) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct HashIdPreimageSorobanAuthorization { + pub network_id: Hash, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub invocation: SorobanAuthorizedInvocation, +} + +impl HashIdPreimageSorobanAuthorization { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage_soroban_authorization(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage_soroban_authorization(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimageSorobanAuthorization`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage_soroban_authorization( + &mut self, + v: &HashIdPreimageSorobanAuthorization, + ) { + self.write_type_hash(&v.network_id); + self.write_i64(v.nonce); + self.write_u32(v.signature_expiration_ledger); + self.write_type_soroban_authorized_invocation(&v.invocation); + } +} diff --git a/src/generated/const/hash_id_preimage_soroban_authorization_with_address.rs b/src/generated/const/hash_id_preimage_soroban_authorization_with_address.rs new file mode 100644 index 000000000..3145bbfe3 --- /dev/null +++ b/src/generated/const/hash_id_preimage_soroban_authorization_with_address.rs @@ -0,0 +1,65 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// HashIdPreimageSorobanAuthorizationWithAddress is a borrowing equivalent of [`HashIdPreimageSorobanAuthorizationWithAddress`](super::super::HashIdPreimageSorobanAuthorizationWithAddress) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct HashIdPreimageSorobanAuthorizationWithAddress { + pub network_id: Hash, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub address: ScAddress, + pub invocation: SorobanAuthorizedInvocation, +} + +impl HashIdPreimageSorobanAuthorizationWithAddress { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hash_id_preimage_soroban_authorization_with_address(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hash_id_preimage_soroban_authorization_with_address(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HashIdPreimageSorobanAuthorizationWithAddress`], mirroring `::write_xdr`. + pub const fn write_type_hash_id_preimage_soroban_authorization_with_address( + &mut self, + v: &HashIdPreimageSorobanAuthorizationWithAddress, + ) { + self.write_type_hash(&v.network_id); + self.write_i64(v.nonce); + self.write_u32(v.signature_expiration_ledger); + self.write_type_sc_address(&v.address); + self.write_type_soroban_authorized_invocation(&v.invocation); + } +} diff --git a/src/generated/const/hello.rs b/src/generated/const/hello.rs new file mode 100644 index 000000000..cee8d7166 --- /dev/null +++ b/src/generated/const/hello.rs @@ -0,0 +1,70 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Hello is a borrowing equivalent of [`Hello`](super::super::Hello) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Hello { + pub ledger_version: u32, + pub overlay_version: u32, + pub overlay_min_version: u32, + pub network_id: Hash, + pub version_str: StringM<100>, + pub listening_port: i32, + pub peer_id: NodeId, + pub cert: AuthCert, + pub nonce: Uint256, +} + +impl Hello { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hello(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hello(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Hello`], mirroring `::write_xdr`. + pub const fn write_type_hello(&mut self, v: &Hello) { + self.write_u32(v.ledger_version); + self.write_u32(v.overlay_version); + self.write_u32(v.overlay_min_version); + self.write_type_hash(&v.network_id); + self.write_var_opaque(v.version_str.as_slice()); + self.write_i32(v.listening_port); + self.write_type_node_id(&v.peer_id); + self.write_type_auth_cert(&v.cert); + self.write_type_uint256(&v.nonce); + } +} diff --git a/src/generated/const/hmac_sha256_key.rs b/src/generated/const/hmac_sha256_key.rs new file mode 100644 index 000000000..fcbef237e --- /dev/null +++ b/src/generated/const/hmac_sha256_key.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HmacSha256Key { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hmac_sha256_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hmac_sha256_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HmacSha256Key`], mirroring `::write_xdr`. + pub const fn write_type_hmac_sha256_key(&mut self, v: &HmacSha256Key) { + self.write_fixed_opaque(&v.key); + } +} diff --git a/src/generated/const/hmac_sha256_mac.rs b/src/generated/const/hmac_sha256_mac.rs new file mode 100644 index 000000000..527a281be --- /dev/null +++ b/src/generated/const/hmac_sha256_mac.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HmacSha256Mac { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hmac_sha256_mac(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hmac_sha256_mac(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HmacSha256Mac`], mirroring `::write_xdr`. + pub const fn write_type_hmac_sha256_mac(&mut self, v: &HmacSha256Mac) { + self.write_fixed_opaque(&v.mac); + } +} diff --git a/src/generated/const/host_function.rs b/src/generated/const/host_function.rs new file mode 100644 index 000000000..e3d238c3e --- /dev/null +++ b/src/generated/const/host_function.rs @@ -0,0 +1,87 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// HostFunction is a borrowing equivalent of [`HostFunction`](super::super::HostFunction) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum HostFunction { + InvokeContract(InvokeContractArgs), + CreateContract(CreateContractArgs), + UploadContractWasm(BytesM), + CreateContractV2(CreateContractArgsV2), +} + +impl HostFunction { + #[must_use] + pub const fn discriminant(&self) -> HostFunctionType { + #[allow(clippy::match_same_arms)] + match self { + Self::InvokeContract(_) => HostFunctionType::InvokeContract, + Self::CreateContract(_) => HostFunctionType::CreateContract, + Self::UploadContractWasm(_) => HostFunctionType::UploadContractWasm, + Self::CreateContractV2(_) => HostFunctionType::CreateContractV2, + } + } +} + +impl HostFunction { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_host_function(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_host_function(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HostFunction`], mirroring `::write_xdr`. + pub const fn write_type_host_function(&mut self, v: &HostFunction) { + let d = v.discriminant(); + self.write_type_host_function_type(&d); + #[allow(clippy::match_same_arms)] + match v { + HostFunction::InvokeContract(value) => { + self.write_type_invoke_contract_args(value); + } + HostFunction::CreateContract(value) => { + self.write_type_create_contract_args(value); + } + HostFunction::UploadContractWasm(value) => { + self.write_var_opaque(value.as_slice()); + } + HostFunction::CreateContractV2(value) => { + self.write_type_create_contract_args_v2(value); + } + } + } +} diff --git a/src/generated/const/host_function_type.rs b/src/generated/const/host_function_type.rs new file mode 100644 index 000000000..777333e6a --- /dev/null +++ b/src/generated/const/host_function_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HostFunctionType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_host_function_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_host_function_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HostFunctionType`], mirroring `::write_xdr`. + pub const fn write_type_host_function_type(&mut self, v: &HostFunctionType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/hot_archive_bucket_entry.rs b/src/generated/const/hot_archive_bucket_entry.rs new file mode 100644 index 000000000..506bed2cc --- /dev/null +++ b/src/generated/const/hot_archive_bucket_entry.rs @@ -0,0 +1,82 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// HotArchiveBucketEntry is a borrowing equivalent of [`HotArchiveBucketEntry`](super::super::HotArchiveBucketEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum HotArchiveBucketEntry { + Archived(LedgerEntry), + Live(LedgerKey), + Metaentry(BucketMetadata), +} + +impl HotArchiveBucketEntry { + #[must_use] + pub const fn discriminant(&self) -> HotArchiveBucketEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Archived(_) => HotArchiveBucketEntryType::Archived, + Self::Live(_) => HotArchiveBucketEntryType::Live, + Self::Metaentry(_) => HotArchiveBucketEntryType::Metaentry, + } + } +} + +impl HotArchiveBucketEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hot_archive_bucket_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hot_archive_bucket_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HotArchiveBucketEntry`], mirroring `::write_xdr`. + pub const fn write_type_hot_archive_bucket_entry(&mut self, v: &HotArchiveBucketEntry) { + let d = v.discriminant(); + self.write_type_hot_archive_bucket_entry_type(&d); + #[allow(clippy::match_same_arms)] + match v { + HotArchiveBucketEntry::Archived(value) => { + self.write_type_ledger_entry(value); + } + HotArchiveBucketEntry::Live(value) => { + self.write_type_ledger_key(value); + } + HotArchiveBucketEntry::Metaentry(value) => { + self.write_type_bucket_metadata(value); + } + } + } +} diff --git a/src/generated/const/hot_archive_bucket_entry_type.rs b/src/generated/const/hot_archive_bucket_entry_type.rs new file mode 100644 index 000000000..fbd3c13e8 --- /dev/null +++ b/src/generated/const/hot_archive_bucket_entry_type.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl HotArchiveBucketEntryType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_hot_archive_bucket_entry_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_hot_archive_bucket_entry_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`HotArchiveBucketEntryType`], mirroring `::write_xdr`. + pub const fn write_type_hot_archive_bucket_entry_type( + &mut self, + v: &HotArchiveBucketEntryType, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/inflation_payout.rs b/src/generated/const/inflation_payout.rs new file mode 100644 index 000000000..99e5a65c5 --- /dev/null +++ b/src/generated/const/inflation_payout.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl InflationPayout { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inflation_payout(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inflation_payout(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InflationPayout`], mirroring `::write_xdr`. + pub const fn write_type_inflation_payout(&mut self, v: &InflationPayout) { + self.write_type_account_id(&v.destination); + self.write_i64(v.amount); + } + + /// Serializes a variable-length array of [`InflationPayout`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_inflation_payout( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_inflation_payout(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/inflation_result.rs b/src/generated/const/inflation_result.rs new file mode 100644 index 000000000..130b2d205 --- /dev/null +++ b/src/generated/const/inflation_result.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InflationResult is a borrowing equivalent of [`InflationResult`](super::super::InflationResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum InflationResult { + Success(VecM), + NotTime, +} + +impl InflationResult { + #[must_use] + pub const fn discriminant(&self) -> InflationResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => InflationResultCode::Success, + Self::NotTime => InflationResultCode::NotTime, + } + } +} + +impl InflationResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inflation_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inflation_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InflationResult`], mirroring `::write_xdr`. + pub const fn write_type_inflation_result(&mut self, v: &InflationResult) { + let d = v.discriminant(); + self.write_type_inflation_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + InflationResult::Success(value) => { + self.write_type_vec_inflation_payout(value); + } + InflationResult::NotTime => {} + } + } +} diff --git a/src/generated/const/inflation_result_code.rs b/src/generated/const/inflation_result_code.rs new file mode 100644 index 000000000..a96af8cd3 --- /dev/null +++ b/src/generated/const/inflation_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl InflationResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inflation_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inflation_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InflationResultCode`], mirroring `::write_xdr`. + pub const fn write_type_inflation_result_code(&mut self, v: &InflationResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/inner_transaction_result.rs b/src/generated/const/inner_transaction_result.rs new file mode 100644 index 000000000..5111346d0 --- /dev/null +++ b/src/generated/const/inner_transaction_result.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InnerTransactionResult is a borrowing equivalent of [`InnerTransactionResult`](super::super::InnerTransactionResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct InnerTransactionResult { + pub fee_charged: i64, + pub result: InnerTransactionResultResult, + pub ext: InnerTransactionResultExt, +} + +impl InnerTransactionResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inner_transaction_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inner_transaction_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InnerTransactionResult`], mirroring `::write_xdr`. + pub const fn write_type_inner_transaction_result(&mut self, v: &InnerTransactionResult) { + self.write_i64(v.fee_charged); + self.write_type_inner_transaction_result_result(&v.result); + self.write_type_inner_transaction_result_ext(&v.ext); + } +} diff --git a/src/generated/const/inner_transaction_result_ext.rs b/src/generated/const/inner_transaction_result_ext.rs new file mode 100644 index 000000000..da326a68f --- /dev/null +++ b/src/generated/const/inner_transaction_result_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl InnerTransactionResultExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inner_transaction_result_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inner_transaction_result_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InnerTransactionResultExt`], mirroring `::write_xdr`. + pub const fn write_type_inner_transaction_result_ext(&mut self, v: &InnerTransactionResultExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + InnerTransactionResultExt::V0 => {} + } + } +} diff --git a/src/generated/const/inner_transaction_result_pair.rs b/src/generated/const/inner_transaction_result_pair.rs new file mode 100644 index 000000000..0b6022358 --- /dev/null +++ b/src/generated/const/inner_transaction_result_pair.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InnerTransactionResultPair is a borrowing equivalent of [`InnerTransactionResultPair`](super::super::InnerTransactionResultPair) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct InnerTransactionResultPair { + pub transaction_hash: Hash, + pub result: InnerTransactionResult, +} + +impl InnerTransactionResultPair { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inner_transaction_result_pair(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inner_transaction_result_pair(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InnerTransactionResultPair`], mirroring `::write_xdr`. + pub const fn write_type_inner_transaction_result_pair( + &mut self, + v: &InnerTransactionResultPair, + ) { + self.write_type_hash(&v.transaction_hash); + self.write_type_inner_transaction_result(&v.result); + } +} diff --git a/src/generated/const/inner_transaction_result_result.rs b/src/generated/const/inner_transaction_result_result.rs new file mode 100644 index 000000000..30f9d9fd3 --- /dev/null +++ b/src/generated/const/inner_transaction_result_result.rs @@ -0,0 +1,128 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InnerTransactionResultResult is a borrowing equivalent of [`InnerTransactionResultResult`](super::super::InnerTransactionResultResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum InnerTransactionResultResult { + TxSuccess(VecM), + TxFailed(VecM), + TxTooEarly, + TxTooLate, + TxMissingOperation, + TxBadSeq, + TxBadAuth, + TxInsufficientBalance, + TxNoAccount, + TxInsufficientFee, + TxBadAuthExtra, + TxInternalError, + TxNotSupported, + TxBadSponsorship, + TxBadMinSeqAgeOrGap, + TxMalformed, + TxSorobanInvalid, + TxFrozenKeyAccessed, +} + +impl InnerTransactionResultResult { + #[must_use] + pub const fn discriminant(&self) -> TransactionResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::TxSuccess(_) => TransactionResultCode::TxSuccess, + Self::TxFailed(_) => TransactionResultCode::TxFailed, + Self::TxTooEarly => TransactionResultCode::TxTooEarly, + Self::TxTooLate => TransactionResultCode::TxTooLate, + Self::TxMissingOperation => TransactionResultCode::TxMissingOperation, + Self::TxBadSeq => TransactionResultCode::TxBadSeq, + Self::TxBadAuth => TransactionResultCode::TxBadAuth, + Self::TxInsufficientBalance => TransactionResultCode::TxInsufficientBalance, + Self::TxNoAccount => TransactionResultCode::TxNoAccount, + Self::TxInsufficientFee => TransactionResultCode::TxInsufficientFee, + Self::TxBadAuthExtra => TransactionResultCode::TxBadAuthExtra, + Self::TxInternalError => TransactionResultCode::TxInternalError, + Self::TxNotSupported => TransactionResultCode::TxNotSupported, + Self::TxBadSponsorship => TransactionResultCode::TxBadSponsorship, + Self::TxBadMinSeqAgeOrGap => TransactionResultCode::TxBadMinSeqAgeOrGap, + Self::TxMalformed => TransactionResultCode::TxMalformed, + Self::TxSorobanInvalid => TransactionResultCode::TxSorobanInvalid, + Self::TxFrozenKeyAccessed => TransactionResultCode::TxFrozenKeyAccessed, + } + } +} + +impl InnerTransactionResultResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_inner_transaction_result_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_inner_transaction_result_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InnerTransactionResultResult`], mirroring `::write_xdr`. + pub const fn write_type_inner_transaction_result_result( + &mut self, + v: &InnerTransactionResultResult, + ) { + let d = v.discriminant(); + self.write_type_transaction_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + InnerTransactionResultResult::TxSuccess(value) => { + self.write_type_vec_operation_result(value); + } + InnerTransactionResultResult::TxFailed(value) => { + self.write_type_vec_operation_result(value); + } + InnerTransactionResultResult::TxTooEarly => {} + InnerTransactionResultResult::TxTooLate => {} + InnerTransactionResultResult::TxMissingOperation => {} + InnerTransactionResultResult::TxBadSeq => {} + InnerTransactionResultResult::TxBadAuth => {} + InnerTransactionResultResult::TxInsufficientBalance => {} + InnerTransactionResultResult::TxNoAccount => {} + InnerTransactionResultResult::TxInsufficientFee => {} + InnerTransactionResultResult::TxBadAuthExtra => {} + InnerTransactionResultResult::TxInternalError => {} + InnerTransactionResultResult::TxNotSupported => {} + InnerTransactionResultResult::TxBadSponsorship => {} + InnerTransactionResultResult::TxBadMinSeqAgeOrGap => {} + InnerTransactionResultResult::TxMalformed => {} + InnerTransactionResultResult::TxSorobanInvalid => {} + InnerTransactionResultResult::TxFrozenKeyAccessed => {} + } + } +} diff --git a/src/generated/const/int128_parts.rs b/src/generated/const/int128_parts.rs new file mode 100644 index 000000000..e8c6858c6 --- /dev/null +++ b/src/generated/const/int128_parts.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Int128Parts { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_int128_parts(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_int128_parts(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Int128Parts`], mirroring `::write_xdr`. + pub const fn write_type_int128_parts(&mut self, v: &Int128Parts) { + self.write_i64(v.hi); + self.write_u64(v.lo); + } +} diff --git a/src/generated/const/int256_parts.rs b/src/generated/const/int256_parts.rs new file mode 100644 index 000000000..c6efe95e5 --- /dev/null +++ b/src/generated/const/int256_parts.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Int256Parts { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_int256_parts(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_int256_parts(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Int256Parts`], mirroring `::write_xdr`. + pub const fn write_type_int256_parts(&mut self, v: &Int256Parts) { + self.write_i64(v.hi_hi); + self.write_u64(v.hi_lo); + self.write_u64(v.lo_hi); + self.write_u64(v.lo_lo); + } +} diff --git a/src/generated/const/invoke_contract_args.rs b/src/generated/const/invoke_contract_args.rs new file mode 100644 index 000000000..aa26e092d --- /dev/null +++ b/src/generated/const/invoke_contract_args.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InvokeContractArgs is a borrowing equivalent of [`InvokeContractArgs`](super::super::InvokeContractArgs) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct InvokeContractArgs { + pub contract_address: ScAddress, + pub function_name: ScSymbol, + pub args: VecM, +} + +impl InvokeContractArgs { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_invoke_contract_args(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_invoke_contract_args(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InvokeContractArgs`], mirroring `::write_xdr`. + pub const fn write_type_invoke_contract_args(&mut self, v: &InvokeContractArgs) { + self.write_type_sc_address(&v.contract_address); + self.write_type_sc_symbol(&v.function_name); + self.write_type_vec_sc_val(&v.args); + } +} diff --git a/src/generated/const/invoke_host_function_op.rs b/src/generated/const/invoke_host_function_op.rs new file mode 100644 index 000000000..c40f3580a --- /dev/null +++ b/src/generated/const/invoke_host_function_op.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InvokeHostFunctionOp is a borrowing equivalent of [`InvokeHostFunctionOp`](super::super::InvokeHostFunctionOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct InvokeHostFunctionOp { + pub host_function: HostFunction, + pub auth: VecM, +} + +impl InvokeHostFunctionOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_invoke_host_function_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_invoke_host_function_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InvokeHostFunctionOp`], mirroring `::write_xdr`. + pub const fn write_type_invoke_host_function_op(&mut self, v: &InvokeHostFunctionOp) { + self.write_type_host_function(&v.host_function); + self.write_type_vec_soroban_authorization_entry(&v.auth); + } +} diff --git a/src/generated/const/invoke_host_function_result.rs b/src/generated/const/invoke_host_function_result.rs new file mode 100644 index 000000000..4d74eecac --- /dev/null +++ b/src/generated/const/invoke_host_function_result.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl InvokeHostFunctionResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_invoke_host_function_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_invoke_host_function_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InvokeHostFunctionResult`], mirroring `::write_xdr`. + pub const fn write_type_invoke_host_function_result(&mut self, v: &InvokeHostFunctionResult) { + let d = v.discriminant(); + self.write_type_invoke_host_function_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + InvokeHostFunctionResult::Success(value) => { + self.write_type_hash(value); + } + InvokeHostFunctionResult::Malformed => {} + InvokeHostFunctionResult::Trapped => {} + InvokeHostFunctionResult::ResourceLimitExceeded => {} + InvokeHostFunctionResult::EntryArchived => {} + InvokeHostFunctionResult::InsufficientRefundableFee => {} + } + } +} diff --git a/src/generated/const/invoke_host_function_result_code.rs b/src/generated/const/invoke_host_function_result_code.rs new file mode 100644 index 000000000..2c1b82de3 --- /dev/null +++ b/src/generated/const/invoke_host_function_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl InvokeHostFunctionResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_invoke_host_function_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_invoke_host_function_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InvokeHostFunctionResultCode`], mirroring `::write_xdr`. + pub const fn write_type_invoke_host_function_result_code( + &mut self, + v: &InvokeHostFunctionResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/invoke_host_function_success_pre_image.rs b/src/generated/const/invoke_host_function_success_pre_image.rs new file mode 100644 index 000000000..2d8c0e179 --- /dev/null +++ b/src/generated/const/invoke_host_function_success_pre_image.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// InvokeHostFunctionSuccessPreImage is a borrowing equivalent of [`InvokeHostFunctionSuccessPreImage`](super::super::InvokeHostFunctionSuccessPreImage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct InvokeHostFunctionSuccessPreImage { + pub return_value: ScVal, + pub events: VecM, +} + +impl InvokeHostFunctionSuccessPreImage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_invoke_host_function_success_pre_image(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_invoke_host_function_success_pre_image(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`InvokeHostFunctionSuccessPreImage`], mirroring `::write_xdr`. + pub const fn write_type_invoke_host_function_success_pre_image( + &mut self, + v: &InvokeHostFunctionSuccessPreImage, + ) { + self.write_type_sc_val(&v.return_value); + self.write_type_vec_contract_event(&v.events); + } +} diff --git a/src/generated/const/ip_addr_type.rs b/src/generated/const/ip_addr_type.rs new file mode 100644 index 000000000..6b942faa3 --- /dev/null +++ b/src/generated/const/ip_addr_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl IpAddrType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ip_addr_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ip_addr_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`IpAddrType`], mirroring `::write_xdr`. + pub const fn write_type_ip_addr_type(&mut self, v: &IpAddrType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/ledger_bounds.rs b/src/generated/const/ledger_bounds.rs new file mode 100644 index 000000000..9e4012898 --- /dev/null +++ b/src/generated/const/ledger_bounds.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerBounds { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_bounds(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_bounds(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerBounds`], mirroring `::write_xdr`. + pub const fn write_type_ledger_bounds(&mut self, v: &LedgerBounds) { + self.write_u32(v.min_ledger); + self.write_u32(v.max_ledger); + } + + /// Serializes an optional [`LedgerBounds`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_ledger_bounds(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_ledger_bounds(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/ledger_close_meta.rs b/src/generated/const/ledger_close_meta.rs new file mode 100644 index 000000000..9a3738f92 --- /dev/null +++ b/src/generated/const/ledger_close_meta.rs @@ -0,0 +1,97 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseMeta is a borrowing equivalent of [`LedgerCloseMeta`](super::super::LedgerCloseMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum LedgerCloseMeta { + V0(LedgerCloseMetaV0), + V1(LedgerCloseMetaV1), + V2(LedgerCloseMetaV2), +} + +impl LedgerCloseMeta { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + Self::V2(_) => 2, + } + } +} + +impl LedgerCloseMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMeta`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta(&mut self, v: &LedgerCloseMeta) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerCloseMeta::V0(value) => { + self.write_type_ledger_close_meta_v0(value); + } + LedgerCloseMeta::V1(value) => { + self.write_type_ledger_close_meta_v1(value); + } + LedgerCloseMeta::V2(value) => { + self.write_type_ledger_close_meta_v2(value); + } + } + } + + /// Serializes a variable-length array of [`LedgerCloseMeta`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_ledger_close_meta( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_ledger_close_meta(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/ledger_close_meta_batch.rs b/src/generated/const/ledger_close_meta_batch.rs new file mode 100644 index 000000000..ee58c1dbc --- /dev/null +++ b/src/generated/const/ledger_close_meta_batch.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseMetaBatch is a borrowing equivalent of [`LedgerCloseMetaBatch`](super::super::LedgerCloseMetaBatch) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerCloseMetaBatch { + pub start_sequence: u32, + pub end_sequence: u32, + pub ledger_close_metas: VecM, +} + +impl LedgerCloseMetaBatch { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_batch(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_batch(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaBatch`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_batch(&mut self, v: &LedgerCloseMetaBatch) { + self.write_u32(v.start_sequence); + self.write_u32(v.end_sequence); + self.write_type_vec_ledger_close_meta(&v.ledger_close_metas); + } +} diff --git a/src/generated/const/ledger_close_meta_ext.rs b/src/generated/const/ledger_close_meta_ext.rs new file mode 100644 index 000000000..d3cc7e8ec --- /dev/null +++ b/src/generated/const/ledger_close_meta_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerCloseMetaExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaExt`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_ext(&mut self, v: &LedgerCloseMetaExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerCloseMetaExt::V0 => {} + LedgerCloseMetaExt::V1(value) => { + self.write_type_ledger_close_meta_ext_v1(value); + } + } + } +} diff --git a/src/generated/const/ledger_close_meta_ext_v1.rs b/src/generated/const/ledger_close_meta_ext_v1.rs new file mode 100644 index 000000000..700ef8d52 --- /dev/null +++ b/src/generated/const/ledger_close_meta_ext_v1.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerCloseMetaExtV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_ext_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_ext_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaExtV1`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_ext_v1(&mut self, v: &LedgerCloseMetaExtV1) { + self.write_type_extension_point(&v.ext); + self.write_i64(v.soroban_fee_write1_kb); + } +} diff --git a/src/generated/const/ledger_close_meta_v0.rs b/src/generated/const/ledger_close_meta_v0.rs new file mode 100644 index 000000000..0fb65654d --- /dev/null +++ b/src/generated/const/ledger_close_meta_v0.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseMetaV0 is a borrowing equivalent of [`LedgerCloseMetaV0`](super::super::LedgerCloseMetaV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerCloseMetaV0 { + pub ledger_header: LedgerHeaderHistoryEntry, + pub tx_set: TransactionSet, + pub tx_processing: VecM, + pub upgrades_processing: VecM, + pub scp_info: VecM, +} + +impl LedgerCloseMetaV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaV0`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_v0(&mut self, v: &LedgerCloseMetaV0) { + self.write_type_ledger_header_history_entry(&v.ledger_header); + self.write_type_transaction_set(&v.tx_set); + self.write_type_vec_transaction_result_meta(&v.tx_processing); + self.write_type_vec_upgrade_entry_meta(&v.upgrades_processing); + self.write_type_vec_scp_history_entry(&v.scp_info); + } +} diff --git a/src/generated/const/ledger_close_meta_v1.rs b/src/generated/const/ledger_close_meta_v1.rs new file mode 100644 index 000000000..a1073a626 --- /dev/null +++ b/src/generated/const/ledger_close_meta_v1.rs @@ -0,0 +1,70 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseMetaV1 is a borrowing equivalent of [`LedgerCloseMetaV1`](super::super::LedgerCloseMetaV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerCloseMetaV1 { + pub ext: LedgerCloseMetaExt, + pub ledger_header: LedgerHeaderHistoryEntry, + pub tx_set: GeneralizedTransactionSet, + pub tx_processing: VecM, + pub upgrades_processing: VecM, + pub scp_info: VecM, + pub total_byte_size_of_live_soroban_state: u64, + pub evicted_keys: VecM, + pub unused: VecM, +} + +impl LedgerCloseMetaV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaV1`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_v1(&mut self, v: &LedgerCloseMetaV1) { + self.write_type_ledger_close_meta_ext(&v.ext); + self.write_type_ledger_header_history_entry(&v.ledger_header); + self.write_type_generalized_transaction_set(&v.tx_set); + self.write_type_vec_transaction_result_meta(&v.tx_processing); + self.write_type_vec_upgrade_entry_meta(&v.upgrades_processing); + self.write_type_vec_scp_history_entry(&v.scp_info); + self.write_u64(v.total_byte_size_of_live_soroban_state); + self.write_type_vec_ledger_key(&v.evicted_keys); + self.write_type_vec_ledger_entry(&v.unused); + } +} diff --git a/src/generated/const/ledger_close_meta_v2.rs b/src/generated/const/ledger_close_meta_v2.rs new file mode 100644 index 000000000..d14391a9f --- /dev/null +++ b/src/generated/const/ledger_close_meta_v2.rs @@ -0,0 +1,68 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseMetaV2 is a borrowing equivalent of [`LedgerCloseMetaV2`](super::super::LedgerCloseMetaV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerCloseMetaV2 { + pub ext: LedgerCloseMetaExt, + pub ledger_header: LedgerHeaderHistoryEntry, + pub tx_set: GeneralizedTransactionSet, + pub tx_processing: VecM, + pub upgrades_processing: VecM, + pub scp_info: VecM, + pub total_byte_size_of_live_soroban_state: u64, + pub evicted_keys: VecM, +} + +impl LedgerCloseMetaV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_meta_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_meta_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseMetaV2`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_meta_v2(&mut self, v: &LedgerCloseMetaV2) { + self.write_type_ledger_close_meta_ext(&v.ext); + self.write_type_ledger_header_history_entry(&v.ledger_header); + self.write_type_generalized_transaction_set(&v.tx_set); + self.write_type_vec_transaction_result_meta_v1(&v.tx_processing); + self.write_type_vec_upgrade_entry_meta(&v.upgrades_processing); + self.write_type_vec_scp_history_entry(&v.scp_info); + self.write_u64(v.total_byte_size_of_live_soroban_state); + self.write_type_vec_ledger_key(&v.evicted_keys); + } +} diff --git a/src/generated/const/ledger_close_value_signature.rs b/src/generated/const/ledger_close_value_signature.rs new file mode 100644 index 000000000..d919f831c --- /dev/null +++ b/src/generated/const/ledger_close_value_signature.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerCloseValueSignature is a borrowing equivalent of [`LedgerCloseValueSignature`](super::super::LedgerCloseValueSignature) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerCloseValueSignature { + pub node_id: NodeId, + pub signature: Signature, +} + +impl LedgerCloseValueSignature { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_close_value_signature(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_close_value_signature(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerCloseValueSignature`], mirroring `::write_xdr`. + pub const fn write_type_ledger_close_value_signature(&mut self, v: &LedgerCloseValueSignature) { + self.write_type_node_id(&v.node_id); + self.write_type_signature(&v.signature); + } +} diff --git a/src/generated/const/ledger_entry.rs b/src/generated/const/ledger_entry.rs new file mode 100644 index 000000000..a26ce6889 --- /dev/null +++ b/src/generated/const/ledger_entry.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerEntry is a borrowing equivalent of [`LedgerEntry`](super::super::LedgerEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerEntry { + pub last_modified_ledger_seq: u32, + pub data: LedgerEntryData, + pub ext: LedgerEntryExt, +} + +impl LedgerEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntry`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry(&mut self, v: &LedgerEntry) { + self.write_u32(v.last_modified_ledger_seq); + self.write_type_ledger_entry_data(&v.data); + self.write_type_ledger_entry_ext(&v.ext); + } + + /// Serializes a variable-length array of [`LedgerEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_ledger_entry( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_ledger_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/ledger_entry_change.rs b/src/generated/const/ledger_entry_change.rs new file mode 100644 index 000000000..10016ba02 --- /dev/null +++ b/src/generated/const/ledger_entry_change.rs @@ -0,0 +1,107 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerEntryChange is a borrowing equivalent of [`LedgerEntryChange`](super::super::LedgerEntryChange) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum LedgerEntryChange { + Created(LedgerEntry), + Updated(LedgerEntry), + Removed(LedgerKey), + State(LedgerEntry), + Restored(LedgerEntry), +} + +impl LedgerEntryChange { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryChangeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Created(_) => LedgerEntryChangeType::Created, + Self::Updated(_) => LedgerEntryChangeType::Updated, + Self::Removed(_) => LedgerEntryChangeType::Removed, + Self::State(_) => LedgerEntryChangeType::State, + Self::Restored(_) => LedgerEntryChangeType::Restored, + } + } +} + +impl LedgerEntryChange { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_change(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_change(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryChange`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_change(&mut self, v: &LedgerEntryChange) { + let d = v.discriminant(); + self.write_type_ledger_entry_change_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryChange::Created(value) => { + self.write_type_ledger_entry(value); + } + LedgerEntryChange::Updated(value) => { + self.write_type_ledger_entry(value); + } + LedgerEntryChange::Removed(value) => { + self.write_type_ledger_key(value); + } + LedgerEntryChange::State(value) => { + self.write_type_ledger_entry(value); + } + LedgerEntryChange::Restored(value) => { + self.write_type_ledger_entry(value); + } + } + } + + /// Serializes a variable-length array of [`LedgerEntryChange`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_ledger_entry_change( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_ledger_entry_change(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/ledger_entry_change_type.rs b/src/generated/const/ledger_entry_change_type.rs new file mode 100644 index 000000000..3082bdfc4 --- /dev/null +++ b/src/generated/const/ledger_entry_change_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerEntryChangeType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_change_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_change_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryChangeType`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_change_type(&mut self, v: &LedgerEntryChangeType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/ledger_entry_changes.rs b/src/generated/const/ledger_entry_changes.rs new file mode 100644 index 000000000..62429118c --- /dev/null +++ b/src/generated/const/ledger_entry_changes.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerEntryChanges is a borrowing equivalent of [`LedgerEntryChanges`](super::super::LedgerEntryChanges) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerEntryChanges(pub VecM); + +impl LedgerEntryChanges { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_changes(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_changes(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryChanges`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_changes(&mut self, v: &LedgerEntryChanges) { + self.write_type_vec_ledger_entry_change(&v.0); + } +} diff --git a/src/generated/const/ledger_entry_data.rs b/src/generated/const/ledger_entry_data.rs new file mode 100644 index 000000000..20e9af7d9 --- /dev/null +++ b/src/generated/const/ledger_entry_data.rs @@ -0,0 +1,117 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerEntryData is a borrowing equivalent of [`LedgerEntryData`](super::super::LedgerEntryData) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum LedgerEntryData { + Account(AccountEntry), + Trustline(TrustLineEntry), + Offer(OfferEntry), + Data(DataEntry), + ClaimableBalance(ClaimableBalanceEntry), + LiquidityPool(LiquidityPoolEntry), + ContractData(ContractDataEntry), + ContractCode(ContractCodeEntry), + ConfigSetting(ConfigSettingEntry), + Ttl(TtlEntry), +} + +impl LedgerEntryData { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Account(_) => LedgerEntryType::Account, + Self::Trustline(_) => LedgerEntryType::Trustline, + Self::Offer(_) => LedgerEntryType::Offer, + Self::Data(_) => LedgerEntryType::Data, + Self::ClaimableBalance(_) => LedgerEntryType::ClaimableBalance, + Self::LiquidityPool(_) => LedgerEntryType::LiquidityPool, + Self::ContractData(_) => LedgerEntryType::ContractData, + Self::ContractCode(_) => LedgerEntryType::ContractCode, + Self::ConfigSetting(_) => LedgerEntryType::ConfigSetting, + Self::Ttl(_) => LedgerEntryType::Ttl, + } + } +} + +impl LedgerEntryData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryData`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_data(&mut self, v: &LedgerEntryData) { + let d = v.discriminant(); + self.write_type_ledger_entry_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryData::Account(value) => { + self.write_type_account_entry(value); + } + LedgerEntryData::Trustline(value) => { + self.write_type_trust_line_entry(value); + } + LedgerEntryData::Offer(value) => { + self.write_type_offer_entry(value); + } + LedgerEntryData::Data(value) => { + self.write_type_data_entry(value); + } + LedgerEntryData::ClaimableBalance(value) => { + self.write_type_claimable_balance_entry(value); + } + LedgerEntryData::LiquidityPool(value) => { + self.write_type_liquidity_pool_entry(value); + } + LedgerEntryData::ContractData(value) => { + self.write_type_contract_data_entry(value); + } + LedgerEntryData::ContractCode(value) => { + self.write_type_contract_code_entry(value); + } + LedgerEntryData::ConfigSetting(value) => { + self.write_type_config_setting_entry(value); + } + LedgerEntryData::Ttl(value) => { + self.write_type_ttl_entry(value); + } + } + } +} diff --git a/src/generated/const/ledger_entry_ext.rs b/src/generated/const/ledger_entry_ext.rs new file mode 100644 index 000000000..bb5ce13ab --- /dev/null +++ b/src/generated/const/ledger_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_ext(&mut self, v: &LedgerEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryExt::V0 => {} + LedgerEntryExt::V1(value) => { + self.write_type_ledger_entry_extension_v1(value); + } + } + } +} diff --git a/src/generated/const/ledger_entry_extension_v1.rs b/src/generated/const/ledger_entry_extension_v1.rs new file mode 100644 index 000000000..21c7bba87 --- /dev/null +++ b/src/generated/const/ledger_entry_extension_v1.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerEntryExtensionV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_extension_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_extension_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryExtensionV1`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_extension_v1(&mut self, v: &LedgerEntryExtensionV1) { + self.write_type_sponsorship_descriptor(&v.sponsoring_id); + self.write_type_ledger_entry_extension_v1_ext(&v.ext); + } +} diff --git a/src/generated/const/ledger_entry_extension_v1_ext.rs b/src/generated/const/ledger_entry_extension_v1_ext.rs new file mode 100644 index 000000000..fd6097686 --- /dev/null +++ b/src/generated/const/ledger_entry_extension_v1_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerEntryExtensionV1Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_extension_v1_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_extension_v1_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryExtensionV1Ext`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_extension_v1_ext( + &mut self, + v: &LedgerEntryExtensionV1Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryExtensionV1Ext::V0 => {} + } + } +} diff --git a/src/generated/const/ledger_entry_type.rs b/src/generated/const/ledger_entry_type.rs new file mode 100644 index 000000000..031971d22 --- /dev/null +++ b/src/generated/const/ledger_entry_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerEntryType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_entry_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_entry_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerEntryType`], mirroring `::write_xdr`. + pub const fn write_type_ledger_entry_type(&mut self, v: &LedgerEntryType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/ledger_footprint.rs b/src/generated/const/ledger_footprint.rs new file mode 100644 index 000000000..143a21528 --- /dev/null +++ b/src/generated/const/ledger_footprint.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerFootprint is a borrowing equivalent of [`LedgerFootprint`](super::super::LedgerFootprint) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerFootprint { + pub read_only: VecM, + pub read_write: VecM, +} + +impl LedgerFootprint { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_footprint(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_footprint(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerFootprint`], mirroring `::write_xdr`. + pub const fn write_type_ledger_footprint(&mut self, v: &LedgerFootprint) { + self.write_type_vec_ledger_key(&v.read_only); + self.write_type_vec_ledger_key(&v.read_write); + } +} diff --git a/src/generated/const/ledger_header.rs b/src/generated/const/ledger_header.rs new file mode 100644 index 000000000..3b25ddc3f --- /dev/null +++ b/src/generated/const/ledger_header.rs @@ -0,0 +1,88 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerHeader is a borrowing equivalent of [`LedgerHeader`](super::super::LedgerHeader) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerHeader { + pub ledger_version: u32, + pub previous_ledger_hash: Hash, + pub scp_value: StellarValue, + pub tx_set_result_hash: Hash, + pub bucket_list_hash: Hash, + pub ledger_seq: u32, + pub total_coins: i64, + pub fee_pool: i64, + pub inflation_seq: u32, + pub id_pool: u64, + pub base_fee: u32, + pub base_reserve: u32, + pub max_tx_set_size: u32, + pub skip_list: [Hash; 4], + pub ext: LedgerHeaderExt, +} + +impl LedgerHeader { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeader`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header(&mut self, v: &LedgerHeader) { + self.write_u32(v.ledger_version); + self.write_type_hash(&v.previous_ledger_hash); + self.write_type_stellar_value(&v.scp_value); + self.write_type_hash(&v.tx_set_result_hash); + self.write_type_hash(&v.bucket_list_hash); + self.write_u32(v.ledger_seq); + self.write_i64(v.total_coins); + self.write_i64(v.fee_pool); + self.write_u32(v.inflation_seq); + self.write_u64(v.id_pool); + self.write_u32(v.base_fee); + self.write_u32(v.base_reserve); + self.write_u32(v.max_tx_set_size); + { + let mut i = 0usize; + while i < 4 { + self.write_type_hash(&v.skip_list[i]); + i += 1; + } + } + self.write_type_ledger_header_ext(&v.ext); + } +} diff --git a/src/generated/const/ledger_header_ext.rs b/src/generated/const/ledger_header_ext.rs new file mode 100644 index 000000000..e928bfa24 --- /dev/null +++ b/src/generated/const/ledger_header_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerHeaderExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderExt`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_ext(&mut self, v: &LedgerHeaderExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerHeaderExt::V0 => {} + LedgerHeaderExt::V1(value) => { + self.write_type_ledger_header_extension_v1(value); + } + } + } +} diff --git a/src/generated/const/ledger_header_extension_v1.rs b/src/generated/const/ledger_header_extension_v1.rs new file mode 100644 index 000000000..2da2fdc2b --- /dev/null +++ b/src/generated/const/ledger_header_extension_v1.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerHeaderExtensionV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_extension_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_extension_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderExtensionV1`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_extension_v1(&mut self, v: &LedgerHeaderExtensionV1) { + self.write_u32(v.flags); + self.write_type_ledger_header_extension_v1_ext(&v.ext); + } +} diff --git a/src/generated/const/ledger_header_extension_v1_ext.rs b/src/generated/const/ledger_header_extension_v1_ext.rs new file mode 100644 index 000000000..9b02a9ccb --- /dev/null +++ b/src/generated/const/ledger_header_extension_v1_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerHeaderExtensionV1Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_extension_v1_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_extension_v1_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderExtensionV1Ext`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_extension_v1_ext( + &mut self, + v: &LedgerHeaderExtensionV1Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerHeaderExtensionV1Ext::V0 => {} + } + } +} diff --git a/src/generated/const/ledger_header_flags.rs b/src/generated/const/ledger_header_flags.rs new file mode 100644 index 000000000..de8d8e236 --- /dev/null +++ b/src/generated/const/ledger_header_flags.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerHeaderFlags { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_flags(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_flags(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderFlags`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_flags(&mut self, v: &LedgerHeaderFlags) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/ledger_header_history_entry.rs b/src/generated/const/ledger_header_history_entry.rs new file mode 100644 index 000000000..5a57acd70 --- /dev/null +++ b/src/generated/const/ledger_header_history_entry.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerHeaderHistoryEntry is a borrowing equivalent of [`LedgerHeaderHistoryEntry`](super::super::LedgerHeaderHistoryEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerHeaderHistoryEntry { + pub hash: Hash, + pub header: LedgerHeader, + pub ext: LedgerHeaderHistoryEntryExt, +} + +impl LedgerHeaderHistoryEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_history_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_history_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderHistoryEntry`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_history_entry(&mut self, v: &LedgerHeaderHistoryEntry) { + self.write_type_hash(&v.hash); + self.write_type_ledger_header(&v.header); + self.write_type_ledger_header_history_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/ledger_header_history_entry_ext.rs b/src/generated/const/ledger_header_history_entry_ext.rs new file mode 100644 index 000000000..029e92fe5 --- /dev/null +++ b/src/generated/const/ledger_header_history_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerHeaderHistoryEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_header_history_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_header_history_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerHeaderHistoryEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_ledger_header_history_entry_ext( + &mut self, + v: &LedgerHeaderHistoryEntryExt, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + LedgerHeaderHistoryEntryExt::V0 => {} + } + } +} diff --git a/src/generated/const/ledger_key.rs b/src/generated/const/ledger_key.rs new file mode 100644 index 000000000..4113a0bfd --- /dev/null +++ b/src/generated/const/ledger_key.rs @@ -0,0 +1,129 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerKey is a borrowing equivalent of [`LedgerKey`](super::super::LedgerKey) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum LedgerKey { + Account(LedgerKeyAccount), + Trustline(LedgerKeyTrustLine), + Offer(LedgerKeyOffer), + Data(LedgerKeyData), + ClaimableBalance(LedgerKeyClaimableBalance), + LiquidityPool(LedgerKeyLiquidityPool), + ContractData(LedgerKeyContractData), + ContractCode(LedgerKeyContractCode), + ConfigSetting(LedgerKeyConfigSetting), + Ttl(LedgerKeyTtl), +} + +impl LedgerKey { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Account(_) => LedgerEntryType::Account, + Self::Trustline(_) => LedgerEntryType::Trustline, + Self::Offer(_) => LedgerEntryType::Offer, + Self::Data(_) => LedgerEntryType::Data, + Self::ClaimableBalance(_) => LedgerEntryType::ClaimableBalance, + Self::LiquidityPool(_) => LedgerEntryType::LiquidityPool, + Self::ContractData(_) => LedgerEntryType::ContractData, + Self::ContractCode(_) => LedgerEntryType::ContractCode, + Self::ConfigSetting(_) => LedgerEntryType::ConfigSetting, + Self::Ttl(_) => LedgerEntryType::Ttl, + } + } +} + +impl LedgerKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKey`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key(&mut self, v: &LedgerKey) { + let d = v.discriminant(); + self.write_type_ledger_entry_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LedgerKey::Account(value) => { + self.write_type_ledger_key_account(value); + } + LedgerKey::Trustline(value) => { + self.write_type_ledger_key_trust_line(value); + } + LedgerKey::Offer(value) => { + self.write_type_ledger_key_offer(value); + } + LedgerKey::Data(value) => { + self.write_type_ledger_key_data(value); + } + LedgerKey::ClaimableBalance(value) => { + self.write_type_ledger_key_claimable_balance(value); + } + LedgerKey::LiquidityPool(value) => { + self.write_type_ledger_key_liquidity_pool(value); + } + LedgerKey::ContractData(value) => { + self.write_type_ledger_key_contract_data(value); + } + LedgerKey::ContractCode(value) => { + self.write_type_ledger_key_contract_code(value); + } + LedgerKey::ConfigSetting(value) => { + self.write_type_ledger_key_config_setting(value); + } + LedgerKey::Ttl(value) => { + self.write_type_ledger_key_ttl(value); + } + } + } + + /// Serializes a variable-length array of [`LedgerKey`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_ledger_key(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_ledger_key(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/ledger_key_account.rs b/src/generated/const/ledger_key_account.rs new file mode 100644 index 000000000..09c0aad6d --- /dev/null +++ b/src/generated/const/ledger_key_account.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyAccount { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_account(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_account(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyAccount`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_account(&mut self, v: &LedgerKeyAccount) { + self.write_type_account_id(&v.account_id); + } +} diff --git a/src/generated/const/ledger_key_claimable_balance.rs b/src/generated/const/ledger_key_claimable_balance.rs new file mode 100644 index 000000000..25893f8bd --- /dev/null +++ b/src/generated/const/ledger_key_claimable_balance.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyClaimableBalance { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_claimable_balance(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_claimable_balance(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyClaimableBalance`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_claimable_balance(&mut self, v: &LedgerKeyClaimableBalance) { + self.write_type_claimable_balance_id(&v.balance_id); + } +} diff --git a/src/generated/const/ledger_key_config_setting.rs b/src/generated/const/ledger_key_config_setting.rs new file mode 100644 index 000000000..554f6a692 --- /dev/null +++ b/src/generated/const/ledger_key_config_setting.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyConfigSetting { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_config_setting(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_config_setting(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyConfigSetting`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_config_setting(&mut self, v: &LedgerKeyConfigSetting) { + self.write_type_config_setting_id(&v.config_setting_id); + } +} diff --git a/src/generated/const/ledger_key_contract_code.rs b/src/generated/const/ledger_key_contract_code.rs new file mode 100644 index 000000000..8b2177142 --- /dev/null +++ b/src/generated/const/ledger_key_contract_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyContractCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_contract_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_contract_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyContractCode`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_contract_code(&mut self, v: &LedgerKeyContractCode) { + self.write_type_hash(&v.hash); + } +} diff --git a/src/generated/const/ledger_key_contract_data.rs b/src/generated/const/ledger_key_contract_data.rs new file mode 100644 index 000000000..1090e93de --- /dev/null +++ b/src/generated/const/ledger_key_contract_data.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerKeyContractData is a borrowing equivalent of [`LedgerKeyContractData`](super::super::LedgerKeyContractData) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerKeyContractData { + pub contract: ScAddress, + pub key: ScVal, + pub durability: ContractDataDurability, +} + +impl LedgerKeyContractData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_contract_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_contract_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyContractData`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_contract_data(&mut self, v: &LedgerKeyContractData) { + self.write_type_sc_address(&v.contract); + self.write_type_sc_val(&v.key); + self.write_type_contract_data_durability(&v.durability); + } +} diff --git a/src/generated/const/ledger_key_data.rs b/src/generated/const/ledger_key_data.rs new file mode 100644 index 000000000..6452bc3ce --- /dev/null +++ b/src/generated/const/ledger_key_data.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerKeyData is a borrowing equivalent of [`LedgerKeyData`](super::super::LedgerKeyData) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerKeyData { + pub account_id: AccountId, + pub data_name: String64, +} + +impl LedgerKeyData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyData`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_data(&mut self, v: &LedgerKeyData) { + self.write_type_account_id(&v.account_id); + self.write_type_string64(&v.data_name); + } +} diff --git a/src/generated/const/ledger_key_liquidity_pool.rs b/src/generated/const/ledger_key_liquidity_pool.rs new file mode 100644 index 000000000..a76b6a38f --- /dev/null +++ b/src/generated/const/ledger_key_liquidity_pool.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyLiquidityPool { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_liquidity_pool(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_liquidity_pool(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyLiquidityPool`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_liquidity_pool(&mut self, v: &LedgerKeyLiquidityPool) { + self.write_type_pool_id(&v.liquidity_pool_id); + } +} diff --git a/src/generated/const/ledger_key_offer.rs b/src/generated/const/ledger_key_offer.rs new file mode 100644 index 000000000..ba0d0b132 --- /dev/null +++ b/src/generated/const/ledger_key_offer.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyOffer { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_offer(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_offer(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyOffer`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_offer(&mut self, v: &LedgerKeyOffer) { + self.write_type_account_id(&v.seller_id); + self.write_i64(v.offer_id); + } +} diff --git a/src/generated/const/ledger_key_trust_line.rs b/src/generated/const/ledger_key_trust_line.rs new file mode 100644 index 000000000..854b3d8f5 --- /dev/null +++ b/src/generated/const/ledger_key_trust_line.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyTrustLine { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_trust_line(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_trust_line(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyTrustLine`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_trust_line(&mut self, v: &LedgerKeyTrustLine) { + self.write_type_account_id(&v.account_id); + self.write_type_trust_line_asset(&v.asset); + } +} diff --git a/src/generated/const/ledger_key_ttl.rs b/src/generated/const/ledger_key_ttl.rs new file mode 100644 index 000000000..d0e5520d1 --- /dev/null +++ b/src/generated/const/ledger_key_ttl.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerKeyTtl { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_key_ttl(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_key_ttl(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerKeyTtl`], mirroring `::write_xdr`. + pub const fn write_type_ledger_key_ttl(&mut self, v: &LedgerKeyTtl) { + self.write_type_hash(&v.key_hash); + } +} diff --git a/src/generated/const/ledger_scp_messages.rs b/src/generated/const/ledger_scp_messages.rs new file mode 100644 index 000000000..75a2d4394 --- /dev/null +++ b/src/generated/const/ledger_scp_messages.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// LedgerScpMessages is a borrowing equivalent of [`LedgerScpMessages`](super::super::LedgerScpMessages) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct LedgerScpMessages { + pub ledger_seq: u32, + pub messages: VecM, +} + +impl LedgerScpMessages { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_scp_messages(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_scp_messages(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerScpMessages`], mirroring `::write_xdr`. + pub const fn write_type_ledger_scp_messages(&mut self, v: &LedgerScpMessages) { + self.write_u32(v.ledger_seq); + self.write_type_vec_scp_envelope(&v.messages); + } +} diff --git a/src/generated/const/ledger_upgrade.rs b/src/generated/const/ledger_upgrade.rs new file mode 100644 index 000000000..203131aa6 --- /dev/null +++ b/src/generated/const/ledger_upgrade.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerUpgrade { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_upgrade(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_upgrade(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerUpgrade`], mirroring `::write_xdr`. + pub const fn write_type_ledger_upgrade(&mut self, v: &LedgerUpgrade) { + let d = v.discriminant(); + self.write_type_ledger_upgrade_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LedgerUpgrade::Version(value) => { + self.write_u32(*value); + } + LedgerUpgrade::BaseFee(value) => { + self.write_u32(*value); + } + LedgerUpgrade::MaxTxSetSize(value) => { + self.write_u32(*value); + } + LedgerUpgrade::BaseReserve(value) => { + self.write_u32(*value); + } + LedgerUpgrade::Flags(value) => { + self.write_u32(*value); + } + LedgerUpgrade::Config(value) => { + self.write_type_config_upgrade_set_key(value); + } + LedgerUpgrade::MaxSorobanTxSetSize(value) => { + self.write_u32(*value); + } + } + } +} diff --git a/src/generated/const/ledger_upgrade_type.rs b/src/generated/const/ledger_upgrade_type.rs new file mode 100644 index 000000000..a57364b31 --- /dev/null +++ b/src/generated/const/ledger_upgrade_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LedgerUpgradeType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ledger_upgrade_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ledger_upgrade_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LedgerUpgradeType`], mirroring `::write_xdr`. + pub const fn write_type_ledger_upgrade_type(&mut self, v: &LedgerUpgradeType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/liabilities.rs b/src/generated/const/liabilities.rs new file mode 100644 index 000000000..0c794c278 --- /dev/null +++ b/src/generated/const/liabilities.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Liabilities { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liabilities(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liabilities(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Liabilities`], mirroring `::write_xdr`. + pub const fn write_type_liabilities(&mut self, v: &Liabilities) { + self.write_i64(v.buying); + self.write_i64(v.selling); + } +} diff --git a/src/generated/const/liquidity_pool_constant_product_parameters.rs b/src/generated/const/liquidity_pool_constant_product_parameters.rs new file mode 100644 index 000000000..4d1a4f55d --- /dev/null +++ b/src/generated/const/liquidity_pool_constant_product_parameters.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolConstantProductParameters { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_constant_product_parameters(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_constant_product_parameters(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolConstantProductParameters`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_constant_product_parameters( + &mut self, + v: &LiquidityPoolConstantProductParameters, + ) { + self.write_type_asset(&v.asset_a); + self.write_type_asset(&v.asset_b); + self.write_i32(v.fee); + } +} diff --git a/src/generated/const/liquidity_pool_deposit_op.rs b/src/generated/const/liquidity_pool_deposit_op.rs new file mode 100644 index 000000000..5965ab239 --- /dev/null +++ b/src/generated/const/liquidity_pool_deposit_op.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolDepositOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_deposit_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_deposit_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolDepositOp`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_deposit_op(&mut self, v: &LiquidityPoolDepositOp) { + self.write_type_pool_id(&v.liquidity_pool_id); + self.write_i64(v.max_amount_a); + self.write_i64(v.max_amount_b); + self.write_type_price(&v.min_price); + self.write_type_price(&v.max_price); + } +} diff --git a/src/generated/const/liquidity_pool_deposit_result.rs b/src/generated/const/liquidity_pool_deposit_result.rs new file mode 100644 index 000000000..70876574f --- /dev/null +++ b/src/generated/const/liquidity_pool_deposit_result.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolDepositResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_deposit_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_deposit_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolDepositResult`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_deposit_result( + &mut self, + v: &LiquidityPoolDepositResult, + ) { + let d = v.discriminant(); + self.write_type_liquidity_pool_deposit_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + LiquidityPoolDepositResult::Success => {} + LiquidityPoolDepositResult::Malformed => {} + LiquidityPoolDepositResult::NoTrust => {} + LiquidityPoolDepositResult::NotAuthorized => {} + LiquidityPoolDepositResult::Underfunded => {} + LiquidityPoolDepositResult::LineFull => {} + LiquidityPoolDepositResult::BadPrice => {} + LiquidityPoolDepositResult::PoolFull => {} + LiquidityPoolDepositResult::TrustlineFrozen => {} + } + } +} diff --git a/src/generated/const/liquidity_pool_deposit_result_code.rs b/src/generated/const/liquidity_pool_deposit_result_code.rs new file mode 100644 index 000000000..b5cca0e1f --- /dev/null +++ b/src/generated/const/liquidity_pool_deposit_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolDepositResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_deposit_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_deposit_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolDepositResultCode`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_deposit_result_code( + &mut self, + v: &LiquidityPoolDepositResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/liquidity_pool_entry.rs b/src/generated/const/liquidity_pool_entry.rs new file mode 100644 index 000000000..bab72fa96 --- /dev/null +++ b/src/generated/const/liquidity_pool_entry.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolEntry`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_entry(&mut self, v: &LiquidityPoolEntry) { + self.write_type_pool_id(&v.liquidity_pool_id); + self.write_type_liquidity_pool_entry_body(&v.body); + } +} diff --git a/src/generated/const/liquidity_pool_entry_body.rs b/src/generated/const/liquidity_pool_entry_body.rs new file mode 100644 index 000000000..c7aed220c --- /dev/null +++ b/src/generated/const/liquidity_pool_entry_body.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolEntryBody { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_entry_body(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_entry_body(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolEntryBody`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_entry_body(&mut self, v: &LiquidityPoolEntryBody) { + let d = v.discriminant(); + self.write_type_liquidity_pool_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LiquidityPoolEntryBody::LiquidityPoolConstantProduct(value) => { + self.write_type_liquidity_pool_entry_constant_product(value); + } + } + } +} diff --git a/src/generated/const/liquidity_pool_entry_constant_product.rs b/src/generated/const/liquidity_pool_entry_constant_product.rs new file mode 100644 index 000000000..0d5a4a421 --- /dev/null +++ b/src/generated/const/liquidity_pool_entry_constant_product.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolEntryConstantProduct { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_entry_constant_product(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_entry_constant_product(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolEntryConstantProduct`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_entry_constant_product( + &mut self, + v: &LiquidityPoolEntryConstantProduct, + ) { + self.write_type_liquidity_pool_constant_product_parameters(&v.params); + self.write_i64(v.reserve_a); + self.write_i64(v.reserve_b); + self.write_i64(v.total_pool_shares); + self.write_i64(v.pool_shares_trust_line_count); + } +} diff --git a/src/generated/const/liquidity_pool_parameters.rs b/src/generated/const/liquidity_pool_parameters.rs new file mode 100644 index 000000000..691862ca9 --- /dev/null +++ b/src/generated/const/liquidity_pool_parameters.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolParameters { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_parameters(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_parameters(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolParameters`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_parameters(&mut self, v: &LiquidityPoolParameters) { + let d = v.discriminant(); + self.write_type_liquidity_pool_type(&d); + #[allow(clippy::match_same_arms)] + match v { + LiquidityPoolParameters::LiquidityPoolConstantProduct(value) => { + self.write_type_liquidity_pool_constant_product_parameters(value); + } + } + } +} diff --git a/src/generated/const/liquidity_pool_type.rs b/src/generated/const/liquidity_pool_type.rs new file mode 100644 index 000000000..36ede1aef --- /dev/null +++ b/src/generated/const/liquidity_pool_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolType`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_type(&mut self, v: &LiquidityPoolType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/liquidity_pool_withdraw_op.rs b/src/generated/const/liquidity_pool_withdraw_op.rs new file mode 100644 index 000000000..c155a430a --- /dev/null +++ b/src/generated/const/liquidity_pool_withdraw_op.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolWithdrawOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_withdraw_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_withdraw_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolWithdrawOp`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_withdraw_op(&mut self, v: &LiquidityPoolWithdrawOp) { + self.write_type_pool_id(&v.liquidity_pool_id); + self.write_i64(v.amount); + self.write_i64(v.min_amount_a); + self.write_i64(v.min_amount_b); + } +} diff --git a/src/generated/const/liquidity_pool_withdraw_result.rs b/src/generated/const/liquidity_pool_withdraw_result.rs new file mode 100644 index 000000000..1873ef6e2 --- /dev/null +++ b/src/generated/const/liquidity_pool_withdraw_result.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolWithdrawResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_withdraw_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_withdraw_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolWithdrawResult`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_withdraw_result( + &mut self, + v: &LiquidityPoolWithdrawResult, + ) { + let d = v.discriminant(); + self.write_type_liquidity_pool_withdraw_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + LiquidityPoolWithdrawResult::Success => {} + LiquidityPoolWithdrawResult::Malformed => {} + LiquidityPoolWithdrawResult::NoTrust => {} + LiquidityPoolWithdrawResult::Underfunded => {} + LiquidityPoolWithdrawResult::LineFull => {} + LiquidityPoolWithdrawResult::UnderMinimum => {} + LiquidityPoolWithdrawResult::TrustlineFrozen => {} + } + } +} diff --git a/src/generated/const/liquidity_pool_withdraw_result_code.rs b/src/generated/const/liquidity_pool_withdraw_result_code.rs new file mode 100644 index 000000000..cae3f1a5f --- /dev/null +++ b/src/generated/const/liquidity_pool_withdraw_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl LiquidityPoolWithdrawResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_liquidity_pool_withdraw_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_liquidity_pool_withdraw_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`LiquidityPoolWithdrawResultCode`], mirroring `::write_xdr`. + pub const fn write_type_liquidity_pool_withdraw_result_code( + &mut self, + v: &LiquidityPoolWithdrawResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/manage_buy_offer_op.rs b/src/generated/const/manage_buy_offer_op.rs new file mode 100644 index 000000000..db0367340 --- /dev/null +++ b/src/generated/const/manage_buy_offer_op.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageBuyOfferOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_buy_offer_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_buy_offer_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageBuyOfferOp`], mirroring `::write_xdr`. + pub const fn write_type_manage_buy_offer_op(&mut self, v: &ManageBuyOfferOp) { + self.write_type_asset(&v.selling); + self.write_type_asset(&v.buying); + self.write_i64(v.buy_amount); + self.write_type_price(&v.price); + self.write_i64(v.offer_id); + } +} diff --git a/src/generated/const/manage_buy_offer_result.rs b/src/generated/const/manage_buy_offer_result.rs new file mode 100644 index 000000000..cc976af00 --- /dev/null +++ b/src/generated/const/manage_buy_offer_result.rs @@ -0,0 +1,108 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ManageBuyOfferResult is a borrowing equivalent of [`ManageBuyOfferResult`](super::super::ManageBuyOfferResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ManageBuyOfferResult { + Success(ManageOfferSuccessResult), + Malformed, + SellNoTrust, + BuyNoTrust, + SellNotAuthorized, + BuyNotAuthorized, + LineFull, + Underfunded, + CrossSelf, + SellNoIssuer, + BuyNoIssuer, + NotFound, + LowReserve, +} + +impl ManageBuyOfferResult { + #[must_use] + pub const fn discriminant(&self) -> ManageBuyOfferResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => ManageBuyOfferResultCode::Success, + Self::Malformed => ManageBuyOfferResultCode::Malformed, + Self::SellNoTrust => ManageBuyOfferResultCode::SellNoTrust, + Self::BuyNoTrust => ManageBuyOfferResultCode::BuyNoTrust, + Self::SellNotAuthorized => ManageBuyOfferResultCode::SellNotAuthorized, + Self::BuyNotAuthorized => ManageBuyOfferResultCode::BuyNotAuthorized, + Self::LineFull => ManageBuyOfferResultCode::LineFull, + Self::Underfunded => ManageBuyOfferResultCode::Underfunded, + Self::CrossSelf => ManageBuyOfferResultCode::CrossSelf, + Self::SellNoIssuer => ManageBuyOfferResultCode::SellNoIssuer, + Self::BuyNoIssuer => ManageBuyOfferResultCode::BuyNoIssuer, + Self::NotFound => ManageBuyOfferResultCode::NotFound, + Self::LowReserve => ManageBuyOfferResultCode::LowReserve, + } + } +} + +impl ManageBuyOfferResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_buy_offer_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_buy_offer_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageBuyOfferResult`], mirroring `::write_xdr`. + pub const fn write_type_manage_buy_offer_result(&mut self, v: &ManageBuyOfferResult) { + let d = v.discriminant(); + self.write_type_manage_buy_offer_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ManageBuyOfferResult::Success(value) => { + self.write_type_manage_offer_success_result(value); + } + ManageBuyOfferResult::Malformed => {} + ManageBuyOfferResult::SellNoTrust => {} + ManageBuyOfferResult::BuyNoTrust => {} + ManageBuyOfferResult::SellNotAuthorized => {} + ManageBuyOfferResult::BuyNotAuthorized => {} + ManageBuyOfferResult::LineFull => {} + ManageBuyOfferResult::Underfunded => {} + ManageBuyOfferResult::CrossSelf => {} + ManageBuyOfferResult::SellNoIssuer => {} + ManageBuyOfferResult::BuyNoIssuer => {} + ManageBuyOfferResult::NotFound => {} + ManageBuyOfferResult::LowReserve => {} + } + } +} diff --git a/src/generated/const/manage_buy_offer_result_code.rs b/src/generated/const/manage_buy_offer_result_code.rs new file mode 100644 index 000000000..7c1a7110a --- /dev/null +++ b/src/generated/const/manage_buy_offer_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageBuyOfferResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_buy_offer_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_buy_offer_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageBuyOfferResultCode`], mirroring `::write_xdr`. + pub const fn write_type_manage_buy_offer_result_code(&mut self, v: &ManageBuyOfferResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/manage_data_op.rs b/src/generated/const/manage_data_op.rs new file mode 100644 index 000000000..ecbde780d --- /dev/null +++ b/src/generated/const/manage_data_op.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ManageDataOp is a borrowing equivalent of [`ManageDataOp`](super::super::ManageDataOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ManageDataOp { + pub data_name: String64, + pub data_value: Option, +} + +impl ManageDataOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_data_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_data_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageDataOp`], mirroring `::write_xdr`. + pub const fn write_type_manage_data_op(&mut self, v: &ManageDataOp) { + self.write_type_string64(&v.data_name); + self.write_type_option_data_value(&v.data_value); + } +} diff --git a/src/generated/const/manage_data_result.rs b/src/generated/const/manage_data_result.rs new file mode 100644 index 000000000..1312b5fba --- /dev/null +++ b/src/generated/const/manage_data_result.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageDataResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_data_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_data_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageDataResult`], mirroring `::write_xdr`. + pub const fn write_type_manage_data_result(&mut self, v: &ManageDataResult) { + let d = v.discriminant(); + self.write_type_manage_data_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ManageDataResult::Success => {} + ManageDataResult::NotSupportedYet => {} + ManageDataResult::NameNotFound => {} + ManageDataResult::LowReserve => {} + ManageDataResult::InvalidName => {} + } + } +} diff --git a/src/generated/const/manage_data_result_code.rs b/src/generated/const/manage_data_result_code.rs new file mode 100644 index 000000000..ddceda50a --- /dev/null +++ b/src/generated/const/manage_data_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageDataResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_data_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_data_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageDataResultCode`], mirroring `::write_xdr`. + pub const fn write_type_manage_data_result_code(&mut self, v: &ManageDataResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/manage_offer_effect.rs b/src/generated/const/manage_offer_effect.rs new file mode 100644 index 000000000..f94baddd3 --- /dev/null +++ b/src/generated/const/manage_offer_effect.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageOfferEffect { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_offer_effect(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_offer_effect(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageOfferEffect`], mirroring `::write_xdr`. + pub const fn write_type_manage_offer_effect(&mut self, v: &ManageOfferEffect) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/manage_offer_success_result.rs b/src/generated/const/manage_offer_success_result.rs new file mode 100644 index 000000000..8761c0aed --- /dev/null +++ b/src/generated/const/manage_offer_success_result.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ManageOfferSuccessResult is a borrowing equivalent of [`ManageOfferSuccessResult`](super::super::ManageOfferSuccessResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ManageOfferSuccessResult { + pub offers_claimed: VecM, + pub offer: ManageOfferSuccessResultOffer, +} + +impl ManageOfferSuccessResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_offer_success_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_offer_success_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageOfferSuccessResult`], mirroring `::write_xdr`. + pub const fn write_type_manage_offer_success_result(&mut self, v: &ManageOfferSuccessResult) { + self.write_type_vec_claim_atom(&v.offers_claimed); + self.write_type_manage_offer_success_result_offer(&v.offer); + } +} diff --git a/src/generated/const/manage_offer_success_result_offer.rs b/src/generated/const/manage_offer_success_result_offer.rs new file mode 100644 index 000000000..81c326198 --- /dev/null +++ b/src/generated/const/manage_offer_success_result_offer.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageOfferSuccessResultOffer { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_offer_success_result_offer(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_offer_success_result_offer(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageOfferSuccessResultOffer`], mirroring `::write_xdr`. + pub const fn write_type_manage_offer_success_result_offer( + &mut self, + v: &ManageOfferSuccessResultOffer, + ) { + let d = v.discriminant(); + self.write_type_manage_offer_effect(&d); + #[allow(clippy::match_same_arms)] + match v { + ManageOfferSuccessResultOffer::Created(value) => { + self.write_type_offer_entry(value); + } + ManageOfferSuccessResultOffer::Updated(value) => { + self.write_type_offer_entry(value); + } + ManageOfferSuccessResultOffer::Deleted => {} + } + } +} diff --git a/src/generated/const/manage_sell_offer_op.rs b/src/generated/const/manage_sell_offer_op.rs new file mode 100644 index 000000000..d7ee72331 --- /dev/null +++ b/src/generated/const/manage_sell_offer_op.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageSellOfferOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_sell_offer_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_sell_offer_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageSellOfferOp`], mirroring `::write_xdr`. + pub const fn write_type_manage_sell_offer_op(&mut self, v: &ManageSellOfferOp) { + self.write_type_asset(&v.selling); + self.write_type_asset(&v.buying); + self.write_i64(v.amount); + self.write_type_price(&v.price); + self.write_i64(v.offer_id); + } +} diff --git a/src/generated/const/manage_sell_offer_result.rs b/src/generated/const/manage_sell_offer_result.rs new file mode 100644 index 000000000..a4381aa89 --- /dev/null +++ b/src/generated/const/manage_sell_offer_result.rs @@ -0,0 +1,108 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ManageSellOfferResult is a borrowing equivalent of [`ManageSellOfferResult`](super::super::ManageSellOfferResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ManageSellOfferResult { + Success(ManageOfferSuccessResult), + Malformed, + SellNoTrust, + BuyNoTrust, + SellNotAuthorized, + BuyNotAuthorized, + LineFull, + Underfunded, + CrossSelf, + SellNoIssuer, + BuyNoIssuer, + NotFound, + LowReserve, +} + +impl ManageSellOfferResult { + #[must_use] + pub const fn discriminant(&self) -> ManageSellOfferResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => ManageSellOfferResultCode::Success, + Self::Malformed => ManageSellOfferResultCode::Malformed, + Self::SellNoTrust => ManageSellOfferResultCode::SellNoTrust, + Self::BuyNoTrust => ManageSellOfferResultCode::BuyNoTrust, + Self::SellNotAuthorized => ManageSellOfferResultCode::SellNotAuthorized, + Self::BuyNotAuthorized => ManageSellOfferResultCode::BuyNotAuthorized, + Self::LineFull => ManageSellOfferResultCode::LineFull, + Self::Underfunded => ManageSellOfferResultCode::Underfunded, + Self::CrossSelf => ManageSellOfferResultCode::CrossSelf, + Self::SellNoIssuer => ManageSellOfferResultCode::SellNoIssuer, + Self::BuyNoIssuer => ManageSellOfferResultCode::BuyNoIssuer, + Self::NotFound => ManageSellOfferResultCode::NotFound, + Self::LowReserve => ManageSellOfferResultCode::LowReserve, + } + } +} + +impl ManageSellOfferResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_sell_offer_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_sell_offer_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageSellOfferResult`], mirroring `::write_xdr`. + pub const fn write_type_manage_sell_offer_result(&mut self, v: &ManageSellOfferResult) { + let d = v.discriminant(); + self.write_type_manage_sell_offer_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + ManageSellOfferResult::Success(value) => { + self.write_type_manage_offer_success_result(value); + } + ManageSellOfferResult::Malformed => {} + ManageSellOfferResult::SellNoTrust => {} + ManageSellOfferResult::BuyNoTrust => {} + ManageSellOfferResult::SellNotAuthorized => {} + ManageSellOfferResult::BuyNotAuthorized => {} + ManageSellOfferResult::LineFull => {} + ManageSellOfferResult::Underfunded => {} + ManageSellOfferResult::CrossSelf => {} + ManageSellOfferResult::SellNoIssuer => {} + ManageSellOfferResult::BuyNoIssuer => {} + ManageSellOfferResult::NotFound => {} + ManageSellOfferResult::LowReserve => {} + } + } +} diff --git a/src/generated/const/manage_sell_offer_result_code.rs b/src/generated/const/manage_sell_offer_result_code.rs new file mode 100644 index 000000000..4e4e94b8e --- /dev/null +++ b/src/generated/const/manage_sell_offer_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ManageSellOfferResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_manage_sell_offer_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_manage_sell_offer_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ManageSellOfferResultCode`], mirroring `::write_xdr`. + pub const fn write_type_manage_sell_offer_result_code( + &mut self, + v: &ManageSellOfferResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/memo.rs b/src/generated/const/memo.rs new file mode 100644 index 000000000..227cc65ec --- /dev/null +++ b/src/generated/const/memo.rs @@ -0,0 +1,90 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Memo is a borrowing equivalent of [`Memo`](super::super::Memo) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum Memo { + None, + Text(StringM<28>), + Id(u64), + Hash(Hash), + Return(Hash), +} + +impl Memo { + #[must_use] + pub const fn discriminant(&self) -> MemoType { + #[allow(clippy::match_same_arms)] + match self { + Self::None => MemoType::None, + Self::Text(_) => MemoType::Text, + Self::Id(_) => MemoType::Id, + Self::Hash(_) => MemoType::Hash, + Self::Return(_) => MemoType::Return, + } + } +} + +impl Memo { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_memo(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_memo(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Memo`], mirroring `::write_xdr`. + pub const fn write_type_memo(&mut self, v: &Memo) { + let d = v.discriminant(); + self.write_type_memo_type(&d); + #[allow(clippy::match_same_arms)] + match v { + Memo::None => {} + Memo::Text(value) => { + self.write_var_opaque(value.as_slice()); + } + Memo::Id(value) => { + self.write_u64(*value); + } + Memo::Hash(value) => { + self.write_type_hash(value); + } + Memo::Return(value) => { + self.write_type_hash(value); + } + } + } +} diff --git a/src/generated/const/memo_type.rs b/src/generated/const/memo_type.rs new file mode 100644 index 000000000..c3dc5736c --- /dev/null +++ b/src/generated/const/memo_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl MemoType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_memo_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_memo_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`MemoType`], mirroring `::write_xdr`. + pub const fn write_type_memo_type(&mut self, v: &MemoType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/message_type.rs b/src/generated/const/message_type.rs new file mode 100644 index 000000000..5fccfae74 --- /dev/null +++ b/src/generated/const/message_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl MessageType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_message_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_message_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`MessageType`], mirroring `::write_xdr`. + pub const fn write_type_message_type(&mut self, v: &MessageType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/muxed_account.rs b/src/generated/const/muxed_account.rs new file mode 100644 index 000000000..a3370bba9 --- /dev/null +++ b/src/generated/const/muxed_account.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl MuxedAccount { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_muxed_account(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_muxed_account(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`MuxedAccount`], mirroring `::write_xdr`. + pub const fn write_type_muxed_account(&mut self, v: &MuxedAccount) { + let d = v.discriminant(); + self.write_type_crypto_key_type(&d); + #[allow(clippy::match_same_arms)] + match v { + MuxedAccount::Ed25519(value) => { + self.write_type_uint256(value); + } + MuxedAccount::MuxedEd25519(value) => { + self.write_type_muxed_account_med25519(value); + } + } + } + + /// Serializes an optional [`MuxedAccount`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_muxed_account(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_muxed_account(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/muxed_account_med25519.rs b/src/generated/const/muxed_account_med25519.rs new file mode 100644 index 000000000..3d1020365 --- /dev/null +++ b/src/generated/const/muxed_account_med25519.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl MuxedAccountMed25519 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_muxed_account_med25519(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_muxed_account_med25519(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`MuxedAccountMed25519`], mirroring `::write_xdr`. + pub const fn write_type_muxed_account_med25519(&mut self, v: &MuxedAccountMed25519) { + self.write_u64(v.id); + self.write_type_uint256(&v.ed25519); + } +} diff --git a/src/generated/const/muxed_contract.rs b/src/generated/const/muxed_contract.rs new file mode 100644 index 000000000..3b1499b75 --- /dev/null +++ b/src/generated/const/muxed_contract.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +#[cfg(feature = "cap_0084_muxed_contract")] +impl MuxedContract { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_muxed_contract(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_muxed_contract(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + #[cfg(feature = "cap_0084_muxed_contract")] + /// Serializes a [`MuxedContract`], mirroring `::write_xdr`. + pub const fn write_type_muxed_contract(&mut self, v: &MuxedContract) { + self.write_u64(v.id); + self.write_type_contract_id(&v.contract_id); + } +} diff --git a/src/generated/const/muxed_ed25519_account.rs b/src/generated/const/muxed_ed25519_account.rs new file mode 100644 index 000000000..e3f3bde45 --- /dev/null +++ b/src/generated/const/muxed_ed25519_account.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl MuxedEd25519Account { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_muxed_ed25519_account(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_muxed_ed25519_account(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`MuxedEd25519Account`], mirroring `::write_xdr`. + pub const fn write_type_muxed_ed25519_account(&mut self, v: &MuxedEd25519Account) { + self.write_u64(v.id); + self.write_type_uint256(&v.ed25519); + } +} diff --git a/src/generated/const/node_id.rs b/src/generated/const/node_id.rs new file mode 100644 index 000000000..84f0b0191 --- /dev/null +++ b/src/generated/const/node_id.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl NodeId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_node_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_node_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`NodeId`], mirroring `::write_xdr`. + pub const fn write_type_node_id(&mut self, v: &NodeId) { + self.write_type_public_key(&v.0); + } + + /// Serializes a variable-length array of [`NodeId`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_node_id(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_node_id(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/offer_entry.rs b/src/generated/const/offer_entry.rs new file mode 100644 index 000000000..a70747401 --- /dev/null +++ b/src/generated/const/offer_entry.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl OfferEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_offer_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_offer_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OfferEntry`], mirroring `::write_xdr`. + pub const fn write_type_offer_entry(&mut self, v: &OfferEntry) { + self.write_type_account_id(&v.seller_id); + self.write_i64(v.offer_id); + self.write_type_asset(&v.selling); + self.write_type_asset(&v.buying); + self.write_i64(v.amount); + self.write_type_price(&v.price); + self.write_u32(v.flags); + self.write_type_offer_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/offer_entry_ext.rs b/src/generated/const/offer_entry_ext.rs new file mode 100644 index 000000000..f68aeeb0c --- /dev/null +++ b/src/generated/const/offer_entry_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl OfferEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_offer_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_offer_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OfferEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_offer_entry_ext(&mut self, v: &OfferEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + OfferEntryExt::V0 => {} + } + } +} diff --git a/src/generated/const/offer_entry_flags.rs b/src/generated/const/offer_entry_flags.rs new file mode 100644 index 000000000..f5ae2d116 --- /dev/null +++ b/src/generated/const/offer_entry_flags.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl OfferEntryFlags { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_offer_entry_flags(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_offer_entry_flags(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OfferEntryFlags`], mirroring `::write_xdr`. + pub const fn write_type_offer_entry_flags(&mut self, v: &OfferEntryFlags) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/operation.rs b/src/generated/const/operation.rs new file mode 100644 index 000000000..d0ccc6bbb --- /dev/null +++ b/src/generated/const/operation.rs @@ -0,0 +1,68 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Operation is a borrowing equivalent of [`Operation`](super::super::Operation) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Operation { + pub source_account: Option, + pub body: OperationBody, +} + +impl Operation { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Operation`], mirroring `::write_xdr`. + pub const fn write_type_operation(&mut self, v: &Operation) { + self.write_type_option_muxed_account(&v.source_account); + self.write_type_operation_body(&v.body); + } + + /// Serializes a variable-length array of [`Operation`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_operation(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_operation(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/operation_body.rs b/src/generated/const/operation_body.rs new file mode 100644 index 000000000..baa5ecada --- /dev/null +++ b/src/generated/const/operation_body.rs @@ -0,0 +1,198 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// OperationBody is a borrowing equivalent of [`OperationBody`](super::super::OperationBody) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum OperationBody { + CreateAccount(CreateAccountOp), + Payment(PaymentOp), + PathPaymentStrictReceive(PathPaymentStrictReceiveOp), + ManageSellOffer(ManageSellOfferOp), + CreatePassiveSellOffer(CreatePassiveSellOfferOp), + SetOptions(SetOptionsOp), + ChangeTrust(ChangeTrustOp), + AllowTrust(AllowTrustOp), + AccountMerge(MuxedAccount), + Inflation, + ManageData(ManageDataOp), + BumpSequence(BumpSequenceOp), + ManageBuyOffer(ManageBuyOfferOp), + PathPaymentStrictSend(PathPaymentStrictSendOp), + CreateClaimableBalance(CreateClaimableBalanceOp), + ClaimClaimableBalance(ClaimClaimableBalanceOp), + BeginSponsoringFutureReserves(BeginSponsoringFutureReservesOp), + EndSponsoringFutureReserves, + RevokeSponsorship(RevokeSponsorshipOp), + Clawback(ClawbackOp), + ClawbackClaimableBalance(ClawbackClaimableBalanceOp), + SetTrustLineFlags(SetTrustLineFlagsOp), + LiquidityPoolDeposit(LiquidityPoolDepositOp), + LiquidityPoolWithdraw(LiquidityPoolWithdrawOp), + InvokeHostFunction(InvokeHostFunctionOp), + ExtendFootprintTtl(ExtendFootprintTtlOp), + RestoreFootprint(RestoreFootprintOp), +} + +impl OperationBody { + #[must_use] + pub const fn discriminant(&self) -> OperationType { + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(_) => OperationType::CreateAccount, + Self::Payment(_) => OperationType::Payment, + Self::PathPaymentStrictReceive(_) => OperationType::PathPaymentStrictReceive, + Self::ManageSellOffer(_) => OperationType::ManageSellOffer, + Self::CreatePassiveSellOffer(_) => OperationType::CreatePassiveSellOffer, + Self::SetOptions(_) => OperationType::SetOptions, + Self::ChangeTrust(_) => OperationType::ChangeTrust, + Self::AllowTrust(_) => OperationType::AllowTrust, + Self::AccountMerge(_) => OperationType::AccountMerge, + Self::Inflation => OperationType::Inflation, + Self::ManageData(_) => OperationType::ManageData, + Self::BumpSequence(_) => OperationType::BumpSequence, + Self::ManageBuyOffer(_) => OperationType::ManageBuyOffer, + Self::PathPaymentStrictSend(_) => OperationType::PathPaymentStrictSend, + Self::CreateClaimableBalance(_) => OperationType::CreateClaimableBalance, + Self::ClaimClaimableBalance(_) => OperationType::ClaimClaimableBalance, + Self::BeginSponsoringFutureReserves(_) => OperationType::BeginSponsoringFutureReserves, + Self::EndSponsoringFutureReserves => OperationType::EndSponsoringFutureReserves, + Self::RevokeSponsorship(_) => OperationType::RevokeSponsorship, + Self::Clawback(_) => OperationType::Clawback, + Self::ClawbackClaimableBalance(_) => OperationType::ClawbackClaimableBalance, + Self::SetTrustLineFlags(_) => OperationType::SetTrustLineFlags, + Self::LiquidityPoolDeposit(_) => OperationType::LiquidityPoolDeposit, + Self::LiquidityPoolWithdraw(_) => OperationType::LiquidityPoolWithdraw, + Self::InvokeHostFunction(_) => OperationType::InvokeHostFunction, + Self::ExtendFootprintTtl(_) => OperationType::ExtendFootprintTtl, + Self::RestoreFootprint(_) => OperationType::RestoreFootprint, + } + } +} + +impl OperationBody { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_body(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_body(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationBody`], mirroring `::write_xdr`. + pub const fn write_type_operation_body(&mut self, v: &OperationBody) { + let d = v.discriminant(); + self.write_type_operation_type(&d); + #[allow(clippy::match_same_arms)] + match v { + OperationBody::CreateAccount(value) => { + self.write_type_create_account_op(value); + } + OperationBody::Payment(value) => { + self.write_type_payment_op(value); + } + OperationBody::PathPaymentStrictReceive(value) => { + self.write_type_path_payment_strict_receive_op(value); + } + OperationBody::ManageSellOffer(value) => { + self.write_type_manage_sell_offer_op(value); + } + OperationBody::CreatePassiveSellOffer(value) => { + self.write_type_create_passive_sell_offer_op(value); + } + OperationBody::SetOptions(value) => { + self.write_type_set_options_op(value); + } + OperationBody::ChangeTrust(value) => { + self.write_type_change_trust_op(value); + } + OperationBody::AllowTrust(value) => { + self.write_type_allow_trust_op(value); + } + OperationBody::AccountMerge(value) => { + self.write_type_muxed_account(value); + } + OperationBody::Inflation => {} + OperationBody::ManageData(value) => { + self.write_type_manage_data_op(value); + } + OperationBody::BumpSequence(value) => { + self.write_type_bump_sequence_op(value); + } + OperationBody::ManageBuyOffer(value) => { + self.write_type_manage_buy_offer_op(value); + } + OperationBody::PathPaymentStrictSend(value) => { + self.write_type_path_payment_strict_send_op(value); + } + OperationBody::CreateClaimableBalance(value) => { + self.write_type_create_claimable_balance_op(value); + } + OperationBody::ClaimClaimableBalance(value) => { + self.write_type_claim_claimable_balance_op(value); + } + OperationBody::BeginSponsoringFutureReserves(value) => { + self.write_type_begin_sponsoring_future_reserves_op(value); + } + OperationBody::EndSponsoringFutureReserves => {} + OperationBody::RevokeSponsorship(value) => { + self.write_type_revoke_sponsorship_op(value); + } + OperationBody::Clawback(value) => { + self.write_type_clawback_op(value); + } + OperationBody::ClawbackClaimableBalance(value) => { + self.write_type_clawback_claimable_balance_op(value); + } + OperationBody::SetTrustLineFlags(value) => { + self.write_type_set_trust_line_flags_op(value); + } + OperationBody::LiquidityPoolDeposit(value) => { + self.write_type_liquidity_pool_deposit_op(value); + } + OperationBody::LiquidityPoolWithdraw(value) => { + self.write_type_liquidity_pool_withdraw_op(value); + } + OperationBody::InvokeHostFunction(value) => { + self.write_type_invoke_host_function_op(value); + } + OperationBody::ExtendFootprintTtl(value) => { + self.write_type_extend_footprint_ttl_op(value); + } + OperationBody::RestoreFootprint(value) => { + self.write_type_restore_footprint_op(value); + } + } + } +} diff --git a/src/generated/const/operation_meta.rs b/src/generated/const/operation_meta.rs new file mode 100644 index 000000000..51f6a8c01 --- /dev/null +++ b/src/generated/const/operation_meta.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// OperationMeta is a borrowing equivalent of [`OperationMeta`](super::super::OperationMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct OperationMeta { + pub changes: LedgerEntryChanges, +} + +impl OperationMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationMeta`], mirroring `::write_xdr`. + pub const fn write_type_operation_meta(&mut self, v: &OperationMeta) { + self.write_type_ledger_entry_changes(&v.changes); + } + + /// Serializes a variable-length array of [`OperationMeta`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_operation_meta( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_operation_meta(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/operation_meta_v2.rs b/src/generated/const/operation_meta_v2.rs new file mode 100644 index 000000000..970632fb8 --- /dev/null +++ b/src/generated/const/operation_meta_v2.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// OperationMetaV2 is a borrowing equivalent of [`OperationMetaV2`](super::super::OperationMetaV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct OperationMetaV2 { + pub ext: ExtensionPoint, + pub changes: LedgerEntryChanges, + pub events: VecM, +} + +impl OperationMetaV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_meta_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_meta_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationMetaV2`], mirroring `::write_xdr`. + pub const fn write_type_operation_meta_v2(&mut self, v: &OperationMetaV2) { + self.write_type_extension_point(&v.ext); + self.write_type_ledger_entry_changes(&v.changes); + self.write_type_vec_contract_event(&v.events); + } + + /// Serializes a variable-length array of [`OperationMetaV2`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_operation_meta_v2( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_operation_meta_v2(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/operation_result.rs b/src/generated/const/operation_result.rs new file mode 100644 index 000000000..0216c1a7a --- /dev/null +++ b/src/generated/const/operation_result.rs @@ -0,0 +1,105 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// OperationResult is a borrowing equivalent of [`OperationResult`](super::super::OperationResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum OperationResult { + OpInner(OperationResultTr), + OpBadAuth, + OpNoAccount, + OpNotSupported, + OpTooManySubentries, + OpExceededWorkLimit, + OpTooManySponsoring, +} + +impl OperationResult { + #[must_use] + pub const fn discriminant(&self) -> OperationResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::OpInner(_) => OperationResultCode::OpInner, + Self::OpBadAuth => OperationResultCode::OpBadAuth, + Self::OpNoAccount => OperationResultCode::OpNoAccount, + Self::OpNotSupported => OperationResultCode::OpNotSupported, + Self::OpTooManySubentries => OperationResultCode::OpTooManySubentries, + Self::OpExceededWorkLimit => OperationResultCode::OpExceededWorkLimit, + Self::OpTooManySponsoring => OperationResultCode::OpTooManySponsoring, + } + } +} + +impl OperationResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationResult`], mirroring `::write_xdr`. + pub const fn write_type_operation_result(&mut self, v: &OperationResult) { + let d = v.discriminant(); + self.write_type_operation_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + OperationResult::OpInner(value) => { + self.write_type_operation_result_tr(value); + } + OperationResult::OpBadAuth => {} + OperationResult::OpNoAccount => {} + OperationResult::OpNotSupported => {} + OperationResult::OpTooManySubentries => {} + OperationResult::OpExceededWorkLimit => {} + OperationResult::OpTooManySponsoring => {} + } + } + + /// Serializes a variable-length array of [`OperationResult`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_operation_result( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_operation_result(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/operation_result_code.rs b/src/generated/const/operation_result_code.rs new file mode 100644 index 000000000..ac171eb0c --- /dev/null +++ b/src/generated/const/operation_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl OperationResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationResultCode`], mirroring `::write_xdr`. + pub const fn write_type_operation_result_code(&mut self, v: &OperationResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/operation_result_tr.rs b/src/generated/const/operation_result_tr.rs new file mode 100644 index 000000000..8ab96b944 --- /dev/null +++ b/src/generated/const/operation_result_tr.rs @@ -0,0 +1,202 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// OperationResultTr is a borrowing equivalent of [`OperationResultTr`](super::super::OperationResultTr) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum OperationResultTr { + CreateAccount(CreateAccountResult), + Payment(PaymentResult), + PathPaymentStrictReceive(PathPaymentStrictReceiveResult), + ManageSellOffer(ManageSellOfferResult), + CreatePassiveSellOffer(ManageSellOfferResult), + SetOptions(SetOptionsResult), + ChangeTrust(ChangeTrustResult), + AllowTrust(AllowTrustResult), + AccountMerge(AccountMergeResult), + Inflation(InflationResult), + ManageData(ManageDataResult), + BumpSequence(BumpSequenceResult), + ManageBuyOffer(ManageBuyOfferResult), + PathPaymentStrictSend(PathPaymentStrictSendResult), + CreateClaimableBalance(CreateClaimableBalanceResult), + ClaimClaimableBalance(ClaimClaimableBalanceResult), + BeginSponsoringFutureReserves(BeginSponsoringFutureReservesResult), + EndSponsoringFutureReserves(EndSponsoringFutureReservesResult), + RevokeSponsorship(RevokeSponsorshipResult), + Clawback(ClawbackResult), + ClawbackClaimableBalance(ClawbackClaimableBalanceResult), + SetTrustLineFlags(SetTrustLineFlagsResult), + LiquidityPoolDeposit(LiquidityPoolDepositResult), + LiquidityPoolWithdraw(LiquidityPoolWithdrawResult), + InvokeHostFunction(InvokeHostFunctionResult), + ExtendFootprintTtl(ExtendFootprintTtlResult), + RestoreFootprint(RestoreFootprintResult), +} + +impl OperationResultTr { + #[must_use] + pub const fn discriminant(&self) -> OperationType { + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(_) => OperationType::CreateAccount, + Self::Payment(_) => OperationType::Payment, + Self::PathPaymentStrictReceive(_) => OperationType::PathPaymentStrictReceive, + Self::ManageSellOffer(_) => OperationType::ManageSellOffer, + Self::CreatePassiveSellOffer(_) => OperationType::CreatePassiveSellOffer, + Self::SetOptions(_) => OperationType::SetOptions, + Self::ChangeTrust(_) => OperationType::ChangeTrust, + Self::AllowTrust(_) => OperationType::AllowTrust, + Self::AccountMerge(_) => OperationType::AccountMerge, + Self::Inflation(_) => OperationType::Inflation, + Self::ManageData(_) => OperationType::ManageData, + Self::BumpSequence(_) => OperationType::BumpSequence, + Self::ManageBuyOffer(_) => OperationType::ManageBuyOffer, + Self::PathPaymentStrictSend(_) => OperationType::PathPaymentStrictSend, + Self::CreateClaimableBalance(_) => OperationType::CreateClaimableBalance, + Self::ClaimClaimableBalance(_) => OperationType::ClaimClaimableBalance, + Self::BeginSponsoringFutureReserves(_) => OperationType::BeginSponsoringFutureReserves, + Self::EndSponsoringFutureReserves(_) => OperationType::EndSponsoringFutureReserves, + Self::RevokeSponsorship(_) => OperationType::RevokeSponsorship, + Self::Clawback(_) => OperationType::Clawback, + Self::ClawbackClaimableBalance(_) => OperationType::ClawbackClaimableBalance, + Self::SetTrustLineFlags(_) => OperationType::SetTrustLineFlags, + Self::LiquidityPoolDeposit(_) => OperationType::LiquidityPoolDeposit, + Self::LiquidityPoolWithdraw(_) => OperationType::LiquidityPoolWithdraw, + Self::InvokeHostFunction(_) => OperationType::InvokeHostFunction, + Self::ExtendFootprintTtl(_) => OperationType::ExtendFootprintTtl, + Self::RestoreFootprint(_) => OperationType::RestoreFootprint, + } + } +} + +impl OperationResultTr { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_result_tr(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_result_tr(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationResultTr`], mirroring `::write_xdr`. + pub const fn write_type_operation_result_tr(&mut self, v: &OperationResultTr) { + let d = v.discriminant(); + self.write_type_operation_type(&d); + #[allow(clippy::match_same_arms)] + match v { + OperationResultTr::CreateAccount(value) => { + self.write_type_create_account_result(value); + } + OperationResultTr::Payment(value) => { + self.write_type_payment_result(value); + } + OperationResultTr::PathPaymentStrictReceive(value) => { + self.write_type_path_payment_strict_receive_result(value); + } + OperationResultTr::ManageSellOffer(value) => { + self.write_type_manage_sell_offer_result(value); + } + OperationResultTr::CreatePassiveSellOffer(value) => { + self.write_type_manage_sell_offer_result(value); + } + OperationResultTr::SetOptions(value) => { + self.write_type_set_options_result(value); + } + OperationResultTr::ChangeTrust(value) => { + self.write_type_change_trust_result(value); + } + OperationResultTr::AllowTrust(value) => { + self.write_type_allow_trust_result(value); + } + OperationResultTr::AccountMerge(value) => { + self.write_type_account_merge_result(value); + } + OperationResultTr::Inflation(value) => { + self.write_type_inflation_result(value); + } + OperationResultTr::ManageData(value) => { + self.write_type_manage_data_result(value); + } + OperationResultTr::BumpSequence(value) => { + self.write_type_bump_sequence_result(value); + } + OperationResultTr::ManageBuyOffer(value) => { + self.write_type_manage_buy_offer_result(value); + } + OperationResultTr::PathPaymentStrictSend(value) => { + self.write_type_path_payment_strict_send_result(value); + } + OperationResultTr::CreateClaimableBalance(value) => { + self.write_type_create_claimable_balance_result(value); + } + OperationResultTr::ClaimClaimableBalance(value) => { + self.write_type_claim_claimable_balance_result(value); + } + OperationResultTr::BeginSponsoringFutureReserves(value) => { + self.write_type_begin_sponsoring_future_reserves_result(value); + } + OperationResultTr::EndSponsoringFutureReserves(value) => { + self.write_type_end_sponsoring_future_reserves_result(value); + } + OperationResultTr::RevokeSponsorship(value) => { + self.write_type_revoke_sponsorship_result(value); + } + OperationResultTr::Clawback(value) => { + self.write_type_clawback_result(value); + } + OperationResultTr::ClawbackClaimableBalance(value) => { + self.write_type_clawback_claimable_balance_result(value); + } + OperationResultTr::SetTrustLineFlags(value) => { + self.write_type_set_trust_line_flags_result(value); + } + OperationResultTr::LiquidityPoolDeposit(value) => { + self.write_type_liquidity_pool_deposit_result(value); + } + OperationResultTr::LiquidityPoolWithdraw(value) => { + self.write_type_liquidity_pool_withdraw_result(value); + } + OperationResultTr::InvokeHostFunction(value) => { + self.write_type_invoke_host_function_result(value); + } + OperationResultTr::ExtendFootprintTtl(value) => { + self.write_type_extend_footprint_ttl_result(value); + } + OperationResultTr::RestoreFootprint(value) => { + self.write_type_restore_footprint_result(value); + } + } + } +} diff --git a/src/generated/const/operation_type.rs b/src/generated/const/operation_type.rs new file mode 100644 index 000000000..8302981a3 --- /dev/null +++ b/src/generated/const/operation_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl OperationType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_operation_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_operation_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`OperationType`], mirroring `::write_xdr`. + pub const fn write_type_operation_type(&mut self, v: &OperationType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/parallel_tx_execution_stage.rs b/src/generated/const/parallel_tx_execution_stage.rs new file mode 100644 index 000000000..5c25d5d63 --- /dev/null +++ b/src/generated/const/parallel_tx_execution_stage.rs @@ -0,0 +1,67 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ParallelTxExecutionStage is a borrowing equivalent of [`ParallelTxExecutionStage`](super::super::ParallelTxExecutionStage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ParallelTxExecutionStage(pub VecM); + +impl ParallelTxExecutionStage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_parallel_tx_execution_stage(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_parallel_tx_execution_stage(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ParallelTxExecutionStage`], mirroring `::write_xdr`. + pub const fn write_type_parallel_tx_execution_stage(&mut self, v: &ParallelTxExecutionStage) { + self.write_type_vec_dependent_tx_cluster(&v.0); + } + + /// Serializes a variable-length array of [`ParallelTxExecutionStage`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_parallel_tx_execution_stage( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_parallel_tx_execution_stage(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/parallel_txs_component.rs b/src/generated/const/parallel_txs_component.rs new file mode 100644 index 000000000..bd332abd0 --- /dev/null +++ b/src/generated/const/parallel_txs_component.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ParallelTxsComponent is a borrowing equivalent of [`ParallelTxsComponent`](super::super::ParallelTxsComponent) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ParallelTxsComponent { + pub base_fee: Option, + pub execution_stages: VecM, +} + +impl ParallelTxsComponent { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_parallel_txs_component(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_parallel_txs_component(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ParallelTxsComponent`], mirroring `::write_xdr`. + pub const fn write_type_parallel_txs_component(&mut self, v: &ParallelTxsComponent) { + self.write_option_i64(&v.base_fee); + self.write_type_vec_parallel_tx_execution_stage(&v.execution_stages); + } +} diff --git a/src/generated/const/path_payment_strict_receive_op.rs b/src/generated/const/path_payment_strict_receive_op.rs new file mode 100644 index 000000000..7ba729bbc --- /dev/null +++ b/src/generated/const/path_payment_strict_receive_op.rs @@ -0,0 +1,67 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictReceiveOp is a borrowing equivalent of [`PathPaymentStrictReceiveOp`](super::super::PathPaymentStrictReceiveOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PathPaymentStrictReceiveOp { + pub send_asset: Asset, + pub send_max: i64, + pub destination: MuxedAccount, + pub dest_asset: Asset, + pub dest_amount: i64, + pub path: VecM, +} + +impl PathPaymentStrictReceiveOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_receive_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_receive_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictReceiveOp`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_receive_op( + &mut self, + v: &PathPaymentStrictReceiveOp, + ) { + self.write_type_asset(&v.send_asset); + self.write_i64(v.send_max); + self.write_type_muxed_account(&v.destination); + self.write_type_asset(&v.dest_asset); + self.write_i64(v.dest_amount); + self.write_type_vec_asset(&v.path); + } +} diff --git a/src/generated/const/path_payment_strict_receive_result.rs b/src/generated/const/path_payment_strict_receive_result.rs new file mode 100644 index 000000000..166afe345 --- /dev/null +++ b/src/generated/const/path_payment_strict_receive_result.rs @@ -0,0 +1,113 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictReceiveResult is a borrowing equivalent of [`PathPaymentStrictReceiveResult`](super::super::PathPaymentStrictReceiveResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum PathPaymentStrictReceiveResult { + Success(PathPaymentStrictReceiveResultSuccess), + Malformed, + Underfunded, + SrcNoTrust, + SrcNotAuthorized, + NoDestination, + NoTrust, + NotAuthorized, + LineFull, + NoIssuer(Asset), + TooFewOffers, + OfferCrossSelf, + OverSendmax, +} + +impl PathPaymentStrictReceiveResult { + #[must_use] + pub const fn discriminant(&self) -> PathPaymentStrictReceiveResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => PathPaymentStrictReceiveResultCode::Success, + Self::Malformed => PathPaymentStrictReceiveResultCode::Malformed, + Self::Underfunded => PathPaymentStrictReceiveResultCode::Underfunded, + Self::SrcNoTrust => PathPaymentStrictReceiveResultCode::SrcNoTrust, + Self::SrcNotAuthorized => PathPaymentStrictReceiveResultCode::SrcNotAuthorized, + Self::NoDestination => PathPaymentStrictReceiveResultCode::NoDestination, + Self::NoTrust => PathPaymentStrictReceiveResultCode::NoTrust, + Self::NotAuthorized => PathPaymentStrictReceiveResultCode::NotAuthorized, + Self::LineFull => PathPaymentStrictReceiveResultCode::LineFull, + Self::NoIssuer(_) => PathPaymentStrictReceiveResultCode::NoIssuer, + Self::TooFewOffers => PathPaymentStrictReceiveResultCode::TooFewOffers, + Self::OfferCrossSelf => PathPaymentStrictReceiveResultCode::OfferCrossSelf, + Self::OverSendmax => PathPaymentStrictReceiveResultCode::OverSendmax, + } + } +} + +impl PathPaymentStrictReceiveResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_receive_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_receive_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictReceiveResult`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_receive_result( + &mut self, + v: &PathPaymentStrictReceiveResult, + ) { + let d = v.discriminant(); + self.write_type_path_payment_strict_receive_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + PathPaymentStrictReceiveResult::Success(value) => { + self.write_type_path_payment_strict_receive_result_success(value); + } + PathPaymentStrictReceiveResult::Malformed => {} + PathPaymentStrictReceiveResult::Underfunded => {} + PathPaymentStrictReceiveResult::SrcNoTrust => {} + PathPaymentStrictReceiveResult::SrcNotAuthorized => {} + PathPaymentStrictReceiveResult::NoDestination => {} + PathPaymentStrictReceiveResult::NoTrust => {} + PathPaymentStrictReceiveResult::NotAuthorized => {} + PathPaymentStrictReceiveResult::LineFull => {} + PathPaymentStrictReceiveResult::NoIssuer(value) => { + self.write_type_asset(value); + } + PathPaymentStrictReceiveResult::TooFewOffers => {} + PathPaymentStrictReceiveResult::OfferCrossSelf => {} + PathPaymentStrictReceiveResult::OverSendmax => {} + } + } +} diff --git a/src/generated/const/path_payment_strict_receive_result_code.rs b/src/generated/const/path_payment_strict_receive_result_code.rs new file mode 100644 index 000000000..3472f243a --- /dev/null +++ b/src/generated/const/path_payment_strict_receive_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PathPaymentStrictReceiveResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_receive_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_receive_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictReceiveResultCode`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_receive_result_code( + &mut self, + v: &PathPaymentStrictReceiveResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/path_payment_strict_receive_result_success.rs b/src/generated/const/path_payment_strict_receive_result_success.rs new file mode 100644 index 000000000..d52516234 --- /dev/null +++ b/src/generated/const/path_payment_strict_receive_result_success.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictReceiveResultSuccess is a borrowing equivalent of [`PathPaymentStrictReceiveResultSuccess`](super::super::PathPaymentStrictReceiveResultSuccess) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PathPaymentStrictReceiveResultSuccess { + pub offers: VecM, + pub last: SimplePaymentResult, +} + +impl PathPaymentStrictReceiveResultSuccess { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_receive_result_success(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_receive_result_success(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictReceiveResultSuccess`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_receive_result_success( + &mut self, + v: &PathPaymentStrictReceiveResultSuccess, + ) { + self.write_type_vec_claim_atom(&v.offers); + self.write_type_simple_payment_result(&v.last); + } +} diff --git a/src/generated/const/path_payment_strict_send_op.rs b/src/generated/const/path_payment_strict_send_op.rs new file mode 100644 index 000000000..0d87f9d25 --- /dev/null +++ b/src/generated/const/path_payment_strict_send_op.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictSendOp is a borrowing equivalent of [`PathPaymentStrictSendOp`](super::super::PathPaymentStrictSendOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PathPaymentStrictSendOp { + pub send_asset: Asset, + pub send_amount: i64, + pub destination: MuxedAccount, + pub dest_asset: Asset, + pub dest_min: i64, + pub path: VecM, +} + +impl PathPaymentStrictSendOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_send_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_send_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictSendOp`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_send_op(&mut self, v: &PathPaymentStrictSendOp) { + self.write_type_asset(&v.send_asset); + self.write_i64(v.send_amount); + self.write_type_muxed_account(&v.destination); + self.write_type_asset(&v.dest_asset); + self.write_i64(v.dest_min); + self.write_type_vec_asset(&v.path); + } +} diff --git a/src/generated/const/path_payment_strict_send_result.rs b/src/generated/const/path_payment_strict_send_result.rs new file mode 100644 index 000000000..7a0dcb653 --- /dev/null +++ b/src/generated/const/path_payment_strict_send_result.rs @@ -0,0 +1,113 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictSendResult is a borrowing equivalent of [`PathPaymentStrictSendResult`](super::super::PathPaymentStrictSendResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum PathPaymentStrictSendResult { + Success(PathPaymentStrictSendResultSuccess), + Malformed, + Underfunded, + SrcNoTrust, + SrcNotAuthorized, + NoDestination, + NoTrust, + NotAuthorized, + LineFull, + NoIssuer(Asset), + TooFewOffers, + OfferCrossSelf, + UnderDestmin, +} + +impl PathPaymentStrictSendResult { + #[must_use] + pub const fn discriminant(&self) -> PathPaymentStrictSendResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => PathPaymentStrictSendResultCode::Success, + Self::Malformed => PathPaymentStrictSendResultCode::Malformed, + Self::Underfunded => PathPaymentStrictSendResultCode::Underfunded, + Self::SrcNoTrust => PathPaymentStrictSendResultCode::SrcNoTrust, + Self::SrcNotAuthorized => PathPaymentStrictSendResultCode::SrcNotAuthorized, + Self::NoDestination => PathPaymentStrictSendResultCode::NoDestination, + Self::NoTrust => PathPaymentStrictSendResultCode::NoTrust, + Self::NotAuthorized => PathPaymentStrictSendResultCode::NotAuthorized, + Self::LineFull => PathPaymentStrictSendResultCode::LineFull, + Self::NoIssuer(_) => PathPaymentStrictSendResultCode::NoIssuer, + Self::TooFewOffers => PathPaymentStrictSendResultCode::TooFewOffers, + Self::OfferCrossSelf => PathPaymentStrictSendResultCode::OfferCrossSelf, + Self::UnderDestmin => PathPaymentStrictSendResultCode::UnderDestmin, + } + } +} + +impl PathPaymentStrictSendResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_send_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_send_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictSendResult`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_send_result( + &mut self, + v: &PathPaymentStrictSendResult, + ) { + let d = v.discriminant(); + self.write_type_path_payment_strict_send_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + PathPaymentStrictSendResult::Success(value) => { + self.write_type_path_payment_strict_send_result_success(value); + } + PathPaymentStrictSendResult::Malformed => {} + PathPaymentStrictSendResult::Underfunded => {} + PathPaymentStrictSendResult::SrcNoTrust => {} + PathPaymentStrictSendResult::SrcNotAuthorized => {} + PathPaymentStrictSendResult::NoDestination => {} + PathPaymentStrictSendResult::NoTrust => {} + PathPaymentStrictSendResult::NotAuthorized => {} + PathPaymentStrictSendResult::LineFull => {} + PathPaymentStrictSendResult::NoIssuer(value) => { + self.write_type_asset(value); + } + PathPaymentStrictSendResult::TooFewOffers => {} + PathPaymentStrictSendResult::OfferCrossSelf => {} + PathPaymentStrictSendResult::UnderDestmin => {} + } + } +} diff --git a/src/generated/const/path_payment_strict_send_result_code.rs b/src/generated/const/path_payment_strict_send_result_code.rs new file mode 100644 index 000000000..93a378055 --- /dev/null +++ b/src/generated/const/path_payment_strict_send_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PathPaymentStrictSendResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_send_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_send_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictSendResultCode`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_send_result_code( + &mut self, + v: &PathPaymentStrictSendResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/path_payment_strict_send_result_success.rs b/src/generated/const/path_payment_strict_send_result_success.rs new file mode 100644 index 000000000..37ae88fe9 --- /dev/null +++ b/src/generated/const/path_payment_strict_send_result_success.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PathPaymentStrictSendResultSuccess is a borrowing equivalent of [`PathPaymentStrictSendResultSuccess`](super::super::PathPaymentStrictSendResultSuccess) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PathPaymentStrictSendResultSuccess { + pub offers: VecM, + pub last: SimplePaymentResult, +} + +impl PathPaymentStrictSendResultSuccess { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_path_payment_strict_send_result_success(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_path_payment_strict_send_result_success(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PathPaymentStrictSendResultSuccess`], mirroring `::write_xdr`. + pub const fn write_type_path_payment_strict_send_result_success( + &mut self, + v: &PathPaymentStrictSendResultSuccess, + ) { + self.write_type_vec_claim_atom(&v.offers); + self.write_type_simple_payment_result(&v.last); + } +} diff --git a/src/generated/const/payment_op.rs b/src/generated/const/payment_op.rs new file mode 100644 index 000000000..891fd62b6 --- /dev/null +++ b/src/generated/const/payment_op.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PaymentOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_payment_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_payment_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PaymentOp`], mirroring `::write_xdr`. + pub const fn write_type_payment_op(&mut self, v: &PaymentOp) { + self.write_type_muxed_account(&v.destination); + self.write_type_asset(&v.asset); + self.write_i64(v.amount); + } +} diff --git a/src/generated/const/payment_result.rs b/src/generated/const/payment_result.rs new file mode 100644 index 000000000..9939fec8d --- /dev/null +++ b/src/generated/const/payment_result.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PaymentResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_payment_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_payment_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PaymentResult`], mirroring `::write_xdr`. + pub const fn write_type_payment_result(&mut self, v: &PaymentResult) { + let d = v.discriminant(); + self.write_type_payment_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + PaymentResult::Success => {} + PaymentResult::Malformed => {} + PaymentResult::Underfunded => {} + PaymentResult::SrcNoTrust => {} + PaymentResult::SrcNotAuthorized => {} + PaymentResult::NoDestination => {} + PaymentResult::NoTrust => {} + PaymentResult::NotAuthorized => {} + PaymentResult::LineFull => {} + PaymentResult::NoIssuer => {} + } + } +} diff --git a/src/generated/const/payment_result_code.rs b/src/generated/const/payment_result_code.rs new file mode 100644 index 000000000..663e7a29c --- /dev/null +++ b/src/generated/const/payment_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PaymentResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_payment_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_payment_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PaymentResultCode`], mirroring `::write_xdr`. + pub const fn write_type_payment_result_code(&mut self, v: &PaymentResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/peer_address.rs b/src/generated/const/peer_address.rs new file mode 100644 index 000000000..83a64f537 --- /dev/null +++ b/src/generated/const/peer_address.rs @@ -0,0 +1,63 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PeerAddress { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_peer_address(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_peer_address(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PeerAddress`], mirroring `::write_xdr`. + pub const fn write_type_peer_address(&mut self, v: &PeerAddress) { + self.write_type_peer_address_ip(&v.ip); + self.write_u32(v.port); + self.write_u32(v.num_failures); + } + + /// Serializes a variable-length array of [`PeerAddress`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_peer_address( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_peer_address(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/peer_address_ip.rs b/src/generated/const/peer_address_ip.rs new file mode 100644 index 000000000..04f64a566 --- /dev/null +++ b/src/generated/const/peer_address_ip.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PeerAddressIp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_peer_address_ip(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_peer_address_ip(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PeerAddressIp`], mirroring `::write_xdr`. + pub const fn write_type_peer_address_ip(&mut self, v: &PeerAddressIp) { + let d = v.discriminant(); + self.write_type_ip_addr_type(&d); + #[allow(clippy::match_same_arms)] + match v { + PeerAddressIp::IPv4(value) => { + self.write_fixed_opaque(value); + } + PeerAddressIp::IPv6(value) => { + self.write_fixed_opaque(value); + } + } + } +} diff --git a/src/generated/const/peer_stats.rs b/src/generated/const/peer_stats.rs new file mode 100644 index 000000000..a604fd5fd --- /dev/null +++ b/src/generated/const/peer_stats.rs @@ -0,0 +1,82 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PeerStats is a borrowing equivalent of [`PeerStats`](super::super::PeerStats) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PeerStats { + pub id: NodeId, + pub version_str: StringM<100>, + pub messages_read: u64, + pub messages_written: u64, + pub bytes_read: u64, + pub bytes_written: u64, + pub seconds_connected: u64, + pub unique_flood_bytes_recv: u64, + pub duplicate_flood_bytes_recv: u64, + pub unique_fetch_bytes_recv: u64, + pub duplicate_fetch_bytes_recv: u64, + pub unique_flood_message_recv: u64, + pub duplicate_flood_message_recv: u64, + pub unique_fetch_message_recv: u64, + pub duplicate_fetch_message_recv: u64, +} + +impl PeerStats { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_peer_stats(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_peer_stats(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PeerStats`], mirroring `::write_xdr`. + pub const fn write_type_peer_stats(&mut self, v: &PeerStats) { + self.write_type_node_id(&v.id); + self.write_var_opaque(v.version_str.as_slice()); + self.write_u64(v.messages_read); + self.write_u64(v.messages_written); + self.write_u64(v.bytes_read); + self.write_u64(v.bytes_written); + self.write_u64(v.seconds_connected); + self.write_u64(v.unique_flood_bytes_recv); + self.write_u64(v.duplicate_flood_bytes_recv); + self.write_u64(v.unique_fetch_bytes_recv); + self.write_u64(v.duplicate_fetch_bytes_recv); + self.write_u64(v.unique_flood_message_recv); + self.write_u64(v.duplicate_flood_message_recv); + self.write_u64(v.unique_fetch_message_recv); + self.write_u64(v.duplicate_fetch_message_recv); + } +} diff --git a/src/generated/const/persisted_scp_state.rs b/src/generated/const/persisted_scp_state.rs new file mode 100644 index 000000000..af18cb904 --- /dev/null +++ b/src/generated/const/persisted_scp_state.rs @@ -0,0 +1,77 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PersistedScpState is a borrowing equivalent of [`PersistedScpState`](super::super::PersistedScpState) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum PersistedScpState { + V0(PersistedScpStateV0), + V1(PersistedScpStateV1), +} + +impl PersistedScpState { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl PersistedScpState { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_persisted_scp_state(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_persisted_scp_state(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PersistedScpState`], mirroring `::write_xdr`. + pub const fn write_type_persisted_scp_state(&mut self, v: &PersistedScpState) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + PersistedScpState::V0(value) => { + self.write_type_persisted_scp_state_v0(value); + } + PersistedScpState::V1(value) => { + self.write_type_persisted_scp_state_v1(value); + } + } + } +} diff --git a/src/generated/const/persisted_scp_state_v0.rs b/src/generated/const/persisted_scp_state_v0.rs new file mode 100644 index 000000000..0192c8ab6 --- /dev/null +++ b/src/generated/const/persisted_scp_state_v0.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PersistedScpStateV0 is a borrowing equivalent of [`PersistedScpStateV0`](super::super::PersistedScpStateV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PersistedScpStateV0 { + pub scp_envelopes: VecM, + pub quorum_sets: VecM, + pub tx_sets: VecM, +} + +impl PersistedScpStateV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_persisted_scp_state_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_persisted_scp_state_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PersistedScpStateV0`], mirroring `::write_xdr`. + pub const fn write_type_persisted_scp_state_v0(&mut self, v: &PersistedScpStateV0) { + self.write_type_vec_scp_envelope(&v.scp_envelopes); + self.write_type_vec_scp_quorum_set(&v.quorum_sets); + self.write_type_vec_stored_transaction_set(&v.tx_sets); + } +} diff --git a/src/generated/const/persisted_scp_state_v1.rs b/src/generated/const/persisted_scp_state_v1.rs new file mode 100644 index 000000000..2834538c4 --- /dev/null +++ b/src/generated/const/persisted_scp_state_v1.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PersistedScpStateV1 is a borrowing equivalent of [`PersistedScpStateV1`](super::super::PersistedScpStateV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PersistedScpStateV1 { + pub scp_envelopes: VecM, + pub quorum_sets: VecM, +} + +impl PersistedScpStateV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_persisted_scp_state_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_persisted_scp_state_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PersistedScpStateV1`], mirroring `::write_xdr`. + pub const fn write_type_persisted_scp_state_v1(&mut self, v: &PersistedScpStateV1) { + self.write_type_vec_scp_envelope(&v.scp_envelopes); + self.write_type_vec_scp_quorum_set(&v.quorum_sets); + } +} diff --git a/src/generated/const/pool_id.rs b/src/generated/const/pool_id.rs new file mode 100644 index 000000000..fe33e765d --- /dev/null +++ b/src/generated/const/pool_id.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PoolId { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_pool_id(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_pool_id(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PoolId`], mirroring `::write_xdr`. + pub const fn write_type_pool_id(&mut self, v: &PoolId) { + self.write_type_hash(&v.0); + } +} diff --git a/src/generated/const/precondition_type.rs b/src/generated/const/precondition_type.rs new file mode 100644 index 000000000..dc04982fe --- /dev/null +++ b/src/generated/const/precondition_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PreconditionType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_precondition_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_precondition_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PreconditionType`], mirroring `::write_xdr`. + pub const fn write_type_precondition_type(&mut self, v: &PreconditionType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/preconditions.rs b/src/generated/const/preconditions.rs new file mode 100644 index 000000000..264d148b6 --- /dev/null +++ b/src/generated/const/preconditions.rs @@ -0,0 +1,80 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Preconditions is a borrowing equivalent of [`Preconditions`](super::super::Preconditions) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum Preconditions { + None, + Time(TimeBounds), + V2(PreconditionsV2), +} + +impl Preconditions { + #[must_use] + pub const fn discriminant(&self) -> PreconditionType { + #[allow(clippy::match_same_arms)] + match self { + Self::None => PreconditionType::None, + Self::Time(_) => PreconditionType::Time, + Self::V2(_) => PreconditionType::V2, + } + } +} + +impl Preconditions { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_preconditions(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_preconditions(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Preconditions`], mirroring `::write_xdr`. + pub const fn write_type_preconditions(&mut self, v: &Preconditions) { + let d = v.discriminant(); + self.write_type_precondition_type(&d); + #[allow(clippy::match_same_arms)] + match v { + Preconditions::None => {} + Preconditions::Time(value) => { + self.write_type_time_bounds(value); + } + Preconditions::V2(value) => { + self.write_type_preconditions_v2(value); + } + } + } +} diff --git a/src/generated/const/preconditions_v2.rs b/src/generated/const/preconditions_v2.rs new file mode 100644 index 000000000..2f247d58d --- /dev/null +++ b/src/generated/const/preconditions_v2.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// PreconditionsV2 is a borrowing equivalent of [`PreconditionsV2`](super::super::PreconditionsV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct PreconditionsV2 { + pub time_bounds: Option, + pub ledger_bounds: Option, + pub min_seq_num: Option, + pub min_seq_age: Duration, + pub min_seq_ledger_gap: u32, + pub extra_signers: VecM, +} + +impl PreconditionsV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_preconditions_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_preconditions_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PreconditionsV2`], mirroring `::write_xdr`. + pub const fn write_type_preconditions_v2(&mut self, v: &PreconditionsV2) { + self.write_type_option_time_bounds(&v.time_bounds); + self.write_type_option_ledger_bounds(&v.ledger_bounds); + self.write_type_option_sequence_number(&v.min_seq_num); + self.write_type_duration(&v.min_seq_age); + self.write_u32(v.min_seq_ledger_gap); + self.write_type_vec_signer_key(&v.extra_signers); + } +} diff --git a/src/generated/const/price.rs b/src/generated/const/price.rs new file mode 100644 index 000000000..7c204eed0 --- /dev/null +++ b/src/generated/const/price.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Price { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_price(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_price(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Price`], mirroring `::write_xdr`. + pub const fn write_type_price(&mut self, v: &Price) { + self.write_i32(v.n); + self.write_i32(v.d); + } +} diff --git a/src/generated/const/public_key.rs b/src/generated/const/public_key.rs new file mode 100644 index 000000000..7c0448451 --- /dev/null +++ b/src/generated/const/public_key.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PublicKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_public_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_public_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PublicKey`], mirroring `::write_xdr`. + pub const fn write_type_public_key(&mut self, v: &PublicKey) { + let d = v.discriminant(); + self.write_type_public_key_type(&d); + #[allow(clippy::match_same_arms)] + match v { + PublicKey::PublicKeyTypeEd25519(value) => { + self.write_type_uint256(value); + } + } + } +} diff --git a/src/generated/const/public_key_type.rs b/src/generated/const/public_key_type.rs new file mode 100644 index 000000000..a1db9397f --- /dev/null +++ b/src/generated/const/public_key_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl PublicKeyType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_public_key_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_public_key_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`PublicKeyType`], mirroring `::write_xdr`. + pub const fn write_type_public_key_type(&mut self, v: &PublicKeyType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/restore_footprint_op.rs b/src/generated/const/restore_footprint_op.rs new file mode 100644 index 000000000..bb9ad0818 --- /dev/null +++ b/src/generated/const/restore_footprint_op.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RestoreFootprintOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_restore_footprint_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_restore_footprint_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RestoreFootprintOp`], mirroring `::write_xdr`. + pub const fn write_type_restore_footprint_op(&mut self, v: &RestoreFootprintOp) { + self.write_type_extension_point(&v.ext); + } +} diff --git a/src/generated/const/restore_footprint_result.rs b/src/generated/const/restore_footprint_result.rs new file mode 100644 index 000000000..b8a0a04ee --- /dev/null +++ b/src/generated/const/restore_footprint_result.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RestoreFootprintResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_restore_footprint_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_restore_footprint_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RestoreFootprintResult`], mirroring `::write_xdr`. + pub const fn write_type_restore_footprint_result(&mut self, v: &RestoreFootprintResult) { + let d = v.discriminant(); + self.write_type_restore_footprint_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + RestoreFootprintResult::Success => {} + RestoreFootprintResult::Malformed => {} + RestoreFootprintResult::ResourceLimitExceeded => {} + RestoreFootprintResult::InsufficientRefundableFee => {} + } + } +} diff --git a/src/generated/const/restore_footprint_result_code.rs b/src/generated/const/restore_footprint_result_code.rs new file mode 100644 index 000000000..3cee2eba0 --- /dev/null +++ b/src/generated/const/restore_footprint_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RestoreFootprintResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_restore_footprint_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_restore_footprint_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RestoreFootprintResultCode`], mirroring `::write_xdr`. + pub const fn write_type_restore_footprint_result_code( + &mut self, + v: &RestoreFootprintResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/revoke_sponsorship_op.rs b/src/generated/const/revoke_sponsorship_op.rs new file mode 100644 index 000000000..86035c044 --- /dev/null +++ b/src/generated/const/revoke_sponsorship_op.rs @@ -0,0 +1,77 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// RevokeSponsorshipOp is a borrowing equivalent of [`RevokeSponsorshipOp`](super::super::RevokeSponsorshipOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum RevokeSponsorshipOp { + LedgerEntry(LedgerKey), + Signer(RevokeSponsorshipOpSigner), +} + +impl RevokeSponsorshipOp { + #[must_use] + pub const fn discriminant(&self) -> RevokeSponsorshipType { + #[allow(clippy::match_same_arms)] + match self { + Self::LedgerEntry(_) => RevokeSponsorshipType::LedgerEntry, + Self::Signer(_) => RevokeSponsorshipType::Signer, + } + } +} + +impl RevokeSponsorshipOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_revoke_sponsorship_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_revoke_sponsorship_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RevokeSponsorshipOp`], mirroring `::write_xdr`. + pub const fn write_type_revoke_sponsorship_op(&mut self, v: &RevokeSponsorshipOp) { + let d = v.discriminant(); + self.write_type_revoke_sponsorship_type(&d); + #[allow(clippy::match_same_arms)] + match v { + RevokeSponsorshipOp::LedgerEntry(value) => { + self.write_type_ledger_key(value); + } + RevokeSponsorshipOp::Signer(value) => { + self.write_type_revoke_sponsorship_op_signer(value); + } + } + } +} diff --git a/src/generated/const/revoke_sponsorship_op_signer.rs b/src/generated/const/revoke_sponsorship_op_signer.rs new file mode 100644 index 000000000..0a599fa9b --- /dev/null +++ b/src/generated/const/revoke_sponsorship_op_signer.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// RevokeSponsorshipOpSigner is a borrowing equivalent of [`RevokeSponsorshipOpSigner`](super::super::RevokeSponsorshipOpSigner) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct RevokeSponsorshipOpSigner { + pub account_id: AccountId, + pub signer_key: SignerKey, +} + +impl RevokeSponsorshipOpSigner { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_revoke_sponsorship_op_signer(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_revoke_sponsorship_op_signer(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RevokeSponsorshipOpSigner`], mirroring `::write_xdr`. + pub const fn write_type_revoke_sponsorship_op_signer(&mut self, v: &RevokeSponsorshipOpSigner) { + self.write_type_account_id(&v.account_id); + self.write_type_signer_key(&v.signer_key); + } +} diff --git a/src/generated/const/revoke_sponsorship_result.rs b/src/generated/const/revoke_sponsorship_result.rs new file mode 100644 index 000000000..c4e4c306b --- /dev/null +++ b/src/generated/const/revoke_sponsorship_result.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RevokeSponsorshipResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_revoke_sponsorship_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_revoke_sponsorship_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RevokeSponsorshipResult`], mirroring `::write_xdr`. + pub const fn write_type_revoke_sponsorship_result(&mut self, v: &RevokeSponsorshipResult) { + let d = v.discriminant(); + self.write_type_revoke_sponsorship_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + RevokeSponsorshipResult::Success => {} + RevokeSponsorshipResult::DoesNotExist => {} + RevokeSponsorshipResult::NotSponsor => {} + RevokeSponsorshipResult::LowReserve => {} + RevokeSponsorshipResult::OnlyTransferable => {} + RevokeSponsorshipResult::Malformed => {} + } + } +} diff --git a/src/generated/const/revoke_sponsorship_result_code.rs b/src/generated/const/revoke_sponsorship_result_code.rs new file mode 100644 index 000000000..8e2425b70 --- /dev/null +++ b/src/generated/const/revoke_sponsorship_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RevokeSponsorshipResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_revoke_sponsorship_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_revoke_sponsorship_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RevokeSponsorshipResultCode`], mirroring `::write_xdr`. + pub const fn write_type_revoke_sponsorship_result_code( + &mut self, + v: &RevokeSponsorshipResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/revoke_sponsorship_type.rs b/src/generated/const/revoke_sponsorship_type.rs new file mode 100644 index 000000000..c2b91db9c --- /dev/null +++ b/src/generated/const/revoke_sponsorship_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl RevokeSponsorshipType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_revoke_sponsorship_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_revoke_sponsorship_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`RevokeSponsorshipType`], mirroring `::write_xdr`. + pub const fn write_type_revoke_sponsorship_type(&mut self, v: &RevokeSponsorshipType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/s_error.rs b/src/generated/const/s_error.rs new file mode 100644 index 000000000..dee7df7b7 --- /dev/null +++ b/src/generated/const/s_error.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SError is a borrowing equivalent of [`SError`](super::super::SError) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SError { + pub code: ErrorCode, + pub msg: StringM<100>, +} + +impl SError { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_s_error(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_s_error(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SError`], mirroring `::write_xdr`. + pub const fn write_type_s_error(&mut self, v: &SError) { + self.write_type_error_code(&v.code); + self.write_var_opaque(v.msg.as_slice()); + } +} diff --git a/src/generated/const/sc_address.rs b/src/generated/const/sc_address.rs new file mode 100644 index 000000000..30710f9e8 --- /dev/null +++ b/src/generated/const/sc_address.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScAddress { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_address(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_address(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScAddress`], mirroring `::write_xdr`. + pub const fn write_type_sc_address(&mut self, v: &ScAddress) { + let d = v.discriminant(); + self.write_type_sc_address_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ScAddress::Account(value) => { + self.write_type_account_id(value); + } + ScAddress::Contract(value) => { + self.write_type_contract_id(value); + } + ScAddress::MuxedAccount(value) => { + self.write_type_muxed_ed25519_account(value); + } + ScAddress::ClaimableBalance(value) => { + self.write_type_claimable_balance_id(value); + } + ScAddress::LiquidityPool(value) => { + self.write_type_pool_id(value); + } + #[cfg(feature = "cap_0084_muxed_contract")] + ScAddress::MuxedContract(value) => { + self.write_type_muxed_contract(value); + } + } + } +} diff --git a/src/generated/const/sc_address_type.rs b/src/generated/const/sc_address_type.rs new file mode 100644 index 000000000..855ac4979 --- /dev/null +++ b/src/generated/const/sc_address_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScAddressType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_address_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_address_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScAddressType`], mirroring `::write_xdr`. + pub const fn write_type_sc_address_type(&mut self, v: &ScAddressType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_bytes.rs b/src/generated/const/sc_bytes.rs new file mode 100644 index 000000000..8e51e4d9f --- /dev/null +++ b/src/generated/const/sc_bytes.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScBytes is a borrowing equivalent of [`ScBytes`](super::super::ScBytes) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScBytes(pub BytesM); + +impl ScBytes { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_bytes(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_bytes(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScBytes`], mirroring `::write_xdr`. + pub const fn write_type_sc_bytes(&mut self, v: &ScBytes) { + self.write_var_opaque(v.0.as_slice()); + } +} diff --git a/src/generated/const/sc_contract_instance.rs b/src/generated/const/sc_contract_instance.rs new file mode 100644 index 000000000..472131a0f --- /dev/null +++ b/src/generated/const/sc_contract_instance.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScContractInstance is a borrowing equivalent of [`ScContractInstance`](super::super::ScContractInstance) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScContractInstance { + pub executable: ContractExecutable, + pub storage: Option, +} + +impl ScContractInstance { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_contract_instance(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_contract_instance(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScContractInstance`], mirroring `::write_xdr`. + pub const fn write_type_sc_contract_instance(&mut self, v: &ScContractInstance) { + self.write_type_contract_executable(&v.executable); + self.write_type_option_sc_map(&v.storage); + } +} diff --git a/src/generated/const/sc_env_meta_entry.rs b/src/generated/const/sc_env_meta_entry.rs new file mode 100644 index 000000000..962007197 --- /dev/null +++ b/src/generated/const/sc_env_meta_entry.rs @@ -0,0 +1,53 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScEnvMetaEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_env_meta_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_env_meta_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScEnvMetaEntry`], mirroring `::write_xdr`. + pub const fn write_type_sc_env_meta_entry(&mut self, v: &ScEnvMetaEntry) { + let d = v.discriminant(); + self.write_type_sc_env_meta_kind(&d); + #[allow(clippy::match_same_arms)] + match v { + ScEnvMetaEntry::ScEnvMetaKindInterfaceVersion(value) => { + self.write_type_sc_env_meta_entry_interface_version(value); + } + } + } +} diff --git a/src/generated/const/sc_env_meta_entry_interface_version.rs b/src/generated/const/sc_env_meta_entry_interface_version.rs new file mode 100644 index 000000000..08ceee6a9 --- /dev/null +++ b/src/generated/const/sc_env_meta_entry_interface_version.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScEnvMetaEntryInterfaceVersion { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_env_meta_entry_interface_version(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_env_meta_entry_interface_version(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScEnvMetaEntryInterfaceVersion`], mirroring `::write_xdr`. + pub const fn write_type_sc_env_meta_entry_interface_version( + &mut self, + v: &ScEnvMetaEntryInterfaceVersion, + ) { + self.write_u32(v.protocol); + self.write_u32(v.pre_release); + } +} diff --git a/src/generated/const/sc_env_meta_kind.rs b/src/generated/const/sc_env_meta_kind.rs new file mode 100644 index 000000000..bb40d8a27 --- /dev/null +++ b/src/generated/const/sc_env_meta_kind.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScEnvMetaKind { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_env_meta_kind(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_env_meta_kind(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScEnvMetaKind`], mirroring `::write_xdr`. + pub const fn write_type_sc_env_meta_kind(&mut self, v: &ScEnvMetaKind) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_error.rs b/src/generated/const/sc_error.rs new file mode 100644 index 000000000..1113a8557 --- /dev/null +++ b/src/generated/const/sc_error.rs @@ -0,0 +1,80 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScError { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_error(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_error(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScError`], mirroring `::write_xdr`. + pub const fn write_type_sc_error(&mut self, v: &ScError) { + let d = v.discriminant(); + self.write_type_sc_error_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ScError::Contract(value) => { + self.write_u32(*value); + } + ScError::WasmVm(value) => { + self.write_type_sc_error_code(value); + } + ScError::Context(value) => { + self.write_type_sc_error_code(value); + } + ScError::Storage(value) => { + self.write_type_sc_error_code(value); + } + ScError::Object(value) => { + self.write_type_sc_error_code(value); + } + ScError::Crypto(value) => { + self.write_type_sc_error_code(value); + } + ScError::Events(value) => { + self.write_type_sc_error_code(value); + } + ScError::Budget(value) => { + self.write_type_sc_error_code(value); + } + ScError::Value(value) => { + self.write_type_sc_error_code(value); + } + ScError::Auth(value) => { + self.write_type_sc_error_code(value); + } + } + } +} diff --git a/src/generated/const/sc_error_code.rs b/src/generated/const/sc_error_code.rs new file mode 100644 index 000000000..ef815c761 --- /dev/null +++ b/src/generated/const/sc_error_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScErrorCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_error_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_error_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScErrorCode`], mirroring `::write_xdr`. + pub const fn write_type_sc_error_code(&mut self, v: &ScErrorCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_error_type.rs b/src/generated/const/sc_error_type.rs new file mode 100644 index 000000000..7dc65e2e4 --- /dev/null +++ b/src/generated/const/sc_error_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScErrorType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_error_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_error_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScErrorType`], mirroring `::write_xdr`. + pub const fn write_type_sc_error_type(&mut self, v: &ScErrorType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_map.rs b/src/generated/const/sc_map.rs new file mode 100644 index 000000000..88619c728 --- /dev/null +++ b/src/generated/const/sc_map.rs @@ -0,0 +1,65 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScMap is a borrowing equivalent of [`ScMap`](super::super::ScMap) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScMap(pub VecM); + +impl ScMap { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_map(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_map(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScMap`], mirroring `::write_xdr`. + pub const fn write_type_sc_map(&mut self, v: &ScMap) { + self.write_type_vec_sc_map_entry(&v.0); + } + + /// Serializes an optional [`ScMap`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_sc_map(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_sc_map(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/sc_map_entry.rs b/src/generated/const/sc_map_entry.rs new file mode 100644 index 000000000..c9c58ee4a --- /dev/null +++ b/src/generated/const/sc_map_entry.rs @@ -0,0 +1,68 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScMapEntry is a borrowing equivalent of [`ScMapEntry`](super::super::ScMapEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScMapEntry { + pub key: ScVal, + pub val: ScVal, +} + +impl ScMapEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_map_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_map_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScMapEntry`], mirroring `::write_xdr`. + pub const fn write_type_sc_map_entry(&mut self, v: &ScMapEntry) { + self.write_type_sc_val(&v.key); + self.write_type_sc_val(&v.val); + } + + /// Serializes a variable-length array of [`ScMapEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_map_entry(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_map_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_meta_entry.rs b/src/generated/const/sc_meta_entry.rs new file mode 100644 index 000000000..bc194d4af --- /dev/null +++ b/src/generated/const/sc_meta_entry.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScMetaEntry is a borrowing equivalent of [`ScMetaEntry`](super::super::ScMetaEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScMetaEntry { + ScMetaV0(ScMetaV0), +} + +impl ScMetaEntry { + #[must_use] + pub const fn discriminant(&self) -> ScMetaKind { + #[allow(clippy::match_same_arms)] + match self { + Self::ScMetaV0(_) => ScMetaKind::ScMetaV0, + } + } +} + +impl ScMetaEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_meta_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_meta_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScMetaEntry`], mirroring `::write_xdr`. + pub const fn write_type_sc_meta_entry(&mut self, v: &ScMetaEntry) { + let d = v.discriminant(); + self.write_type_sc_meta_kind(&d); + #[allow(clippy::match_same_arms)] + match v { + ScMetaEntry::ScMetaV0(value) => { + self.write_type_sc_meta_v0(value); + } + } + } +} diff --git a/src/generated/const/sc_meta_kind.rs b/src/generated/const/sc_meta_kind.rs new file mode 100644 index 000000000..5beef161c --- /dev/null +++ b/src/generated/const/sc_meta_kind.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScMetaKind { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_meta_kind(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_meta_kind(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScMetaKind`], mirroring `::write_xdr`. + pub const fn write_type_sc_meta_kind(&mut self, v: &ScMetaKind) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_meta_v0.rs b/src/generated/const/sc_meta_v0.rs new file mode 100644 index 000000000..afead8e98 --- /dev/null +++ b/src/generated/const/sc_meta_v0.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScMetaV0 is a borrowing equivalent of [`ScMetaV0`](super::super::ScMetaV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScMetaV0 { + pub key: StringM, + pub val: StringM, +} + +impl ScMetaV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_meta_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_meta_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScMetaV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_meta_v0(&mut self, v: &ScMetaV0) { + self.write_var_opaque(v.key.as_slice()); + self.write_var_opaque(v.val.as_slice()); + } +} diff --git a/src/generated/const/sc_nonce_key.rs b/src/generated/const/sc_nonce_key.rs new file mode 100644 index 000000000..03d751bbf --- /dev/null +++ b/src/generated/const/sc_nonce_key.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScNonceKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_nonce_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_nonce_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScNonceKey`], mirroring `::write_xdr`. + pub const fn write_type_sc_nonce_key(&mut self, v: &ScNonceKey) { + self.write_i64(v.nonce); + } +} diff --git a/src/generated/const/sc_spec_entry.rs b/src/generated/const/sc_spec_entry.rs new file mode 100644 index 000000000..d74c517c3 --- /dev/null +++ b/src/generated/const/sc_spec_entry.rs @@ -0,0 +1,97 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecEntry is a borrowing equivalent of [`ScSpecEntry`](super::super::ScSpecEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecEntry { + FunctionV0(ScSpecFunctionV0), + UdtStructV0(ScSpecUdtStructV0), + UdtUnionV0(ScSpecUdtUnionV0), + UdtEnumV0(ScSpecUdtEnumV0), + UdtErrorEnumV0(ScSpecUdtErrorEnumV0), + EventV0(ScSpecEventV0), +} + +impl ScSpecEntry { + #[must_use] + pub const fn discriminant(&self) -> ScSpecEntryKind { + #[allow(clippy::match_same_arms)] + match self { + Self::FunctionV0(_) => ScSpecEntryKind::FunctionV0, + Self::UdtStructV0(_) => ScSpecEntryKind::UdtStructV0, + Self::UdtUnionV0(_) => ScSpecEntryKind::UdtUnionV0, + Self::UdtEnumV0(_) => ScSpecEntryKind::UdtEnumV0, + Self::UdtErrorEnumV0(_) => ScSpecEntryKind::UdtErrorEnumV0, + Self::EventV0(_) => ScSpecEntryKind::EventV0, + } + } +} + +impl ScSpecEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEntry`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_entry(&mut self, v: &ScSpecEntry) { + let d = v.discriminant(); + self.write_type_sc_spec_entry_kind(&d); + #[allow(clippy::match_same_arms)] + match v { + ScSpecEntry::FunctionV0(value) => { + self.write_type_sc_spec_function_v0(value); + } + ScSpecEntry::UdtStructV0(value) => { + self.write_type_sc_spec_udt_struct_v0(value); + } + ScSpecEntry::UdtUnionV0(value) => { + self.write_type_sc_spec_udt_union_v0(value); + } + ScSpecEntry::UdtEnumV0(value) => { + self.write_type_sc_spec_udt_enum_v0(value); + } + ScSpecEntry::UdtErrorEnumV0(value) => { + self.write_type_sc_spec_udt_error_enum_v0(value); + } + ScSpecEntry::EventV0(value) => { + self.write_type_sc_spec_event_v0(value); + } + } + } +} diff --git a/src/generated/const/sc_spec_entry_kind.rs b/src/generated/const/sc_spec_entry_kind.rs new file mode 100644 index 000000000..8cab12fa6 --- /dev/null +++ b/src/generated/const/sc_spec_entry_kind.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecEntryKind { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_entry_kind(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_entry_kind(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEntryKind`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_entry_kind(&mut self, v: &ScSpecEntryKind) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_spec_event_data_format.rs b/src/generated/const/sc_spec_event_data_format.rs new file mode 100644 index 000000000..0fbd0f85d --- /dev/null +++ b/src/generated/const/sc_spec_event_data_format.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecEventDataFormat { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_event_data_format(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_event_data_format(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEventDataFormat`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_event_data_format(&mut self, v: &ScSpecEventDataFormat) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_spec_event_param_location_v0.rs b/src/generated/const/sc_spec_event_param_location_v0.rs new file mode 100644 index 000000000..b06797b7e --- /dev/null +++ b/src/generated/const/sc_spec_event_param_location_v0.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecEventParamLocationV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_event_param_location_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_event_param_location_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEventParamLocationV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_event_param_location_v0( + &mut self, + v: &ScSpecEventParamLocationV0, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_spec_event_param_v0.rs b/src/generated/const/sc_spec_event_param_v0.rs new file mode 100644 index 000000000..46d2d611d --- /dev/null +++ b/src/generated/const/sc_spec_event_param_v0.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecEventParamV0 is a borrowing equivalent of [`ScSpecEventParamV0`](super::super::ScSpecEventParamV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecEventParamV0 { + pub doc: StringM, + pub name: StringM<30>, + pub type_: ScSpecTypeDef, + pub location: ScSpecEventParamLocationV0, +} + +impl ScSpecEventParamV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_event_param_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_event_param_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEventParamV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_event_param_v0(&mut self, v: &ScSpecEventParamV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_sc_spec_type_def(&v.type_); + self.write_type_sc_spec_event_param_location_v0(&v.location); + } + + /// Serializes a variable-length array of [`ScSpecEventParamV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_event_param_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_event_param_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_event_v0.rs b/src/generated/const/sc_spec_event_v0.rs new file mode 100644 index 000000000..22eb0484c --- /dev/null +++ b/src/generated/const/sc_spec_event_v0.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecEventV0 is a borrowing equivalent of [`ScSpecEventV0`](super::super::ScSpecEventV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecEventV0 { + pub doc: StringM, + pub lib: StringM<80>, + pub name: StringM, + pub prefix_topics: VecM, + pub params: VecM, + pub data_format: ScSpecEventDataFormat, +} + +impl ScSpecEventV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_event_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_event_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecEventV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_event_v0(&mut self, v: &ScSpecEventV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.lib.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_symbol(&v.prefix_topics); + self.write_type_vec_sc_spec_event_param_v0(&v.params); + self.write_type_sc_spec_event_data_format(&v.data_format); + } +} diff --git a/src/generated/const/sc_spec_function_input_v0.rs b/src/generated/const/sc_spec_function_input_v0.rs new file mode 100644 index 000000000..4b8086a81 --- /dev/null +++ b/src/generated/const/sc_spec_function_input_v0.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecFunctionInputV0 is a borrowing equivalent of [`ScSpecFunctionInputV0`](super::super::ScSpecFunctionInputV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecFunctionInputV0 { + pub doc: StringM, + pub name: StringM<30>, + pub type_: ScSpecTypeDef, +} + +impl ScSpecFunctionInputV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_function_input_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_function_input_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecFunctionInputV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_function_input_v0(&mut self, v: &ScSpecFunctionInputV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_sc_spec_type_def(&v.type_); + } + + /// Serializes a variable-length array of [`ScSpecFunctionInputV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_function_input_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_function_input_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_function_v0.rs b/src/generated/const/sc_spec_function_v0.rs new file mode 100644 index 000000000..56c1c9624 --- /dev/null +++ b/src/generated/const/sc_spec_function_v0.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecFunctionV0 is a borrowing equivalent of [`ScSpecFunctionV0`](super::super::ScSpecFunctionV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecFunctionV0 { + pub doc: StringM, + pub name: ScSymbol, + pub inputs: VecM, + pub outputs: VecM, +} + +impl ScSpecFunctionV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_function_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_function_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecFunctionV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_function_v0(&mut self, v: &ScSpecFunctionV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_type_sc_symbol(&v.name); + self.write_type_vec_sc_spec_function_input_v0(&v.inputs); + self.write_type_vec_sc_spec_type_def(&v.outputs); + } +} diff --git a/src/generated/const/sc_spec_type.rs b/src/generated/const/sc_spec_type.rs new file mode 100644 index 000000000..6b27b8307 --- /dev/null +++ b/src/generated/const/sc_spec_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecType`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type(&mut self, v: &ScSpecType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_spec_type_bytes_n.rs b/src/generated/const/sc_spec_type_bytes_n.rs new file mode 100644 index 000000000..a5e84b983 --- /dev/null +++ b/src/generated/const/sc_spec_type_bytes_n.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecTypeBytesN { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_bytes_n(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_bytes_n(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeBytesN`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_bytes_n(&mut self, v: &ScSpecTypeBytesN) { + self.write_u32(v.n); + } +} diff --git a/src/generated/const/sc_spec_type_def.rs b/src/generated/const/sc_spec_type_def.rs new file mode 100644 index 000000000..e7150b064 --- /dev/null +++ b/src/generated/const/sc_spec_type_def.rs @@ -0,0 +1,189 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeDef is a borrowing equivalent of [`ScSpecTypeDef`](super::super::ScSpecTypeDef) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecTypeDef { + Val, + Bool, + Void, + Error, + U32, + I32, + U64, + I64, + Timepoint, + Duration, + U128, + I128, + U256, + I256, + Bytes, + String, + Symbol, + Address, + MuxedAddress, + Option( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + &'static ScSpecTypeOption, + ), + Result( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + &'static ScSpecTypeResult, + ), + Vec( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + &'static ScSpecTypeVec, + ), + Map( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + &'static ScSpecTypeMap, + ), + Tuple( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + &'static ScSpecTypeTuple, + ), + BytesN(ScSpecTypeBytesN), + Udt(ScSpecTypeUdt), +} + +impl ScSpecTypeDef { + #[must_use] + pub const fn discriminant(&self) -> ScSpecType { + #[allow(clippy::match_same_arms)] + match self { + Self::Val => ScSpecType::Val, + Self::Bool => ScSpecType::Bool, + Self::Void => ScSpecType::Void, + Self::Error => ScSpecType::Error, + Self::U32 => ScSpecType::U32, + Self::I32 => ScSpecType::I32, + Self::U64 => ScSpecType::U64, + Self::I64 => ScSpecType::I64, + Self::Timepoint => ScSpecType::Timepoint, + Self::Duration => ScSpecType::Duration, + Self::U128 => ScSpecType::U128, + Self::I128 => ScSpecType::I128, + Self::U256 => ScSpecType::U256, + Self::I256 => ScSpecType::I256, + Self::Bytes => ScSpecType::Bytes, + Self::String => ScSpecType::String, + Self::Symbol => ScSpecType::Symbol, + Self::Address => ScSpecType::Address, + Self::MuxedAddress => ScSpecType::MuxedAddress, + Self::Option(_) => ScSpecType::Option, + Self::Result(_) => ScSpecType::Result, + Self::Vec(_) => ScSpecType::Vec, + Self::Map(_) => ScSpecType::Map, + Self::Tuple(_) => ScSpecType::Tuple, + Self::BytesN(_) => ScSpecType::BytesN, + Self::Udt(_) => ScSpecType::Udt, + } + } +} + +impl ScSpecTypeDef { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_def(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_def(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeDef`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_def(&mut self, v: &ScSpecTypeDef) { + let d = v.discriminant(); + self.write_type_sc_spec_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ScSpecTypeDef::Val => {} + ScSpecTypeDef::Bool => {} + ScSpecTypeDef::Void => {} + ScSpecTypeDef::Error => {} + ScSpecTypeDef::U32 => {} + ScSpecTypeDef::I32 => {} + ScSpecTypeDef::U64 => {} + ScSpecTypeDef::I64 => {} + ScSpecTypeDef::Timepoint => {} + ScSpecTypeDef::Duration => {} + ScSpecTypeDef::U128 => {} + ScSpecTypeDef::I128 => {} + ScSpecTypeDef::U256 => {} + ScSpecTypeDef::I256 => {} + ScSpecTypeDef::Bytes => {} + ScSpecTypeDef::String => {} + ScSpecTypeDef::Symbol => {} + ScSpecTypeDef::Address => {} + ScSpecTypeDef::MuxedAddress => {} + ScSpecTypeDef::Option(value) => { + self.write_type_sc_spec_type_option(value); + } + ScSpecTypeDef::Result(value) => { + self.write_type_sc_spec_type_result(value); + } + ScSpecTypeDef::Vec(value) => { + self.write_type_sc_spec_type_vec(value); + } + ScSpecTypeDef::Map(value) => { + self.write_type_sc_spec_type_map(value); + } + ScSpecTypeDef::Tuple(value) => { + self.write_type_sc_spec_type_tuple(value); + } + ScSpecTypeDef::BytesN(value) => { + self.write_type_sc_spec_type_bytes_n(value); + } + ScSpecTypeDef::Udt(value) => { + self.write_type_sc_spec_type_udt(value); + } + } + } + + /// Serializes a variable-length array of [`ScSpecTypeDef`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_type_def( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_type_def(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_type_map.rs b/src/generated/const/sc_spec_type_map.rs new file mode 100644 index 000000000..9aaea76c4 --- /dev/null +++ b/src/generated/const/sc_spec_type_map.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeMap is a borrowing equivalent of [`ScSpecTypeMap`](super::super::ScSpecTypeMap) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeMap { + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub key_type: &'static ScSpecTypeDef, + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub value_type: &'static ScSpecTypeDef, +} + +impl ScSpecTypeMap { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_map(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_map(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeMap`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_map(&mut self, v: &ScSpecTypeMap) { + self.write_type_sc_spec_type_def(v.key_type); + self.write_type_sc_spec_type_def(v.value_type); + } +} diff --git a/src/generated/const/sc_spec_type_option.rs b/src/generated/const/sc_spec_type_option.rs new file mode 100644 index 000000000..b9592960e --- /dev/null +++ b/src/generated/const/sc_spec_type_option.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeOption is a borrowing equivalent of [`ScSpecTypeOption`](super::super::ScSpecTypeOption) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeOption { + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub value_type: &'static ScSpecTypeDef, +} + +impl ScSpecTypeOption { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_option(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_option(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeOption`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_option(&mut self, v: &ScSpecTypeOption) { + self.write_type_sc_spec_type_def(v.value_type); + } +} diff --git a/src/generated/const/sc_spec_type_result.rs b/src/generated/const/sc_spec_type_result.rs new file mode 100644 index 000000000..2ab848b17 --- /dev/null +++ b/src/generated/const/sc_spec_type_result.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeResult is a borrowing equivalent of [`ScSpecTypeResult`](super::super::ScSpecTypeResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeResult { + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub ok_type: &'static ScSpecTypeDef, + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub error_type: &'static ScSpecTypeDef, +} + +impl ScSpecTypeResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeResult`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_result(&mut self, v: &ScSpecTypeResult) { + self.write_type_sc_spec_type_def(v.ok_type); + self.write_type_sc_spec_type_def(v.error_type); + } +} diff --git a/src/generated/const/sc_spec_type_tuple.rs b/src/generated/const/sc_spec_type_tuple.rs new file mode 100644 index 000000000..f55f1ed43 --- /dev/null +++ b/src/generated/const/sc_spec_type_tuple.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeTuple is a borrowing equivalent of [`ScSpecTypeTuple`](super::super::ScSpecTypeTuple) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeTuple { + pub value_types: VecM, +} + +impl ScSpecTypeTuple { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_tuple(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_tuple(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeTuple`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_tuple(&mut self, v: &ScSpecTypeTuple) { + self.write_type_vec_sc_spec_type_def(&v.value_types); + } +} diff --git a/src/generated/const/sc_spec_type_udt.rs b/src/generated/const/sc_spec_type_udt.rs new file mode 100644 index 000000000..7b5bc818b --- /dev/null +++ b/src/generated/const/sc_spec_type_udt.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeUdt is a borrowing equivalent of [`ScSpecTypeUdt`](super::super::ScSpecTypeUdt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeUdt { + pub name: StringM, +} + +impl ScSpecTypeUdt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_udt(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_udt(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeUdt`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_udt(&mut self, v: &ScSpecTypeUdt) { + self.write_var_opaque(v.name.as_slice()); + } +} diff --git a/src/generated/const/sc_spec_type_vec.rs b/src/generated/const/sc_spec_type_vec.rs new file mode 100644 index 000000000..be0b9601c --- /dev/null +++ b/src/generated/const/sc_spec_type_vec.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecTypeVec is a borrowing equivalent of [`ScSpecTypeVec`](super::super::ScSpecTypeVec) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecTypeVec { + #[cfg_attr(feature = "arbitrary", arbitrary(with = arbitrary_ref::))] + pub element_type: &'static ScSpecTypeDef, +} + +impl ScSpecTypeVec { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_type_vec(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_type_vec(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecTypeVec`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_type_vec(&mut self, v: &ScSpecTypeVec) { + self.write_type_sc_spec_type_def(v.element_type); + } +} diff --git a/src/generated/const/sc_spec_udt_enum_case_v0.rs b/src/generated/const/sc_spec_udt_enum_case_v0.rs new file mode 100644 index 000000000..04e9f35d4 --- /dev/null +++ b/src/generated/const/sc_spec_udt_enum_case_v0.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtEnumCaseV0 is a borrowing equivalent of [`ScSpecUdtEnumCaseV0`](super::super::ScSpecUdtEnumCaseV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtEnumCaseV0 { + pub doc: StringM, + pub name: StringM<60>, + pub value: u32, +} + +impl ScSpecUdtEnumCaseV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_enum_case_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_enum_case_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtEnumCaseV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_enum_case_v0(&mut self, v: &ScSpecUdtEnumCaseV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_u32(v.value); + } + + /// Serializes a variable-length array of [`ScSpecUdtEnumCaseV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_udt_enum_case_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_udt_enum_case_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_udt_enum_v0.rs b/src/generated/const/sc_spec_udt_enum_v0.rs new file mode 100644 index 000000000..48016c926 --- /dev/null +++ b/src/generated/const/sc_spec_udt_enum_v0.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtEnumV0 is a borrowing equivalent of [`ScSpecUdtEnumV0`](super::super::ScSpecUdtEnumV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtEnumV0 { + pub doc: StringM, + pub lib: StringM<80>, + pub name: StringM, + pub cases: VecM, +} + +impl ScSpecUdtEnumV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_enum_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_enum_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtEnumV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_enum_v0(&mut self, v: &ScSpecUdtEnumV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.lib.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_spec_udt_enum_case_v0(&v.cases); + } +} diff --git a/src/generated/const/sc_spec_udt_error_enum_case_v0.rs b/src/generated/const/sc_spec_udt_error_enum_case_v0.rs new file mode 100644 index 000000000..8a5167f84 --- /dev/null +++ b/src/generated/const/sc_spec_udt_error_enum_case_v0.rs @@ -0,0 +1,76 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtErrorEnumCaseV0 is a borrowing equivalent of [`ScSpecUdtErrorEnumCaseV0`](super::super::ScSpecUdtErrorEnumCaseV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtErrorEnumCaseV0 { + pub doc: StringM, + pub name: StringM<60>, + pub value: u32, +} + +impl ScSpecUdtErrorEnumCaseV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_error_enum_case_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_error_enum_case_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtErrorEnumCaseV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_error_enum_case_v0( + &mut self, + v: &ScSpecUdtErrorEnumCaseV0, + ) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_u32(v.value); + } + + /// Serializes a variable-length array of [`ScSpecUdtErrorEnumCaseV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_udt_error_enum_case_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_udt_error_enum_case_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_udt_error_enum_v0.rs b/src/generated/const/sc_spec_udt_error_enum_v0.rs new file mode 100644 index 000000000..56db0e9b0 --- /dev/null +++ b/src/generated/const/sc_spec_udt_error_enum_v0.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtErrorEnumV0 is a borrowing equivalent of [`ScSpecUdtErrorEnumV0`](super::super::ScSpecUdtErrorEnumV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtErrorEnumV0 { + pub doc: StringM, + pub lib: StringM<80>, + pub name: StringM, + pub cases: VecM, +} + +impl ScSpecUdtErrorEnumV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_error_enum_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_error_enum_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtErrorEnumV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_error_enum_v0(&mut self, v: &ScSpecUdtErrorEnumV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.lib.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_spec_udt_error_enum_case_v0(&v.cases); + } +} diff --git a/src/generated/const/sc_spec_udt_struct_field_v0.rs b/src/generated/const/sc_spec_udt_struct_field_v0.rs new file mode 100644 index 000000000..6fdc3bb08 --- /dev/null +++ b/src/generated/const/sc_spec_udt_struct_field_v0.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtStructFieldV0 is a borrowing equivalent of [`ScSpecUdtStructFieldV0`](super::super::ScSpecUdtStructFieldV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtStructFieldV0 { + pub doc: StringM, + pub name: StringM<30>, + pub type_: ScSpecTypeDef, +} + +impl ScSpecUdtStructFieldV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_struct_field_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_struct_field_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtStructFieldV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_struct_field_v0(&mut self, v: &ScSpecUdtStructFieldV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_sc_spec_type_def(&v.type_); + } + + /// Serializes a variable-length array of [`ScSpecUdtStructFieldV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_udt_struct_field_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_udt_struct_field_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_udt_struct_v0.rs b/src/generated/const/sc_spec_udt_struct_v0.rs new file mode 100644 index 000000000..d5b30ff4d --- /dev/null +++ b/src/generated/const/sc_spec_udt_struct_v0.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtStructV0 is a borrowing equivalent of [`ScSpecUdtStructV0`](super::super::ScSpecUdtStructV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtStructV0 { + pub doc: StringM, + pub lib: StringM<80>, + pub name: StringM, + pub fields: VecM, +} + +impl ScSpecUdtStructV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_struct_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_struct_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtStructV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_struct_v0(&mut self, v: &ScSpecUdtStructV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.lib.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_spec_udt_struct_field_v0(&v.fields); + } +} diff --git a/src/generated/const/sc_spec_udt_union_case_tuple_v0.rs b/src/generated/const/sc_spec_udt_union_case_tuple_v0.rs new file mode 100644 index 000000000..de06eeac0 --- /dev/null +++ b/src/generated/const/sc_spec_udt_union_case_tuple_v0.rs @@ -0,0 +1,61 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtUnionCaseTupleV0 is a borrowing equivalent of [`ScSpecUdtUnionCaseTupleV0`](super::super::ScSpecUdtUnionCaseTupleV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtUnionCaseTupleV0 { + pub doc: StringM, + pub name: StringM<60>, + pub type_: VecM, +} + +impl ScSpecUdtUnionCaseTupleV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_union_case_tuple_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_union_case_tuple_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtUnionCaseTupleV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_union_case_tuple_v0( + &mut self, + v: &ScSpecUdtUnionCaseTupleV0, + ) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_spec_type_def(&v.type_); + } +} diff --git a/src/generated/const/sc_spec_udt_union_case_v0.rs b/src/generated/const/sc_spec_udt_union_case_v0.rs new file mode 100644 index 000000000..6dd28ede9 --- /dev/null +++ b/src/generated/const/sc_spec_udt_union_case_v0.rs @@ -0,0 +1,92 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtUnionCaseV0 is a borrowing equivalent of [`ScSpecUdtUnionCaseV0`](super::super::ScSpecUdtUnionCaseV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecUdtUnionCaseV0 { + VoidV0(ScSpecUdtUnionCaseVoidV0), + TupleV0(ScSpecUdtUnionCaseTupleV0), +} + +impl ScSpecUdtUnionCaseV0 { + #[must_use] + pub const fn discriminant(&self) -> ScSpecUdtUnionCaseV0Kind { + #[allow(clippy::match_same_arms)] + match self { + Self::VoidV0(_) => ScSpecUdtUnionCaseV0Kind::VoidV0, + Self::TupleV0(_) => ScSpecUdtUnionCaseV0Kind::TupleV0, + } + } +} + +impl ScSpecUdtUnionCaseV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_union_case_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_union_case_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtUnionCaseV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_union_case_v0(&mut self, v: &ScSpecUdtUnionCaseV0) { + let d = v.discriminant(); + self.write_type_sc_spec_udt_union_case_v0_kind(&d); + #[allow(clippy::match_same_arms)] + match v { + ScSpecUdtUnionCaseV0::VoidV0(value) => { + self.write_type_sc_spec_udt_union_case_void_v0(value); + } + ScSpecUdtUnionCaseV0::TupleV0(value) => { + self.write_type_sc_spec_udt_union_case_tuple_v0(value); + } + } + } + + /// Serializes a variable-length array of [`ScSpecUdtUnionCaseV0`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_spec_udt_union_case_v0( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_spec_udt_union_case_v0(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_spec_udt_union_case_v0_kind.rs b/src/generated/const/sc_spec_udt_union_case_v0_kind.rs new file mode 100644 index 000000000..522b4c1cd --- /dev/null +++ b/src/generated/const/sc_spec_udt_union_case_v0_kind.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScSpecUdtUnionCaseV0Kind { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_union_case_v0_kind(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_union_case_v0_kind(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtUnionCaseV0Kind`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_union_case_v0_kind( + &mut self, + v: &ScSpecUdtUnionCaseV0Kind, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_spec_udt_union_case_void_v0.rs b/src/generated/const/sc_spec_udt_union_case_void_v0.rs new file mode 100644 index 000000000..14b8354c5 --- /dev/null +++ b/src/generated/const/sc_spec_udt_union_case_void_v0.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtUnionCaseVoidV0 is a borrowing equivalent of [`ScSpecUdtUnionCaseVoidV0`](super::super::ScSpecUdtUnionCaseVoidV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtUnionCaseVoidV0 { + pub doc: StringM, + pub name: StringM<60>, +} + +impl ScSpecUdtUnionCaseVoidV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_union_case_void_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_union_case_void_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtUnionCaseVoidV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_union_case_void_v0( + &mut self, + v: &ScSpecUdtUnionCaseVoidV0, + ) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.name.as_slice()); + } +} diff --git a/src/generated/const/sc_spec_udt_union_v0.rs b/src/generated/const/sc_spec_udt_union_v0.rs new file mode 100644 index 000000000..57c373785 --- /dev/null +++ b/src/generated/const/sc_spec_udt_union_v0.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSpecUdtUnionV0 is a borrowing equivalent of [`ScSpecUdtUnionV0`](super::super::ScSpecUdtUnionV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSpecUdtUnionV0 { + pub doc: StringM, + pub lib: StringM<80>, + pub name: StringM, + pub cases: VecM, +} + +impl ScSpecUdtUnionV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_spec_udt_union_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_spec_udt_union_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSpecUdtUnionV0`], mirroring `::write_xdr`. + pub const fn write_type_sc_spec_udt_union_v0(&mut self, v: &ScSpecUdtUnionV0) { + self.write_var_opaque(v.doc.as_slice()); + self.write_var_opaque(v.lib.as_slice()); + self.write_var_opaque(v.name.as_slice()); + self.write_type_vec_sc_spec_udt_union_case_v0(&v.cases); + } +} diff --git a/src/generated/const/sc_string.rs b/src/generated/const/sc_string.rs new file mode 100644 index 000000000..e1b9e247c --- /dev/null +++ b/src/generated/const/sc_string.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScString is a borrowing equivalent of [`ScString`](super::super::ScString) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScString(pub StringM); + +impl ScString { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_string(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_string(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScString`], mirroring `::write_xdr`. + pub const fn write_type_sc_string(&mut self, v: &ScString) { + self.write_var_opaque(v.0.as_slice()); + } +} diff --git a/src/generated/const/sc_symbol.rs b/src/generated/const/sc_symbol.rs new file mode 100644 index 000000000..6a2706183 --- /dev/null +++ b/src/generated/const/sc_symbol.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScSymbol is a borrowing equivalent of [`ScSymbol`](super::super::ScSymbol) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScSymbol(pub StringM); + +impl ScSymbol { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_symbol(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_symbol(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScSymbol`], mirroring `::write_xdr`. + pub const fn write_type_sc_symbol(&mut self, v: &ScSymbol) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes a variable-length array of [`ScSymbol`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_symbol(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_symbol(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_val.rs b/src/generated/const/sc_val.rs new file mode 100644 index 000000000..a20b97131 --- /dev/null +++ b/src/generated/const/sc_val.rs @@ -0,0 +1,203 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScVal is a borrowing equivalent of [`ScVal`](super::super::ScVal) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScVal { + Bool(bool), + Void, + Error(ScError), + U32(u32), + I32(i32), + U64(u64), + I64(i64), + Timepoint(TimePoint), + Duration(Duration), + U128(UInt128Parts), + I128(Int128Parts), + U256(UInt256Parts), + I256(Int256Parts), + Bytes(ScBytes), + String(ScString), + Symbol(ScSymbol), + Vec(Option), + Map(Option), + Address(ScAddress), + ContractInstance(ScContractInstance), + LedgerKeyContractInstance, + LedgerKeyNonce(ScNonceKey), + ExecutableTag(ScString), +} + +impl ScVal { + #[must_use] + pub const fn discriminant(&self) -> ScValType { + #[allow(clippy::match_same_arms)] + match self { + Self::Bool(_) => ScValType::Bool, + Self::Void => ScValType::Void, + Self::Error(_) => ScValType::Error, + Self::U32(_) => ScValType::U32, + Self::I32(_) => ScValType::I32, + Self::U64(_) => ScValType::U64, + Self::I64(_) => ScValType::I64, + Self::Timepoint(_) => ScValType::Timepoint, + Self::Duration(_) => ScValType::Duration, + Self::U128(_) => ScValType::U128, + Self::I128(_) => ScValType::I128, + Self::U256(_) => ScValType::U256, + Self::I256(_) => ScValType::I256, + Self::Bytes(_) => ScValType::Bytes, + Self::String(_) => ScValType::String, + Self::Symbol(_) => ScValType::Symbol, + Self::Vec(_) => ScValType::Vec, + Self::Map(_) => ScValType::Map, + Self::Address(_) => ScValType::Address, + Self::ContractInstance(_) => ScValType::ContractInstance, + Self::LedgerKeyContractInstance => ScValType::LedgerKeyContractInstance, + Self::LedgerKeyNonce(_) => ScValType::LedgerKeyNonce, + Self::ExecutableTag(_) => ScValType::ExecutableTag, + } + } +} + +impl ScVal { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_val(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_val(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScVal`], mirroring `::write_xdr`. + pub const fn write_type_sc_val(&mut self, v: &ScVal) { + let d = v.discriminant(); + self.write_type_sc_val_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ScVal::Bool(value) => { + self.write_bool(*value); + } + ScVal::Void => {} + ScVal::Error(value) => { + self.write_type_sc_error(value); + } + ScVal::U32(value) => { + self.write_u32(*value); + } + ScVal::I32(value) => { + self.write_i32(*value); + } + ScVal::U64(value) => { + self.write_u64(*value); + } + ScVal::I64(value) => { + self.write_i64(*value); + } + ScVal::Timepoint(value) => { + self.write_type_time_point(value); + } + ScVal::Duration(value) => { + self.write_type_duration(value); + } + ScVal::U128(value) => { + self.write_type_u_int128_parts(value); + } + ScVal::I128(value) => { + self.write_type_int128_parts(value); + } + ScVal::U256(value) => { + self.write_type_u_int256_parts(value); + } + ScVal::I256(value) => { + self.write_type_int256_parts(value); + } + ScVal::Bytes(value) => { + self.write_type_sc_bytes(value); + } + ScVal::String(value) => { + self.write_type_sc_string(value); + } + ScVal::Symbol(value) => { + self.write_type_sc_symbol(value); + } + ScVal::Vec(value) => { + self.write_type_option_sc_vec(value); + } + ScVal::Map(value) => { + self.write_type_option_sc_map(value); + } + ScVal::Address(value) => { + self.write_type_sc_address(value); + } + ScVal::ContractInstance(value) => { + self.write_type_sc_contract_instance(value); + } + ScVal::LedgerKeyContractInstance => {} + ScVal::LedgerKeyNonce(value) => { + self.write_type_sc_nonce_key(value); + } + ScVal::ExecutableTag(value) => { + self.write_type_sc_string(value); + } + } + } + + /// Serializes an optional [`ScVal`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_sc_val(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_sc_val(v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes a variable-length array of [`ScVal`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sc_val(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sc_val(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/sc_val_type.rs b/src/generated/const/sc_val_type.rs new file mode 100644 index 000000000..756e5bd91 --- /dev/null +++ b/src/generated/const/sc_val_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScValType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_val_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_val_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScValType`], mirroring `::write_xdr`. + pub const fn write_type_sc_val_type(&mut self, v: &ScValType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/sc_vec.rs b/src/generated/const/sc_vec.rs new file mode 100644 index 000000000..d48012e92 --- /dev/null +++ b/src/generated/const/sc_vec.rs @@ -0,0 +1,65 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScVec is a borrowing equivalent of [`ScVec`](super::super::ScVec) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScVec(pub VecM); + +impl ScVec { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sc_vec(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sc_vec(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScVec`], mirroring `::write_xdr`. + pub const fn write_type_sc_vec(&mut self, v: &ScVec) { + self.write_type_vec_sc_val(&v.0); + } + + /// Serializes an optional [`ScVec`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_sc_vec(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_sc_vec(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/scp_ballot.rs b/src/generated/const/scp_ballot.rs new file mode 100644 index 000000000..1d5e4aae3 --- /dev/null +++ b/src/generated/const/scp_ballot.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpBallot is a borrowing equivalent of [`ScpBallot`](super::super::ScpBallot) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpBallot { + pub counter: u32, + pub value: Value, +} + +impl ScpBallot { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_ballot(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_ballot(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpBallot`], mirroring `::write_xdr`. + pub const fn write_type_scp_ballot(&mut self, v: &ScpBallot) { + self.write_u32(v.counter); + self.write_type_value(&v.value); + } + + /// Serializes an optional [`ScpBallot`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_scp_ballot(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_scp_ballot(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/scp_envelope.rs b/src/generated/const/scp_envelope.rs new file mode 100644 index 000000000..b4bbcf159 --- /dev/null +++ b/src/generated/const/scp_envelope.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpEnvelope is a borrowing equivalent of [`ScpEnvelope`](super::super::ScpEnvelope) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpEnvelope { + pub statement: ScpStatement, + pub signature: Signature, +} + +impl ScpEnvelope { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_envelope(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_envelope(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpEnvelope`], mirroring `::write_xdr`. + pub const fn write_type_scp_envelope(&mut self, v: &ScpEnvelope) { + self.write_type_scp_statement(&v.statement); + self.write_type_signature(&v.signature); + } + + /// Serializes a variable-length array of [`ScpEnvelope`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_scp_envelope( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_scp_envelope(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/scp_history_entry.rs b/src/generated/const/scp_history_entry.rs new file mode 100644 index 000000000..85c3f20df --- /dev/null +++ b/src/generated/const/scp_history_entry.rs @@ -0,0 +1,87 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpHistoryEntry is a borrowing equivalent of [`ScpHistoryEntry`](super::super::ScpHistoryEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScpHistoryEntry { + V0(ScpHistoryEntryV0), +} + +impl ScpHistoryEntry { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl ScpHistoryEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_history_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_history_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpHistoryEntry`], mirroring `::write_xdr`. + pub const fn write_type_scp_history_entry(&mut self, v: &ScpHistoryEntry) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + ScpHistoryEntry::V0(value) => { + self.write_type_scp_history_entry_v0(value); + } + } + } + + /// Serializes a variable-length array of [`ScpHistoryEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_scp_history_entry( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_scp_history_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/scp_history_entry_v0.rs b/src/generated/const/scp_history_entry_v0.rs new file mode 100644 index 000000000..5bbd7f874 --- /dev/null +++ b/src/generated/const/scp_history_entry_v0.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpHistoryEntryV0 is a borrowing equivalent of [`ScpHistoryEntryV0`](super::super::ScpHistoryEntryV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpHistoryEntryV0 { + pub quorum_sets: VecM, + pub ledger_messages: LedgerScpMessages, +} + +impl ScpHistoryEntryV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_history_entry_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_history_entry_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpHistoryEntryV0`], mirroring `::write_xdr`. + pub const fn write_type_scp_history_entry_v0(&mut self, v: &ScpHistoryEntryV0) { + self.write_type_vec_scp_quorum_set(&v.quorum_sets); + self.write_type_ledger_scp_messages(&v.ledger_messages); + } +} diff --git a/src/generated/const/scp_nomination.rs b/src/generated/const/scp_nomination.rs new file mode 100644 index 000000000..82d2c444a --- /dev/null +++ b/src/generated/const/scp_nomination.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpNomination is a borrowing equivalent of [`ScpNomination`](super::super::ScpNomination) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpNomination { + pub quorum_set_hash: Hash, + pub votes: VecM, + pub accepted: VecM, +} + +impl ScpNomination { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_nomination(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_nomination(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpNomination`], mirroring `::write_xdr`. + pub const fn write_type_scp_nomination(&mut self, v: &ScpNomination) { + self.write_type_hash(&v.quorum_set_hash); + self.write_type_vec_value(&v.votes); + self.write_type_vec_value(&v.accepted); + } +} diff --git a/src/generated/const/scp_quorum_set.rs b/src/generated/const/scp_quorum_set.rs new file mode 100644 index 000000000..5094b26f5 --- /dev/null +++ b/src/generated/const/scp_quorum_set.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpQuorumSet is a borrowing equivalent of [`ScpQuorumSet`](super::super::ScpQuorumSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpQuorumSet { + pub threshold: u32, + pub validators: VecM, + pub inner_sets: VecM, +} + +impl ScpQuorumSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_quorum_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_quorum_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpQuorumSet`], mirroring `::write_xdr`. + pub const fn write_type_scp_quorum_set(&mut self, v: &ScpQuorumSet) { + self.write_u32(v.threshold); + self.write_type_vec_node_id(&v.validators); + self.write_type_vec_scp_quorum_set(&v.inner_sets); + } + + /// Serializes a variable-length array of [`ScpQuorumSet`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_scp_quorum_set( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_scp_quorum_set(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/scp_statement.rs b/src/generated/const/scp_statement.rs new file mode 100644 index 000000000..61a48227f --- /dev/null +++ b/src/generated/const/scp_statement.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpStatement is a borrowing equivalent of [`ScpStatement`](super::super::ScpStatement) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpStatement { + pub node_id: NodeId, + pub slot_index: u64, + pub pledges: ScpStatementPledges, +} + +impl ScpStatement { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatement`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement(&mut self, v: &ScpStatement) { + self.write_type_node_id(&v.node_id); + self.write_u64(v.slot_index); + self.write_type_scp_statement_pledges(&v.pledges); + } +} diff --git a/src/generated/const/scp_statement_confirm.rs b/src/generated/const/scp_statement_confirm.rs new file mode 100644 index 000000000..1e6088aa8 --- /dev/null +++ b/src/generated/const/scp_statement_confirm.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpStatementConfirm is a borrowing equivalent of [`ScpStatementConfirm`](super::super::ScpStatementConfirm) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpStatementConfirm { + pub ballot: ScpBallot, + pub n_prepared: u32, + pub n_commit: u32, + pub n_h: u32, + pub quorum_set_hash: Hash, +} + +impl ScpStatementConfirm { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement_confirm(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement_confirm(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatementConfirm`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement_confirm(&mut self, v: &ScpStatementConfirm) { + self.write_type_scp_ballot(&v.ballot); + self.write_u32(v.n_prepared); + self.write_u32(v.n_commit); + self.write_u32(v.n_h); + self.write_type_hash(&v.quorum_set_hash); + } +} diff --git a/src/generated/const/scp_statement_externalize.rs b/src/generated/const/scp_statement_externalize.rs new file mode 100644 index 000000000..13750b63f --- /dev/null +++ b/src/generated/const/scp_statement_externalize.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpStatementExternalize is a borrowing equivalent of [`ScpStatementExternalize`](super::super::ScpStatementExternalize) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpStatementExternalize { + pub commit: ScpBallot, + pub n_h: u32, + pub commit_quorum_set_hash: Hash, +} + +impl ScpStatementExternalize { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement_externalize(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement_externalize(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatementExternalize`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement_externalize(&mut self, v: &ScpStatementExternalize) { + self.write_type_scp_ballot(&v.commit); + self.write_u32(v.n_h); + self.write_type_hash(&v.commit_quorum_set_hash); + } +} diff --git a/src/generated/const/scp_statement_pledges.rs b/src/generated/const/scp_statement_pledges.rs new file mode 100644 index 000000000..549a5054a --- /dev/null +++ b/src/generated/const/scp_statement_pledges.rs @@ -0,0 +1,87 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpStatementPledges is a borrowing equivalent of [`ScpStatementPledges`](super::super::ScpStatementPledges) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum ScpStatementPledges { + Prepare(ScpStatementPrepare), + Confirm(ScpStatementConfirm), + Externalize(ScpStatementExternalize), + Nominate(ScpNomination), +} + +impl ScpStatementPledges { + #[must_use] + pub const fn discriminant(&self) -> ScpStatementType { + #[allow(clippy::match_same_arms)] + match self { + Self::Prepare(_) => ScpStatementType::Prepare, + Self::Confirm(_) => ScpStatementType::Confirm, + Self::Externalize(_) => ScpStatementType::Externalize, + Self::Nominate(_) => ScpStatementType::Nominate, + } + } +} + +impl ScpStatementPledges { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement_pledges(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement_pledges(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatementPledges`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement_pledges(&mut self, v: &ScpStatementPledges) { + let d = v.discriminant(); + self.write_type_scp_statement_type(&d); + #[allow(clippy::match_same_arms)] + match v { + ScpStatementPledges::Prepare(value) => { + self.write_type_scp_statement_prepare(value); + } + ScpStatementPledges::Confirm(value) => { + self.write_type_scp_statement_confirm(value); + } + ScpStatementPledges::Externalize(value) => { + self.write_type_scp_statement_externalize(value); + } + ScpStatementPledges::Nominate(value) => { + self.write_type_scp_nomination(value); + } + } + } +} diff --git a/src/generated/const/scp_statement_prepare.rs b/src/generated/const/scp_statement_prepare.rs new file mode 100644 index 000000000..811004fbd --- /dev/null +++ b/src/generated/const/scp_statement_prepare.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// ScpStatementPrepare is a borrowing equivalent of [`ScpStatementPrepare`](super::super::ScpStatementPrepare) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct ScpStatementPrepare { + pub quorum_set_hash: Hash, + pub ballot: ScpBallot, + pub prepared: Option, + pub prepared_prime: Option, + pub n_c: u32, + pub n_h: u32, +} + +impl ScpStatementPrepare { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement_prepare(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement_prepare(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatementPrepare`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement_prepare(&mut self, v: &ScpStatementPrepare) { + self.write_type_hash(&v.quorum_set_hash); + self.write_type_scp_ballot(&v.ballot); + self.write_type_option_scp_ballot(&v.prepared); + self.write_type_option_scp_ballot(&v.prepared_prime); + self.write_u32(v.n_c); + self.write_u32(v.n_h); + } +} diff --git a/src/generated/const/scp_statement_type.rs b/src/generated/const/scp_statement_type.rs new file mode 100644 index 000000000..609c56fda --- /dev/null +++ b/src/generated/const/scp_statement_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ScpStatementType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_scp_statement_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_scp_statement_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ScpStatementType`], mirroring `::write_xdr`. + pub const fn write_type_scp_statement_type(&mut self, v: &ScpStatementType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/send_more.rs b/src/generated/const/send_more.rs new file mode 100644 index 000000000..dbe0e34ba --- /dev/null +++ b/src/generated/const/send_more.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SendMore { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_send_more(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_send_more(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SendMore`], mirroring `::write_xdr`. + pub const fn write_type_send_more(&mut self, v: &SendMore) { + self.write_u32(v.num_messages); + } +} diff --git a/src/generated/const/send_more_extended.rs b/src/generated/const/send_more_extended.rs new file mode 100644 index 000000000..e0b2259c3 --- /dev/null +++ b/src/generated/const/send_more_extended.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SendMoreExtended { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_send_more_extended(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_send_more_extended(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SendMoreExtended`], mirroring `::write_xdr`. + pub const fn write_type_send_more_extended(&mut self, v: &SendMoreExtended) { + self.write_u32(v.num_messages); + self.write_u32(v.num_bytes); + } +} diff --git a/src/generated/const/sequence_number.rs b/src/generated/const/sequence_number.rs new file mode 100644 index 000000000..e7a7cc80f --- /dev/null +++ b/src/generated/const/sequence_number.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SequenceNumber { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sequence_number(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sequence_number(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SequenceNumber`], mirroring `::write_xdr`. + pub const fn write_type_sequence_number(&mut self, v: &SequenceNumber) { + self.write_i64(v.0); + } + + /// Serializes an optional [`SequenceNumber`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_sequence_number(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_sequence_number(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/serialized_binary_fuse_filter.rs b/src/generated/const/serialized_binary_fuse_filter.rs new file mode 100644 index 000000000..a141bec6a --- /dev/null +++ b/src/generated/const/serialized_binary_fuse_filter.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SerializedBinaryFuseFilter is a borrowing equivalent of [`SerializedBinaryFuseFilter`](super::super::SerializedBinaryFuseFilter) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SerializedBinaryFuseFilter { + pub type_: BinaryFuseFilterType, + pub input_hash_seed: ShortHashSeed, + pub filter_seed: ShortHashSeed, + pub segment_length: u32, + pub segement_length_mask: u32, + pub segment_count: u32, + pub segment_count_length: u32, + pub fingerprint_length: u32, + pub fingerprints: BytesM, +} + +impl SerializedBinaryFuseFilter { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_serialized_binary_fuse_filter(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_serialized_binary_fuse_filter(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SerializedBinaryFuseFilter`], mirroring `::write_xdr`. + pub const fn write_type_serialized_binary_fuse_filter( + &mut self, + v: &SerializedBinaryFuseFilter, + ) { + self.write_type_binary_fuse_filter_type(&v.type_); + self.write_type_short_hash_seed(&v.input_hash_seed); + self.write_type_short_hash_seed(&v.filter_seed); + self.write_u32(v.segment_length); + self.write_u32(v.segement_length_mask); + self.write_u32(v.segment_count); + self.write_u32(v.segment_count_length); + self.write_u32(v.fingerprint_length); + self.write_var_opaque(v.fingerprints.as_slice()); + } +} diff --git a/src/generated/const/set_options_op.rs b/src/generated/const/set_options_op.rs new file mode 100644 index 000000000..e0d5491bb --- /dev/null +++ b/src/generated/const/set_options_op.rs @@ -0,0 +1,70 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SetOptionsOp is a borrowing equivalent of [`SetOptionsOp`](super::super::SetOptionsOp) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SetOptionsOp { + pub inflation_dest: Option, + pub clear_flags: Option, + pub set_flags: Option, + pub master_weight: Option, + pub low_threshold: Option, + pub med_threshold: Option, + pub high_threshold: Option, + pub home_domain: Option, + pub signer: Option, +} + +impl SetOptionsOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_options_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_options_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetOptionsOp`], mirroring `::write_xdr`. + pub const fn write_type_set_options_op(&mut self, v: &SetOptionsOp) { + self.write_type_option_account_id(&v.inflation_dest); + self.write_option_u32(&v.clear_flags); + self.write_option_u32(&v.set_flags); + self.write_option_u32(&v.master_weight); + self.write_option_u32(&v.low_threshold); + self.write_option_u32(&v.med_threshold); + self.write_option_u32(&v.high_threshold); + self.write_type_option_string32(&v.home_domain); + self.write_type_option_signer(&v.signer); + } +} diff --git a/src/generated/const/set_options_result.rs b/src/generated/const/set_options_result.rs new file mode 100644 index 000000000..72ffd91ae --- /dev/null +++ b/src/generated/const/set_options_result.rs @@ -0,0 +1,61 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SetOptionsResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_options_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_options_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetOptionsResult`], mirroring `::write_xdr`. + pub const fn write_type_set_options_result(&mut self, v: &SetOptionsResult) { + let d = v.discriminant(); + self.write_type_set_options_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + SetOptionsResult::Success => {} + SetOptionsResult::LowReserve => {} + SetOptionsResult::TooManySigners => {} + SetOptionsResult::BadFlags => {} + SetOptionsResult::InvalidInflation => {} + SetOptionsResult::CantChange => {} + SetOptionsResult::UnknownFlag => {} + SetOptionsResult::ThresholdOutOfRange => {} + SetOptionsResult::BadSigner => {} + SetOptionsResult::InvalidHomeDomain => {} + SetOptionsResult::AuthRevocableRequired => {} + } + } +} diff --git a/src/generated/const/set_options_result_code.rs b/src/generated/const/set_options_result_code.rs new file mode 100644 index 000000000..5a557d88c --- /dev/null +++ b/src/generated/const/set_options_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SetOptionsResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_options_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_options_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetOptionsResultCode`], mirroring `::write_xdr`. + pub const fn write_type_set_options_result_code(&mut self, v: &SetOptionsResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/set_trust_line_flags_op.rs b/src/generated/const/set_trust_line_flags_op.rs new file mode 100644 index 000000000..66a6be635 --- /dev/null +++ b/src/generated/const/set_trust_line_flags_op.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SetTrustLineFlagsOp { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_trust_line_flags_op(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_trust_line_flags_op(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetTrustLineFlagsOp`], mirroring `::write_xdr`. + pub const fn write_type_set_trust_line_flags_op(&mut self, v: &SetTrustLineFlagsOp) { + self.write_type_account_id(&v.trustor); + self.write_type_asset(&v.asset); + self.write_u32(v.clear_flags); + self.write_u32(v.set_flags); + } +} diff --git a/src/generated/const/set_trust_line_flags_result.rs b/src/generated/const/set_trust_line_flags_result.rs new file mode 100644 index 000000000..a2cd382fc --- /dev/null +++ b/src/generated/const/set_trust_line_flags_result.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SetTrustLineFlagsResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_trust_line_flags_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_trust_line_flags_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetTrustLineFlagsResult`], mirroring `::write_xdr`. + pub const fn write_type_set_trust_line_flags_result(&mut self, v: &SetTrustLineFlagsResult) { + let d = v.discriminant(); + self.write_type_set_trust_line_flags_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + SetTrustLineFlagsResult::Success => {} + SetTrustLineFlagsResult::Malformed => {} + SetTrustLineFlagsResult::NoTrustLine => {} + SetTrustLineFlagsResult::CantRevoke => {} + SetTrustLineFlagsResult::InvalidState => {} + SetTrustLineFlagsResult::LowReserve => {} + } + } +} diff --git a/src/generated/const/set_trust_line_flags_result_code.rs b/src/generated/const/set_trust_line_flags_result_code.rs new file mode 100644 index 000000000..c17ec6fa8 --- /dev/null +++ b/src/generated/const/set_trust_line_flags_result_code.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SetTrustLineFlagsResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_set_trust_line_flags_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_set_trust_line_flags_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SetTrustLineFlagsResultCode`], mirroring `::write_xdr`. + pub const fn write_type_set_trust_line_flags_result_code( + &mut self, + v: &SetTrustLineFlagsResultCode, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/short_hash_seed.rs b/src/generated/const/short_hash_seed.rs new file mode 100644 index 000000000..1dacd1f81 --- /dev/null +++ b/src/generated/const/short_hash_seed.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ShortHashSeed { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_short_hash_seed(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_short_hash_seed(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ShortHashSeed`], mirroring `::write_xdr`. + pub const fn write_type_short_hash_seed(&mut self, v: &ShortHashSeed) { + self.write_fixed_opaque(&v.seed); + } +} diff --git a/src/generated/const/signature.rs b/src/generated/const/signature.rs new file mode 100644 index 000000000..290201fe9 --- /dev/null +++ b/src/generated/const/signature.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Signature is a borrowing equivalent of [`Signature`](super::super::Signature) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Signature(pub BytesM<64>); + +impl Signature { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signature(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signature(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Signature`], mirroring `::write_xdr`. + pub const fn write_type_signature(&mut self, v: &Signature) { + self.write_var_opaque(v.0.as_slice()); + } +} diff --git a/src/generated/const/signature_hint.rs b/src/generated/const/signature_hint.rs new file mode 100644 index 000000000..b504817a6 --- /dev/null +++ b/src/generated/const/signature_hint.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SignatureHint { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signature_hint(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signature_hint(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignatureHint`], mirroring `::write_xdr`. + pub const fn write_type_signature_hint(&mut self, v: &SignatureHint) { + self.write_fixed_opaque(&v.0); + } +} diff --git a/src/generated/const/signed_time_sliced_survey_request_message.rs b/src/generated/const/signed_time_sliced_survey_request_message.rs new file mode 100644 index 000000000..edc4493c3 --- /dev/null +++ b/src/generated/const/signed_time_sliced_survey_request_message.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignedTimeSlicedSurveyRequestMessage is a borrowing equivalent of [`SignedTimeSlicedSurveyRequestMessage`](super::super::SignedTimeSlicedSurveyRequestMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SignedTimeSlicedSurveyRequestMessage { + pub request_signature: Signature, + pub request: TimeSlicedSurveyRequestMessage, +} + +impl SignedTimeSlicedSurveyRequestMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signed_time_sliced_survey_request_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signed_time_sliced_survey_request_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignedTimeSlicedSurveyRequestMessage`], mirroring `::write_xdr`. + pub const fn write_type_signed_time_sliced_survey_request_message( + &mut self, + v: &SignedTimeSlicedSurveyRequestMessage, + ) { + self.write_type_signature(&v.request_signature); + self.write_type_time_sliced_survey_request_message(&v.request); + } +} diff --git a/src/generated/const/signed_time_sliced_survey_response_message.rs b/src/generated/const/signed_time_sliced_survey_response_message.rs new file mode 100644 index 000000000..6868520ac --- /dev/null +++ b/src/generated/const/signed_time_sliced_survey_response_message.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignedTimeSlicedSurveyResponseMessage is a borrowing equivalent of [`SignedTimeSlicedSurveyResponseMessage`](super::super::SignedTimeSlicedSurveyResponseMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SignedTimeSlicedSurveyResponseMessage { + pub response_signature: Signature, + pub response: TimeSlicedSurveyResponseMessage, +} + +impl SignedTimeSlicedSurveyResponseMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signed_time_sliced_survey_response_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signed_time_sliced_survey_response_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignedTimeSlicedSurveyResponseMessage`], mirroring `::write_xdr`. + pub const fn write_type_signed_time_sliced_survey_response_message( + &mut self, + v: &SignedTimeSlicedSurveyResponseMessage, + ) { + self.write_type_signature(&v.response_signature); + self.write_type_time_sliced_survey_response_message(&v.response); + } +} diff --git a/src/generated/const/signed_time_sliced_survey_start_collecting_message.rs b/src/generated/const/signed_time_sliced_survey_start_collecting_message.rs new file mode 100644 index 000000000..ee7a600a4 --- /dev/null +++ b/src/generated/const/signed_time_sliced_survey_start_collecting_message.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignedTimeSlicedSurveyStartCollectingMessage is a borrowing equivalent of [`SignedTimeSlicedSurveyStartCollectingMessage`](super::super::SignedTimeSlicedSurveyStartCollectingMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SignedTimeSlicedSurveyStartCollectingMessage { + pub signature: Signature, + pub start_collecting: TimeSlicedSurveyStartCollectingMessage, +} + +impl SignedTimeSlicedSurveyStartCollectingMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signed_time_sliced_survey_start_collecting_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signed_time_sliced_survey_start_collecting_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignedTimeSlicedSurveyStartCollectingMessage`], mirroring `::write_xdr`. + pub const fn write_type_signed_time_sliced_survey_start_collecting_message( + &mut self, + v: &SignedTimeSlicedSurveyStartCollectingMessage, + ) { + self.write_type_signature(&v.signature); + self.write_type_time_sliced_survey_start_collecting_message(&v.start_collecting); + } +} diff --git a/src/generated/const/signed_time_sliced_survey_stop_collecting_message.rs b/src/generated/const/signed_time_sliced_survey_stop_collecting_message.rs new file mode 100644 index 000000000..be2ff4c83 --- /dev/null +++ b/src/generated/const/signed_time_sliced_survey_stop_collecting_message.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignedTimeSlicedSurveyStopCollectingMessage is a borrowing equivalent of [`SignedTimeSlicedSurveyStopCollectingMessage`](super::super::SignedTimeSlicedSurveyStopCollectingMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SignedTimeSlicedSurveyStopCollectingMessage { + pub signature: Signature, + pub stop_collecting: TimeSlicedSurveyStopCollectingMessage, +} + +impl SignedTimeSlicedSurveyStopCollectingMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signed_time_sliced_survey_stop_collecting_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signed_time_sliced_survey_stop_collecting_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignedTimeSlicedSurveyStopCollectingMessage`], mirroring `::write_xdr`. + pub const fn write_type_signed_time_sliced_survey_stop_collecting_message( + &mut self, + v: &SignedTimeSlicedSurveyStopCollectingMessage, + ) { + self.write_type_signature(&v.signature); + self.write_type_time_sliced_survey_stop_collecting_message(&v.stop_collecting); + } +} diff --git a/src/generated/const/signer.rs b/src/generated/const/signer.rs new file mode 100644 index 000000000..31a0c1340 --- /dev/null +++ b/src/generated/const/signer.rs @@ -0,0 +1,81 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Signer is a borrowing equivalent of [`Signer`](super::super::Signer) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Signer { + pub key: SignerKey, + pub weight: u32, +} + +impl Signer { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signer(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signer(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Signer`], mirroring `::write_xdr`. + pub const fn write_type_signer(&mut self, v: &Signer) { + self.write_type_signer_key(&v.key); + self.write_u32(v.weight); + } + + /// Serializes an optional [`Signer`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_signer(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_signer(v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes a variable-length array of [`Signer`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_signer(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_signer(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/signer_key.rs b/src/generated/const/signer_key.rs new file mode 100644 index 000000000..deec1ded8 --- /dev/null +++ b/src/generated/const/signer_key.rs @@ -0,0 +1,99 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignerKey is a borrowing equivalent of [`SignerKey`](super::super::SignerKey) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum SignerKey { + Ed25519(Uint256), + PreAuthTx(Uint256), + HashX(Uint256), + Ed25519SignedPayload(SignerKeyEd25519SignedPayload), +} + +impl SignerKey { + #[must_use] + pub const fn discriminant(&self) -> SignerKeyType { + #[allow(clippy::match_same_arms)] + match self { + Self::Ed25519(_) => SignerKeyType::Ed25519, + Self::PreAuthTx(_) => SignerKeyType::PreAuthTx, + Self::HashX(_) => SignerKeyType::HashX, + Self::Ed25519SignedPayload(_) => SignerKeyType::Ed25519SignedPayload, + } + } +} + +impl SignerKey { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signer_key(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signer_key(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignerKey`], mirroring `::write_xdr`. + pub const fn write_type_signer_key(&mut self, v: &SignerKey) { + let d = v.discriminant(); + self.write_type_signer_key_type(&d); + #[allow(clippy::match_same_arms)] + match v { + SignerKey::Ed25519(value) => { + self.write_type_uint256(value); + } + SignerKey::PreAuthTx(value) => { + self.write_type_uint256(value); + } + SignerKey::HashX(value) => { + self.write_type_uint256(value); + } + SignerKey::Ed25519SignedPayload(value) => { + self.write_type_signer_key_ed25519_signed_payload(value); + } + } + } + + /// Serializes a variable-length array of [`SignerKey`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_signer_key(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_signer_key(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/signer_key_ed25519_signed_payload.rs b/src/generated/const/signer_key_ed25519_signed_payload.rs new file mode 100644 index 000000000..dbde3379f --- /dev/null +++ b/src/generated/const/signer_key_ed25519_signed_payload.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SignerKeyEd25519SignedPayload is a borrowing equivalent of [`SignerKeyEd25519SignedPayload`](super::super::SignerKeyEd25519SignedPayload) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SignerKeyEd25519SignedPayload { + pub ed25519: Uint256, + pub payload: BytesM<64>, +} + +impl SignerKeyEd25519SignedPayload { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signer_key_ed25519_signed_payload(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signer_key_ed25519_signed_payload(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignerKeyEd25519SignedPayload`], mirroring `::write_xdr`. + pub const fn write_type_signer_key_ed25519_signed_payload( + &mut self, + v: &SignerKeyEd25519SignedPayload, + ) { + self.write_type_uint256(&v.ed25519); + self.write_var_opaque(v.payload.as_slice()); + } +} diff --git a/src/generated/const/signer_key_type.rs b/src/generated/const/signer_key_type.rs new file mode 100644 index 000000000..bf43c22e0 --- /dev/null +++ b/src/generated/const/signer_key_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SignerKeyType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_signer_key_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_signer_key_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SignerKeyType`], mirroring `::write_xdr`. + pub const fn write_type_signer_key_type(&mut self, v: &SignerKeyType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/simple_payment_result.rs b/src/generated/const/simple_payment_result.rs new file mode 100644 index 000000000..3da8c75e2 --- /dev/null +++ b/src/generated/const/simple_payment_result.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SimplePaymentResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_simple_payment_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_simple_payment_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SimplePaymentResult`], mirroring `::write_xdr`. + pub const fn write_type_simple_payment_result(&mut self, v: &SimplePaymentResult) { + self.write_type_account_id(&v.destination); + self.write_type_asset(&v.asset); + self.write_i64(v.amount); + } +} diff --git a/src/generated/const/soroban_address_credentials.rs b/src/generated/const/soroban_address_credentials.rs new file mode 100644 index 000000000..e31f12835 --- /dev/null +++ b/src/generated/const/soroban_address_credentials.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAddressCredentials is a borrowing equivalent of [`SorobanAddressCredentials`](super::super::SorobanAddressCredentials) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanAddressCredentials { + pub address: ScAddress, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub signature: ScVal, +} + +impl SorobanAddressCredentials { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_address_credentials(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_address_credentials(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAddressCredentials`], mirroring `::write_xdr`. + pub const fn write_type_soroban_address_credentials(&mut self, v: &SorobanAddressCredentials) { + self.write_type_sc_address(&v.address); + self.write_i64(v.nonce); + self.write_u32(v.signature_expiration_ledger); + self.write_type_sc_val(&v.signature); + } +} diff --git a/src/generated/const/soroban_address_credentials_with_delegates.rs b/src/generated/const/soroban_address_credentials_with_delegates.rs new file mode 100644 index 000000000..fc69e8b28 --- /dev/null +++ b/src/generated/const/soroban_address_credentials_with_delegates.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAddressCredentialsWithDelegates is a borrowing equivalent of [`SorobanAddressCredentialsWithDelegates`](super::super::SorobanAddressCredentialsWithDelegates) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanAddressCredentialsWithDelegates { + pub address_credentials: SorobanAddressCredentials, + pub delegates: VecM, +} + +impl SorobanAddressCredentialsWithDelegates { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_address_credentials_with_delegates(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_address_credentials_with_delegates(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAddressCredentialsWithDelegates`], mirroring `::write_xdr`. + pub const fn write_type_soroban_address_credentials_with_delegates( + &mut self, + v: &SorobanAddressCredentialsWithDelegates, + ) { + self.write_type_soroban_address_credentials(&v.address_credentials); + self.write_type_vec_soroban_delegate_signature(&v.delegates); + } +} diff --git a/src/generated/const/soroban_authorization_entries.rs b/src/generated/const/soroban_authorization_entries.rs new file mode 100644 index 000000000..82493ebc3 --- /dev/null +++ b/src/generated/const/soroban_authorization_entries.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAuthorizationEntries is a borrowing equivalent of [`SorobanAuthorizationEntries`](super::super::SorobanAuthorizationEntries) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanAuthorizationEntries(pub VecM); + +impl SorobanAuthorizationEntries { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_authorization_entries(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_authorization_entries(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAuthorizationEntries`], mirroring `::write_xdr`. + pub const fn write_type_soroban_authorization_entries( + &mut self, + v: &SorobanAuthorizationEntries, + ) { + self.write_type_vec_soroban_authorization_entry(&v.0); + } +} diff --git a/src/generated/const/soroban_authorization_entry.rs b/src/generated/const/soroban_authorization_entry.rs new file mode 100644 index 000000000..05b045e48 --- /dev/null +++ b/src/generated/const/soroban_authorization_entry.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAuthorizationEntry is a borrowing equivalent of [`SorobanAuthorizationEntry`](super::super::SorobanAuthorizationEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanAuthorizationEntry { + pub credentials: SorobanCredentials, + pub root_invocation: SorobanAuthorizedInvocation, +} + +impl SorobanAuthorizationEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_authorization_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_authorization_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAuthorizationEntry`], mirroring `::write_xdr`. + pub const fn write_type_soroban_authorization_entry(&mut self, v: &SorobanAuthorizationEntry) { + self.write_type_soroban_credentials(&v.credentials); + self.write_type_soroban_authorized_invocation(&v.root_invocation); + } + + /// Serializes a variable-length array of [`SorobanAuthorizationEntry`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_soroban_authorization_entry( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_soroban_authorization_entry(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/soroban_authorized_function.rs b/src/generated/const/soroban_authorized_function.rs new file mode 100644 index 000000000..1f04ffc6d --- /dev/null +++ b/src/generated/const/soroban_authorized_function.rs @@ -0,0 +1,84 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAuthorizedFunction is a borrowing equivalent of [`SorobanAuthorizedFunction`](super::super::SorobanAuthorizedFunction) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum SorobanAuthorizedFunction { + ContractFn(InvokeContractArgs), + CreateContractHostFn(CreateContractArgs), + CreateContractV2HostFn(CreateContractArgsV2), +} + +impl SorobanAuthorizedFunction { + #[must_use] + pub const fn discriminant(&self) -> SorobanAuthorizedFunctionType { + #[allow(clippy::match_same_arms)] + match self { + Self::ContractFn(_) => SorobanAuthorizedFunctionType::ContractFn, + Self::CreateContractHostFn(_) => SorobanAuthorizedFunctionType::CreateContractHostFn, + Self::CreateContractV2HostFn(_) => { + SorobanAuthorizedFunctionType::CreateContractV2HostFn + } + } + } +} + +impl SorobanAuthorizedFunction { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_authorized_function(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_authorized_function(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAuthorizedFunction`], mirroring `::write_xdr`. + pub const fn write_type_soroban_authorized_function(&mut self, v: &SorobanAuthorizedFunction) { + let d = v.discriminant(); + self.write_type_soroban_authorized_function_type(&d); + #[allow(clippy::match_same_arms)] + match v { + SorobanAuthorizedFunction::ContractFn(value) => { + self.write_type_invoke_contract_args(value); + } + SorobanAuthorizedFunction::CreateContractHostFn(value) => { + self.write_type_create_contract_args(value); + } + SorobanAuthorizedFunction::CreateContractV2HostFn(value) => { + self.write_type_create_contract_args_v2(value); + } + } + } +} diff --git a/src/generated/const/soroban_authorized_function_type.rs b/src/generated/const/soroban_authorized_function_type.rs new file mode 100644 index 000000000..61c12de1e --- /dev/null +++ b/src/generated/const/soroban_authorized_function_type.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SorobanAuthorizedFunctionType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_authorized_function_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_authorized_function_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAuthorizedFunctionType`], mirroring `::write_xdr`. + pub const fn write_type_soroban_authorized_function_type( + &mut self, + v: &SorobanAuthorizedFunctionType, + ) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/soroban_authorized_invocation.rs b/src/generated/const/soroban_authorized_invocation.rs new file mode 100644 index 000000000..e66c56cb6 --- /dev/null +++ b/src/generated/const/soroban_authorized_invocation.rs @@ -0,0 +1,74 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanAuthorizedInvocation is a borrowing equivalent of [`SorobanAuthorizedInvocation`](super::super::SorobanAuthorizedInvocation) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanAuthorizedInvocation { + pub function: SorobanAuthorizedFunction, + pub sub_invocations: VecM, +} + +impl SorobanAuthorizedInvocation { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_authorized_invocation(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_authorized_invocation(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanAuthorizedInvocation`], mirroring `::write_xdr`. + pub const fn write_type_soroban_authorized_invocation( + &mut self, + v: &SorobanAuthorizedInvocation, + ) { + self.write_type_soroban_authorized_function(&v.function); + self.write_type_vec_soroban_authorized_invocation(&v.sub_invocations); + } + + /// Serializes a variable-length array of [`SorobanAuthorizedInvocation`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_soroban_authorized_invocation( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_soroban_authorized_invocation(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/soroban_credentials.rs b/src/generated/const/soroban_credentials.rs new file mode 100644 index 000000000..ecdd1b29d --- /dev/null +++ b/src/generated/const/soroban_credentials.rs @@ -0,0 +1,85 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanCredentials is a borrowing equivalent of [`SorobanCredentials`](super::super::SorobanCredentials) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum SorobanCredentials { + SourceAccount, + Address(SorobanAddressCredentials), + AddressV2(SorobanAddressCredentials), + AddressWithDelegates(SorobanAddressCredentialsWithDelegates), +} + +impl SorobanCredentials { + #[must_use] + pub const fn discriminant(&self) -> SorobanCredentialsType { + #[allow(clippy::match_same_arms)] + match self { + Self::SourceAccount => SorobanCredentialsType::SourceAccount, + Self::Address(_) => SorobanCredentialsType::Address, + Self::AddressV2(_) => SorobanCredentialsType::AddressV2, + Self::AddressWithDelegates(_) => SorobanCredentialsType::AddressWithDelegates, + } + } +} + +impl SorobanCredentials { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_credentials(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_credentials(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanCredentials`], mirroring `::write_xdr`. + pub const fn write_type_soroban_credentials(&mut self, v: &SorobanCredentials) { + let d = v.discriminant(); + self.write_type_soroban_credentials_type(&d); + #[allow(clippy::match_same_arms)] + match v { + SorobanCredentials::SourceAccount => {} + SorobanCredentials::Address(value) => { + self.write_type_soroban_address_credentials(value); + } + SorobanCredentials::AddressV2(value) => { + self.write_type_soroban_address_credentials(value); + } + SorobanCredentials::AddressWithDelegates(value) => { + self.write_type_soroban_address_credentials_with_delegates(value); + } + } + } +} diff --git a/src/generated/const/soroban_credentials_type.rs b/src/generated/const/soroban_credentials_type.rs new file mode 100644 index 000000000..596f01037 --- /dev/null +++ b/src/generated/const/soroban_credentials_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SorobanCredentialsType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_credentials_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_credentials_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanCredentialsType`], mirroring `::write_xdr`. + pub const fn write_type_soroban_credentials_type(&mut self, v: &SorobanCredentialsType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/soroban_delegate_signature.rs b/src/generated/const/soroban_delegate_signature.rs new file mode 100644 index 000000000..01632dc30 --- /dev/null +++ b/src/generated/const/soroban_delegate_signature.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanDelegateSignature is a borrowing equivalent of [`SorobanDelegateSignature`](super::super::SorobanDelegateSignature) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanDelegateSignature { + pub address: ScAddress, + pub signature: ScVal, + pub nested_delegates: VecM, +} + +impl SorobanDelegateSignature { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_delegate_signature(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_delegate_signature(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanDelegateSignature`], mirroring `::write_xdr`. + pub const fn write_type_soroban_delegate_signature(&mut self, v: &SorobanDelegateSignature) { + self.write_type_sc_address(&v.address); + self.write_type_sc_val(&v.signature); + self.write_type_vec_soroban_delegate_signature(&v.nested_delegates); + } + + /// Serializes a variable-length array of [`SorobanDelegateSignature`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_soroban_delegate_signature( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_soroban_delegate_signature(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/soroban_resources.rs b/src/generated/const/soroban_resources.rs new file mode 100644 index 000000000..26ffb4459 --- /dev/null +++ b/src/generated/const/soroban_resources.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanResources is a borrowing equivalent of [`SorobanResources`](super::super::SorobanResources) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanResources { + pub footprint: LedgerFootprint, + pub instructions: u32, + pub disk_read_bytes: u32, + pub write_bytes: u32, +} + +impl SorobanResources { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_resources(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_resources(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanResources`], mirroring `::write_xdr`. + pub const fn write_type_soroban_resources(&mut self, v: &SorobanResources) { + self.write_type_ledger_footprint(&v.footprint); + self.write_u32(v.instructions); + self.write_u32(v.disk_read_bytes); + self.write_u32(v.write_bytes); + } +} diff --git a/src/generated/const/soroban_resources_ext_v0.rs b/src/generated/const/soroban_resources_ext_v0.rs new file mode 100644 index 000000000..d7d200292 --- /dev/null +++ b/src/generated/const/soroban_resources_ext_v0.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanResourcesExtV0 is a borrowing equivalent of [`SorobanResourcesExtV0`](super::super::SorobanResourcesExtV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanResourcesExtV0 { + pub archived_soroban_entries: VecM, +} + +impl SorobanResourcesExtV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_resources_ext_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_resources_ext_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanResourcesExtV0`], mirroring `::write_xdr`. + pub const fn write_type_soroban_resources_ext_v0(&mut self, v: &SorobanResourcesExtV0) { + self.write_vec_u32(&v.archived_soroban_entries); + } +} diff --git a/src/generated/const/soroban_transaction_data.rs b/src/generated/const/soroban_transaction_data.rs new file mode 100644 index 000000000..2f39cdc85 --- /dev/null +++ b/src/generated/const/soroban_transaction_data.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanTransactionData is a borrowing equivalent of [`SorobanTransactionData`](super::super::SorobanTransactionData) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanTransactionData { + pub ext: SorobanTransactionDataExt, + pub resources: SorobanResources, + pub resource_fee: i64, +} + +impl SorobanTransactionData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionData`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_data(&mut self, v: &SorobanTransactionData) { + self.write_type_soroban_transaction_data_ext(&v.ext); + self.write_type_soroban_resources(&v.resources); + self.write_i64(v.resource_fee); + } +} diff --git a/src/generated/const/soroban_transaction_data_ext.rs b/src/generated/const/soroban_transaction_data_ext.rs new file mode 100644 index 000000000..dff58e752 --- /dev/null +++ b/src/generated/const/soroban_transaction_data_ext.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanTransactionDataExt is a borrowing equivalent of [`SorobanTransactionDataExt`](super::super::SorobanTransactionDataExt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum SorobanTransactionDataExt { + V0, + V1(SorobanResourcesExtV0), +} + +impl SorobanTransactionDataExt { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl SorobanTransactionDataExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_data_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_data_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionDataExt`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_data_ext(&mut self, v: &SorobanTransactionDataExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + SorobanTransactionDataExt::V0 => {} + SorobanTransactionDataExt::V1(value) => { + self.write_type_soroban_resources_ext_v0(value); + } + } + } +} diff --git a/src/generated/const/soroban_transaction_meta.rs b/src/generated/const/soroban_transaction_meta.rs new file mode 100644 index 000000000..04aec7a79 --- /dev/null +++ b/src/generated/const/soroban_transaction_meta.rs @@ -0,0 +1,76 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanTransactionMeta is a borrowing equivalent of [`SorobanTransactionMeta`](super::super::SorobanTransactionMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanTransactionMeta { + pub ext: SorobanTransactionMetaExt, + pub events: VecM, + pub return_value: ScVal, + pub diagnostic_events: VecM, +} + +impl SorobanTransactionMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionMeta`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_meta(&mut self, v: &SorobanTransactionMeta) { + self.write_type_soroban_transaction_meta_ext(&v.ext); + self.write_type_vec_contract_event(&v.events); + self.write_type_sc_val(&v.return_value); + self.write_type_vec_diagnostic_event(&v.diagnostic_events); + } + + /// Serializes an optional [`SorobanTransactionMeta`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_soroban_transaction_meta( + &mut self, + v: &Option, + ) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_soroban_transaction_meta(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/soroban_transaction_meta_ext.rs b/src/generated/const/soroban_transaction_meta_ext.rs new file mode 100644 index 000000000..2786ba6a9 --- /dev/null +++ b/src/generated/const/soroban_transaction_meta_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SorobanTransactionMetaExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_meta_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_meta_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionMetaExt`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_meta_ext(&mut self, v: &SorobanTransactionMetaExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + SorobanTransactionMetaExt::V0 => {} + SorobanTransactionMetaExt::V1(value) => { + self.write_type_soroban_transaction_meta_ext_v1(value); + } + } + } +} diff --git a/src/generated/const/soroban_transaction_meta_ext_v1.rs b/src/generated/const/soroban_transaction_meta_ext_v1.rs new file mode 100644 index 000000000..ea0b2e230 --- /dev/null +++ b/src/generated/const/soroban_transaction_meta_ext_v1.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SorobanTransactionMetaExtV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_meta_ext_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_meta_ext_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionMetaExtV1`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_meta_ext_v1( + &mut self, + v: &SorobanTransactionMetaExtV1, + ) { + self.write_type_extension_point(&v.ext); + self.write_i64(v.total_non_refundable_resource_fee_charged); + self.write_i64(v.total_refundable_resource_fee_charged); + self.write_i64(v.rent_fee_charged); + } +} diff --git a/src/generated/const/soroban_transaction_meta_v2.rs b/src/generated/const/soroban_transaction_meta_v2.rs new file mode 100644 index 000000000..5e9fc5362 --- /dev/null +++ b/src/generated/const/soroban_transaction_meta_v2.rs @@ -0,0 +1,72 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SorobanTransactionMetaV2 is a borrowing equivalent of [`SorobanTransactionMetaV2`](super::super::SorobanTransactionMetaV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SorobanTransactionMetaV2 { + pub ext: SorobanTransactionMetaExt, + pub return_value: Option, +} + +impl SorobanTransactionMetaV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_soroban_transaction_meta_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_soroban_transaction_meta_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SorobanTransactionMetaV2`], mirroring `::write_xdr`. + pub const fn write_type_soroban_transaction_meta_v2(&mut self, v: &SorobanTransactionMetaV2) { + self.write_type_soroban_transaction_meta_ext(&v.ext); + self.write_type_option_sc_val(&v.return_value); + } + + /// Serializes an optional [`SorobanTransactionMetaV2`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_soroban_transaction_meta_v2( + &mut self, + v: &Option, + ) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_soroban_transaction_meta_v2(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/sponsorship_descriptor.rs b/src/generated/const/sponsorship_descriptor.rs new file mode 100644 index 000000000..983b04d0d --- /dev/null +++ b/src/generated/const/sponsorship_descriptor.rs @@ -0,0 +1,61 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SponsorshipDescriptor { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_sponsorship_descriptor(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_sponsorship_descriptor(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SponsorshipDescriptor`], mirroring `::write_xdr`. + pub const fn write_type_sponsorship_descriptor(&mut self, v: &SponsorshipDescriptor) { + self.write_type_option_account_id(&v.0); + } + + /// Serializes a variable-length array of [`SponsorshipDescriptor`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_sponsorship_descriptor( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_sponsorship_descriptor(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/state_archival_settings.rs b/src/generated/const/state_archival_settings.rs new file mode 100644 index 000000000..e95e2f451 --- /dev/null +++ b/src/generated/const/state_archival_settings.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl StateArchivalSettings { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_state_archival_settings(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_state_archival_settings(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StateArchivalSettings`], mirroring `::write_xdr`. + pub const fn write_type_state_archival_settings(&mut self, v: &StateArchivalSettings) { + self.write_u32(v.max_entry_ttl); + self.write_u32(v.min_temporary_ttl); + self.write_u32(v.min_persistent_ttl); + self.write_i64(v.persistent_rent_rate_denominator); + self.write_i64(v.temp_rent_rate_denominator); + self.write_u32(v.max_entries_to_archive); + self.write_u32(v.live_soroban_state_size_window_sample_size); + self.write_u32(v.live_soroban_state_size_window_sample_period); + self.write_u32(v.eviction_scan_size); + self.write_u32(v.starting_eviction_scan_level); + } +} diff --git a/src/generated/const/stellar_message.rs b/src/generated/const/stellar_message.rs new file mode 100644 index 000000000..e1a1bc44d --- /dev/null +++ b/src/generated/const/stellar_message.rs @@ -0,0 +1,174 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarMessage is a borrowing equivalent of [`StellarMessage`](super::super::StellarMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum StellarMessage { + ErrorMsg(SError), + Hello(Hello), + Auth(Auth), + DontHave(DontHave), + Peers(VecM), + GetTxSet(Uint256), + TxSet(TransactionSet), + GeneralizedTxSet(GeneralizedTransactionSet), + Transaction(TransactionEnvelope), + TimeSlicedSurveyRequest(SignedTimeSlicedSurveyRequestMessage), + TimeSlicedSurveyResponse(SignedTimeSlicedSurveyResponseMessage), + TimeSlicedSurveyStartCollecting(SignedTimeSlicedSurveyStartCollectingMessage), + TimeSlicedSurveyStopCollecting(SignedTimeSlicedSurveyStopCollectingMessage), + GetScpQuorumset(Uint256), + ScpQuorumset(ScpQuorumSet), + ScpMessage(ScpEnvelope), + GetScpState(u32), + SendMore(SendMore), + SendMoreExtended(SendMoreExtended), + FloodAdvert(FloodAdvert), + FloodDemand(FloodDemand), +} + +impl StellarMessage { + #[must_use] + pub const fn discriminant(&self) -> MessageType { + #[allow(clippy::match_same_arms)] + match self { + Self::ErrorMsg(_) => MessageType::ErrorMsg, + Self::Hello(_) => MessageType::Hello, + Self::Auth(_) => MessageType::Auth, + Self::DontHave(_) => MessageType::DontHave, + Self::Peers(_) => MessageType::Peers, + Self::GetTxSet(_) => MessageType::GetTxSet, + Self::TxSet(_) => MessageType::TxSet, + Self::GeneralizedTxSet(_) => MessageType::GeneralizedTxSet, + Self::Transaction(_) => MessageType::Transaction, + Self::TimeSlicedSurveyRequest(_) => MessageType::TimeSlicedSurveyRequest, + Self::TimeSlicedSurveyResponse(_) => MessageType::TimeSlicedSurveyResponse, + Self::TimeSlicedSurveyStartCollecting(_) => { + MessageType::TimeSlicedSurveyStartCollecting + } + Self::TimeSlicedSurveyStopCollecting(_) => MessageType::TimeSlicedSurveyStopCollecting, + Self::GetScpQuorumset(_) => MessageType::GetScpQuorumset, + Self::ScpQuorumset(_) => MessageType::ScpQuorumset, + Self::ScpMessage(_) => MessageType::ScpMessage, + Self::GetScpState(_) => MessageType::GetScpState, + Self::SendMore(_) => MessageType::SendMore, + Self::SendMoreExtended(_) => MessageType::SendMoreExtended, + Self::FloodAdvert(_) => MessageType::FloodAdvert, + Self::FloodDemand(_) => MessageType::FloodDemand, + } + } +} + +impl StellarMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StellarMessage`], mirroring `::write_xdr`. + pub const fn write_type_stellar_message(&mut self, v: &StellarMessage) { + let d = v.discriminant(); + self.write_type_message_type(&d); + #[allow(clippy::match_same_arms)] + match v { + StellarMessage::ErrorMsg(value) => { + self.write_type_s_error(value); + } + StellarMessage::Hello(value) => { + self.write_type_hello(value); + } + StellarMessage::Auth(value) => { + self.write_type_auth(value); + } + StellarMessage::DontHave(value) => { + self.write_type_dont_have(value); + } + StellarMessage::Peers(value) => { + self.write_type_vec_peer_address(value); + } + StellarMessage::GetTxSet(value) => { + self.write_type_uint256(value); + } + StellarMessage::TxSet(value) => { + self.write_type_transaction_set(value); + } + StellarMessage::GeneralizedTxSet(value) => { + self.write_type_generalized_transaction_set(value); + } + StellarMessage::Transaction(value) => { + self.write_type_transaction_envelope(value); + } + StellarMessage::TimeSlicedSurveyRequest(value) => { + self.write_type_signed_time_sliced_survey_request_message(value); + } + StellarMessage::TimeSlicedSurveyResponse(value) => { + self.write_type_signed_time_sliced_survey_response_message(value); + } + StellarMessage::TimeSlicedSurveyStartCollecting(value) => { + self.write_type_signed_time_sliced_survey_start_collecting_message(value); + } + StellarMessage::TimeSlicedSurveyStopCollecting(value) => { + self.write_type_signed_time_sliced_survey_stop_collecting_message(value); + } + StellarMessage::GetScpQuorumset(value) => { + self.write_type_uint256(value); + } + StellarMessage::ScpQuorumset(value) => { + self.write_type_scp_quorum_set(value); + } + StellarMessage::ScpMessage(value) => { + self.write_type_scp_envelope(value); + } + StellarMessage::GetScpState(value) => { + self.write_u32(*value); + } + StellarMessage::SendMore(value) => { + self.write_type_send_more(value); + } + StellarMessage::SendMoreExtended(value) => { + self.write_type_send_more_extended(value); + } + StellarMessage::FloodAdvert(value) => { + self.write_type_flood_advert(value); + } + StellarMessage::FloodDemand(value) => { + self.write_type_flood_demand(value); + } + } + } +} diff --git a/src/generated/const/stellar_value.rs b/src/generated/const/stellar_value.rs new file mode 100644 index 000000000..838d8d91f --- /dev/null +++ b/src/generated/const/stellar_value.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarValue is a borrowing equivalent of [`StellarValue`](super::super::StellarValue) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct StellarValue { + pub tx_set_hash: Hash, + pub close_time: TimePoint, + pub upgrades: VecM, + pub ext: StellarValueExt, +} + +impl StellarValue { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StellarValue`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value(&mut self, v: &StellarValue) { + self.write_type_hash(&v.tx_set_hash); + self.write_type_time_point(&v.close_time); + self.write_type_vec_upgrade_type(&v.upgrades); + self.write_type_stellar_value_ext(&v.ext); + } +} diff --git a/src/generated/const/stellar_value_ext.rs b/src/generated/const/stellar_value_ext.rs new file mode 100644 index 000000000..011e40942 --- /dev/null +++ b/src/generated/const/stellar_value_ext.rs @@ -0,0 +1,96 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarValueExt is a borrowing equivalent of [`StellarValueExt`](super::super::StellarValueExt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum StellarValueExt { + Basic, + Signed(LedgerCloseValueSignature), + EmptyTxSet(StellarValueProposedValue), + #[cfg(feature = "ms_close_time")] + SignedMs(StellarValueSignedMsValue), + #[cfg(feature = "ms_close_time")] + EmptyTxSetMs(StellarValueProposedMsValue), +} + +impl StellarValueExt { + #[must_use] + pub const fn discriminant(&self) -> StellarValueType { + #[allow(clippy::match_same_arms)] + match self { + Self::Basic => StellarValueType::Basic, + Self::Signed(_) => StellarValueType::Signed, + Self::EmptyTxSet(_) => StellarValueType::EmptyTxSet, + #[cfg(feature = "ms_close_time")] + Self::SignedMs(_) => StellarValueType::SignedMs, + #[cfg(feature = "ms_close_time")] + Self::EmptyTxSetMs(_) => StellarValueType::EmptyTxSetMs, + } + } +} + +impl StellarValueExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StellarValueExt`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value_ext(&mut self, v: &StellarValueExt) { + let d = v.discriminant(); + self.write_type_stellar_value_type(&d); + #[allow(clippy::match_same_arms)] + match v { + StellarValueExt::Basic => {} + StellarValueExt::Signed(value) => { + self.write_type_ledger_close_value_signature(value); + } + StellarValueExt::EmptyTxSet(value) => { + self.write_type_stellar_value_proposed_value(value); + } + #[cfg(feature = "ms_close_time")] + StellarValueExt::SignedMs(value) => { + self.write_type_stellar_value_signed_ms_value(value); + } + #[cfg(feature = "ms_close_time")] + StellarValueExt::EmptyTxSetMs(value) => { + self.write_type_stellar_value_proposed_ms_value(value); + } + } + } +} diff --git a/src/generated/const/stellar_value_proposed_ms_value.rs b/src/generated/const/stellar_value_proposed_ms_value.rs new file mode 100644 index 000000000..8bd1eda00 --- /dev/null +++ b/src/generated/const/stellar_value_proposed_ms_value.rs @@ -0,0 +1,68 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarValueProposedMsValue is a borrowing equivalent of [`StellarValueProposedMsValue`](super::super::StellarValueProposedMsValue) +/// over `'static` data, for const XDR encoding. +#[cfg(feature = "ms_close_time")] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct StellarValueProposedMsValue { + pub close_time_ms: TimePointMilliseconds, + pub tx_set_hash: Hash, + pub previous_ledger_hash: Hash, + pub previous_ledger_version: u32, + pub lc_value_signature: LedgerCloseValueSignature, +} + +#[cfg(feature = "ms_close_time")] +impl StellarValueProposedMsValue { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value_proposed_ms_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value_proposed_ms_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + #[cfg(feature = "ms_close_time")] + /// Serializes a [`StellarValueProposedMsValue`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value_proposed_ms_value( + &mut self, + v: &StellarValueProposedMsValue, + ) { + self.write_type_time_point_milliseconds(&v.close_time_ms); + self.write_type_hash(&v.tx_set_hash); + self.write_type_hash(&v.previous_ledger_hash); + self.write_u32(v.previous_ledger_version); + self.write_type_ledger_close_value_signature(&v.lc_value_signature); + } +} diff --git a/src/generated/const/stellar_value_proposed_value.rs b/src/generated/const/stellar_value_proposed_value.rs new file mode 100644 index 000000000..de530ff0a --- /dev/null +++ b/src/generated/const/stellar_value_proposed_value.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarValueProposedValue is a borrowing equivalent of [`StellarValueProposedValue`](super::super::StellarValueProposedValue) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct StellarValueProposedValue { + pub tx_set_hash: Hash, + pub previous_ledger_hash: Hash, + pub previous_ledger_version: u32, + pub lc_value_signature: LedgerCloseValueSignature, +} + +impl StellarValueProposedValue { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value_proposed_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value_proposed_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StellarValueProposedValue`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value_proposed_value(&mut self, v: &StellarValueProposedValue) { + self.write_type_hash(&v.tx_set_hash); + self.write_type_hash(&v.previous_ledger_hash); + self.write_u32(v.previous_ledger_version); + self.write_type_ledger_close_value_signature(&v.lc_value_signature); + } +} diff --git a/src/generated/const/stellar_value_signed_ms_value.rs b/src/generated/const/stellar_value_signed_ms_value.rs new file mode 100644 index 000000000..8f7205a4c --- /dev/null +++ b/src/generated/const/stellar_value_signed_ms_value.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StellarValueSignedMsValue is a borrowing equivalent of [`StellarValueSignedMsValue`](super::super::StellarValueSignedMsValue) +/// over `'static` data, for const XDR encoding. +#[cfg(feature = "ms_close_time")] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct StellarValueSignedMsValue { + pub close_time_ms: TimePointMilliseconds, + pub lc_value_signature: LedgerCloseValueSignature, +} + +#[cfg(feature = "ms_close_time")] +impl StellarValueSignedMsValue { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value_signed_ms_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value_signed_ms_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + #[cfg(feature = "ms_close_time")] + /// Serializes a [`StellarValueSignedMsValue`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value_signed_ms_value( + &mut self, + v: &StellarValueSignedMsValue, + ) { + self.write_type_time_point_milliseconds(&v.close_time_ms); + self.write_type_ledger_close_value_signature(&v.lc_value_signature); + } +} diff --git a/src/generated/const/stellar_value_type.rs b/src/generated/const/stellar_value_type.rs new file mode 100644 index 000000000..6334051bc --- /dev/null +++ b/src/generated/const/stellar_value_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl StellarValueType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stellar_value_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stellar_value_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StellarValueType`], mirroring `::write_xdr`. + pub const fn write_type_stellar_value_type(&mut self, v: &StellarValueType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/stored_debug_transaction_set.rs b/src/generated/const/stored_debug_transaction_set.rs new file mode 100644 index 000000000..b4558bdc5 --- /dev/null +++ b/src/generated/const/stored_debug_transaction_set.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StoredDebugTransactionSet is a borrowing equivalent of [`StoredDebugTransactionSet`](super::super::StoredDebugTransactionSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct StoredDebugTransactionSet { + pub tx_set: StoredTransactionSet, + pub ledger_seq: u32, + pub scp_value: StellarValue, +} + +impl StoredDebugTransactionSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stored_debug_transaction_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stored_debug_transaction_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StoredDebugTransactionSet`], mirroring `::write_xdr`. + pub const fn write_type_stored_debug_transaction_set(&mut self, v: &StoredDebugTransactionSet) { + self.write_type_stored_transaction_set(&v.tx_set); + self.write_u32(v.ledger_seq); + self.write_type_stellar_value(&v.scp_value); + } +} diff --git a/src/generated/const/stored_transaction_set.rs b/src/generated/const/stored_transaction_set.rs new file mode 100644 index 000000000..c059622d2 --- /dev/null +++ b/src/generated/const/stored_transaction_set.rs @@ -0,0 +1,92 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// StoredTransactionSet is a borrowing equivalent of [`StoredTransactionSet`](super::super::StoredTransactionSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum StoredTransactionSet { + V0(TransactionSet), + V1(GeneralizedTransactionSet), +} + +impl StoredTransactionSet { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl StoredTransactionSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_stored_transaction_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_stored_transaction_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`StoredTransactionSet`], mirroring `::write_xdr`. + pub const fn write_type_stored_transaction_set(&mut self, v: &StoredTransactionSet) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + StoredTransactionSet::V0(value) => { + self.write_type_transaction_set(value); + } + StoredTransactionSet::V1(value) => { + self.write_type_generalized_transaction_set(value); + } + } + } + + /// Serializes a variable-length array of [`StoredTransactionSet`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_stored_transaction_set( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_stored_transaction_set(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/string32.rs b/src/generated/const/string32.rs new file mode 100644 index 000000000..c930e9b45 --- /dev/null +++ b/src/generated/const/string32.rs @@ -0,0 +1,65 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// String32 is a borrowing equivalent of [`String32`](super::super::String32) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct String32(pub StringM<32>); + +impl String32 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_string32(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_string32(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`String32`], mirroring `::write_xdr`. + pub const fn write_type_string32(&mut self, v: &String32) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes an optional [`String32`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_string32(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_string32(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/string64.rs b/src/generated/const/string64.rs new file mode 100644 index 000000000..54d7f6213 --- /dev/null +++ b/src/generated/const/string64.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// String64 is a borrowing equivalent of [`String64`](super::super::String64) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct String64(pub StringM<64>); + +impl String64 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_string64(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_string64(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`String64`], mirroring `::write_xdr`. + pub const fn write_type_string64(&mut self, v: &String64) { + self.write_var_opaque(v.0.as_slice()); + } +} diff --git a/src/generated/const/survey_message_command_type.rs b/src/generated/const/survey_message_command_type.rs new file mode 100644 index 000000000..1abd6d5a2 --- /dev/null +++ b/src/generated/const/survey_message_command_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SurveyMessageCommandType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_survey_message_command_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_survey_message_command_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SurveyMessageCommandType`], mirroring `::write_xdr`. + pub const fn write_type_survey_message_command_type(&mut self, v: &SurveyMessageCommandType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/survey_message_response_type.rs b/src/generated/const/survey_message_response_type.rs new file mode 100644 index 000000000..1d013cfa6 --- /dev/null +++ b/src/generated/const/survey_message_response_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SurveyMessageResponseType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_survey_message_response_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_survey_message_response_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SurveyMessageResponseType`], mirroring `::write_xdr`. + pub const fn write_type_survey_message_response_type(&mut self, v: &SurveyMessageResponseType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/survey_request_message.rs b/src/generated/const/survey_request_message.rs new file mode 100644 index 000000000..60e8f47fe --- /dev/null +++ b/src/generated/const/survey_request_message.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl SurveyRequestMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_survey_request_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_survey_request_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SurveyRequestMessage`], mirroring `::write_xdr`. + pub const fn write_type_survey_request_message(&mut self, v: &SurveyRequestMessage) { + self.write_type_node_id(&v.surveyor_peer_id); + self.write_type_node_id(&v.surveyed_peer_id); + self.write_u32(v.ledger_num); + self.write_type_curve25519_public(&v.encryption_key); + self.write_type_survey_message_command_type(&v.command_type); + } +} diff --git a/src/generated/const/survey_response_body.rs b/src/generated/const/survey_response_body.rs new file mode 100644 index 000000000..59a8f9ea8 --- /dev/null +++ b/src/generated/const/survey_response_body.rs @@ -0,0 +1,74 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SurveyResponseBody is a borrowing equivalent of [`SurveyResponseBody`](super::super::SurveyResponseBody) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum SurveyResponseBody { + SurveyTopologyResponseV2(TopologyResponseBodyV2), +} + +impl SurveyResponseBody { + #[must_use] + pub const fn discriminant(&self) -> SurveyMessageResponseType { + #[allow(clippy::match_same_arms)] + match self { + Self::SurveyTopologyResponseV2(_) => { + SurveyMessageResponseType::SurveyTopologyResponseV2 + } + } + } +} + +impl SurveyResponseBody { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_survey_response_body(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_survey_response_body(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SurveyResponseBody`], mirroring `::write_xdr`. + pub const fn write_type_survey_response_body(&mut self, v: &SurveyResponseBody) { + let d = v.discriminant(); + self.write_type_survey_message_response_type(&d); + #[allow(clippy::match_same_arms)] + match v { + SurveyResponseBody::SurveyTopologyResponseV2(value) => { + self.write_type_topology_response_body_v2(value); + } + } + } +} diff --git a/src/generated/const/survey_response_message.rs b/src/generated/const/survey_response_message.rs new file mode 100644 index 000000000..e2440a49e --- /dev/null +++ b/src/generated/const/survey_response_message.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// SurveyResponseMessage is a borrowing equivalent of [`SurveyResponseMessage`](super::super::SurveyResponseMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct SurveyResponseMessage { + pub surveyor_peer_id: NodeId, + pub surveyed_peer_id: NodeId, + pub ledger_num: u32, + pub command_type: SurveyMessageCommandType, + pub encrypted_body: EncryptedBody, +} + +impl SurveyResponseMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_survey_response_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_survey_response_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`SurveyResponseMessage`], mirroring `::write_xdr`. + pub const fn write_type_survey_response_message(&mut self, v: &SurveyResponseMessage) { + self.write_type_node_id(&v.surveyor_peer_id); + self.write_type_node_id(&v.surveyed_peer_id); + self.write_u32(v.ledger_num); + self.write_type_survey_message_command_type(&v.command_type); + self.write_type_encrypted_body(&v.encrypted_body); + } +} diff --git a/src/generated/const/test_next_type.rs b/src/generated/const/test_next_type.rs new file mode 100644 index 000000000..b6ecfbce6 --- /dev/null +++ b/src/generated/const/test_next_type.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +#[cfg(feature = "test_feature")] +impl TestNextType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_test_next_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_test_next_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + #[cfg(feature = "test_feature")] + /// Serializes a [`TestNextType`], mirroring `::write_xdr`. + pub const fn write_type_test_next_type(&mut self, v: &TestNextType) { + self.write_i32(v.value); + } +} diff --git a/src/generated/const/threshold_indexes.rs b/src/generated/const/threshold_indexes.rs new file mode 100644 index 000000000..21a4c82bc --- /dev/null +++ b/src/generated/const/threshold_indexes.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl ThresholdIndexes { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_threshold_indexes(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_threshold_indexes(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`ThresholdIndexes`], mirroring `::write_xdr`. + pub const fn write_type_threshold_indexes(&mut self, v: &ThresholdIndexes) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/thresholds.rs b/src/generated/const/thresholds.rs new file mode 100644 index 000000000..d4d96063a --- /dev/null +++ b/src/generated/const/thresholds.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Thresholds { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_thresholds(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_thresholds(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Thresholds`], mirroring `::write_xdr`. + pub const fn write_type_thresholds(&mut self, v: &Thresholds) { + self.write_fixed_opaque(&v.0); + } +} diff --git a/src/generated/const/time_bounds.rs b/src/generated/const/time_bounds.rs new file mode 100644 index 000000000..f1312a982 --- /dev/null +++ b/src/generated/const/time_bounds.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimeBounds { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_bounds(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_bounds(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeBounds`], mirroring `::write_xdr`. + pub const fn write_type_time_bounds(&mut self, v: &TimeBounds) { + self.write_type_time_point(&v.min_time); + self.write_type_time_point(&v.max_time); + } + + /// Serializes an optional [`TimeBounds`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_option_time_bounds(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_type_time_bounds(v); + } + None => { + self.write_u32(0); + } + } + } +} diff --git a/src/generated/const/time_point.rs b/src/generated/const/time_point.rs new file mode 100644 index 000000000..53eea4e99 --- /dev/null +++ b/src/generated/const/time_point.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimePoint { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_point(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_point(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimePoint`], mirroring `::write_xdr`. + pub const fn write_type_time_point(&mut self, v: &TimePoint) { + self.write_u64(v.0); + } +} diff --git a/src/generated/const/time_point_milliseconds.rs b/src/generated/const/time_point_milliseconds.rs new file mode 100644 index 000000000..ab6e01982 --- /dev/null +++ b/src/generated/const/time_point_milliseconds.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +#[cfg(feature = "ms_close_time")] +impl TimePointMilliseconds { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_point_milliseconds(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_point_milliseconds(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + #[cfg(feature = "ms_close_time")] + /// Serializes a [`TimePointMilliseconds`], mirroring `::write_xdr`. + pub const fn write_type_time_point_milliseconds(&mut self, v: &TimePointMilliseconds) { + self.write_u64(v.0); + } +} diff --git a/src/generated/const/time_sliced_node_data.rs b/src/generated/const/time_sliced_node_data.rs new file mode 100644 index 000000000..1ceddd14b --- /dev/null +++ b/src/generated/const/time_sliced_node_data.rs @@ -0,0 +1,55 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimeSlicedNodeData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_node_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_node_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedNodeData`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_node_data(&mut self, v: &TimeSlicedNodeData) { + self.write_u32(v.added_authenticated_peers); + self.write_u32(v.dropped_authenticated_peers); + self.write_u32(v.total_inbound_peer_count); + self.write_u32(v.total_outbound_peer_count); + self.write_u32(v.p75_scp_first_to_self_latency_ms); + self.write_u32(v.p75_scp_self_to_other_latency_ms); + self.write_u32(v.lost_sync_count); + self.write_bool(v.is_validator); + self.write_u32(v.max_inbound_peer_count); + self.write_u32(v.max_outbound_peer_count); + } +} diff --git a/src/generated/const/time_sliced_peer_data.rs b/src/generated/const/time_sliced_peer_data.rs new file mode 100644 index 000000000..6acd54f10 --- /dev/null +++ b/src/generated/const/time_sliced_peer_data.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TimeSlicedPeerData is a borrowing equivalent of [`TimeSlicedPeerData`](super::super::TimeSlicedPeerData) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TimeSlicedPeerData { + pub peer_stats: PeerStats, + pub average_latency_ms: u32, +} + +impl TimeSlicedPeerData { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_peer_data(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_peer_data(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedPeerData`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_peer_data(&mut self, v: &TimeSlicedPeerData) { + self.write_type_peer_stats(&v.peer_stats); + self.write_u32(v.average_latency_ms); + } + + /// Serializes a variable-length array of [`TimeSlicedPeerData`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_time_sliced_peer_data( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_time_sliced_peer_data(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/time_sliced_peer_data_list.rs b/src/generated/const/time_sliced_peer_data_list.rs new file mode 100644 index 000000000..63c4cad64 --- /dev/null +++ b/src/generated/const/time_sliced_peer_data_list.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TimeSlicedPeerDataList is a borrowing equivalent of [`TimeSlicedPeerDataList`](super::super::TimeSlicedPeerDataList) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TimeSlicedPeerDataList(pub VecM); + +impl TimeSlicedPeerDataList { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_peer_data_list(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_peer_data_list(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedPeerDataList`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_peer_data_list(&mut self, v: &TimeSlicedPeerDataList) { + self.write_type_vec_time_sliced_peer_data(&v.0); + } +} diff --git a/src/generated/const/time_sliced_survey_request_message.rs b/src/generated/const/time_sliced_survey_request_message.rs new file mode 100644 index 000000000..8cdf079f1 --- /dev/null +++ b/src/generated/const/time_sliced_survey_request_message.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimeSlicedSurveyRequestMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_survey_request_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_survey_request_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedSurveyRequestMessage`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_survey_request_message( + &mut self, + v: &TimeSlicedSurveyRequestMessage, + ) { + self.write_type_survey_request_message(&v.request); + self.write_u32(v.nonce); + self.write_u32(v.inbound_peers_index); + self.write_u32(v.outbound_peers_index); + } +} diff --git a/src/generated/const/time_sliced_survey_response_message.rs b/src/generated/const/time_sliced_survey_response_message.rs new file mode 100644 index 000000000..62dbe12de --- /dev/null +++ b/src/generated/const/time_sliced_survey_response_message.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TimeSlicedSurveyResponseMessage is a borrowing equivalent of [`TimeSlicedSurveyResponseMessage`](super::super::TimeSlicedSurveyResponseMessage) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TimeSlicedSurveyResponseMessage { + pub response: SurveyResponseMessage, + pub nonce: u32, +} + +impl TimeSlicedSurveyResponseMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_survey_response_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_survey_response_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedSurveyResponseMessage`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_survey_response_message( + &mut self, + v: &TimeSlicedSurveyResponseMessage, + ) { + self.write_type_survey_response_message(&v.response); + self.write_u32(v.nonce); + } +} diff --git a/src/generated/const/time_sliced_survey_start_collecting_message.rs b/src/generated/const/time_sliced_survey_start_collecting_message.rs new file mode 100644 index 000000000..a88e9c868 --- /dev/null +++ b/src/generated/const/time_sliced_survey_start_collecting_message.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimeSlicedSurveyStartCollectingMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_survey_start_collecting_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_survey_start_collecting_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedSurveyStartCollectingMessage`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_survey_start_collecting_message( + &mut self, + v: &TimeSlicedSurveyStartCollectingMessage, + ) { + self.write_type_node_id(&v.surveyor_id); + self.write_u32(v.nonce); + self.write_u32(v.ledger_num); + } +} diff --git a/src/generated/const/time_sliced_survey_stop_collecting_message.rs b/src/generated/const/time_sliced_survey_stop_collecting_message.rs new file mode 100644 index 000000000..2303faf7e --- /dev/null +++ b/src/generated/const/time_sliced_survey_stop_collecting_message.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TimeSlicedSurveyStopCollectingMessage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_time_sliced_survey_stop_collecting_message(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_time_sliced_survey_stop_collecting_message(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TimeSlicedSurveyStopCollectingMessage`], mirroring `::write_xdr`. + pub const fn write_type_time_sliced_survey_stop_collecting_message( + &mut self, + v: &TimeSlicedSurveyStopCollectingMessage, + ) { + self.write_type_node_id(&v.surveyor_id); + self.write_u32(v.nonce); + self.write_u32(v.ledger_num); + } +} diff --git a/src/generated/const/topology_response_body_v2.rs b/src/generated/const/topology_response_body_v2.rs new file mode 100644 index 000000000..ca1943d02 --- /dev/null +++ b/src/generated/const/topology_response_body_v2.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TopologyResponseBodyV2 is a borrowing equivalent of [`TopologyResponseBodyV2`](super::super::TopologyResponseBodyV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TopologyResponseBodyV2 { + pub inbound_peers: TimeSlicedPeerDataList, + pub outbound_peers: TimeSlicedPeerDataList, + pub node_data: TimeSlicedNodeData, +} + +impl TopologyResponseBodyV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_topology_response_body_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_topology_response_body_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TopologyResponseBodyV2`], mirroring `::write_xdr`. + pub const fn write_type_topology_response_body_v2(&mut self, v: &TopologyResponseBodyV2) { + self.write_type_time_sliced_peer_data_list(&v.inbound_peers); + self.write_type_time_sliced_peer_data_list(&v.outbound_peers); + self.write_type_time_sliced_node_data(&v.node_data); + } +} diff --git a/src/generated/const/transaction.rs b/src/generated/const/transaction.rs new file mode 100644 index 000000000..3c1260462 --- /dev/null +++ b/src/generated/const/transaction.rs @@ -0,0 +1,66 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Transaction is a borrowing equivalent of [`Transaction`](super::super::Transaction) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Transaction { + pub source_account: MuxedAccount, + pub fee: u32, + pub seq_num: SequenceNumber, + pub cond: Preconditions, + pub memo: Memo, + pub operations: VecM, + pub ext: TransactionExt, +} + +impl Transaction { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Transaction`], mirroring `::write_xdr`. + pub const fn write_type_transaction(&mut self, v: &Transaction) { + self.write_type_muxed_account(&v.source_account); + self.write_u32(v.fee); + self.write_type_sequence_number(&v.seq_num); + self.write_type_preconditions(&v.cond); + self.write_type_memo(&v.memo); + self.write_type_vec_operation(&v.operations); + self.write_type_transaction_ext(&v.ext); + } +} diff --git a/src/generated/const/transaction_envelope.rs b/src/generated/const/transaction_envelope.rs new file mode 100644 index 000000000..9911e866c --- /dev/null +++ b/src/generated/const/transaction_envelope.rs @@ -0,0 +1,97 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionEnvelope is a borrowing equivalent of [`TransactionEnvelope`](super::super::TransactionEnvelope) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionEnvelope { + TxV0(TransactionV0Envelope), + Tx(TransactionV1Envelope), + TxFeeBump(FeeBumpTransactionEnvelope), +} + +impl TransactionEnvelope { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::TxV0(_) => EnvelopeType::TxV0, + Self::Tx(_) => EnvelopeType::Tx, + Self::TxFeeBump(_) => EnvelopeType::TxFeeBump, + } + } +} + +impl TransactionEnvelope { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_envelope(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_envelope(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionEnvelope`], mirroring `::write_xdr`. + pub const fn write_type_transaction_envelope(&mut self, v: &TransactionEnvelope) { + let d = v.discriminant(); + self.write_type_envelope_type(&d); + #[allow(clippy::match_same_arms)] + match v { + TransactionEnvelope::TxV0(value) => { + self.write_type_transaction_v0_envelope(value); + } + TransactionEnvelope::Tx(value) => { + self.write_type_transaction_v1_envelope(value); + } + TransactionEnvelope::TxFeeBump(value) => { + self.write_type_fee_bump_transaction_envelope(value); + } + } + } + + /// Serializes a variable-length array of [`TransactionEnvelope`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_envelope( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_envelope(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_event.rs b/src/generated/const/transaction_event.rs new file mode 100644 index 000000000..1c3ad8f40 --- /dev/null +++ b/src/generated/const/transaction_event.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionEvent is a borrowing equivalent of [`TransactionEvent`](super::super::TransactionEvent) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionEvent { + pub stage: TransactionEventStage, + pub event: ContractEvent, +} + +impl TransactionEvent { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_event(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_event(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionEvent`], mirroring `::write_xdr`. + pub const fn write_type_transaction_event(&mut self, v: &TransactionEvent) { + self.write_type_transaction_event_stage(&v.stage); + self.write_type_contract_event(&v.event); + } + + /// Serializes a variable-length array of [`TransactionEvent`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_event( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_event(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_event_stage.rs b/src/generated/const/transaction_event_stage.rs new file mode 100644 index 000000000..524078c22 --- /dev/null +++ b/src/generated/const/transaction_event_stage.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TransactionEventStage { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_event_stage(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_event_stage(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionEventStage`], mirroring `::write_xdr`. + pub const fn write_type_transaction_event_stage(&mut self, v: &TransactionEventStage) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/transaction_ext.rs b/src/generated/const/transaction_ext.rs new file mode 100644 index 000000000..3869d652d --- /dev/null +++ b/src/generated/const/transaction_ext.rs @@ -0,0 +1,75 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionExt is a borrowing equivalent of [`TransactionExt`](super::super::TransactionExt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionExt { + V0, + V1(SorobanTransactionData), +} + +impl TransactionExt { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl TransactionExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionExt`], mirroring `::write_xdr`. + pub const fn write_type_transaction_ext(&mut self, v: &TransactionExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionExt::V0 => {} + TransactionExt::V1(value) => { + self.write_type_soroban_transaction_data(value); + } + } + } +} diff --git a/src/generated/const/transaction_history_entry.rs b/src/generated/const/transaction_history_entry.rs new file mode 100644 index 000000000..008b7139c --- /dev/null +++ b/src/generated/const/transaction_history_entry.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionHistoryEntry is a borrowing equivalent of [`TransactionHistoryEntry`](super::super::TransactionHistoryEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionHistoryEntry { + pub ledger_seq: u32, + pub tx_set: TransactionSet, + pub ext: TransactionHistoryEntryExt, +} + +impl TransactionHistoryEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_history_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_history_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionHistoryEntry`], mirroring `::write_xdr`. + pub const fn write_type_transaction_history_entry(&mut self, v: &TransactionHistoryEntry) { + self.write_u32(v.ledger_seq); + self.write_type_transaction_set(&v.tx_set); + self.write_type_transaction_history_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/transaction_history_entry_ext.rs b/src/generated/const/transaction_history_entry_ext.rs new file mode 100644 index 000000000..c83382406 --- /dev/null +++ b/src/generated/const/transaction_history_entry_ext.rs @@ -0,0 +1,78 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionHistoryEntryExt is a borrowing equivalent of [`TransactionHistoryEntryExt`](super::super::TransactionHistoryEntryExt) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionHistoryEntryExt { + V0, + V1(GeneralizedTransactionSet), +} + +impl TransactionHistoryEntryExt { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl TransactionHistoryEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_history_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_history_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionHistoryEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_transaction_history_entry_ext( + &mut self, + v: &TransactionHistoryEntryExt, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionHistoryEntryExt::V0 => {} + TransactionHistoryEntryExt::V1(value) => { + self.write_type_generalized_transaction_set(value); + } + } + } +} diff --git a/src/generated/const/transaction_history_result_entry.rs b/src/generated/const/transaction_history_result_entry.rs new file mode 100644 index 000000000..c6140a937 --- /dev/null +++ b/src/generated/const/transaction_history_result_entry.rs @@ -0,0 +1,61 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionHistoryResultEntry is a borrowing equivalent of [`TransactionHistoryResultEntry`](super::super::TransactionHistoryResultEntry) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionHistoryResultEntry { + pub ledger_seq: u32, + pub tx_result_set: TransactionResultSet, + pub ext: TransactionHistoryResultEntryExt, +} + +impl TransactionHistoryResultEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_history_result_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_history_result_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionHistoryResultEntry`], mirroring `::write_xdr`. + pub const fn write_type_transaction_history_result_entry( + &mut self, + v: &TransactionHistoryResultEntry, + ) { + self.write_u32(v.ledger_seq); + self.write_type_transaction_result_set(&v.tx_result_set); + self.write_type_transaction_history_result_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/transaction_history_result_entry_ext.rs b/src/generated/const/transaction_history_result_entry_ext.rs new file mode 100644 index 000000000..186bb5cd1 --- /dev/null +++ b/src/generated/const/transaction_history_result_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TransactionHistoryResultEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_history_result_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_history_result_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionHistoryResultEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_transaction_history_result_entry_ext( + &mut self, + v: &TransactionHistoryResultEntryExt, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionHistoryResultEntryExt::V0 => {} + } + } +} diff --git a/src/generated/const/transaction_meta.rs b/src/generated/const/transaction_meta.rs new file mode 100644 index 000000000..a67ff3bc8 --- /dev/null +++ b/src/generated/const/transaction_meta.rs @@ -0,0 +1,92 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionMeta is a borrowing equivalent of [`TransactionMeta`](super::super::TransactionMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionMeta { + V0(VecM), + V1(TransactionMetaV1), + V2(TransactionMetaV2), + V3(TransactionMetaV3), + V4(TransactionMetaV4), +} + +impl TransactionMeta { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + Self::V2(_) => 2, + Self::V3(_) => 3, + Self::V4(_) => 4, + } + } +} + +impl TransactionMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionMeta`], mirroring `::write_xdr`. + pub const fn write_type_transaction_meta(&mut self, v: &TransactionMeta) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionMeta::V0(value) => { + self.write_type_vec_operation_meta(value); + } + TransactionMeta::V1(value) => { + self.write_type_transaction_meta_v1(value); + } + TransactionMeta::V2(value) => { + self.write_type_transaction_meta_v2(value); + } + TransactionMeta::V3(value) => { + self.write_type_transaction_meta_v3(value); + } + TransactionMeta::V4(value) => { + self.write_type_transaction_meta_v4(value); + } + } + } +} diff --git a/src/generated/const/transaction_meta_v1.rs b/src/generated/const/transaction_meta_v1.rs new file mode 100644 index 000000000..ef67b62bc --- /dev/null +++ b/src/generated/const/transaction_meta_v1.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionMetaV1 is a borrowing equivalent of [`TransactionMetaV1`](super::super::TransactionMetaV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionMetaV1 { + pub tx_changes: LedgerEntryChanges, + pub operations: VecM, +} + +impl TransactionMetaV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_meta_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_meta_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionMetaV1`], mirroring `::write_xdr`. + pub const fn write_type_transaction_meta_v1(&mut self, v: &TransactionMetaV1) { + self.write_type_ledger_entry_changes(&v.tx_changes); + self.write_type_vec_operation_meta(&v.operations); + } +} diff --git a/src/generated/const/transaction_meta_v2.rs b/src/generated/const/transaction_meta_v2.rs new file mode 100644 index 000000000..cddb39e2b --- /dev/null +++ b/src/generated/const/transaction_meta_v2.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionMetaV2 is a borrowing equivalent of [`TransactionMetaV2`](super::super::TransactionMetaV2) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionMetaV2 { + pub tx_changes_before: LedgerEntryChanges, + pub operations: VecM, + pub tx_changes_after: LedgerEntryChanges, +} + +impl TransactionMetaV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_meta_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_meta_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionMetaV2`], mirroring `::write_xdr`. + pub const fn write_type_transaction_meta_v2(&mut self, v: &TransactionMetaV2) { + self.write_type_ledger_entry_changes(&v.tx_changes_before); + self.write_type_vec_operation_meta(&v.operations); + self.write_type_ledger_entry_changes(&v.tx_changes_after); + } +} diff --git a/src/generated/const/transaction_meta_v3.rs b/src/generated/const/transaction_meta_v3.rs new file mode 100644 index 000000000..1f437a535 --- /dev/null +++ b/src/generated/const/transaction_meta_v3.rs @@ -0,0 +1,62 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionMetaV3 is a borrowing equivalent of [`TransactionMetaV3`](super::super::TransactionMetaV3) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionMetaV3 { + pub ext: ExtensionPoint, + pub tx_changes_before: LedgerEntryChanges, + pub operations: VecM, + pub tx_changes_after: LedgerEntryChanges, + pub soroban_meta: Option, +} + +impl TransactionMetaV3 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_meta_v3(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_meta_v3(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionMetaV3`], mirroring `::write_xdr`. + pub const fn write_type_transaction_meta_v3(&mut self, v: &TransactionMetaV3) { + self.write_type_extension_point(&v.ext); + self.write_type_ledger_entry_changes(&v.tx_changes_before); + self.write_type_vec_operation_meta(&v.operations); + self.write_type_ledger_entry_changes(&v.tx_changes_after); + self.write_type_option_soroban_transaction_meta(&v.soroban_meta); + } +} diff --git a/src/generated/const/transaction_meta_v4.rs b/src/generated/const/transaction_meta_v4.rs new file mode 100644 index 000000000..aa5de6faf --- /dev/null +++ b/src/generated/const/transaction_meta_v4.rs @@ -0,0 +1,66 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionMetaV4 is a borrowing equivalent of [`TransactionMetaV4`](super::super::TransactionMetaV4) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionMetaV4 { + pub ext: ExtensionPoint, + pub tx_changes_before: LedgerEntryChanges, + pub operations: VecM, + pub tx_changes_after: LedgerEntryChanges, + pub soroban_meta: Option, + pub events: VecM, + pub diagnostic_events: VecM, +} + +impl TransactionMetaV4 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_meta_v4(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_meta_v4(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionMetaV4`], mirroring `::write_xdr`. + pub const fn write_type_transaction_meta_v4(&mut self, v: &TransactionMetaV4) { + self.write_type_extension_point(&v.ext); + self.write_type_ledger_entry_changes(&v.tx_changes_before); + self.write_type_vec_operation_meta_v2(&v.operations); + self.write_type_ledger_entry_changes(&v.tx_changes_after); + self.write_type_option_soroban_transaction_meta_v2(&v.soroban_meta); + self.write_type_vec_transaction_event(&v.events); + self.write_type_vec_diagnostic_event(&v.diagnostic_events); + } +} diff --git a/src/generated/const/transaction_phase.rs b/src/generated/const/transaction_phase.rs new file mode 100644 index 000000000..6f3d84107 --- /dev/null +++ b/src/generated/const/transaction_phase.rs @@ -0,0 +1,92 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionPhase is a borrowing equivalent of [`TransactionPhase`](super::super::TransactionPhase) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionPhase { + V0(VecM), + V1(ParallelTxsComponent), +} + +impl TransactionPhase { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl TransactionPhase { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_phase(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_phase(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionPhase`], mirroring `::write_xdr`. + pub const fn write_type_transaction_phase(&mut self, v: &TransactionPhase) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionPhase::V0(value) => { + self.write_type_vec_tx_set_component(value); + } + TransactionPhase::V1(value) => { + self.write_type_parallel_txs_component(value); + } + } + } + + /// Serializes a variable-length array of [`TransactionPhase`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_phase( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_phase(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_result.rs b/src/generated/const/transaction_result.rs new file mode 100644 index 000000000..a73324728 --- /dev/null +++ b/src/generated/const/transaction_result.rs @@ -0,0 +1,58 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResult is a borrowing equivalent of [`TransactionResult`](super::super::TransactionResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionResult { + pub fee_charged: i64, + pub result: TransactionResultResult, + pub ext: TransactionResultExt, +} + +impl TransactionResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResult`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result(&mut self, v: &TransactionResult) { + self.write_i64(v.fee_charged); + self.write_type_transaction_result_result(&v.result); + self.write_type_transaction_result_ext(&v.ext); + } +} diff --git a/src/generated/const/transaction_result_code.rs b/src/generated/const/transaction_result_code.rs new file mode 100644 index 000000000..2f63f3b65 --- /dev/null +++ b/src/generated/const/transaction_result_code.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TransactionResultCode { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_code(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_code(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultCode`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_code(&mut self, v: &TransactionResultCode) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/transaction_result_ext.rs b/src/generated/const/transaction_result_ext.rs new file mode 100644 index 000000000..43878deba --- /dev/null +++ b/src/generated/const/transaction_result_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TransactionResultExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultExt`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_ext(&mut self, v: &TransactionResultExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionResultExt::V0 => {} + } + } +} diff --git a/src/generated/const/transaction_result_meta.rs b/src/generated/const/transaction_result_meta.rs new file mode 100644 index 000000000..b3b93a7d6 --- /dev/null +++ b/src/generated/const/transaction_result_meta.rs @@ -0,0 +1,73 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResultMeta is a borrowing equivalent of [`TransactionResultMeta`](super::super::TransactionResultMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionResultMeta { + pub result: TransactionResultPair, + pub fee_processing: LedgerEntryChanges, + pub tx_apply_processing: TransactionMeta, +} + +impl TransactionResultMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultMeta`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_meta(&mut self, v: &TransactionResultMeta) { + self.write_type_transaction_result_pair(&v.result); + self.write_type_ledger_entry_changes(&v.fee_processing); + self.write_type_transaction_meta(&v.tx_apply_processing); + } + + /// Serializes a variable-length array of [`TransactionResultMeta`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_result_meta( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_result_meta(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_result_meta_v1.rs b/src/generated/const/transaction_result_meta_v1.rs new file mode 100644 index 000000000..852f95d74 --- /dev/null +++ b/src/generated/const/transaction_result_meta_v1.rs @@ -0,0 +1,77 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResultMetaV1 is a borrowing equivalent of [`TransactionResultMetaV1`](super::super::TransactionResultMetaV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionResultMetaV1 { + pub ext: ExtensionPoint, + pub result: TransactionResultPair, + pub fee_processing: LedgerEntryChanges, + pub tx_apply_processing: TransactionMeta, + pub post_tx_apply_fee_processing: LedgerEntryChanges, +} + +impl TransactionResultMetaV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_meta_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_meta_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultMetaV1`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_meta_v1(&mut self, v: &TransactionResultMetaV1) { + self.write_type_extension_point(&v.ext); + self.write_type_transaction_result_pair(&v.result); + self.write_type_ledger_entry_changes(&v.fee_processing); + self.write_type_transaction_meta(&v.tx_apply_processing); + self.write_type_ledger_entry_changes(&v.post_tx_apply_fee_processing); + } + + /// Serializes a variable-length array of [`TransactionResultMetaV1`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_result_meta_v1( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_result_meta_v1(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_result_pair.rs b/src/generated/const/transaction_result_pair.rs new file mode 100644 index 000000000..b2c3f2db8 --- /dev/null +++ b/src/generated/const/transaction_result_pair.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResultPair is a borrowing equivalent of [`TransactionResultPair`](super::super::TransactionResultPair) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionResultPair { + pub transaction_hash: Hash, + pub result: TransactionResult, +} + +impl TransactionResultPair { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_pair(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_pair(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultPair`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_pair(&mut self, v: &TransactionResultPair) { + self.write_type_hash(&v.transaction_hash); + self.write_type_transaction_result(&v.result); + } + + /// Serializes a variable-length array of [`TransactionResultPair`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_transaction_result_pair( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_transaction_result_pair(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/transaction_result_result.rs b/src/generated/const/transaction_result_result.rs new file mode 100644 index 000000000..437677dbe --- /dev/null +++ b/src/generated/const/transaction_result_result.rs @@ -0,0 +1,135 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResultResult is a borrowing equivalent of [`TransactionResultResult`](super::super::TransactionResultResult) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionResultResult { + TxFeeBumpInnerSuccess(InnerTransactionResultPair), + TxFeeBumpInnerFailed(InnerTransactionResultPair), + TxSuccess(VecM), + TxFailed(VecM), + TxTooEarly, + TxTooLate, + TxMissingOperation, + TxBadSeq, + TxBadAuth, + TxInsufficientBalance, + TxNoAccount, + TxInsufficientFee, + TxBadAuthExtra, + TxInternalError, + TxNotSupported, + TxBadSponsorship, + TxBadMinSeqAgeOrGap, + TxMalformed, + TxSorobanInvalid, + TxFrozenKeyAccessed, +} + +impl TransactionResultResult { + #[must_use] + pub const fn discriminant(&self) -> TransactionResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::TxFeeBumpInnerSuccess(_) => TransactionResultCode::TxFeeBumpInnerSuccess, + Self::TxFeeBumpInnerFailed(_) => TransactionResultCode::TxFeeBumpInnerFailed, + Self::TxSuccess(_) => TransactionResultCode::TxSuccess, + Self::TxFailed(_) => TransactionResultCode::TxFailed, + Self::TxTooEarly => TransactionResultCode::TxTooEarly, + Self::TxTooLate => TransactionResultCode::TxTooLate, + Self::TxMissingOperation => TransactionResultCode::TxMissingOperation, + Self::TxBadSeq => TransactionResultCode::TxBadSeq, + Self::TxBadAuth => TransactionResultCode::TxBadAuth, + Self::TxInsufficientBalance => TransactionResultCode::TxInsufficientBalance, + Self::TxNoAccount => TransactionResultCode::TxNoAccount, + Self::TxInsufficientFee => TransactionResultCode::TxInsufficientFee, + Self::TxBadAuthExtra => TransactionResultCode::TxBadAuthExtra, + Self::TxInternalError => TransactionResultCode::TxInternalError, + Self::TxNotSupported => TransactionResultCode::TxNotSupported, + Self::TxBadSponsorship => TransactionResultCode::TxBadSponsorship, + Self::TxBadMinSeqAgeOrGap => TransactionResultCode::TxBadMinSeqAgeOrGap, + Self::TxMalformed => TransactionResultCode::TxMalformed, + Self::TxSorobanInvalid => TransactionResultCode::TxSorobanInvalid, + Self::TxFrozenKeyAccessed => TransactionResultCode::TxFrozenKeyAccessed, + } + } +} + +impl TransactionResultResult { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_result(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_result(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultResult`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_result(&mut self, v: &TransactionResultResult) { + let d = v.discriminant(); + self.write_type_transaction_result_code(&d); + #[allow(clippy::match_same_arms)] + match v { + TransactionResultResult::TxFeeBumpInnerSuccess(value) => { + self.write_type_inner_transaction_result_pair(value); + } + TransactionResultResult::TxFeeBumpInnerFailed(value) => { + self.write_type_inner_transaction_result_pair(value); + } + TransactionResultResult::TxSuccess(value) => { + self.write_type_vec_operation_result(value); + } + TransactionResultResult::TxFailed(value) => { + self.write_type_vec_operation_result(value); + } + TransactionResultResult::TxTooEarly => {} + TransactionResultResult::TxTooLate => {} + TransactionResultResult::TxMissingOperation => {} + TransactionResultResult::TxBadSeq => {} + TransactionResultResult::TxBadAuth => {} + TransactionResultResult::TxInsufficientBalance => {} + TransactionResultResult::TxNoAccount => {} + TransactionResultResult::TxInsufficientFee => {} + TransactionResultResult::TxBadAuthExtra => {} + TransactionResultResult::TxInternalError => {} + TransactionResultResult::TxNotSupported => {} + TransactionResultResult::TxBadSponsorship => {} + TransactionResultResult::TxBadMinSeqAgeOrGap => {} + TransactionResultResult::TxMalformed => {} + TransactionResultResult::TxSorobanInvalid => {} + TransactionResultResult::TxFrozenKeyAccessed => {} + } + } +} diff --git a/src/generated/const/transaction_result_set.rs b/src/generated/const/transaction_result_set.rs new file mode 100644 index 000000000..8f32c2b23 --- /dev/null +++ b/src/generated/const/transaction_result_set.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionResultSet is a borrowing equivalent of [`TransactionResultSet`](super::super::TransactionResultSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionResultSet { + pub results: VecM, +} + +impl TransactionResultSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_result_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_result_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionResultSet`], mirroring `::write_xdr`. + pub const fn write_type_transaction_result_set(&mut self, v: &TransactionResultSet) { + self.write_type_vec_transaction_result_pair(&v.results); + } +} diff --git a/src/generated/const/transaction_set.rs b/src/generated/const/transaction_set.rs new file mode 100644 index 000000000..da8044f8b --- /dev/null +++ b/src/generated/const/transaction_set.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionSet is a borrowing equivalent of [`TransactionSet`](super::super::TransactionSet) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionSet { + pub previous_ledger_hash: Hash, + pub txs: VecM, +} + +impl TransactionSet { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_set(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_set(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionSet`], mirroring `::write_xdr`. + pub const fn write_type_transaction_set(&mut self, v: &TransactionSet) { + self.write_type_hash(&v.previous_ledger_hash); + self.write_type_vec_transaction_envelope(&v.txs); + } +} diff --git a/src/generated/const/transaction_set_v1.rs b/src/generated/const/transaction_set_v1.rs new file mode 100644 index 000000000..8b728fa44 --- /dev/null +++ b/src/generated/const/transaction_set_v1.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionSetV1 is a borrowing equivalent of [`TransactionSetV1`](super::super::TransactionSetV1) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionSetV1 { + pub previous_ledger_hash: Hash, + pub phases: VecM, +} + +impl TransactionSetV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_set_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_set_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionSetV1`], mirroring `::write_xdr`. + pub const fn write_type_transaction_set_v1(&mut self, v: &TransactionSetV1) { + self.write_type_hash(&v.previous_ledger_hash); + self.write_type_vec_transaction_phase(&v.phases); + } +} diff --git a/src/generated/const/transaction_signature_payload.rs b/src/generated/const/transaction_signature_payload.rs new file mode 100644 index 000000000..66cb691eb --- /dev/null +++ b/src/generated/const/transaction_signature_payload.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionSignaturePayload is a borrowing equivalent of [`TransactionSignaturePayload`](super::super::TransactionSignaturePayload) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionSignaturePayload { + pub network_id: Hash, + pub tagged_transaction: TransactionSignaturePayloadTaggedTransaction, +} + +impl TransactionSignaturePayload { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_signature_payload(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_signature_payload(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionSignaturePayload`], mirroring `::write_xdr`. + pub const fn write_type_transaction_signature_payload( + &mut self, + v: &TransactionSignaturePayload, + ) { + self.write_type_hash(&v.network_id); + self.write_type_transaction_signature_payload_tagged_transaction(&v.tagged_transaction); + } +} diff --git a/src/generated/const/transaction_signature_payload_tagged_transaction.rs b/src/generated/const/transaction_signature_payload_tagged_transaction.rs new file mode 100644 index 000000000..e0098c8ff --- /dev/null +++ b/src/generated/const/transaction_signature_payload_tagged_transaction.rs @@ -0,0 +1,80 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionSignaturePayloadTaggedTransaction is a borrowing equivalent of [`TransactionSignaturePayloadTaggedTransaction`](super::super::TransactionSignaturePayloadTaggedTransaction) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TransactionSignaturePayloadTaggedTransaction { + Tx(Transaction), + TxFeeBump(FeeBumpTransaction), +} + +impl TransactionSignaturePayloadTaggedTransaction { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(_) => EnvelopeType::Tx, + Self::TxFeeBump(_) => EnvelopeType::TxFeeBump, + } + } +} + +impl TransactionSignaturePayloadTaggedTransaction { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_signature_payload_tagged_transaction(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_signature_payload_tagged_transaction(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionSignaturePayloadTaggedTransaction`], mirroring `::write_xdr`. + pub const fn write_type_transaction_signature_payload_tagged_transaction( + &mut self, + v: &TransactionSignaturePayloadTaggedTransaction, + ) { + let d = v.discriminant(); + self.write_type_envelope_type(&d); + #[allow(clippy::match_same_arms)] + match v { + TransactionSignaturePayloadTaggedTransaction::Tx(value) => { + self.write_type_transaction(value); + } + TransactionSignaturePayloadTaggedTransaction::TxFeeBump(value) => { + self.write_type_fee_bump_transaction(value); + } + } + } +} diff --git a/src/generated/const/transaction_v0.rs b/src/generated/const/transaction_v0.rs new file mode 100644 index 000000000..eb8460391 --- /dev/null +++ b/src/generated/const/transaction_v0.rs @@ -0,0 +1,66 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionV0 is a borrowing equivalent of [`TransactionV0`](super::super::TransactionV0) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionV0 { + pub source_account_ed25519: Uint256, + pub fee: u32, + pub seq_num: SequenceNumber, + pub time_bounds: Option, + pub memo: Memo, + pub operations: VecM, + pub ext: TransactionV0Ext, +} + +impl TransactionV0 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_v0(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_v0(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionV0`], mirroring `::write_xdr`. + pub const fn write_type_transaction_v0(&mut self, v: &TransactionV0) { + self.write_type_uint256(&v.source_account_ed25519); + self.write_u32(v.fee); + self.write_type_sequence_number(&v.seq_num); + self.write_type_option_time_bounds(&v.time_bounds); + self.write_type_memo(&v.memo); + self.write_type_vec_operation(&v.operations); + self.write_type_transaction_v0_ext(&v.ext); + } +} diff --git a/src/generated/const/transaction_v0_envelope.rs b/src/generated/const/transaction_v0_envelope.rs new file mode 100644 index 000000000..7858d2651 --- /dev/null +++ b/src/generated/const/transaction_v0_envelope.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionV0Envelope is a borrowing equivalent of [`TransactionV0Envelope`](super::super::TransactionV0Envelope) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionV0Envelope { + pub tx: TransactionV0, + pub signatures: VecM, +} + +impl TransactionV0Envelope { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_v0_envelope(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_v0_envelope(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionV0Envelope`], mirroring `::write_xdr`. + pub const fn write_type_transaction_v0_envelope(&mut self, v: &TransactionV0Envelope) { + self.write_type_transaction_v0(&v.tx); + self.write_type_vec_decorated_signature(&v.signatures); + } +} diff --git a/src/generated/const/transaction_v0_ext.rs b/src/generated/const/transaction_v0_ext.rs new file mode 100644 index 000000000..ec559a9e8 --- /dev/null +++ b/src/generated/const/transaction_v0_ext.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TransactionV0Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_v0_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_v0_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionV0Ext`], mirroring `::write_xdr`. + pub const fn write_type_transaction_v0_ext(&mut self, v: &TransactionV0Ext) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TransactionV0Ext::V0 => {} + } + } +} diff --git a/src/generated/const/transaction_v1_envelope.rs b/src/generated/const/transaction_v1_envelope.rs new file mode 100644 index 000000000..0b46194f5 --- /dev/null +++ b/src/generated/const/transaction_v1_envelope.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TransactionV1Envelope is a borrowing equivalent of [`TransactionV1Envelope`](super::super::TransactionV1Envelope) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TransactionV1Envelope { + pub tx: Transaction, + pub signatures: VecM, +} + +impl TransactionV1Envelope { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_transaction_v1_envelope(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_transaction_v1_envelope(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TransactionV1Envelope`], mirroring `::write_xdr`. + pub const fn write_type_transaction_v1_envelope(&mut self, v: &TransactionV1Envelope) { + self.write_type_transaction(&v.tx); + self.write_type_vec_decorated_signature(&v.signatures); + } +} diff --git a/src/generated/const/trust_line_asset.rs b/src/generated/const/trust_line_asset.rs new file mode 100644 index 000000000..1088d39e8 --- /dev/null +++ b/src/generated/const/trust_line_asset.rs @@ -0,0 +1,60 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineAsset { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_asset(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_asset(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineAsset`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_asset(&mut self, v: &TrustLineAsset) { + let d = v.discriminant(); + self.write_type_asset_type(&d); + #[allow(clippy::match_same_arms)] + match v { + TrustLineAsset::Native => {} + TrustLineAsset::CreditAlphanum4(value) => { + self.write_type_alpha_num4(value); + } + TrustLineAsset::CreditAlphanum12(value) => { + self.write_type_alpha_num12(value); + } + TrustLineAsset::PoolShare(value) => { + self.write_type_pool_id(value); + } + } + } +} diff --git a/src/generated/const/trust_line_entry.rs b/src/generated/const/trust_line_entry.rs new file mode 100644 index 000000000..4aed2ab35 --- /dev/null +++ b/src/generated/const/trust_line_entry.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntry`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry(&mut self, v: &TrustLineEntry) { + self.write_type_account_id(&v.account_id); + self.write_type_trust_line_asset(&v.asset); + self.write_i64(v.balance); + self.write_i64(v.limit); + self.write_u32(v.flags); + self.write_type_trust_line_entry_ext(&v.ext); + } +} diff --git a/src/generated/const/trust_line_entry_ext.rs b/src/generated/const/trust_line_entry_ext.rs new file mode 100644 index 000000000..16e1c67bd --- /dev/null +++ b/src/generated/const/trust_line_entry_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntryExt { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntryExt`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry_ext(&mut self, v: &TrustLineEntryExt) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TrustLineEntryExt::V0 => {} + TrustLineEntryExt::V1(value) => { + self.write_type_trust_line_entry_v1(value); + } + } + } +} diff --git a/src/generated/const/trust_line_entry_extension_v2.rs b/src/generated/const/trust_line_entry_extension_v2.rs new file mode 100644 index 000000000..55774563d --- /dev/null +++ b/src/generated/const/trust_line_entry_extension_v2.rs @@ -0,0 +1,50 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntryExtensionV2 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry_extension_v2(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry_extension_v2(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntryExtensionV2`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry_extension_v2( + &mut self, + v: &TrustLineEntryExtensionV2, + ) { + self.write_i32(v.liquidity_pool_use_count); + self.write_type_trust_line_entry_extension_v2_ext(&v.ext); + } +} diff --git a/src/generated/const/trust_line_entry_extension_v2_ext.rs b/src/generated/const/trust_line_entry_extension_v2_ext.rs new file mode 100644 index 000000000..89dccf404 --- /dev/null +++ b/src/generated/const/trust_line_entry_extension_v2_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntryExtensionV2Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry_extension_v2_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry_extension_v2_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntryExtensionV2Ext`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry_extension_v2_ext( + &mut self, + v: &TrustLineEntryExtensionV2Ext, + ) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TrustLineEntryExtensionV2Ext::V0 => {} + } + } +} diff --git a/src/generated/const/trust_line_entry_v1.rs b/src/generated/const/trust_line_entry_v1.rs new file mode 100644 index 000000000..f3512c7b7 --- /dev/null +++ b/src/generated/const/trust_line_entry_v1.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntryV1 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry_v1(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry_v1(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntryV1`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry_v1(&mut self, v: &TrustLineEntryV1) { + self.write_type_liabilities(&v.liabilities); + self.write_type_trust_line_entry_v1_ext(&v.ext); + } +} diff --git a/src/generated/const/trust_line_entry_v1_ext.rs b/src/generated/const/trust_line_entry_v1_ext.rs new file mode 100644 index 000000000..7d7115bc7 --- /dev/null +++ b/src/generated/const/trust_line_entry_v1_ext.rs @@ -0,0 +1,54 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineEntryV1Ext { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_entry_v1_ext(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_entry_v1_ext(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineEntryV1Ext`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_entry_v1_ext(&mut self, v: &TrustLineEntryV1Ext) { + let d = v.discriminant(); + self.write_i32(d); + #[allow(clippy::match_same_arms)] + match v { + TrustLineEntryV1Ext::V0 => {} + TrustLineEntryV1Ext::V2(value) => { + self.write_type_trust_line_entry_extension_v2(value); + } + } + } +} diff --git a/src/generated/const/trust_line_flags.rs b/src/generated/const/trust_line_flags.rs new file mode 100644 index 000000000..77b97dd3b --- /dev/null +++ b/src/generated/const/trust_line_flags.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TrustLineFlags { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_trust_line_flags(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_trust_line_flags(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TrustLineFlags`], mirroring `::write_xdr`. + pub const fn write_type_trust_line_flags(&mut self, v: &TrustLineFlags) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/ttl_entry.rs b/src/generated/const/ttl_entry.rs new file mode 100644 index 000000000..ed9f4e51a --- /dev/null +++ b/src/generated/const/ttl_entry.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TtlEntry { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_ttl_entry(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_ttl_entry(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TtlEntry`], mirroring `::write_xdr`. + pub const fn write_type_ttl_entry(&mut self, v: &TtlEntry) { + self.write_type_hash(&v.key_hash); + self.write_u32(v.live_until_ledger_seq); + } +} diff --git a/src/generated/const/tx_advert_vector.rs b/src/generated/const/tx_advert_vector.rs new file mode 100644 index 000000000..caa4b1f9d --- /dev/null +++ b/src/generated/const/tx_advert_vector.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TxAdvertVector is a borrowing equivalent of [`TxAdvertVector`](super::super::TxAdvertVector) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TxAdvertVector(pub VecM); + +impl TxAdvertVector { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_tx_advert_vector(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_tx_advert_vector(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TxAdvertVector`], mirroring `::write_xdr`. + pub const fn write_type_tx_advert_vector(&mut self, v: &TxAdvertVector) { + self.write_type_vec_hash(&v.0); + } +} diff --git a/src/generated/const/tx_demand_vector.rs b/src/generated/const/tx_demand_vector.rs new file mode 100644 index 000000000..4247f9cc2 --- /dev/null +++ b/src/generated/const/tx_demand_vector.rs @@ -0,0 +1,52 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TxDemandVector is a borrowing equivalent of [`TxDemandVector`](super::super::TxDemandVector) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TxDemandVector(pub VecM); + +impl TxDemandVector { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_tx_demand_vector(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_tx_demand_vector(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TxDemandVector`], mirroring `::write_xdr`. + pub const fn write_type_tx_demand_vector(&mut self, v: &TxDemandVector) { + self.write_type_vec_hash(&v.0); + } +} diff --git a/src/generated/const/tx_set_component.rs b/src/generated/const/tx_set_component.rs new file mode 100644 index 000000000..62dd1a8f5 --- /dev/null +++ b/src/generated/const/tx_set_component.rs @@ -0,0 +1,89 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TxSetComponent is a borrowing equivalent of [`TxSetComponent`](super::super::TxSetComponent) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum TxSetComponent { + TxsetCompTxsMaybeDiscountedFee(TxSetComponentTxsMaybeDiscountedFee), +} + +impl TxSetComponent { + #[must_use] + pub const fn discriminant(&self) -> TxSetComponentType { + #[allow(clippy::match_same_arms)] + match self { + Self::TxsetCompTxsMaybeDiscountedFee(_) => { + TxSetComponentType::TxsetCompTxsMaybeDiscountedFee + } + } + } +} + +impl TxSetComponent { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_tx_set_component(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_tx_set_component(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TxSetComponent`], mirroring `::write_xdr`. + pub const fn write_type_tx_set_component(&mut self, v: &TxSetComponent) { + let d = v.discriminant(); + self.write_type_tx_set_component_type(&d); + #[allow(clippy::match_same_arms)] + match v { + TxSetComponent::TxsetCompTxsMaybeDiscountedFee(value) => { + self.write_type_tx_set_component_txs_maybe_discounted_fee(value); + } + } + } + + /// Serializes a variable-length array of [`TxSetComponent`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_tx_set_component( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_tx_set_component(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/tx_set_component_txs_maybe_discounted_fee.rs b/src/generated/const/tx_set_component_txs_maybe_discounted_fee.rs new file mode 100644 index 000000000..3a6160042 --- /dev/null +++ b/src/generated/const/tx_set_component_txs_maybe_discounted_fee.rs @@ -0,0 +1,59 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// TxSetComponentTxsMaybeDiscountedFee is a borrowing equivalent of [`TxSetComponentTxsMaybeDiscountedFee`](super::super::TxSetComponentTxsMaybeDiscountedFee) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct TxSetComponentTxsMaybeDiscountedFee { + pub base_fee: Option, + pub txs: VecM, +} + +impl TxSetComponentTxsMaybeDiscountedFee { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_tx_set_component_txs_maybe_discounted_fee(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_tx_set_component_txs_maybe_discounted_fee(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TxSetComponentTxsMaybeDiscountedFee`], mirroring `::write_xdr`. + pub const fn write_type_tx_set_component_txs_maybe_discounted_fee( + &mut self, + v: &TxSetComponentTxsMaybeDiscountedFee, + ) { + self.write_option_i64(&v.base_fee); + self.write_type_vec_transaction_envelope(&v.txs); + } +} diff --git a/src/generated/const/tx_set_component_type.rs b/src/generated/const/tx_set_component_type.rs new file mode 100644 index 000000000..53751672e --- /dev/null +++ b/src/generated/const/tx_set_component_type.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl TxSetComponentType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_tx_set_component_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_tx_set_component_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`TxSetComponentType`], mirroring `::write_xdr`. + pub const fn write_type_tx_set_component_type(&mut self, v: &TxSetComponentType) { + self.write_i32(*v as i32); + } +} diff --git a/src/generated/const/u_int128_parts.rs b/src/generated/const/u_int128_parts.rs new file mode 100644 index 000000000..c48a68d28 --- /dev/null +++ b/src/generated/const/u_int128_parts.rs @@ -0,0 +1,47 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl UInt128Parts { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_u_int128_parts(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_u_int128_parts(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`UInt128Parts`], mirroring `::write_xdr`. + pub const fn write_type_u_int128_parts(&mut self, v: &UInt128Parts) { + self.write_u64(v.hi); + self.write_u64(v.lo); + } +} diff --git a/src/generated/const/u_int256_parts.rs b/src/generated/const/u_int256_parts.rs new file mode 100644 index 000000000..8b40a71e1 --- /dev/null +++ b/src/generated/const/u_int256_parts.rs @@ -0,0 +1,49 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl UInt256Parts { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_u_int256_parts(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_u_int256_parts(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`UInt256Parts`], mirroring `::write_xdr`. + pub const fn write_type_u_int256_parts(&mut self, v: &UInt256Parts) { + self.write_u64(v.hi_hi); + self.write_u64(v.hi_lo); + self.write_u64(v.lo_hi); + self.write_u64(v.lo_lo); + } +} diff --git a/src/generated/const/uint256.rs b/src/generated/const/uint256.rs new file mode 100644 index 000000000..4b7d2ee61 --- /dev/null +++ b/src/generated/const/uint256.rs @@ -0,0 +1,46 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +impl Uint256 { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_uint256(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_uint256(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Uint256`], mirroring `::write_xdr`. + pub const fn write_type_uint256(&mut self, v: &Uint256) { + self.write_fixed_opaque(&v.0); + } +} diff --git a/src/generated/const/upgrade_entry_meta.rs b/src/generated/const/upgrade_entry_meta.rs new file mode 100644 index 000000000..c0bf4e276 --- /dev/null +++ b/src/generated/const/upgrade_entry_meta.rs @@ -0,0 +1,71 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// UpgradeEntryMeta is a borrowing equivalent of [`UpgradeEntryMeta`](super::super::UpgradeEntryMeta) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct UpgradeEntryMeta { + pub upgrade: LedgerUpgrade, + pub changes: LedgerEntryChanges, +} + +impl UpgradeEntryMeta { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_upgrade_entry_meta(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_upgrade_entry_meta(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`UpgradeEntryMeta`], mirroring `::write_xdr`. + pub const fn write_type_upgrade_entry_meta(&mut self, v: &UpgradeEntryMeta) { + self.write_type_ledger_upgrade(&v.upgrade); + self.write_type_ledger_entry_changes(&v.changes); + } + + /// Serializes a variable-length array of [`UpgradeEntryMeta`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_upgrade_entry_meta( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_upgrade_entry_meta(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/upgrade_type.rs b/src/generated/const/upgrade_type.rs new file mode 100644 index 000000000..2d437246a --- /dev/null +++ b/src/generated/const/upgrade_type.rs @@ -0,0 +1,67 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// UpgradeType is a borrowing equivalent of [`UpgradeType`](super::super::UpgradeType) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct UpgradeType(pub BytesM<128>); + +impl UpgradeType { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_upgrade_type(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_upgrade_type(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`UpgradeType`], mirroring `::write_xdr`. + pub const fn write_type_upgrade_type(&mut self, v: &UpgradeType) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes a variable-length array of [`UpgradeType`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_upgrade_type( + &mut self, + v: &VecM, + ) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_upgrade_type(&s[i]); + i += 1; + } + } +} diff --git a/src/generated/const/value.rs b/src/generated/const/value.rs new file mode 100644 index 000000000..7eb26b4ea --- /dev/null +++ b/src/generated/const/value.rs @@ -0,0 +1,64 @@ +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; + +/// Value is a borrowing equivalent of [`Value`](super::super::Value) +/// over `'static` data, for const XDR encoding. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Value(pub BytesM); + +impl Value { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.write_type_value(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.write_type_value(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} + +impl ConstWriter<'_> { + /// Serializes a [`Value`], mirroring `::write_xdr`. + pub const fn write_type_value(&mut self, v: &Value) { + self.write_var_opaque(v.0.as_slice()); + } + + /// Serializes a variable-length array of [`Value`], mirroring ` as WriteXdr>::write_xdr`. + pub const fn write_type_vec_value(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_type_value(&s[i]); + i += 1; + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 36f8f2ecc..4b6bdf55c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,13 @@ //! 6. `hex` – Enables support for hex in string representations of some types. //! Automatically enabled when serde is enabled. //! 7. `schemars` – Enables support for JSON Schema generation. (Experimental) +//! 8. `const` – Enables the `const` module, containing a form of every type +//! that can be constructed and encoded to XDR in a const context. Types that +//! own heap data have a borrowing counterpart in the module that wraps +//! `&'static` slices instead; the rest are re-exports of the owned types. +//! Every type in the module has `const_xdr_len` and `const_to_xdr` methods, +//! so XDR can be encoded at compile time into a fixed-size array. Requires no +//! additional dependencies and works without std or alloc. (Experimental) //! //! Features marked experimental may disappear at anytime, see breaking changes //! at anytime, or and may be minimal implementations instead of complete. diff --git a/tests/arbitrary.rs b/tests/arbitrary.rs index db1753938..ea8496ff7 100644 --- a/tests/arbitrary.rs +++ b/tests/arbitrary.rs @@ -1,7 +1,8 @@ #![cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; -use stellar_xdr::ScMap; +use rand::{rngs::StdRng, RngCore, SeedableRng}; +use stellar_xdr::{BytesM, ScMap, ScSpecEntry, StringM, VecM, SCSYMBOL_LIMIT}; #[test] fn arb() { @@ -12,3 +13,56 @@ fn arb() { eprintln!("{x:?}"); } } + +/// The length limit is an invariant of the length-limited types, so the +/// `Arbitrary` impls must not produce values that exceed it. A derived impl +/// would, because the limit lives in a const parameter the derive cannot see. +#[test] +fn arbitrary_stays_within_max() { + let mut bytes = [0u8; 4096]; + StdRng::seed_from_u64(0).fill_bytes(&mut bytes); + for start in 0..bytes.len() / 2 { + let mut u = Unstructured::new(&bytes[start..]); + assert!(StringM::<3>::arbitrary(&mut u).unwrap().len() <= 3); + assert!(BytesM::<5>::arbitrary(&mut u).unwrap().len() <= 5); + assert!(VecM::::arbitrary(&mut u).unwrap().len() <= 2); + } +} + +/// Input past the limit must be left for the fields that follow, rather than +/// read into elements that are then thrown away. +#[test] +fn arbitrary_does_not_consume_past_max() { + // `Vec`'s impl reads a continuation byte before each element, and every + // byte here is non-zero, so the input describes far more elements than the + // limit allows. + let bytes = vec![1u8; 64]; + let mut u = Unstructured::new(&bytes); + let v = VecM::::arbitrary(&mut u).unwrap(); + assert_eq!(v.len(), 2); + // Two elements: a continuation byte and an element byte each, and nothing + // read for a third. + assert_eq!(bytes.len() - u.len(), 4); +} + +/// The same invariant, reached through a generated type: a function returns at +/// most one output, its name is at most `SCSYMBOL_LIMIT` bytes, and an input +/// name at most 30. +#[test] +fn arbitrary_generated_type_stays_within_max() { + let mut bytes = [0u8; 8192]; + StdRng::seed_from_u64(0).fill_bytes(&mut bytes); + for start in 0..bytes.len() / 2 { + let mut u = Unstructured::new(&bytes[start..]); + let Ok(entry) = ScSpecEntry::arbitrary(&mut u) else { + continue; + }; + if let ScSpecEntry::FunctionV0(f) = entry { + assert!(f.outputs.len() <= 1); + assert!(f.name.len() <= SCSYMBOL_LIMIT as usize); + for i in &*f.inputs { + assert!(i.name.len() <= 30); + } + } + } +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 000000000..9700c9f22 --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,436 @@ +//! Significantly complex values, each in a const and an owned form that are +//! identical. +//! +//! The `TransactionEnvelope` covers every shape the generator emits: nested +//! structs, both union kinds with void, scalar, fixed-opaque and heap arms, a +//! heap-free struct the `const` module aliases rather than replaces, a cyclic +//! field where the const form borrows and the owned form boxes, `Option` in +//! both states, `VecM` of borrowing and of heap-free values, an empty `VecM`, +//! `StringM`, `BytesM`, and u32/u64/i64 scalars. +//! +//! The `ScSpecEntry` covers what the envelope cannot: a union whose recursive +//! arms nest several levels deep, where each level is a `&'static` borrow in +//! the const form and a `Box` in the owned one, reached through `VecM` elements +//! as well as through struct fields. + +pub use const_value::{spec_entry_const, tx_env_const}; +pub use owned_value::{spec_entry_owned, tx_env_owned}; + +/// The value as `const`, built from the `const` module's types. +mod const_value { + use stellar_xdr::r#const::*; + + #[allow(clippy::too_many_lines)] + pub const fn tx_env_const() -> TransactionEnvelope { + TransactionEnvelope::Tx(TransactionV1Envelope { + tx: Transaction { + source_account: MuxedAccount::MuxedEd25519(MuxedAccountMed25519 { + id: 0xdead_beef_0000_0001, + ed25519: Uint256([0x11; 32]), + }), + fee: 4_321, + seq_num: SequenceNumber(9_876_543_210), + cond: Preconditions::V2(PreconditionsV2 { + time_bounds: Some(TimeBounds { + min_time: TimePoint(100), + max_time: TimePoint(200), + }), + ledger_bounds: None, + min_seq_num: Some(SequenceNumber(42)), + min_seq_age: Duration(3_600), + min_seq_ledger_gap: 7, + extra_signers: VecM::try_from_slice_or_panic( + &const { + [ + SignerKey::Ed25519(Uint256([0x33; 32])), + SignerKey::Ed25519SignedPayload(SignerKeyEd25519SignedPayload { + ed25519: Uint256([0x44; 32]), + payload: BytesM::try_from_slice_or_panic(b"signed payload"), + }), + ] + }, + ), + }), + memo: Memo::Text(StringM::try_from_str_or_panic("hello world")), + operations: VecM::try_from_slice_or_panic( + &const { + [ + Operation { + source_account: None, + body: OperationBody::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([0x55; 32])), + asset: Asset::CreditAlphanum4(AlphaNum4 { + asset_code: AssetCode4(*b"USDC"), + issuer: AccountId(PublicKey::PublicKeyTypeEd25519( + Uint256([0x22; 32]), + )), + }), + amount: 1_000_000_007, + }), + }, + Operation { + source_account: Some(MuxedAccount::Ed25519(Uint256([0x66; 32]))), + body: OperationBody::ManageData(ManageDataOp { + data_name: String64(StringM::try_from_str_or_panic("config")), + data_value: Some(DataValue(BytesM::try_from_slice_or_panic( + b"value", + ))), + }), + }, + Operation { + source_account: None, + body: OperationBody::Inflation, + }, + Operation { + source_account: None, + body: OperationBody::CreateClaimableBalance( + CreateClaimableBalanceOp { + asset: Asset::Native, + amount: 250_000_000, + claimants: VecM::try_from_slice_or_panic( + &const { + [Claimant::ClaimantTypeV0(ClaimantV0 { + destination: AccountId( + PublicKey::PublicKeyTypeEd25519(Uint256( + [0x22; 32], + )), + ), + predicate: ClaimPredicate::Not(Some( + &ClaimPredicate::BeforeRelativeTime(86_400), + )), + })] + }, + ), + }, + ), + }, + ] + }, + ), + ext: TransactionExt::V1(SorobanTransactionData { + ext: SorobanTransactionDataExt::V0, + resources: SorobanResources { + footprint: LedgerFootprint { + read_only: VecM::try_from_slice_or_panic(&[LedgerKey::Account( + LedgerKeyAccount { + account_id: AccountId(PublicKey::PublicKeyTypeEd25519( + Uint256([0x22; 32]), + )), + }, + )]), + read_write: VecM::try_from_slice_or_panic(&[]), + }, + instructions: 1_000_000, + disk_read_bytes: 2_048, + write_bytes: 512, + }, + resource_fee: 100_000, + }), + }, + signatures: VecM::try_from_slice_or_panic( + &const { + [ + DecoratedSignature { + hint: SignatureHint([1, 2, 3, 4]), + signature: Signature(BytesM::try_from_slice_or_panic(b"sig-one")), + }, + DecoratedSignature { + hint: SignatureHint([5, 6, 7, 8]), + signature: Signature(BytesM::try_from_slice_or_panic(b"sig-two")), + }, + ] + }, + ), + }) + } + + #[allow(clippy::too_many_lines)] + pub const fn spec_entry_const() -> ScSpecEntry { + ScSpecEntry::FunctionV0(ScSpecFunctionV0 { + doc: StringM::try_from_str_or_panic("transfers an amount between two addresses"), + name: ScSymbol(StringM::try_from_str_or_panic("transfer")), + inputs: VecM::try_from_slice_or_panic( + &const { + [ + ScSpecFunctionInputV0 { + doc: StringM::try_from_str_or_panic(""), + name: StringM::try_from_str_or_panic("from"), + type_: ScSpecTypeDef::Address, + }, + ScSpecFunctionInputV0 { + doc: StringM::try_from_str_or_panic("the asset, by name"), + name: StringM::try_from_str_or_panic("asset"), + type_: ScSpecTypeDef::Udt(ScSpecTypeUdt { + name: StringM::try_from_str_or_panic("Asset"), + }), + }, + // option, + // option>>>>, so the borrow nests through a + // struct field, then a VecM element, then a field + // again. + ScSpecFunctionInputV0 { + doc: StringM::try_from_str_or_panic(""), + name: StringM::try_from_str_or_panic("routes"), + type_: ScSpecTypeDef::Option( + &const { + ScSpecTypeOption { + value_type: &const { + ScSpecTypeDef::Vec( + &const { + ScSpecTypeVec { + element_type: &const { + ScSpecTypeDef::Map( + &const { + ScSpecTypeMap { + key_type: &const { + ScSpecTypeDef::Symbol + }, + value_type: &const { + ScSpecTypeDef::Tuple( + &const { + ScSpecTypeTuple { + value_types: VecM::try_from_slice_or_panic( + &const { + [ + ScSpecTypeDef::U32, + ScSpecTypeDef::BytesN(ScSpecTypeBytesN { n: 32 }), + ScSpecTypeDef::Option( + &const { + ScSpecTypeOption { + value_type: &const { ScSpecTypeDef::I128 }, + } + }, + ), + ] + }, + ), + } + }, + ) + }, + } + }, + ) + }, + } + }, + ) + }, + } + }, + ), + }, + // An empty VecM inside a borrowed arm. + ScSpecFunctionInputV0 { + doc: StringM::try_from_str_or_panic(""), + name: StringM::try_from_str_or_panic("extra"), + type_: ScSpecTypeDef::Tuple( + &const { + ScSpecTypeTuple { + value_types: VecM::try_from_slice_or_panic(&[]), + } + }, + ), + }, + ] + }, + ), + outputs: VecM::try_from_slice_or_panic( + &const { + [ScSpecTypeDef::Result( + &const { + ScSpecTypeResult { + ok_type: &const { ScSpecTypeDef::Void }, + error_type: &const { + ScSpecTypeDef::Udt(ScSpecTypeUdt { + name: StringM::try_from_str_or_panic("TransferError"), + }) + }, + } + }, + )] + }, + ), + }) + } +} + +/// The same value owned, built from the generated types. +mod owned_value { + use stellar_xdr::*; + + #[allow(clippy::too_many_lines)] + pub fn tx_env_owned() -> TransactionEnvelope { + TransactionEnvelope::Tx(TransactionV1Envelope { + tx: Transaction { + source_account: MuxedAccount::MuxedEd25519(MuxedAccountMed25519 { + id: 0xdead_beef_0000_0001, + ed25519: Uint256([0x11; 32]), + }), + fee: 4_321, + seq_num: SequenceNumber(9_876_543_210), + cond: Preconditions::V2(PreconditionsV2 { + time_bounds: Some(TimeBounds { + min_time: TimePoint(100), + max_time: TimePoint(200), + }), + ledger_bounds: None, + min_seq_num: Some(SequenceNumber(42)), + min_seq_age: Duration(3_600), + min_seq_ledger_gap: 7, + extra_signers: vec![ + SignerKey::Ed25519(Uint256([0x33; 32])), + SignerKey::Ed25519SignedPayload(SignerKeyEd25519SignedPayload { + ed25519: Uint256([0x44; 32]), + payload: b"signed payload".to_vec().try_into().unwrap(), + }), + ] + .try_into() + .unwrap(), + }), + memo: Memo::Text("hello world".try_into().unwrap()), + operations: vec![ + Operation { + source_account: None, + body: OperationBody::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([0x55; 32])), + asset: Asset::CreditAlphanum4(AlphaNum4 { + asset_code: AssetCode4(*b"USDC"), + issuer: AccountId(PublicKey::PublicKeyTypeEd25519(Uint256( + [0x22; 32], + ))), + }), + amount: 1_000_000_007, + }), + }, + Operation { + source_account: Some(MuxedAccount::Ed25519(Uint256([0x66; 32]))), + body: OperationBody::ManageData(ManageDataOp { + data_name: String64("config".try_into().unwrap()), + data_value: Some(DataValue(b"value".to_vec().try_into().unwrap())), + }), + }, + Operation { + source_account: None, + body: OperationBody::Inflation, + }, + Operation { + source_account: None, + body: OperationBody::CreateClaimableBalance(CreateClaimableBalanceOp { + asset: Asset::Native, + amount: 250_000_000, + claimants: vec![Claimant::ClaimantTypeV0(ClaimantV0 { + destination: AccountId(PublicKey::PublicKeyTypeEd25519(Uint256( + [0x22; 32], + ))), + predicate: ClaimPredicate::Not(Some(Box::new( + ClaimPredicate::BeforeRelativeTime(86_400), + ))), + })] + .try_into() + .unwrap(), + }), + }, + ] + .try_into() + .unwrap(), + ext: TransactionExt::V1(SorobanTransactionData { + ext: SorobanTransactionDataExt::V0, + resources: SorobanResources { + footprint: LedgerFootprint { + read_only: vec![LedgerKey::Account(LedgerKeyAccount { + account_id: AccountId(PublicKey::PublicKeyTypeEd25519(Uint256( + [0x22; 32], + ))), + })] + .try_into() + .unwrap(), + read_write: vec![].try_into().unwrap(), + }, + instructions: 1_000_000, + disk_read_bytes: 2_048, + write_bytes: 512, + }, + resource_fee: 100_000, + }), + }, + signatures: vec![ + DecoratedSignature { + hint: SignatureHint([1, 2, 3, 4]), + signature: Signature(b"sig-one".to_vec().try_into().unwrap()), + }, + DecoratedSignature { + hint: SignatureHint([5, 6, 7, 8]), + signature: Signature(b"sig-two".to_vec().try_into().unwrap()), + }, + ] + .try_into() + .unwrap(), + }) + } + + #[allow(clippy::too_many_lines)] + pub fn spec_entry_owned() -> ScSpecEntry { + ScSpecEntry::FunctionV0(ScSpecFunctionV0 { + doc: "transfers an amount between two addresses" + .try_into() + .unwrap(), + name: ScSymbol("transfer".try_into().unwrap()), + inputs: vec![ + ScSpecFunctionInputV0 { + doc: "".try_into().unwrap(), + name: "from".try_into().unwrap(), + type_: ScSpecTypeDef::Address, + }, + ScSpecFunctionInputV0 { + doc: "the asset, by name".try_into().unwrap(), + name: "asset".try_into().unwrap(), + type_: ScSpecTypeDef::Udt(ScSpecTypeUdt { + name: "Asset".try_into().unwrap(), + }), + }, + ScSpecFunctionInputV0 { + doc: "".try_into().unwrap(), + name: "routes".try_into().unwrap(), + type_: ScSpecTypeDef::Option(Box::new(ScSpecTypeOption { + value_type: Box::new(ScSpecTypeDef::Vec(Box::new(ScSpecTypeVec { + element_type: Box::new(ScSpecTypeDef::Map(Box::new(ScSpecTypeMap { + key_type: Box::new(ScSpecTypeDef::Symbol), + value_type: Box::new(ScSpecTypeDef::Tuple(Box::new( + ScSpecTypeTuple { + value_types: vec![ + ScSpecTypeDef::U32, + ScSpecTypeDef::BytesN(ScSpecTypeBytesN { n: 32 }), + ScSpecTypeDef::Option(Box::new(ScSpecTypeOption { + value_type: Box::new(ScSpecTypeDef::I128), + })), + ] + .try_into() + .unwrap(), + }, + ))), + }))), + }))), + })), + }, + ScSpecFunctionInputV0 { + doc: "".try_into().unwrap(), + name: "extra".try_into().unwrap(), + type_: ScSpecTypeDef::Tuple(Box::new(ScSpecTypeTuple { + value_types: vec![].try_into().unwrap(), + })), + }, + ] + .try_into() + .unwrap(), + outputs: vec![ScSpecTypeDef::Result(Box::new(ScSpecTypeResult { + ok_type: Box::new(ScSpecTypeDef::Void), + error_type: Box::new(ScSpecTypeDef::Udt(ScSpecTypeUdt { + name: "TransferError".try_into().unwrap(), + })), + }))] + .try_into() + .unwrap(), + }) + } +} diff --git a/tests/const_types.rs b/tests/const_types.rs new file mode 100644 index 000000000..d37d84997 --- /dev/null +++ b/tests/const_types.rs @@ -0,0 +1,80 @@ +//! Tests for the `const` module's borrowing types. + +#![cfg(feature = "const")] + +use stellar_xdr::r#const::{BytesM, StringM, VecM}; +use stellar_xdr::ErrorLengthExceedsMax; + +#[test] +fn consts_try_from_enforce_max_len() { + assert!(VecM::::try_from_slice(&[1, 2, 3]).is_ok()); + assert_eq!( + VecM::::try_from_slice(&[1, 2, 3]), + Err(ErrorLengthExceedsMax) + ); + + assert!(BytesM::<3>::try_from_slice(b"abc").is_ok()); + assert_eq!( + BytesM::<2>::try_from_slice(b"abc"), + Err(ErrorLengthExceedsMax) + ); + + assert!(StringM::<3>::try_from_str("abc").is_ok()); + assert_eq!( + StringM::<2>::try_from_str("abc"), + Err(ErrorLengthExceedsMax) + ); + assert!(StringM::<3>::try_from_slice(b"abc").is_ok()); + assert_eq!( + StringM::<2>::try_from_slice(b"abc"), + Err(ErrorLengthExceedsMax) + ); +} + +#[test] +fn consts_try_from_or_panic() { + assert_eq!( + VecM::::try_from_slice_or_panic(&[1, 2, 3]), + VecM::::try_from_slice(&[1, 2, 3]).unwrap() + ); + assert_eq!( + BytesM::<3>::try_from_slice_or_panic(b"abc"), + BytesM::<3>::try_from_slice(b"abc").unwrap() + ); + assert_eq!( + StringM::<3>::try_from_str_or_panic("abc"), + StringM::<3>::try_from_str("abc").unwrap() + ); + assert_eq!( + StringM::<3>::try_from_slice_or_panic(b"abc"), + StringM::<3>::try_from_slice(b"abc").unwrap() + ); +} + +#[test] +#[should_panic(expected = "xdr value max length exceeded")] +fn vecm_const_try_from_or_panic_panics_enforce_max_len() { + let _ = VecM::::try_from_slice_or_panic(&[1, 2, 3]); +} + +#[test] +#[should_panic(expected = "xdr value max length exceeded")] +fn bytesm_const_try_from_or_panic_panics_enforce_max_len() { + let _ = BytesM::<2>::try_from_slice_or_panic(b"abc"); +} + +#[test] +#[should_panic(expected = "xdr value max length exceeded")] +fn stringm_const_try_from_or_panic_panics_enforce_max_len() { + let _ = StringM::<2>::try_from_str_or_panic("abc"); +} + +#[test] +fn consts_default() { + assert_eq!( + VecM::::default(), + VecM::try_from_slice(&[]).unwrap() + ); + assert_eq!(BytesM::<3>::default(), BytesM::try_from_slice(&[]).unwrap()); + assert_eq!(StringM::<3>::default(), StringM::try_from_str("").unwrap()); +} diff --git a/tests/const_writer.rs b/tests/const_writer.rs new file mode 100644 index 000000000..1f3b25fb6 --- /dev/null +++ b/tests/const_writer.rs @@ -0,0 +1,31 @@ +//! Tests for the const XDR serializer. + +#![cfg(all(feature = "const", feature = "std"))] + +use stellar_xdr::{r#const, Limits, ScSpecEntry, TransactionEnvelope, WriteXdr}; + +mod common; +use common::{spec_entry_const, spec_entry_owned, tx_env_const, tx_env_owned}; + +#[test] +fn const_and_owned_encode_same() { + const R: r#const::TransactionEnvelope = const { tx_env_const() }; + let o: TransactionEnvelope = tx_env_owned(); + + let r_xdr: [u8; R.const_xdr_len()] = R.const_to_xdr(); + let o_xdr = o.to_xdr(Limits::none()).unwrap(); + assert_eq!(r_xdr, o_xdr.as_slice()); +} + +/// The same check over a value whose recursive arms nest several levels deep, +/// which is where the const form's `&'static` borrows stand in for the owned +/// form's `Box`. +#[test] +fn const_and_owned_encode_same_spec_entry() { + const R: r#const::ScSpecEntry = const { spec_entry_const() }; + let o: ScSpecEntry = spec_entry_owned(); + + let r_xdr: [u8; R.const_xdr_len()] = R.const_to_xdr(); + let o_xdr = o.to_xdr(Limits::none()).unwrap(); + assert_eq!(r_xdr, o_xdr.as_slice()); +} diff --git a/xdr-generator-rust/generator/const_header.rs b/xdr-generator-rust/generator/const_header.rs new file mode 100644 index 000000000..38cb526bc --- /dev/null +++ b/xdr-generator-rust/generator/const_header.rs @@ -0,0 +1,783 @@ +use core::{ops::Deref, slice}; + +use super::{pad_len, Error, ErrorLengthExceedsMax}; + +#[cfg(feature = "arbitrary")] +use arbitrary::Arbitrary; + +/// `padding` returns the zero bytes that pad an XDR value of the given length +/// out to a multiple of 4. The padding is never more than 3 bytes, so it is a +/// prefix of a single static. +const fn padding(len: usize) -> &'static [u8] { + const PADDING: [u8; 3] = [0; 3]; + PADDING.split_at(pad_len(len)).0 +} + +/// `ConstWriter` serializes XDR into a fixed byte buffer using only const +/// operations. +/// +/// It is the const-evaluable counterpart to [`super::WriteXdr::write_xdr`], +/// producing +/// the same bytes. Unlike the streaming path it enforces no depth or length +/// limits: a const value is fixed at compile time, so there is no untrusted +/// input to bound. +/// +/// The writers below are the primitives. Every type defined in the XDR files +/// additionally has a generated `write_type_{type}` method on `ConstWriter` +/// that serializes one value of that type, taking the type as this module +/// defines it; a type that appears wrapped gets `write_type_option_{type}` and +/// `write_type_vec_{type}` alongside. The `type_` distinguishes them from these primitives, so a +/// wrapper over a primitive is named `write_option_u32` rather than +/// `write_type_option_u32`. +/// +/// Keeping the encoders on the writer, rather than as inherent methods on each +/// generated type, leaves each type with only a thin `const_xdr_len` and +/// `const_to_xdr` pair that wraps its writer method. Each generated method is +/// emitted into the file of the type it serializes, so the two stay together. +/// +/// Serialization is infallible. The only way it can fail is a value whose +/// length does not fit the `u32` XDR length prefix, which panics; in a const +/// context that is a compile-time error. +/// +/// Bytes are only stored while the running length is within the buffer; bytes +/// past the end of the buffer are counted but not written. This allows the +/// exact encoded length to be measured by serializing into an empty buffer and +/// reading [`ConstWriter::len`], then serializing again into a buffer of that +/// size. +pub struct ConstWriter<'a> { + buf: &'a mut [u8], + len: usize, +} + +impl<'a> ConstWriter<'a> { + /// Constructs a new `ConstWriter` that serializes into `buf`. + #[must_use] + pub const fn new(buf: &'a mut [u8]) -> Self { + ConstWriter { buf, len: 0 } + } + + /// Returns the number of bytes serialized so far, which equals the total + /// encoded length once serialization completes (even if it exceeded the + /// buffer). + #[must_use] + pub const fn len(&self) -> usize { + self.len + } + + /// Returns true while nothing has been serialized yet. + #[must_use] + pub const fn is_empty(&self) -> bool { + self.len == 0 + } + + /// Writes `data` into the buffer, advancing the length. Bytes beyond the + /// end of the buffer are counted but not stored. + const fn write_bytes(&mut self, data: &[u8]) { + let mut i = 0; + while i < data.len() { + if self.len < self.buf.len() { + self.buf[self.len] = data[i]; + } + self.len += 1; + i += 1; + } + } + + /// Serializes an `i32`, mirroring `::write_xdr`. + pub const fn write_i32(&mut self, v: i32) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `u32`, mirroring `::write_xdr`. + pub const fn write_u32(&mut self, v: u32) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes an `i64`, mirroring `::write_xdr`. + pub const fn write_i64(&mut self, v: i64) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `u64`, mirroring `::write_xdr`. + pub const fn write_u64(&mut self, v: u64) { + self.write_bytes(&v.to_be_bytes()); + } + + /// Serializes a `bool`, mirroring `::write_xdr`. + pub const fn write_bool(&mut self, v: bool) { + let i = if v { 1u32 } else { 0u32 }; + self.write_u32(i); + } + + /// Serializes a fixed-length opaque array with trailing padding, mirroring + /// `<[u8; N] as WriteXdr>::write_xdr`. + pub const fn write_fixed_opaque(&mut self, data: &[u8]) { + self.write_bytes(data); + self.write_bytes(padding(data.len())); + } + + /// Serializes a `u32` length prefix from a `usize`, mirroring the + /// `len.try_into()` and `len.write_xdr(w)` of the variable-length + /// `WriteXdr` implementations. + /// + /// ### Panics + /// + /// If `len` does not fit in a `u32`. In a const context that is a + /// compile-time error. + #[allow(clippy::cast_possible_truncation)] + pub const fn write_len(&mut self, len: usize) { + assert!(len <= u32::MAX as usize, "xdr value max length exceeded"); + self.write_u32(len as u32); + } + + /// Serializes a variable-length opaque byte sequence: a `u32` length + /// prefix, the bytes, then trailing padding. Mirrors ` as + /// WriteXdr>::write_xdr`, `::write_xdr`, and `::write_xdr`, which XDR encodes identically. + pub const fn write_var_opaque(&mut self, data: &[u8]) { + let n = data.len(); + self.write_len(n); + self.write_bytes(data); + self.write_bytes(padding(n)); + } + + // The `Option` and `VecM` serializers below are the ones whose inner type + // is a builtin scalar. They are written by hand, beside the scalar + // serializers they call, because they have no generated type to sit with: + // the generator emits a wrapper into the file of the type it wraps, and a + // scalar has no file. Wrappers over `opaque`, `string` and defined types + // are still generated. + + /// Serializes an optional `i32`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_i32(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_i32(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `u32`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_u32(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_u32(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `i64`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_i64(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_i64(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `u64`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_u64(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_u64(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes an optional `bool`, mirroring ` as + /// WriteXdr>::write_xdr`. + pub const fn write_option_bool(&mut self, v: &Option) { + match v { + Some(v) => { + self.write_u32(1); + self.write_bool(*v); + } + None => { + self.write_u32(0); + } + } + } + + /// Serializes a variable-length array of `i32`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_i32(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_i32(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `u32`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_u32(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_u32(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `i64`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_i64(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_i64(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `u64`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_u64(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_u64(s[i]); + i += 1; + } + } + + /// Serializes a variable-length array of `bool`, mirroring ` + /// as WriteXdr>::write_xdr`. + pub const fn write_vec_bool(&mut self, v: &VecM) { + let s = v.as_slice(); + let len = s.len(); + self.write_len(len); + let mut i = 0usize; + while i < len { + self.write_bool(s[i]); + i += 1; + } + } +} + +/// A borrowing equivalent of [`super::VecM`] that wraps a slice instead of owning a +/// `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays, without heap allocation. +#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct VecM(&'static [T]); + +// Copy and Clone are implemented manually because the derived impls would +// require `T: Copy`/`T: Clone`, and the wrapped `&[T]` is copyable for any +// `T`. +impl Copy for VecM {} + +#[allow(clippy::expl_impl_clone_on_copy)] +impl Clone for VecM { + fn clone(&self) -> Self { + *self + } +} + +impl Deref for VecM { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for VecM { + fn default() -> Self { + Self(&[]) + } +} + +impl VecM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `VecM` from the given slice, erroring if the length of + /// the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [T]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `VecM` from the given slice, panicking if the length of + /// the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [T]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [T] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn iter(&self) -> slice::Iter<'static, T> { + self.0.iter() + } +} + +impl core::iter::IntoIterator for &VecM { + type Item = &'static T; + type IntoIter = slice::Iter<'static, T>; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl TryFrom<&'static [T]> for VecM { + type Error = Error; + + fn try_from(v: &'static [T]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +/// A borrowing equivalent of [`super::BytesM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct BytesM(&'static [u8]); + +impl core::fmt::Display for BytesM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in self.0 { + write!(f, "{b:02x}")?; + } + Ok(()) + } +} + +impl core::fmt::Debug for BytesM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "BytesM(")?; + for b in self.0 { + write!(f, "{b:02x}")?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for BytesM { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for BytesM { + fn default() -> Self { + Self(&[]) + } +} + +impl BytesM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `BytesM` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `BytesM` from the given slice, panicking if the length + /// of the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [u8]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl TryFrom<&'static [u8]> for BytesM { + type Error = Error; + + fn try_from(v: &'static [u8]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +/// A borrowing equivalent of [`super::StringM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of this module's types from slices +/// of fixed-size arrays or string literals, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StringM(&'static [u8]); + +impl core::fmt::Display for StringM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + Ok(()) + } +} + +impl core::fmt::Debug for StringM { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "StringM(")?; + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for StringM { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for StringM { + fn default() -> Self { + Self(&[]) + } +} + +impl StringM { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `StringM` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_from_slice(v: &'static [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(ErrorLengthExceedsMax) + } + } + + /// Constructs a `StringM` from the given slice, panicking if the length + /// of the slice exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length slice is a compile-time + /// error. Prefer [`Self::try_from_slice`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the slice exceeds `MAX`. + #[must_use] + pub const fn try_from_slice_or_panic(v: &'static [u8]) -> Self { + match Self::try_from_slice(v) { + Ok(r) => r, + Err(ErrorLengthExceedsMax) => panic!("xdr value max length exceeded"), + } + } + + /// Constructs a `StringM` from the UTF-8 bytes of the given str, + /// erroring if the length of the str exceeds `MAX`. + /// + /// The error is [`ErrorLengthExceedsMax`] rather than [`Error`] so the result + /// can be matched in a const context; use `?` to convert it to [`Error`]. + /// + /// ### Errors + /// + /// If the length of the str exceeds `MAX`. + pub const fn try_from_str(s: &'static str) -> Result { + Self::try_from_slice(s.as_bytes()) + } + + /// Constructs a `StringM` from the UTF-8 bytes of the given str, + /// panicking if the length of the str exceeds `MAX`. + /// + /// Usable in const contexts, where an over-length str is a compile-time + /// error. Prefer [`Self::try_from_str`] where a [`Result`] is wanted. + /// + /// ### Panics + /// + /// If the length of the str exceeds `MAX`. + #[must_use] + pub const fn try_from_str_or_panic(s: &'static str) -> Self { + Self::try_from_slice_or_panic(s.as_bytes()) + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'static [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl TryFrom<&'static [u8]> for StringM { + type Error = Error; + + fn try_from(v: &'static [u8]) -> Result { + Ok(Self::try_from_slice(v)?) + } +} + +impl TryFrom<&'static str> for StringM { + type Error = Error; + + fn try_from(s: &'static str) -> Result { + Ok(Self::try_from_str(s)?) + } +} + +/// `Arbitrary` support for the const types, mirroring the owned types byte for +/// byte. +/// +/// Each impl below delegates to the `Arbitrary` impl of the owned field the +/// const type replaces — `VecM` to `Vec`, `BytesM` and `StringM` to +/// `Vec`, a `&'static T` recursive reference to `Box` — and then leaks +/// the result to obtain the `'static` data the const types hold. Consuming the +/// same bytes in the same order as the owned type is what makes a matched pair +/// possible: driving [`arbitrary::Arbitrary`] for an owned type and for its +/// const counterpart from the same input produces the same value in both +/// forms, without any conversion between them. +/// +/// Leaking is why this is behind the `arbitrary` feature, which exists for +/// fuzzing and testing: every value built this way holds its memory for the +/// life of the process. A bounded number of values, as in a test or a fuzz +/// target that caps its iterations, is fine; an unbounded fuzzing run grows +/// without limit. +#[cfg(feature = "arbitrary")] +mod arbitrary_impls { + use super::{BytesM, StringM, VecM}; + use crate::generated::arbitrary_max_len; + use arbitrary::{Arbitrary, Result, Unstructured}; + + /// Builds an arbitrary `T` behind a `&'static` reference, mirroring + /// `Box`, for the recursive references the const types hold in place of + /// a `Box`. + /// + /// Named in the generated types by `#[arbitrary(with = ...)]`. + /// + /// ### Errors + /// + /// If the underlying `T` cannot be built from the remaining input. + pub fn arbitrary_ref<'a, T: Arbitrary<'a> + 'static>( + u: &mut Unstructured<'a>, + ) -> Result<&'static T> { + Ok(Box::leak(Box::new(T::arbitrary(u)?))) + } + + /// The [`arbitrary_ref`] equivalent for an optional recursive reference, + /// mirroring `Option>`. + /// + /// ### Errors + /// + /// If the underlying value cannot be built from the remaining input. + pub fn arbitrary_option_ref<'a, T: Arbitrary<'a> + 'static>( + u: &mut Unstructured<'a>, + ) -> Result> { + Ok(match Option::::arbitrary(u)? { + Some(v) => Some(Box::leak(Box::new(v))), + None => None, + }) + } + + impl<'a, T: Arbitrary<'a> + 'static, const MAX: u32> Arbitrary<'a> for VecM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + // Capped at MAX, and consuming the same bytes as the owned + // type's impl does, so both forms hold the same value. + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // The leak is required because the type holds a static lifetime + // reference to a slice. Even if the ref was not static but some + // other lifetime, the API does not provide any way to pass in an + // arena or similar memory management component to own the + // underlying memory. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } + + impl<'a, const MAX: u32> Arbitrary<'a> for BytesM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // Leaked for the same reason as VecM above. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } + + impl<'a, const MAX: u32> Arbitrary<'a> for StringM { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + let v = u + .arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + // Leaked for the same reason as VecM above. + Ok(Self(Vec::leak(v))) + } + + fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { + let v = u + .arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?; + Ok(Self(Vec::leak(v))) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } + } +} + +#[cfg(feature = "arbitrary")] +pub use arbitrary_impls::{arbitrary_option_ref, arbitrary_ref}; diff --git a/xdr-generator-rust/generator/header.rs b/xdr-generator-rust/generator/header.rs index efcaabb65..d02abecd4 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -166,6 +166,33 @@ impl fmt::Display for Error { } } +/// The error returned by the borrowing `Const` types' `try_from_slice` and +/// `try_from_str` constructors when the input length exceeds the type's `MAX`. +/// +/// Unlike [`Error`] it is `Copy` and free of any destructor, so a +/// `Result<_, ErrorLengthExceedsMax>` can be matched in a const context (a +/// `Result<_, Error>` cannot, because `Error` owns fields that have +/// destructors). It converts into [`Error::LengthExceedsMax`] via [`From`], so +/// runtime callers can still propagate it with `?`. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct ErrorLengthExceedsMax; + +impl From for Error { + #[must_use] + fn from(_: ErrorLengthExceedsMax) -> Self { + Error::LengthExceedsMax + } +} + +impl fmt::Display for ErrorLengthExceedsMax { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "xdr value max length exceeded") + } +} + +#[cfg(feature = "std")] +impl error::Error for ErrorLengthExceedsMax {} + impl From for Error { fn from(_: TryFromSliceError) -> Error { Error::LengthMismatch @@ -426,7 +453,7 @@ impl Iterator for ReadXdrIter { Err(e) => return Some(Err(Error::Io(e))), // If there is data in the buf available for reading, continue. Ok([..]) => (), - }; + } // Read the buf into the type. let r = self.reader.with_limited_depth(|dlr| S::read_xdr(dlr)); match r { @@ -670,8 +697,8 @@ pub trait WriteXdr { /// `Pad_len` returns the number of bytes to pad an XDR value of the given /// length to make the final serialized size a multiple of 4. -#[cfg(feature = "std")] -fn pad_len(len: usize) -> usize { +#[cfg(any(feature = "std", feature = "const"))] +const fn pad_len(len: usize) -> usize { (4 - (len % 4)) % 4 } @@ -945,16 +972,57 @@ impl WriteXdr for [T; N] { serde_with::serde_as, derive(serde::Serialize, serde::Deserialize) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct VecM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct VecM(Vec) where T: 'static; +/// `MAX` as a length, saturating where `usize` is narrower than `u32`. +/// +/// Shared with the const types' `Arbitrary` impls, which must truncate exactly +/// as these do for the two forms to hold the same value. +#[cfg(feature = "arbitrary")] +pub(crate) const fn arbitrary_max_len(max: u32) -> usize { + if max as u64 > usize::MAX as u64 { + usize::MAX + } else { + max as usize + } +} + +/// The length limit is an invariant of the type, and a derived impl would +/// produce values outside it, because `MAX` lives in a const parameter the +/// derive cannot see. +/// +/// `Vec`'s own impl reads a continuation byte before each element, so capping +/// the iterator stops at `MAX` without reading, and then discarding, the +/// elements past it. +#[cfg(feature = "arbitrary")] +impl<'a, T: Arbitrary<'a>, const MAX: u32> Arbitrary<'a> for VecM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl Deref for VecM { type Target = Vec; @@ -1476,14 +1544,36 @@ impl WriteXdr for VecM { feature = "serde", derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct BytesM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct BytesM(Vec); +/// Length limited to `MAX`, as for [`VecM`]. +#[cfg(feature = "arbitrary")] +impl<'a, const MAX: u32> Arbitrary<'a> for BytesM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl core::fmt::Display for BytesM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] @@ -1891,14 +1981,37 @@ impl WriteXdr for BytesM { feature = "serde", derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); #[cfg(not(feature = "alloc"))] #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub struct StringM(Vec); +/// Length limited to `MAX`, as for [`VecM`]. The type holds +/// arbitrary bytes rather than UTF-8, so truncating cannot split a character. +#[cfg(feature = "arbitrary")] +impl<'a, const MAX: u32> Arbitrary<'a> for StringM { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self( + u.arbitrary_take_rest_iter()? + .take(arbitrary_max_len(MAX)) + .collect::>>()?, + )) + } + + fn size_hint(depth: usize) -> (usize, Option) { + Vec::::size_hint(depth) + } +} + impl core::fmt::Display for StringM { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(feature = "alloc")] diff --git a/xdr-generator-rust/generator/src/const_writer.rs b/xdr-generator-rust/generator/src/const_writer.rs new file mode 100644 index 000000000..cf85b8e0a --- /dev/null +++ b/xdr-generator-rust/generator/src/const_writer.rs @@ -0,0 +1,545 @@ +//! Emission of const XDR serialization as inherent methods on `ConstWriter`. +//! +//! Every type defined in the `.x` files gets one +//! `ConstWriter::write_type_{type}` method that serializes a value of that +//! type, instead of each type gaining a `const_write_xdr` of its own. A type +//! that appears inside an `Option` or a `VecM` gets a +//! `write_type_option_{type}` or `write_type_vec_{type}` method alongside, +//! since each wrapped form is a distinct Rust type and const evaluation offers +//! no generic dispatch to share one encoder between them. +//! +//! The `type_` marks a type from the `.x` files, distinguishing these from the +//! primitive writers (`write_u32`, `write_var_opaque`, and so on) that +//! `ConstWriter` defines by hand. A wrapper over a primitive is likewise not a +//! defined type, so it is named `write_option_u32` rather than +//! `write_type_option_u32`. +//! +//! Keeping the encoders on the writer leaves each type with only the thin +//! `const_xdr_len`/`const_to_xdr` pair that wraps its writer method. Each +//! method is still emitted into the file of the type it serializes, so a type +//! and its encoder stay together; the only exception is a wrapper over a +//! builtin scalar, which has no type file and so goes into the `const_writer` +//! module. +//! +//! This module decides what each method does: which writer method serializes +//! each value, how the value is passed, and what wrappers are needed. It emits +//! that as data ([`ConstWriterMethodOutput`]) and the +//! `const_writer_impl.rs.jinja` template renders it as Rust. The rendered code +//! produces the same bytes as the trait-based `WriteXdr::write_xdr` +//! implementations of the owned types, expressed with only const-compatible +//! operations: `while` loops instead of `for`, and direct calls to each +//! concrete type's writer method instead of trait dispatch. + +use std::collections::{BTreeMap, HashMap}; + +use heck::ToSnakeCase; +use xdr_parser::ast::{CfgExpr, Definition, Type, Union, UnionArm, XdrSpec}; +use xdr_parser::types::{is_builtin_type, TypeInfo}; + +use crate::naming::{case_value, field_name, mod_name, type_name}; +use crate::output::{ + ConstDocName, ConstEncode, ConstLoop, ConstPass, ConstSubject, ConstUnionArm, ConstWriterBody, + ConstWriterMethodOutput, ConstWriterOutput, +}; +use crate::types::{const_base_type, const_type, type_ref}; + +/// Build the `ConstWriter` methods for an entire spec. +/// +/// `cfg_by_name` maps a Rust type name to the cfg it is gated by, cleared to +/// `None` where the same name appears in several `#ifdef` branches and so is +/// always present. +pub(crate) fn build( + spec: &XdrSpec, + type_info: &TypeInfo, + cfg_by_name: &HashMap>, +) -> ConstWriterOutput { + let mut c = Collector { + type_info, + cfg_by_name, + wrappers: BTreeMap::new(), + }; + + // One method per definition rather than per name: where the same type name + // appears in several `#ifdef` branches each branch gets its own method, + // carrying that branch's cfg, so only one is ever compiled. + let mut methods: Vec = Vec::new(); + for def in spec.all_definitions() { + if let Some(m) = c.definition_method(def) { + methods.push(m); + } + } + + // Wrapper methods are collected while walking the definitions above, so + // they are appended after. Sorted by name for a stable output. + methods.extend(c.wrappers.into_values()); + + ConstWriterOutput { methods } +} + +struct Collector<'a> { + type_info: &'a TypeInfo, + cfg_by_name: &'a HashMap>, + /// Wrapper (`Option`/`VecM`) methods needed, keyed by method name. + wrappers: BTreeMap, +} + +impl Collector<'_> { + /// The loop index name at `depth` loops deep. Unsuffixed at the outermost + /// loop, which is all this spec needs; a nested loop is suffixed so its + /// index cannot shadow the one it sits inside. + fn index_name(depth: u32) -> String { + if depth == 0 { + "i".to_string() + } else { + format!("i{depth}") + } + } + + /// The cfg gating a Rust type name, if any. + fn cfg_of(&self, name: &str) -> Option { + self.cfg_by_name.get(name).cloned().flatten() + } + + /// The `type_` name marker for a wrapped type: present where the type is + /// defined in the `.x` files, absent where it is a primitive, so a wrapper + /// over a primitive reads like the primitive writers it sits beside. + fn type_marker(&self, type_: &Type) -> &'static str { + if self.owner_module(type_).is_some() { + "type_" + } else { + "" + } + } + + /// The module a wrapper method belongs in: the one holding the type it + /// wraps, found by digging to the innermost named type. + /// + /// `None` for a wrapper over a builtin scalar, which has no type of its own + /// and so no file to live in. + fn owner_module(&self, type_: &Type) -> Option { + match type_ { + Type::Ident(name) => { + if self.type_info.resolve_typedef_to_builtin(type_).is_some() { + None + } else { + Some(mod_name(name)) + } + } + Type::Optional(inner) + | Type::Array { + element_type: inner, + .. + } => self.owner_module(inner), + Type::VarArray { element_type, .. } => self.owner_module(element_type), + _ => None, + } + } + + /// The method-name suffix for an XDR type, e.g. `transaction_envelope`, + /// `option_account_id`, `vec_operation`. + fn suffix(&self, type_: &Type) -> String { + match type_ { + Type::Int => "i32".to_string(), + Type::UnsignedInt => "u32".to_string(), + Type::Hyper => "i64".to_string(), + Type::UnsignedHyper => "u64".to_string(), + Type::Bool => "bool".to_string(), + // Stellar XDR uses no float or double types, so `ConstWriter` has + // no serializer for them (the streaming `WriteXdr` for f32/f64 is + // likewise unimplemented). Fail at generation time rather than + // emit a call to a method that does not exist. + Type::Float | Type::Double => { + unimplemented!("const XDR serialization of float and double is not supported") + } + Type::OpaqueFixed(_) => "opaque_fixed".to_string(), + Type::OpaqueVar(_) => "opaque_var".to_string(), + Type::String(_) => "string".to_string(), + Type::Ident(name) => { + // A typedef of a builtin scalar is a transparent Rust alias, so + // it shares the underlying scalar's name rather than getting a + // duplicate method of its own. + if let Some(builtin) = self.type_info.resolve_typedef_to_builtin(type_) { + self.suffix(builtin) + } else { + type_name(name).to_snake_case() + } + } + Type::Optional(inner) => format!("option_{}", self.suffix(inner)), + Type::Array { element_type, .. } => format!("array_{}", self.suffix(element_type)), + Type::VarArray { element_type, .. } => format!("vec_{}", self.suffix(element_type)), + } + } + + /// The call that serializes `acc`, a value of `type_`. + /// + /// `acc` is either a place expression (`is_ref == false`, e.g. `v.foo` or + /// `s[i]`) or an identifier already bound to a reference (`is_ref == true`, + /// e.g. the binding of a `match` arm). `parent` is the type being + /// serialized, which decides whether a cyclic reference is wrapped. + /// + /// `depth` is how many loops enclose the code being emitted, which names + /// the loop indices. Each generated method is its own scope, so a method + /// starts at zero however deep the code that needed it sits. + fn encode( + &mut self, + type_: &Type, + acc: &str, + is_ref: bool, + parent: Option<&str>, + depth: u32, + ) -> ConstEncode { + let call = |method: &str, pass: ConstPass| ConstEncode { + loops: Vec::new(), + acc: acc.to_string(), + is_ref, + method: method.to_string(), + pass, + }; + match type_ { + Type::Int => call("write_i32", ConstPass::Value), + Type::UnsignedInt => call("write_u32", ConstPass::Value), + Type::Hyper => call("write_i64", ConstPass::Value), + Type::UnsignedHyper => call("write_u64", ConstPass::Value), + Type::Bool => call("write_bool", ConstPass::Value), + Type::Float | Type::Double => { + unimplemented!("const XDR serialization of float and double is not supported") + } + Type::OpaqueFixed(_) => call("write_fixed_opaque", ConstPass::Ref), + // The variable-length byte cases only ever occur inside a const + // type, where the value is the `const` module's borrowing `BytesM` + // or `StringM`, each of which exposes a const `as_slice`. + Type::OpaqueVar(_) | Type::String(_) => call("write_var_opaque", ConstPass::Slice), + Type::Ident(_) => { + if let Some(builtin) = self.type_info.resolve_typedef_to_builtin(type_) { + let builtin = builtin.clone(); + return self.encode(&builtin, acc, is_ref, parent, depth); + } + // Where the ident is cyclic with `parent`, its const form is + // already a reference to the value, so it is passed along + // as-is rather than borrowed again; a `match` binding of one is + // a double reference that auto-deref resolves at the call. + let const_ty = const_type(type_, parent, self.type_info); + let pass = if const_ty.starts_with('&') { + ConstPass::AsIs + } else { + ConstPass::Ref + }; + call(&format!("write_type_{}", self.suffix(type_)), pass) + } + Type::Optional(_) => { + let (name, by_value) = self.need_option(type_, parent); + let pass = if by_value { + ConstPass::Value + } else { + ConstPass::Ref + }; + call(&name, pass) + } + Type::VarArray { .. } => { + let name = self.need_vec(type_); + call(&name, ConstPass::Ref) + } + // A fixed array is a plain `[T; N]` in both the owned and const + // forms, so it is walked inline rather than given a method: there + // is no wrapper type to name one after. + Type::Array { element_type, size } => { + let index = Self::index_name(depth); + let element_type = element_type.clone(); + let elem_acc = format!("{acc}[{index}]"); + // A container holds its elements by value, so an element is + // never a cyclic reference back to the enclosing type. + let mut elem = self.encode(&element_type, &elem_acc, false, None, depth + 1); + elem.loops.insert( + 0, + ConstLoop { + index, + len: self.type_info.size_to_literal(size), + }, + ); + elem + } + } + } + + /// Register (if new) and name the method serializing an `Option` type. + fn need_option(&mut self, type_: &Type, parent: Option<&str>) -> (String, bool) { + let Type::Optional(inner) = type_ else { + unreachable!("need_option called with a non-optional type") + }; + let param = const_type(type_, parent, self.type_info); + // Where the option is cyclic the const form holds a reference to the + // inner value rather than the value itself, which is a different Rust + // type and so needs a method of its own. Such an option is a pair of + // `Copy` words, so it is taken by value rather than by reference. + let by_value = param.starts_with("Option<&"); + let marker = if by_value { "option_ref_" } else { "option_" }; + let name = format!( + "write_{}{marker}{}", + self.type_marker(inner), + self.suffix(inner) + ); + + // A wrapper over a builtin scalar is written by hand on `ConstWriter`, + // beside the scalar serializer it calls, so it is named but not + // generated. + let Some(module) = self.owner_module(inner) else { + assert_hand_written(&name); + return (name, by_value); + }; + + if !self.wrappers.contains_key(&name) { + let inner_encode = self.encode(inner, "v", true, parent, 0); + self.wrappers.insert( + name.clone(), + ConstWriterMethodOutput { + name: name.clone(), + generics: String::new(), + param_type: if by_value { + param.clone() + } else { + format!("&{param}") + }, + cfg: self.wrapper_cfg(inner), + module, + subject: ConstSubject::Option { + inner: self.doc_name(inner), + owned: type_ref(type_, parent, self.type_info), + }, + body: ConstWriterBody::Option(inner_encode), + }, + ); + } + (name, by_value) + } + + /// Register (if new) and name the method serializing a `VecM` type. + fn need_vec(&mut self, type_: &Type) -> String { + let Type::VarArray { element_type, .. } = type_ else { + unreachable!("need_vec called with a non-var-array type") + }; + let name = format!( + "write_{}vec_{}", + self.type_marker(element_type), + self.suffix(element_type) + ); + + // As for options, a wrapper over a builtin scalar is hand-written. + let Some(module) = self.owner_module(element_type) else { + assert_hand_written(&name); + return name; + }; + + if !self.wrappers.contains_key(&name) { + let element_type = element_type.clone(); + // `VecM` borrows its elements as one slice, so each element is + // held by value and is never a cyclic reference. + let elem = self.encode(&element_type, "s[i]", false, None, 1); + // The max length is a const parameter rather than a fixed size, so + // one method serves every `VecM` of this element type whatever its + // declared maximum. + let elem_ty = const_base_type(&element_type, self.type_info); + self.wrappers.insert( + name.clone(), + ConstWriterMethodOutput { + name: name.clone(), + generics: "".to_string(), + param_type: format!("&VecM<{elem_ty}, MAX>"), + cfg: self.wrapper_cfg(&element_type), + module, + subject: ConstSubject::Vec { + inner: self.doc_name(&element_type), + elem: type_ref(&element_type, None, self.type_info), + }, + body: ConstWriterBody::Vec(elem), + }, + ); + } + name + } + + /// The cfg a wrapper method needs: the one gating the type it names in its + /// signature, so the method is present exactly where that type is. + fn wrapper_cfg(&self, inner: &Type) -> Option { + match inner { + Type::Ident(name) => { + if self.type_info.resolve_typedef_to_builtin(inner).is_some() { + None + } else { + self.cfg_of(&type_name(name)) + } + } + Type::Optional(t) + | Type::Array { + element_type: t, .. + } => self.wrapper_cfg(t), + Type::VarArray { element_type, .. } => self.wrapper_cfg(element_type), + _ => None, + } + } + + /// How a type is named in a generated doc comment: a link for a type from + /// the `.x` files, plain code for a builtin. + fn doc_name(&self, type_: &Type) -> ConstDocName { + match type_ { + Type::Ident(name) if self.type_info.resolve_typedef_to_builtin(type_).is_none() => { + ConstDocName { + name: type_name(name), + link: true, + } + } + _ => ConstDocName { + name: type_ref(type_, None, self.type_info), + link: false, + }, + } + } + + /// The method serializing one definition, or `None` for definitions that + /// are not written (consts, and typedefs of builtin scalars, which are + /// transparent Rust aliases served by the underlying scalar's method). + fn definition_method(&mut self, def: &Definition) -> Option { + let name = type_name(def.name()); + let cfg = def.cfg().map(CfgExpr::render); + + let body = match def { + Definition::Const(_) => return None, + Definition::Typedef(t) if is_builtin_type(&t.type_) => return None, + Definition::Typedef(t) => { + ConstWriterBody::Struct(vec![self.encode(&t.type_, "v.0", false, None, 0)]) + } + Definition::Enum(_) => ConstWriterBody::Enum, + Definition::Struct(s) => { + let parent = name.clone(); + ConstWriterBody::Struct( + s.members + .iter() + .map(|m| { + let acc = format!("v.{}", field_name(&m.name)); + self.encode(&m.type_, &acc, false, Some(&parent), 0) + }) + .collect(), + ) + } + Definition::Union(u) => self.union_body(u, &name), + }; + + Some(ConstWriterMethodOutput { + name: format!("write_type_{}", name.to_snake_case()), + generics: String::new(), + // The method is emitted inside the `const` module, so the plain + // name is that module's form of the type: the borrowing one where + // the type owns heap data, an alias to the owned type otherwise. + param_type: format!("&{name}"), + cfg, + module: mod_name(def.name()), + subject: ConstSubject::Type(name), + body, + }) + } + + /// The body serializing a union: its discriminant, then the payload of the + /// selected arm. + fn union_body(&mut self, u: &Union, name: &str) -> ConstWriterBody { + let discriminant_type = type_ref(&u.discriminant.type_, None, self.type_info); + let discriminant_is_builtin = is_builtin_type(&u.discriminant.type_) + || matches!(&u.discriminant.type_, Type::Ident(n) if { + self.type_info.definitions.get(&type_name(n)) + .is_some_and(|d| matches!(d, Definition::Typedef(t) if is_builtin_type(&t.type_))) + }); + let prefix = if discriminant_is_builtin { + String::new() + } else { + self.type_info + .discriminant_enum(&u.discriminant.type_) + .map(|e| e.member_prefix.clone()) + .unwrap_or_default() + }; + + // Both the owned and const forms expose a const `discriminant`, so the + // body mirrors the owned type's `write_xdr`. + let discriminant = self.encode(&u.discriminant.type_, "d", false, None, 0); + + // As for the parameter type, the plain name is the `const` module's + // form of the union, which is the type the parameter holds. + let scrutinee = name.to_string(); + + let arms = u + .arms + .iter() + .flat_map(|arm| { + self.union_arms( + arm, + name, + &discriminant_type, + discriminant_is_builtin, + &prefix, + ) + }) + .collect(); + + ConstWriterBody::Union { + scrutinee, + discriminant, + arms, + } + } + + /// The match arms for one union arm, one per case value it covers. + fn union_arms( + &mut self, + arm: &UnionArm, + parent: &str, + discriminant_type: &str, + discriminant_is_builtin: bool, + prefix: &str, + ) -> Vec { + arm.cases + .iter() + .map(|case| { + let (case_name, _) = case_value( + discriminant_type, + discriminant_is_builtin, + &case.value, + prefix, + ); + ConstUnionArm { + cfg: arm.cfg.as_ref().map(CfgExpr::render), + case_name, + payload: arm + .type_ + .as_ref() + .map(|t| self.encode(t, "value", true, Some(parent), 0)), + } + }) + .collect() + } +} + +/// Check that a wrapper over a builtin scalar is one `ConstWriter` defines by +/// hand. +/// +/// The hand-written set covers the scalars `ConstWriter` can serialize. A +/// wrapper over `opaque`, `string` or a fixed array would also have no file to +/// live in, and the XDR has never needed one; fail at generation time rather +/// than emit a call to a method that does not exist. +fn assert_hand_written(name: &str) { + const HAND_WRITTEN: &[&str] = &[ + "write_option_i32", + "write_option_u32", + "write_option_i64", + "write_option_u64", + "write_option_bool", + "write_vec_i32", + "write_vec_u32", + "write_vec_i64", + "write_vec_u64", + "write_vec_bool", + ]; + assert!( + HAND_WRITTEN.contains(&name), + "`{name}` wraps a builtin scalar, so it has no generated file to live \ + in, but `ConstWriter` does not define it. Write it by hand in \ + xdr-generator-rust/generator/const_header.rs beside the other \ + `write_option_`/`write_vec_` methods." + ); +} diff --git a/xdr-generator-rust/generator/src/generator.rs b/xdr-generator-rust/generator/src/generator.rs index 9613214e7..b2e3c7a38 100644 --- a/xdr-generator-rust/generator/src/generator.rs +++ b/xdr-generator-rust/generator/src/generator.rs @@ -1,9 +1,10 @@ +use heck::ToSnakeCase; use std::collections::hash_map::Entry; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use askama::Template; use xdr_parser::ast::{ - Const, Definition, Enum, Struct, StructMember, Typedef, Union, UnionArm, XdrSpec, + Const, Definition, Enum, Struct, StructMember, Type, Typedef, Union, UnionArm, XdrSpec, }; use xdr_parser::lexer::IntBase; use xdr_parser::types::{is_builtin_type, is_fixed_array, is_fixed_opaque, is_var_array, TypeInfo}; @@ -13,22 +14,35 @@ use crate::naming::{ }; use crate::options::RustOptions; use crate::output::{ - ConstOutput, DefinitionOutput, DefinitionTemplate, EnumOutput, EnumStructMemberOutput, - ModTemplate, ModuleEntry, StructMemberOutput, StructOutput, TypeEnumDefinitionTemplate, - TypeEnumEntry, TypeEnumOutput, TypedefAliasOutput, TypedefNewtypeOutput, UnionArmOutput, - UnionOutput, + ConstDefinitionOutput, ConstDefinitionTemplate, ConstModEntry, ConstModItem, ConstModTemplate, + ConstNewtypeOutput, ConstOutput, ConstStructMemberOutput, ConstStructOutput, + ConstToXdrTemplate, ConstTypeOutput, ConstUnionArmOutput, ConstUnionOutput, + ConstWriterMethodOutput, ConstWriterOutput, DefinitionOutput, DefinitionTemplate, EnumOutput, + EnumStructMemberOutput, ModTemplate, ModuleEntry, StructMemberOutput, StructOutput, + TypeEnumDefinitionTemplate, TypeEnumEntry, TypeEnumOutput, TypedefAliasOutput, + TypedefNewtypeOutput, UnionArmOutput, UnionOutput, }; -use crate::types::{base_type_ref, resolve_type, size_to_u32_string, type_ref}; +use crate::types::{base_type_ref, const_type, resolve_type, size_to_u32_string, type_ref}; pub struct RustGenerator { options: RustOptions, type_info: TypeInfo, + /// Rust type names of generated types that directly or transitively + /// contain heap-allocated data (`VecM`, `BytesM`, `StringM`, or `Box` for + /// cyclic references) under some cfg, and therefore have a borrowing form + /// of their own in the `const` module. + const_required: HashSet, } impl RustGenerator { pub fn new(spec: &XdrSpec, options: RustOptions) -> Self { let type_info = TypeInfo::build(spec, &type_name); - Self { options, type_info } + let const_required = BorrowAnalysis::build(spec).const_required(); + Self { + options, + type_info, + const_required, + } } /// Generate Rust code from the spec and write each definition to its own @@ -39,8 +53,9 @@ impl RustGenerator { module_file: &std::path::Path, output_dir: &std::path::Path, ) -> Result<(), Box> { - // Ensure the output directory exists. + // Ensure the output directories exist. std::fs::create_dir_all(output_dir)?; + std::fs::create_dir_all(output_dir.join("const"))?; self.generate_files(spec, module_file, output_dir, |path, contents| { std::fs::write(path, contents) @@ -60,7 +75,22 @@ impl RustGenerator { mut write: impl FnMut(&std::path::Path, &str) -> std::io::Result<()>, ) -> Result<(), Box> { let header = include_str!("../header.rs"); - let (mut modules, definitions) = self.generate_modules(spec); + let const_header = include_str!("../const_header.rs"); + let (mut modules, definitions, const_modules) = self.generate_modules(spec); + let const_dir = output_dir.join("const"); + + // All const XDR encoding is emitted as methods on `ConstWriter`, each + // into the `const` module's file for the type it serializes, so no + // owned type carries const surface of its own. + let mut const_methods_by_module: HashMap> = + HashMap::new(); + for m in crate::const_writer::build(spec, &self.type_info, &self.cfg_by_name(spec)).methods + { + const_methods_by_module + .entry(m.module.clone()) + .or_default() + .push(m); + } // Write each definition (or group of definitions) to its own file. for (module, defs) in modules.iter().zip(definitions) { @@ -70,6 +100,45 @@ impl RustGenerator { write(&file_path, &rendered)?; } + // Write the `const` module: a file per definition module that has const + // content, and a module file naming them and re-exporting the rest. + let mut const_entries: Vec = Vec::new(); + for const_module in const_modules { + let methods = const_methods_by_module + .remove(&const_module.mod_name) + .unwrap_or_default(); + let has_file = !const_module.definitions.is_empty() || !methods.is_empty(); + if has_file { + let template = ConstDefinitionTemplate { + definitions: const_module.definitions, + const_writer: ConstWriterOutput { methods }, + }; + let rendered = template.render()?; + let file_path = const_dir.join(format!("{}.rs", const_module.mod_name)); + write(&file_path, &rendered)?; + } + const_entries.push(ConstModEntry { + mod_name: has_file.then_some(const_module.mod_name), + items: const_module.items, + }); + } + + // Every method names the module of the type it serializes, and every + // definition is grouped into a file under that same name, so the loop + // above has placed them all. + assert!( + const_methods_by_module.is_empty(), + "const writer methods name modules with no definition file: {:?}", + const_methods_by_module.keys().collect::>() + ); + + let const_mod_template = ConstModTemplate { + header: const_header.to_string(), + entries: const_entries, + }; + let rendered = const_mod_template.render()?; + write(&output_dir.join("const.rs"), &rendered)?; + let type_variant_enum = self.generate_type_enum(spec); let type_enum_template = TypeEnumDefinitionTemplate { type_variant_enum }; let rendered = type_enum_template.render()?; @@ -96,13 +165,49 @@ impl RustGenerator { Ok(()) } - /// Generate module entries and grouped definitions for per-file output. + /// Map each Rust type name to the cfg gating it. + /// + /// A name appearing in several `#ifdef` branches is always present, so its + /// cfg is cleared. + fn cfg_by_name(&self, spec: &XdrSpec) -> HashMap> { + let mut cfg_by_name: HashMap> = HashMap::new(); + for def in spec.all_definitions() { + if matches!(def, Definition::Const(_)) { + continue; + } + let name = type_name(def.name()); + let cfg = self.resolve_cfg(def); + match cfg_by_name.entry(name) { + Entry::Vacant(e) => { + e.insert(cfg); + } + Entry::Occupied(mut e) => { + e.insert(None); + } + } + } + cfg_by_name + } + + /// Generate module entries and grouped definitions for per-file output, + /// for the owned types and for the `const` module alike. /// /// When the same type name appears in multiple `#ifdef`/`#else` branches, /// definitions are grouped into the same file. - fn generate_modules(&self, spec: &XdrSpec) -> (Vec, Vec>) { + fn generate_modules( + &self, + spec: &XdrSpec, + ) -> ( + Vec, + Vec>, + Vec, + ) { let mut order: Vec = Vec::new(); let mut grouped: HashMap> = HashMap::new(); + let mut grouped_const: HashMap> = HashMap::new(); + // The names each module defines, in order, with the cfg of each + // definition of that name, to build the `const` module's re-exports. + let mut names: HashMap)>> = HashMap::new(); for def in spec.all_definitions() { let m = match def { @@ -110,27 +215,87 @@ impl RustGenerator { _ => mod_name(def.name()), }; - let output = self.generate_definition(def); + let (output, const_output) = self.generate_definition(def); match grouped.entry(m.clone()) { Entry::Vacant(e) => { - order.push(m); + order.push(m.clone()); e.insert(vec![output]); } Entry::Occupied(mut e) => { e.get_mut().push(output); } } + // A definition with neither a type of its own nor an encoding + // contributes nothing to its file. + if const_output.type_def.is_some() || !const_output.const_to_xdr.is_empty() { + grouped_const + .entry(m.clone()) + .or_default() + .push(const_output); + } + names + .entry(m) + .or_default() + .push((self.const_name_of(def), self.resolve_cfg(def))); } let mut modules = Vec::new(); let mut definitions = Vec::new(); + let mut const_modules = Vec::new(); for m in order { let defs = grouped.remove(&m).unwrap(); - modules.push(ModuleEntry { mod_name: m }); + let const_defs = grouped_const.remove(&m).unwrap_or_default(); + let items = Self::const_mod_items(&names.remove(&m).unwrap_or_default()); + modules.push(ModuleEntry { + mod_name: m.clone(), + }); definitions.push(defs); + const_modules.push(ConstModuleOutput { + mod_name: m, + definitions: const_defs, + items, + }); } - (modules, definitions) + (modules, definitions, const_modules) + } + + /// How a definition is named in the `const` module, and whether it needs a + /// name of its own there. + fn const_name_of(&self, def: &Definition) -> ConstName { + if let Definition::Const(c) = def { + return ConstName::Reexported(const_name(&c.name)); + } + let name = type_name(def.name()); + if self.const_required.contains(&name) { + ConstName::Defined + } else { + ConstName::Reexported(name) + } + } + + /// The names a module contributes to the `const` module directly: the + /// types it defines that have no borrowing form there, and its XDR consts. + /// + /// A name defined in several `#ifdef` branches is present whatever the + /// configuration, so its alias carries no cfg. + fn const_mod_items(names: &[(ConstName, Option)]) -> Vec { + let mut items: Vec = Vec::new(); + for (name, cfg) in names { + let name = match name { + ConstName::Defined => continue, + ConstName::Reexported(n) => n, + }; + if let Some(existing) = items.iter_mut().find(|i| &i.name == name) { + existing.cfg = None; + } else { + items.push(ConstModItem { + name: name.clone(), + cfg: cfg.clone(), + }); + } + } + items } /// Generate the `TypeEnumOutput` for the type variant enum. @@ -168,6 +333,20 @@ impl RustGenerator { TypeEnumOutput { types } } + /// Render the `const_xdr_len`/`const_to_xdr` wrapper for a definition. + /// + /// The wrapper is emitted inside the `const` module and implemented on the + /// type as that module names it, matching the receiver the type's + /// `ConstWriter::write_type_*` method takes. + fn const_to_xdr(name: &str, cfg: Option<&str>) -> String { + let template = ConstToXdrTemplate { + recv: name.to_string(), + cfg: cfg.map(ToString::to_string), + write_fn: format!("write_type_{}", name.to_snake_case()), + }; + template.render().unwrap_or_default() + } + /// Resolve the cfg expression for a definition, rendered as a string. /// /// This is where additional cfg conditions (e.g. file-based cfg derived @@ -180,27 +359,47 @@ impl RustGenerator { def.cfg().map(xdr_parser::ast::CfgExpr::render) } - fn generate_definition(&self, def: &Definition) -> DefinitionOutput { + /// Generate a definition's owned output and its `const` module output. + fn generate_definition(&self, def: &Definition) -> (DefinitionOutput, ConstDefinitionOutput) { let cfg = self.resolve_cfg(def); match def { - Definition::Struct(s) => DefinitionOutput::Struct(self.generate_struct(s, cfg)), - Definition::Enum(e) => DefinitionOutput::Enum(self.generate_enum(e, cfg)), - Definition::Union(u) => DefinitionOutput::Union(self.generate_union(u, cfg)), + Definition::Struct(s) => { + let (o, c) = self.generate_struct(s, cfg); + (DefinitionOutput::Struct(o), c) + } + Definition::Enum(e) => { + let (o, c) = self.generate_enum(e, cfg); + (DefinitionOutput::Enum(o), c) + } + Definition::Union(u) => { + let (o, c) = self.generate_union(u, cfg); + (DefinitionOutput::Union(o), c) + } Definition::Typedef(t) => self.generate_typedef(t, cfg), - Definition::Const(c) => DefinitionOutput::Const(self.generate_const(c, cfg)), + Definition::Const(c) => ( + DefinitionOutput::Const(self.generate_const(c, cfg)), + ConstDefinitionOutput { + type_def: None, + const_to_xdr: String::new(), + }, + ), } } - fn generate_struct(&self, s: &Struct, cfg: Option) -> StructOutput { + fn generate_struct( + &self, + s: &Struct, + cfg: Option, + ) -> (StructOutput, ConstDefinitionOutput) { let name = type_name(&s.name); let custom_default = self.options.custom_default_impl.contains(&name); let custom_str = self.options.custom_str_impl.contains(&name); - let members: Vec = s + let (members, const_members): (Vec, Vec) = s .members .iter() .map(|m| self.generate_member(m, &name, custom_str)) - .collect(); + .unzip(); let member_names: String = members .iter() @@ -213,18 +412,32 @@ impl RustGenerator { } else { "Struct" }; - StructOutput { - name, - source_comment: source_comment(&s.source, type_kind), - has_default: !custom_default, - is_custom_str: custom_str, - members, - member_names, - cfg, - } + let const_output = ConstDefinitionOutput { + type_def: self.const_required.contains(&name).then(|| { + ConstTypeOutput::Struct(ConstStructOutput { + name: name.clone(), + cfg: cfg.clone(), + members: const_members, + }) + }), + const_to_xdr: Self::const_to_xdr(&name, cfg.as_deref()), + }; + + ( + StructOutput { + name, + source_comment: source_comment(&s.source, type_kind), + has_default: !custom_default, + is_custom_str: custom_str, + members, + member_names, + cfg, + }, + const_output, + ) } - fn generate_enum(&self, e: &Enum, cfg: Option) -> EnumOutput { + fn generate_enum(&self, e: &Enum, cfg: Option) -> (EnumOutput, ConstDefinitionOutput) { let name = type_name(&e.name); let custom_default = self.options.custom_default_impl.contains(&name); let custom_str = self.options.custom_str_impl.contains(&name); @@ -242,17 +455,31 @@ impl RustGenerator { }) .collect(); - EnumOutput { - name, - source_comment: source_comment(&e.source, "Enum"), - has_default: !custom_default, - is_custom_str: custom_str, - members, - cfg, - } + // An enum owns no heap data, so the `const` module aliases it rather + // than giving it a borrowing form. + let const_output = ConstDefinitionOutput { + type_def: None, + const_to_xdr: Self::const_to_xdr(&name, cfg.as_deref()), + }; + + ( + EnumOutput { + name, + source_comment: source_comment(&e.source, "Enum"), + has_default: !custom_default, + is_custom_str: custom_str, + members, + cfg, + }, + const_output, + ) } - fn generate_union(&self, u: &Union, cfg: Option) -> UnionOutput { + fn generate_union( + &self, + u: &Union, + cfg: Option, + ) -> (UnionOutput, ConstDefinitionOutput) { let name = type_name(&u.name); let custom_default = self.options.custom_default_impl.contains(&name); let custom_str = self.options.custom_str_impl.contains(&name); @@ -273,7 +500,7 @@ impl RustGenerator { .unwrap_or_default() }; - let arms: Vec = u + let (arms, const_arms): (Vec, Vec) = u .arms .iter() .flat_map(|arm| { @@ -286,7 +513,7 @@ impl RustGenerator { custom_str, ) }) - .collect(); + .unzip(); let type_kind = if u.is_nested { "NestedUnion" } else { "Union" }; let default_arm_cfg = u @@ -294,28 +521,55 @@ impl RustGenerator { .first() .and_then(|a| a.cfg.as_ref().map(xdr_parser::ast::CfgExpr::render)); - UnionOutput { - name, - source_comment: source_comment(&u.source, type_kind), - has_default: !custom_default, - is_custom_str: custom_str, - discriminant_type, - arms, - cfg, - default_arm_cfg, - } + let const_output = ConstDefinitionOutput { + type_def: self.const_required.contains(&name).then(|| { + ConstTypeOutput::Union(ConstUnionOutput { + name: name.clone(), + cfg: cfg.clone(), + discriminant_type: discriminant_type.clone(), + arms: const_arms, + }) + }), + const_to_xdr: Self::const_to_xdr(&name, cfg.as_deref()), + }; + + ( + UnionOutput { + name, + source_comment: source_comment(&u.source, type_kind), + has_default: !custom_default, + is_custom_str: custom_str, + discriminant_type, + arms, + cfg, + default_arm_cfg, + }, + const_output, + ) } - fn generate_typedef(&self, t: &Typedef, cfg: Option) -> DefinitionOutput { + fn generate_typedef( + &self, + t: &Typedef, + cfg: Option, + ) -> (DefinitionOutput, ConstDefinitionOutput) { let name = type_name(&t.name); if is_builtin_type(&t.type_) { - return DefinitionOutput::TypedefAlias(TypedefAliasOutput { - name, - source_comment: source_comment(&t.source, "Typedef"), - type_ref: base_type_ref(&t.type_, None), - cfg, - }); + // A transparent alias to a builtin is served by the builtin's own + // encoding, so it has none of its own. + return ( + DefinitionOutput::TypedefAlias(TypedefAliasOutput { + name, + source_comment: source_comment(&t.source, "Typedef"), + type_ref: base_type_ref(&t.type_, None), + cfg, + }), + ConstDefinitionOutput { + type_def: None, + const_to_xdr: String::new(), + }, + ); } let custom_default = self.options.custom_default_impl.contains(&name); @@ -333,24 +587,38 @@ impl RustGenerator { _ => None, }; - DefinitionOutput::TypedefNewtype(TypedefNewtypeOutput { - name, - source_comment: source_comment(&t.source, "Typedef"), - has_default: !custom_default, - is_var_array: is_var_array_type, - is_fixed_opaque: is_fixed_opaque_type, - is_fixed_array: is_fixed_array_type, - is_custom_str: custom_str, - type_ref: resolved.type_ref, - turbofish_type: resolved.turbofish_type, - serde_as_type: resolved.serde_as_type, - element_type: resolved.element_type, - size, - custom_debug: is_fixed_opaque_type, - custom_display_fromstr: is_fixed_opaque_type && !custom_str && !no_display_fromstr, - custom_schemars: is_fixed_opaque_type && !custom_str && !no_display_fromstr, - cfg, - }) + let const_output = ConstDefinitionOutput { + type_def: self.const_required.contains(&name).then(|| { + ConstTypeOutput::Newtype(ConstNewtypeOutput { + name: name.clone(), + cfg: cfg.clone(), + type_ref: const_type(&t.type_, None, &self.type_info), + }) + }), + const_to_xdr: Self::const_to_xdr(&name, cfg.as_deref()), + }; + + ( + DefinitionOutput::TypedefNewtype(TypedefNewtypeOutput { + name, + source_comment: source_comment(&t.source, "Typedef"), + has_default: !custom_default, + is_var_array: is_var_array_type, + is_fixed_opaque: is_fixed_opaque_type, + is_fixed_array: is_fixed_array_type, + is_custom_str: custom_str, + type_ref: resolved.type_ref, + turbofish_type: resolved.turbofish_type, + serde_as_type: resolved.serde_as_type, + element_type: resolved.element_type, + size, + custom_debug: is_fixed_opaque_type, + custom_display_fromstr: is_fixed_opaque_type && !custom_str && !no_display_fromstr, + custom_schemars: is_fixed_opaque_type && !custom_str && !no_display_fromstr, + cfg, + }), + const_output, + ) } // Takes &self for consistency with the other generate_* methods, which do @@ -375,18 +643,26 @@ impl RustGenerator { m: &StructMember, parent: &str, custom_str: bool, - ) -> StructMemberOutput { + ) -> (StructMemberOutput, ConstStructMemberOutput) { let name = field_name(&m.name); let serde_rename = field_json_rename(&m.name); let resolved = resolve_type(&m.type_, Some(parent), &self.type_info, custom_str); - - StructMemberOutput { - name, - type_ref: resolved.type_ref, - turbofish_type: resolved.turbofish_type, - serde_as_type: resolved.serde_as_type, - serde_rename, - } + let const_type = const_type(&m.type_, Some(parent), &self.type_info); + + ( + StructMemberOutput { + name: name.clone(), + type_ref: resolved.type_ref, + turbofish_type: resolved.turbofish_type, + serde_as_type: resolved.serde_as_type, + serde_rename, + }, + ConstStructMemberOutput { + arbitrary_with: const_arbitrary_with(&const_type), + name, + type_ref: const_type, + }, + ) } fn generate_union_arm( @@ -397,7 +673,7 @@ impl RustGenerator { discriminant_is_builtin: bool, discriminant_prefix: &str, custom_str: bool, - ) -> Vec { + ) -> Vec<(UnionArmOutput, ConstUnionArmOutput)> { arm.cases .iter() .map(|case| { @@ -412,17 +688,183 @@ impl RustGenerator { .type_ .as_ref() .map(|t| resolve_type(t, Some(parent), &self.type_info, custom_str)); - - UnionArmOutput { - case_name, - case_value: case_value_expr, - is_void: arm.type_.is_none(), - type_ref: resolved.as_ref().map(|r| r.type_ref.clone()), - turbofish_type: resolved.as_ref().map(|r| r.turbofish_type.clone()), - serde_as_type: resolved.and_then(|r| r.serde_as_type), - cfg: arm.cfg.as_ref().map(xdr_parser::ast::CfgExpr::render), - } + let const_type = arm + .type_ + .as_ref() + .map(|t| const_type(t, Some(parent), &self.type_info)); + let cfg = arm.cfg.as_ref().map(xdr_parser::ast::CfgExpr::render); + + ( + UnionArmOutput { + case_name: case_name.clone(), + case_value: case_value_expr.clone(), + is_void: arm.type_.is_none(), + type_ref: resolved.as_ref().map(|r| r.type_ref.clone()), + turbofish_type: resolved.as_ref().map(|r| r.turbofish_type.clone()), + serde_as_type: resolved.as_ref().and_then(|r| r.serde_as_type.clone()), + cfg: cfg.clone(), + }, + ConstUnionArmOutput { + case_name, + case_value: case_value_expr, + is_void: arm.type_.is_none(), + arbitrary_with: const_type.as_deref().and_then(const_arbitrary_with), + type_ref: const_type, + cfg, + }, + ) }) .collect() } } + +/// The `#[arbitrary(with = ...)]` a const field needs, if any. +/// +/// A const type stands in for an owned `Box` with a `&'static` reference, and +/// there is no `Arbitrary` impl for a reference to give the derive. The +/// helpers named here build one the way `Box` does, so the const type consumes +/// the same input bytes as the owned type. Every other const field type has an +/// `Arbitrary` impl the derive finds on its own. +fn const_arbitrary_with(const_type: &str) -> Option { + if let Some(t) = const_type.strip_prefix("&'static ") { + return Some(format!("arbitrary_ref::<{t}>")); + } + const_type + .strip_prefix("Option<&'static ") + .and_then(|t| t.strip_suffix('>')) + .map(|t| format!("arbitrary_option_ref::<{t}>")) +} + +/// One definition module's contribution to the `const` module. +struct ConstModuleOutput { + mod_name: String, + /// The definitions with const content of their own, which go in the + /// module's file. Empty where the module contributes only names. + definitions: Vec, + /// The names the module contributes to the `const` module directly. + items: Vec, +} + +/// How a definition is named in the `const` module. +enum ConstName { + /// The `const` module defines a borrowing form under the name itself. + Defined, + /// The `const` module re-exports the parent's definition under this name. + Reexported(String), +} + +// ============================================================================= +// Borrow analysis +// ============================================================================= + +/// Borrow analysis over a whole spec, resolving type references by name. +struct BorrowAnalysis<'a> { + defs_by_name: HashMap>, + /// Whether each name holds heap data under some cfg, keyed by Rust type + /// name and memoized. + by_name: HashMap, + /// Names currently being resolved, for cycle detection. + stack: HashSet, +} + +impl<'a> BorrowAnalysis<'a> { + fn build(spec: &'a XdrSpec) -> Self { + let mut defs_by_name: HashMap> = HashMap::new(); + for def in spec.all_definitions() { + defs_by_name + .entry(type_name(def.name())) + .or_default() + .push(def); + } + let mut analysis = Self { + defs_by_name, + by_name: HashMap::new(), + stack: HashSet::new(), + }; + let names: Vec = analysis.defs_by_name.keys().cloned().collect(); + for name in names { + analysis.of_name(&name); + } + analysis + } + + /// The names that get a `Const` form, i.e. that hold heap data under some + /// cfg. + /// + /// A name whose heap data sits only behind a cfg is included. It has to be: + /// a container naming it does so unconditionally, and the owned type in + /// that position cannot be built or serialized in a const context wherever + /// the cfg turns its heap data on. + fn const_required(&self) -> HashSet { + self.by_name + .iter() + .filter(|(_, borrows)| **borrows) + .map(|(n, _)| n.clone()) + .collect() + } + + /// Whether a name holds heap data under any of its cfg branches. + /// + /// A name already on the stack indicates a reference cycle. Valid XDR + /// breaks cycles with optional or variable-length types, both of which the + /// generator maps to heap allocations (`Box` or `VecM`), so a type on a + /// cycle always borrows. + fn of_name(&mut self, name: &str) -> bool { + if let Some(b) = self.by_name.get(name) { + return *b; + } + if self.stack.contains(name) { + return true; + } + let Some(defs) = self.defs_by_name.get(name).cloned() else { + return false; + }; + self.stack.insert(name.to_string()); + let borrows = defs + .into_iter() + .fold(false, |acc, def| acc | self.of_def(def)); + self.stack.remove(name); + self.by_name.insert(name.to_string(), borrows); + borrows + } + + /// Whether a single definition holds heap data. A cfg-gated union arm + /// counts: the `Const` form is emitted under every cfg, with the arm gated + /// inside it. + /// + /// The folds below use `|` rather than `||` so the walk visits every + /// member instead of stopping at the first that borrows, leaving what the + /// analysis memoizes independent of member order. + fn of_def(&mut self, def: &Definition) -> bool { + match def { + Definition::Struct(s) => s + .members + .iter() + .fold(false, |acc, m| acc | self.of_type(&m.type_)), + Definition::Union(u) => u + .arms + .iter() + .filter_map(|arm| arm.type_.as_ref()) + .fold(false, |acc, t| acc | self.of_type(t)), + Definition::Typedef(t) => self.of_type(&t.type_), + Definition::Enum(_) | Definition::Const(_) => false, + } + } + + fn of_type(&mut self, type_: &Type) -> bool { + match type_ { + Type::OpaqueVar(_) | Type::String(_) | Type::VarArray { .. } => true, + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => false, + Type::Ident(name) => self.of_name(&type_name(name)), + Type::Optional(inner) => self.of_type(inner), + Type::Array { element_type, .. } => self.of_type(element_type), + } + } +} diff --git a/xdr-generator-rust/generator/src/main.rs b/xdr-generator-rust/generator/src/main.rs index 7f4e4d1d6..91002ceb9 100644 --- a/xdr-generator-rust/generator/src/main.rs +++ b/xdr-generator-rust/generator/src/main.rs @@ -1,5 +1,6 @@ //! CLI entry point for the XDR code generator. +mod const_writer; mod generator; mod naming; mod options; diff --git a/xdr-generator-rust/generator/src/output.rs b/xdr-generator-rust/generator/src/output.rs index b6c587caf..0d8820e22 100644 --- a/xdr-generator-rust/generator/src/output.rs +++ b/xdr-generator-rust/generator/src/output.rs @@ -8,6 +8,95 @@ pub struct ModTemplate { pub modules: Vec, } +/// The `const` module file: the header, and an entry per definition module. +#[derive(Template)] +#[template(path = "const_mod.rs.jinja", escape = "none")] +pub struct ConstModTemplate { + pub header: String, + pub entries: Vec, +} + +/// What one definition module contributes to the `const` module. +pub struct ConstModEntry { + /// The module's file, when it has const content of its own. + pub mod_name: Option, + /// The names the module contributes to the `const` module directly, rather + /// than through its file. + pub items: Vec, +} + +/// A name the `const` module takes from its parent unchanged: a type with no +/// borrowing form, or an XDR const. +/// +/// It is re-exported rather than aliased so that the name works in both +/// namespaces: a `pub type` alias cannot be used to construct a tuple struct +/// or name a unit variant. +pub struct ConstModItem { + pub name: String, + pub cfg: Option, +} + +/// One definition module's file inside the `const` module. +#[derive(Template)] +#[template(path = "const_definition.rs.jinja", escape = "none")] +pub struct ConstDefinitionTemplate { + pub definitions: Vec, + /// The `ConstWriter` methods serializing the types defined in this file. + pub const_writer: ConstWriterOutput, +} + +/// The const-module form of one definition. +pub struct ConstDefinitionOutput { + /// The borrowing type the definition gets in the `const` module, where it + /// owns heap data. Where it does not, the `const` module aliases the owned + /// type instead and this is `None`. + pub type_def: Option, + /// The rendered `const_xdr_len`/`const_to_xdr` wrapper impl block, empty + /// for a definition with no const encoding of its own. + pub const_to_xdr: String, +} + +/// A borrowing type definition in the `const` module. +pub enum ConstTypeOutput { + Struct(ConstStructOutput), + Union(ConstUnionOutput), + Newtype(ConstNewtypeOutput), +} + +pub struct ConstStructOutput { + pub name: String, + pub cfg: Option, + pub members: Vec, +} + +pub struct ConstStructMemberOutput { + pub name: String, + pub type_ref: String, + pub arbitrary_with: Option, +} + +pub struct ConstUnionOutput { + pub name: String, + pub cfg: Option, + pub discriminant_type: String, + pub arms: Vec, +} + +pub struct ConstUnionArmOutput { + pub case_name: String, + pub case_value: String, + pub is_void: bool, + pub type_ref: Option, + pub arbitrary_with: Option, + pub cfg: Option, +} + +pub struct ConstNewtypeOutput { + pub name: String, + pub cfg: Option, + pub type_ref: String, +} + #[derive(Template)] #[template(path = "type_enum_definition.rs.jinja", escape = "none")] pub struct TypeEnumDefinitionTemplate { @@ -24,6 +113,122 @@ pub struct DefinitionTemplate { pub definitions: Vec, } +/// The `const_xdr_len` / `const_to_xdr` wrapper emitted on a type, which sets +/// up a `ConstWriter` and calls that type's `write_type_*` method. +#[derive(Template)] +#[template(path = "const_to_xdr.rs.jinja", escape = "none")] +pub struct ConstToXdrTemplate { + /// The receiver the wrapper is implemented on, e.g. `Memo`, naming the + /// type as the `const` module names it. + pub recv: String, + pub cfg: Option, + /// The `ConstWriter` method the wrapper calls. + pub write_fn: String, +} + +/// The `ConstWriter` methods that serialize each generated type. +pub struct ConstWriterOutput { + pub methods: Vec, +} + +/// One `ConstWriter::write_*` method: what it serializes and how. +pub struct ConstWriterMethodOutput { + pub name: String, + /// Generic parameters, e.g. `` for the `VecM` methods. + pub generics: String, + /// The type of the value parameter, e.g. `&Transaction`, naming the type + /// as the `const` module names it. + pub param_type: String, + pub cfg: Option, + /// The module the method is emitted into: the one holding the type it + /// serializes. Every method has one, because a wrapper over a builtin has + /// no type file and so is hand-written on `ConstWriter` instead. + pub module: String, + /// What the method serializes, for its doc comment. + pub subject: ConstSubject, + pub body: ConstWriterBody, +} + +/// What a `ConstWriter` method serializes. +pub enum ConstSubject { + /// A type defined in the `.x` files, by Rust name. + Type(String), + /// An optional value; `owned` is the owned Rust type of the whole option. + Option { inner: ConstDocName, owned: String }, + /// A variable-length array; `elem` is the owned Rust type of an element. + Vec { inner: ConstDocName, elem: String }, +} + +/// How a type is named in a generated doc comment. +pub struct ConstDocName { + pub name: String, + /// Whether the name is a type from the `.x` files, and so an intra-doc + /// link, rather than a builtin shown as plain code. + pub link: bool, +} + +/// The body of a `ConstWriter` method, by the shape of the type it serializes. +pub enum ConstWriterBody { + /// A struct: each member in order. A typedef newtype is one of these with + /// a single member, its inner value. + Struct(Vec), + /// An enum: its discriminant value as an XDR int. + Enum, + /// A union: its discriminant, then the payload of the selected arm. + Union { + /// The type matched on, named as the `const` module names it. + scrutinee: String, + discriminant: ConstEncode, + arms: Vec, + }, + /// An `Option`: a presence flag, then the value when present. + Option(ConstEncode), + /// A `VecM`: its length, then each element. + Vec(ConstEncode), +} + +pub struct ConstUnionArm { + pub cfg: Option, + pub case_name: String, + /// The encoding of the arm's payload, bound by reference to `value`; `None` + /// for a void arm. + pub payload: Option, +} + +/// One call to a `ConstWriter` method, serializing one value. +pub struct ConstEncode { + /// The fixed-array loops the call sits inside, outermost first. + pub loops: Vec, + /// The expression naming the value: a place such as `v.foo` or `s[i]`, or + /// a `match` binding. + pub acc: String, + /// Whether `acc` is a binding that already holds a reference to the value. + pub is_ref: bool, + /// The `ConstWriter` method to call. + pub method: String, + /// How the method takes the value. + pub pass: ConstPass, +} + +/// A `while` loop over a fixed-size array. +pub struct ConstLoop { + pub index: String, + pub len: String, +} + +/// How a `ConstWriter` method takes the value passed to it. +pub enum ConstPass { + /// By value: the value is `Copy`. + Value, + /// By reference. + Ref, + /// As it is: the value is already a reference, the const form of a cyclic + /// type. + AsIs, + /// As the byte slice the `const` module's `BytesM`/`StringM` exposes. + Slice, +} + pub enum DefinitionOutput { Struct(StructOutput), Enum(EnumOutput), diff --git a/xdr-generator-rust/generator/src/tests/generator.rs b/xdr-generator-rust/generator/src/tests/generator.rs index 8dc258850..59018c201 100644 --- a/xdr-generator-rust/generator/src/tests/generator.rs +++ b/xdr-generator-rust/generator/src/tests/generator.rs @@ -23,6 +23,35 @@ fn generate_from_xdr(xdr: &str) -> String { output } +/// Generates and returns the `const` module — the module file and every +/// per-definition file under it, concatenated — since that is where the const +/// forms live. +fn generate_const_from_xdr(xdr: &str) -> String { + let spec = xdr_parser::parser::parse(xdr).unwrap(); + let options = RustOptions { + custom_default_impl: HashSet::new(), + custom_str_impl: HashSet::new(), + no_display_fromstr: HashSet::new(), + }; + let generator = RustGenerator::new(&spec, options); + let mut output = String::new(); + let module_file = std::path::Path::new("generated.rs"); + let output_dir = std::path::Path::new("generated"); + generator + .generate_files(&spec, module_file, output_dir, |path, contents| { + // The const module is `generated/const.rs`, and the file of each + // definition module that has const content sits under + // `generated/const/`. Everything else is the owned form. + if path == output_dir.join("const.rs") || path.starts_with(output_dir.join("const")) { + output.push_str(contents); + output.push('\n'); + } + Ok(()) + }) + .unwrap(); + output +} + fn assert_contains(output: &str, expected: &str) { assert!( output.contains(expected), @@ -30,6 +59,13 @@ fn assert_contains(output: &str, expected: &str) { ); } +fn assert_not_contains(output: &str, unexpected: &str) { + assert!( + !output.contains(unexpected), + "expected output not to contain:\n{unexpected}\n\nfull output:\n{output}" + ); +} + #[test] fn test_ifdef_generates_cfg_on_struct() { let output = generate_from_xdr( @@ -215,3 +251,180 @@ fn test_ifdef_generates_cfg_on_const() { pub const MAX_SIZE: u32 = 100;"#, ); } + +#[test] +fn test_const_form_for_both_ifdef_branches() { + // Foo holds heap data only in the FEATURE_X branch. Both branches get a + // const form, each gated like its definition, so the name resolves under + // every cfg; the heap-free branch mirrors the owned fields. + let output = generate_const_from_xdr( + r" + #ifdef FEATURE_X + struct Foo { string s<10>; }; + #else + struct Foo { int y; }; + #endif + ", + ); + assert_contains( + &output, + r#"#[cfg(feature = "feature_x")] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Foo { + pub s: StringM<10>, +}"#, + ); + assert_contains( + &output, + r#"#[cfg(not(feature = "feature_x"))] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Foo { + pub y: i32, +}"#, + ); +} + +#[test] +fn test_const_form_for_both_ifdef_branches_typedef() { + let output = generate_const_from_xdr( + r" + #ifdef FEATURE_X + typedef string Foo<10>; + #else + typedef opaque Foo[4]; + #endif + ", + ); + assert_contains( + &output, + r#"#[cfg(feature = "feature_x")] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Foo(pub StringM<10>);"#, + ); + assert_contains( + &output, + r#"#[cfg(not(feature = "feature_x"))] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Foo(pub [u8; 4]);"#, + ); +} + +#[test] +fn test_const_form_for_both_ifdef_branches_union() { + let output = generate_const_from_xdr( + r" + #ifdef FEATURE_X + union Foo switch (int v) { case 0: string s<10>; }; + #else + union Foo switch (int v) { case 0: int y; }; + #endif + ", + ); + assert_contains( + &output, + r#"#[cfg(feature = "feature_x")] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum Foo { + #[cfg(feature = "feature_x")] + V0(StringM<10>), +}"#, + ); + assert_contains( + &output, + r#"#[cfg(not(feature = "feature_x"))] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum Foo { + #[cfg(not(feature = "feature_x"))] + V0(i32), +}"#, + ); +} + +#[test] +fn test_const_form_when_only_a_cfg_gated_arm_borrows() { + // The union's only heap sits behind a cfg-gated arm. The const form is + // emitted unconditionally with the arm gated inside it, so the arm's + // payload is the borrowing StringM wherever the cfg turns it on. + let output = generate_const_from_xdr( + r" + union Foo switch (int v) { + case 0: int y; + #ifdef FEATURE_X + case 1: string s<10>; + #endif + }; + ", + ); + assert_contains( + &output, + r#"pub enum Foo { + V0(i32), + #[cfg(feature = "feature_x")] + V1(StringM<10>), +}"#, + ); +} + +#[test] +fn test_cfg_gated_heap_gets_a_const_form() { + // Exec borrows only via its cfg-gated arm, so types holding an Exec name + // the const module's Exec in that position under every cfg. Leaving the + // owned Exec there would not compile with the feature on: serializing it + // reaches a Vec-backed StringM from a const fn. + let output = generate_const_from_xdr( + r" + union Exec switch (int type) + { + case 0: + void; + #ifdef FEATURE_X + case 1: + string tag<64>; + #endif + }; + struct OnlyExec { Exec exec; int n; }; + struct Parent { Exec exec; string label<32>; }; + ", + ); + assert_contains( + &output, + r#"#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct Parent { + pub exec: Exec, + pub label: StringM<32>, +}"#, + ); + assert_contains( + &output, + r#"#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct OnlyExec { + pub exec: Exec, + pub n: i32, +}"#, + ); +} + +#[test] +fn test_no_const_form_for_heap_free_types() { + // A type with no heap under any cfg gets no borrowing form of its own, + // since there is nothing for it to borrow. The const module re-exports the + // owned type under the same name instead, so the name still resolves + // there. + let output = generate_const_from_xdr( + r" + struct Flat { int a; opaque b[4]; }; + ", + ); + assert_not_contains(&output, "pub struct Flat {"); + assert_contains(&output, "pub use super::Flat;"); +} diff --git a/xdr-generator-rust/generator/src/types.rs b/xdr-generator-rust/generator/src/types.rs index 2b2709ebb..55c70725b 100644 --- a/xdr-generator-rust/generator/src/types.rs +++ b/xdr-generator-rust/generator/src/types.rs @@ -40,6 +40,26 @@ pub(crate) fn base_type_ref(type_: &Type, type_info: Option<&TypeInfo>) -> Strin TypeMapping::new(type_, type_info, None).base_type_ref() } +/// The Rust type that holds this XDR type in a const context, named as the +/// `const` module names it: every type has a name there, either a borrowing +/// form of its own or an alias to the owned type. +/// +/// Mirrors [`type_ref`], including the reference wrapping applied where +/// `parent_type` makes the type cyclic. +pub(crate) fn const_type(type_: &Type, parent_type: Option<&str>, type_info: &TypeInfo) -> String { + TypeMapping::new(type_, Some(type_info), parent_type).const_type() +} + +/// As [`const_type`], but without the reference wrapping for cyclic +/// types. +/// +/// This is the form an element takes inside a container such as the `const` +/// module's `VecM`, which borrows its elements as a slice rather than +/// individually. +pub(crate) fn const_base_type(type_: &Type, type_info: &TypeInfo) -> String { + TypeMapping::new(type_, Some(type_info), None).const_base_type() +} + /// Convert a Size to a Rust `u32` const generic argument, as used by /// `BytesM`, `StringM`, and `VecM`. Named sizes refer to the generated const, /// which is emitted as a `u32`. @@ -172,6 +192,87 @@ impl<'a> TypeMapping<'a> { } } + /// The Rust type used for this XDR type inside the `const` module, without + /// the reference wrapping applied for cyclic types. + /// + /// Mirrors `base_type_ref`. Every name it produces is resolved in the + /// `const` module, where a type that owns heap data is the borrowing form + /// and every other name is an alias to the owned type, so the names are the + /// same as the owned ones. + fn const_base_type(&self) -> String { + match self.type_ { + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => self.base_type_ref(), + Type::OpaqueVar(max) => match max { + Some(size) => format!("BytesM<{}>", size_to_u32_string(size)), + None => "BytesM".to_string(), + }, + Type::String(max) => match max { + Some(size) => format!("StringM<{}>", size_to_u32_string(size)), + None => "StringM".to_string(), + }, + Type::Ident(_) => { + if let Some(ti) = self.type_info { + if let Some(builtin) = ti.resolve_typedef_to_builtin(self.type_) { + return self.child(builtin).const_base_type(); + } + } + if let Type::Ident(name) = self.type_ { + type_name(name) + } else { + unreachable!() + } + } + Type::Optional(inner) => { + format!("Option<{}>", self.child(inner).const_base_type()) + } + Type::Array { element_type, size } => { + format!( + "[{}; {}]", + self.child(element_type).const_base_type(), + size_to_usize_string(size) + ) + } + Type::VarArray { + element_type, + max_size, + } => { + let elem = self.child(element_type).const_base_type(); + match max_size { + Some(size) => format!("VecM<{elem}, {}>", size_to_u32_string(size)), + None => format!("VecM<{elem}>"), + } + } + } + } + + /// The Rust type used for this XDR type inside the `const` module. + /// + /// Mirrors `type_ref`: where the owned type wraps cyclic references in + /// `Box`, the const form uses a plain reference instead. + fn const_type(&self) -> String { + let base = self.const_base_type(); + + if !self.is_cyclic() { + return base; + } + + match self.type_ { + Type::Optional(inner) => { + let inner = self.child(inner).const_base_type(); + format!("Option<&'static {inner}>") + } + Type::Array { .. } | Type::VarArray { .. } => base, + _ => format!("&'static {base}"), + } + } + fn turbofish_type(&self) -> String { let cyclic = self.is_cyclic(); diff --git a/xdr-generator-rust/generator/templates/const_definition.rs.jinja b/xdr-generator-rust/generator/templates/const_definition.rs.jinja new file mode 100644 index 000000000..b5a344a0b --- /dev/null +++ b/xdr-generator-rust/generator/templates/const_definition.rs.jinja @@ -0,0 +1,83 @@ +{#- One definition module's file inside the `const` module. The whole module is + behind the `const` feature, so nothing here carries a feature gate of its + own; the only cfgs are the ones the `.x` files ask for. #} +#[allow(unused_imports, clippy::wildcard_imports)] +use super::*; +{% for definition in definitions %} +{%- if let Some(type_def) = definition.type_def %} +{%- match type_def %} +{%- when ConstTypeOutput::Struct(s) %} +/// {{ s.name }} is a borrowing equivalent of [`{{ s.name }}`](super::super::{{ s.name }}) +/// over `'static` data, for const XDR encoding. +{%- if let Some(cfg) = s.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct {{ s.name }} { +{%- for m in s.members %} +{%- if let Some(with) = m.arbitrary_with %} + #[cfg_attr(feature = "arbitrary", arbitrary(with = {{ with }}))] +{%- endif %} + pub {{ m.name }}: {{ m.type_ref }}, +{%- endfor %} +} +{%- when ConstTypeOutput::Union(u) %} +/// {{ u.name }} is a borrowing equivalent of [`{{ u.name }}`](super::super::{{ u.name }}) +/// over `'static` data, for const XDR encoding. +{%- if let Some(cfg) = u.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[allow(clippy::large_enum_variant)] +pub enum {{ u.name }} { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + {{ arm.case_name }}, +{%- else if let Some(with) = arm.arbitrary_with %} + {{ arm.case_name }}(#[cfg_attr(feature = "arbitrary", arbitrary(with = {{ with }}))] {{ arm.type_ref.as_ref().unwrap() }}), +{%- else %} + {{ arm.case_name }}({{ arm.type_ref.as_ref().unwrap() }}), +{%- endif %} +{%- endfor %} +} + +{% if let Some(cfg) = u.cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +impl {{ u.name }} { + #[must_use] + pub const fn discriminant(&self) -> {{ u.discriminant_type }} { + #[allow(clippy::match_same_arms)] + match self { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + Self::{{ arm.case_name }} => {{ arm.case_value }}, +{%- else %} + Self::{{ arm.case_name }}(_) => {{ arm.case_value }}, +{%- endif %} +{%- endfor %} + } + } +} +{%- when ConstTypeOutput::Newtype(t) %} +/// {{ t.name }} is a borrowing equivalent of [`{{ t.name }}`](super::super::{{ t.name }}) +/// over `'static` data, for const XDR encoding. +{%- if let Some(cfg) = t.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub struct {{ t.name }}(pub {{ t.type_ref }}); +{%- endmatch %} +{% endif %} +{{ definition.const_to_xdr }} +{%- endfor %} +{% include "const_writer_impl.rs.jinja" %} diff --git a/xdr-generator-rust/generator/templates/const_mod.rs.jinja b/xdr-generator-rust/generator/templates/const_mod.rs.jinja new file mode 100644 index 000000000..df69dae9d --- /dev/null +++ b/xdr-generator-rust/generator/templates/const_mod.rs.jinja @@ -0,0 +1,28 @@ +//! Const-evaluable forms of the generated XDR types. +//! +//! Every type in the parent module has a name here. A type that owns heap data +//! has a borrowing equivalent of its own, holding `&'static` data so it can be +//! built in a const context; every other type is an alias to the owned type, +//! which const evaluation can already hold. So a value of any type can be +//! written as `const`, and encoded to XDR at compile time with the type's +//! `const_xdr_len` and `const_to_xdr`. +//! +//! The names are those of the parent module, without a suffix: `const::Memo` is +//! the const form of [`super::Memo`]. Types that cannot be built in a const +//! context (`Vec`, `String`, `Box`) are replaced by [`VecM`], [`BytesM`], +//! [`StringM`], and `&'static` references respectively. + +{{ header }} +{%- for e in entries %} +{%- if let Some(mod_name) = e.mod_name %} +mod {{ mod_name }}; +#[allow(unused_imports)] +pub use {{ mod_name }}::*; +{%- endif %} +{%- for i in e.items %} +{%- if let Some(cfg) = i.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +pub use super::{{ i.name }}; +{%- endfor %} +{%- endfor %} diff --git a/xdr-generator-rust/generator/templates/const_to_xdr.rs.jinja b/xdr-generator-rust/generator/templates/const_to_xdr.rs.jinja new file mode 100644 index 000000000..7768816fa --- /dev/null +++ b/xdr-generator-rust/generator/templates/const_to_xdr.rs.jinja @@ -0,0 +1,38 @@ +{% if let Some(cfg) = cfg %}#[cfg({{ cfg }})] +{% endif -%} +impl {{ recv }} { + /// The exact XDR-encoded length of this value, in bytes. + /// + /// Evaluable in a const context, so a caller (such as a proc-macro) can + /// size a buffer for [`Self::const_to_xdr`] at compile time. + #[must_use] + pub const fn const_xdr_len(&self) -> usize { + let mut empty: [u8; 0] = []; + let mut w = ConstWriter::new(&mut empty); + w.{{ write_fn }}(self); + w.len() + } + + /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const + /// operations. This is the const counterpart to + /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr). + /// + /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such + /// as a proc-macro, that compute the length with `const_xdr_len` and pass + /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`. + /// + /// # Panics + /// + /// Panics if `N` does not equal the value's [`Self::const_xdr_len`]. + #[must_use] + pub const fn const_to_xdr(&self) -> [u8; N] { + let mut buf = [0u8; N]; + let mut w = ConstWriter::new(&mut buf); + w.{{ write_fn }}(self); + assert!( + w.len() == N, + "const_to_xdr: N does not equal the XDR-encoded length" + ); + buf + } +} diff --git a/xdr-generator-rust/generator/templates/const_writer_impl.rs.jinja b/xdr-generator-rust/generator/templates/const_writer_impl.rs.jinja new file mode 100644 index 000000000..f6204822b --- /dev/null +++ b/xdr-generator-rust/generator/templates/const_writer_impl.rs.jinja @@ -0,0 +1,115 @@ +{#- Const XDR encoding lives on `ConstWriter` rather than on the generated + types, but is emitted beside the type it serializes. The `const_writer` + module decides what each method does; this template renders it. + + The generated files are run through rustfmt (see the Makefile), so the + indentation here is not significant and is left out: writing it would only + create a second layout to keep in step with the first. Line breaks are + significant, because rustfmt keeps the blank lines it is given, which is + what the `{%-` markers below are for. #} + +{#- How a type is named in a doc comment. -#} +{%- macro doc_name(d) -%} +{%- if d.link %}[`{{ d.name }}`]{% else %}`{{ d.name }}`{% endif -%} +{%- endmacro %} + +{#- The doc comment for a method, naming what it serializes and the + `WriteXdr` implementation it mirrors. -#} +{%- macro doc(m) %} +{%- match m.subject %} +{%- when ConstSubject::Type(name) %} +/// Serializes a [`{{ name }}`], mirroring `<{{ name }} as WriteXdr>::write_xdr`. +{%- when ConstSubject::Option with { inner, owned } %} +/// Serializes an optional {% call doc_name(inner) %}, mirroring `<{{ owned }} as WriteXdr>::write_xdr`. +{%- when ConstSubject::Vec with { inner, elem } %} +/// Serializes a variable-length array of {% call doc_name(inner) %}, mirroring ` as WriteXdr>::write_xdr`. +{%- endmatch %} +{%- endmacro %} + +{#- The value `e` names, as the argument its writer method takes. A `match` + binding is already a reference, so it is dereferenced where the method takes + a value and passed as-is where it takes a reference; a place expression is + used or borrowed directly. -#} +{%- macro arg(e) -%} +{%- match e.pass -%} +{%- when ConstPass::Value -%}{% if e.is_ref %}*{% endif %}{{ e.acc }} +{%- when ConstPass::Ref -%}{% if !e.is_ref %}&{% endif %}{{ e.acc }} +{%- when ConstPass::AsIs -%}{{ e.acc }} +{%- when ConstPass::Slice -%}{{ e.acc }}.as_slice() +{%- endmatch -%} +{%- endmacro %} + +{#- The statement serializing `e`, inside a `while` loop for each fixed array + it is an element of. -#} +{%- macro encode(e) %} +{%- for l in e.loops %} +{ +let mut {{ l.index }} = 0usize; +while {{ l.index }} < {{ l.len }} { +{%- endfor %} +self.{{ e.method }}({% call arg(e) %}); +{%- for l in e.loops.iter().rev() %} +{{ l.index }} += 1; +} +} +{%- endfor %} +{%- endmacro %} + +{%- if !const_writer.methods.is_empty() %} + +impl ConstWriter<'_> { +{%- for m in const_writer.methods %} +{% if let Some(cfg) = m.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +{%- call doc(m) %} +pub const fn {{ m.name }}{{ m.generics }}(&mut self, v: {{ m.param_type }}) { +{%- match m.body %} +{%- when ConstWriterBody::Struct(members) %} +{%- for e in members %} +{%- call encode(e) %} +{%- endfor %} +{%- when ConstWriterBody::Enum %} +self.write_i32(*v as i32); +{%- when ConstWriterBody::Union with { scrutinee, discriminant, arms } %} +let d = v.discriminant(); +{%- call encode(discriminant) %} +#[allow(clippy::match_same_arms)] +match v { +{%- for arm in arms %} +{%- if let Some(cfg) = arm.cfg %} +#[cfg({{ cfg }})] +{%- endif %} +{%- if let Some(payload) = arm.payload %} +{{ scrutinee }}::{{ arm.case_name }}(value) => { +{%- call encode(payload) %} +} +{%- else %} +{{ scrutinee }}::{{ arm.case_name }} => {} +{%- endif %} +{%- endfor %} +} +{%- when ConstWriterBody::Option(inner) %} +match v { +Some(v) => { +self.write_u32(1); +{%- call encode(inner) %} +} +None => { +self.write_u32(0); +} +} +{%- when ConstWriterBody::Vec(elem) %} +let s = v.as_slice(); +let len = s.len(); +self.write_len(len); +let mut i = 0usize; +while i < len { +{%- call encode(elem) %} +i += 1; +} +{%- endmatch %} +} +{%- endfor %} +} +{%- endif %} diff --git a/xdr-generator-rust/generator/templates/mod.rs.jinja b/xdr-generator-rust/generator/templates/mod.rs.jinja index cb6ff7089..10448e311 100644 --- a/xdr-generator-rust/generator/templates/mod.rs.jinja +++ b/xdr-generator-rust/generator/templates/mod.rs.jinja @@ -21,3 +21,6 @@ mod {{ m.mod_name }}; #[allow(unused_imports)] pub use {{ m.mod_name }}::*; {%- endfor %} + +#[cfg(feature = "const")] +pub mod r#const;