Skip to main content

stellar_xdr/
generated.rs

1// Module is generated from:
2//  xdr/Stellar-SCP.x
3//  xdr/Stellar-contract-config-setting.x
4//  xdr/Stellar-contract-env-meta.x
5//  xdr/Stellar-contract-meta.x
6//  xdr/Stellar-contract-spec.x
7//  xdr/Stellar-contract.x
8//  xdr/Stellar-exporter.x
9//  xdr/Stellar-internal.x
10//  xdr/Stellar-ledger-entries.x
11//  xdr/Stellar-ledger.x
12//  xdr/Stellar-overlay.x
13//  xdr/Stellar-transaction.x
14//  xdr/Stellar-types.x
15
16#![allow(
17    clippy::missing_errors_doc,
18    clippy::too_many_lines,
19    clippy::unreadable_literal,
20    clippy::wildcard_imports
21)]
22
23/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
24pub const XDR_FILES_SHA256: [(&str, &str); 13] = [
25    (
26        "xdr/Stellar-SCP.x",
27        "41ff1f6a3de9fcb07372953e73a9e49071e278081e411a62e69683ad3591a218",
28    ),
29    (
30        "xdr/Stellar-contract-config-setting.x",
31        "63e548e5cab4823747325bc370760c7437a026f13b389de809e52542ecd41d2f",
32    ),
33    (
34        "xdr/Stellar-contract-env-meta.x",
35        "e1f0595afd6249879ea4898f0ccb2293025c21db3a6590178ba129bc1e99d8c9",
36    ),
37    (
38        "xdr/Stellar-contract-meta.x",
39        "5f2ad607144ef4dcc44c6d4fbf3c10cc07d716e707281a8789fb958c83904e16",
40    ),
41    (
42        "xdr/Stellar-contract-spec.x",
43        "38910bfa0f616916659db405c37e8c63ac7e0b46ce1bf10bd53b5fafc4f599fe",
44    ),
45    (
46        "xdr/Stellar-contract.x",
47        "7f8a55a7d03c35979fc540f9bd14873668d6970adb6957323b485838114a7da2",
48    ),
49    (
50        "xdr/Stellar-exporter.x",
51        "d36ec815cceb534e3f565448aa79ba8dd7f6be6485de050dfb62613eb05b11a4",
52    ),
53    (
54        "xdr/Stellar-internal.x",
55        "81f9804d6a5f88afdb62e8d00506c348e45c7b70012d781d14ef22ddc7414833",
56    ),
57    (
58        "xdr/Stellar-ledger-entries.x",
59        "3e212dab2177c86c0a0a439dd870f4e71dda70472930f17096f48b9507e4ef1a",
60    ),
61    (
62        "xdr/Stellar-ledger.x",
63        "35c1d96aa2f39e737c3088e8b35bdf2099bed35f3959934a0552b76d92cdf9c5",
64    ),
65    (
66        "xdr/Stellar-overlay.x",
67        "ad2ea6b317d8b0e72bf8b08b6a4b11dc81352afb7bf6409dc4c84e48dd76b092",
68    ),
69    (
70        "xdr/Stellar-transaction.x",
71        "840ee5f5216c8e35ded4590e2976d246fa5f8b4e60670051b8373e7282c20278",
72    ),
73    (
74        "xdr/Stellar-types.x",
75        "be1f32162c58275273ae2805a57bb69ec2fdb9ccc2313556f42bf08b9763e757",
76    ),
77];
78
79use core::{array::TryFromSliceError, fmt, fmt::Debug, marker::Sized, ops::Deref, slice};
80
81#[cfg(feature = "std")]
82use core::marker::PhantomData;
83
84// When feature alloc is turned off use static lifetime Box and Vec types.
85#[cfg(not(feature = "alloc"))]
86mod noalloc {
87    pub mod boxed {
88        pub type Box<T> = &'static T;
89    }
90    pub mod vec {
91        pub type Vec<T> = &'static [T];
92    }
93}
94#[cfg(not(feature = "alloc"))]
95use noalloc::{boxed::Box, vec::Vec};
96
97// When feature std is turned off, but feature alloc is turned on import the
98// alloc crate and use its Box and Vec types.
99#[cfg(all(not(feature = "std"), feature = "alloc"))]
100extern crate alloc;
101#[cfg(all(not(feature = "std"), feature = "alloc"))]
102use alloc::{
103    borrow::ToOwned,
104    boxed::Box,
105    string::{FromUtf8Error, String},
106    vec::Vec,
107};
108#[cfg(feature = "std")]
109use std::string::FromUtf8Error;
110
111#[cfg(feature = "arbitrary")]
112use arbitrary::Arbitrary;
113
114#[cfg(all(feature = "schemars", feature = "alloc", not(feature = "std")))]
115use alloc::borrow::Cow;
116#[cfg(all(feature = "schemars", feature = "alloc", feature = "std"))]
117use std::borrow::Cow;
118
119// TODO: Add support for read/write xdr fns when std not available.
120
121#[cfg(feature = "std")]
122use std::{
123    error, io,
124    io::{BufRead, BufReader, Cursor, Read, Write},
125};
126
127/// Error contains all errors returned by functions in this crate. It can be
128/// compared via `PartialEq`, however any contained IO errors will only be
129/// compared on their `ErrorKind`.
130#[derive(Debug)]
131pub enum Error {
132    Invalid,
133    Unsupported,
134    LengthExceedsMax,
135    LengthMismatch,
136    NonZeroPadding,
137    Utf8Error(core::str::Utf8Error),
138    #[cfg(feature = "alloc")]
139    InvalidHex,
140    #[cfg(feature = "std")]
141    Io(io::Error),
142    DepthLimitExceeded,
143    #[cfg(feature = "serde_json")]
144    Json(serde_json::Error),
145    LengthLimitExceeded,
146    #[cfg(feature = "arbitrary")]
147    Arbitrary(arbitrary::Error),
148}
149
150impl PartialEq for Error {
151    fn eq(&self, other: &Self) -> bool {
152        match (self, other) {
153            (Self::Invalid, Self::Invalid)
154            | (Self::Unsupported, Self::Unsupported)
155            | (Self::LengthExceedsMax, Self::LengthExceedsMax)
156            | (Self::LengthMismatch, Self::LengthMismatch)
157            | (Self::NonZeroPadding, Self::NonZeroPadding) => true,
158
159            (Self::Utf8Error(l), Self::Utf8Error(r)) => l == r,
160
161            #[cfg(feature = "alloc")]
162            (Self::InvalidHex, Self::InvalidHex) => true,
163
164            // IO errors cannot be compared, but in the absence of any more
165            // meaningful way to compare the errors we compare the kind of error
166            // and ignore the embedded source error or OS error. The main use
167            // case for comparing errors outputted by the XDR library is for
168            // error case testing, and a lack of the ability to compare has a
169            // detrimental affect on failure testing, so this is a tradeoff.
170            #[cfg(feature = "std")]
171            (Self::Io(l), Self::Io(r)) => l.kind() == r.kind(),
172
173            (Self::DepthLimitExceeded, Self::DepthLimitExceeded) => true,
174
175            #[cfg(feature = "serde_json")]
176            (Self::Json(l), Self::Json(r)) => l.classify() == r.classify(),
177
178            (Self::LengthLimitExceeded, Self::LengthLimitExceeded) => true,
179
180            #[cfg(feature = "arbitrary")]
181            (Self::Arbitrary(l), Self::Arbitrary(r)) => l == r,
182
183            _ => false,
184        }
185    }
186}
187
188#[cfg(feature = "std")]
189impl error::Error for Error {
190    #[must_use]
191    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
192        match self {
193            Error::Invalid
194            | Error::Unsupported
195            | Error::LengthExceedsMax
196            | Error::LengthMismatch
197            | Error::NonZeroPadding => None,
198
199            Error::Utf8Error(e) => Some(e),
200
201            Self::InvalidHex => None,
202
203            Self::Io(e) => Some(e),
204
205            Self::DepthLimitExceeded => None,
206
207            #[cfg(feature = "serde_json")]
208            Self::Json(e) => Some(e),
209
210            Self::LengthLimitExceeded => None,
211
212            #[cfg(feature = "arbitrary")]
213            Self::Arbitrary(e) => Some(e),
214        }
215    }
216}
217
218impl fmt::Display for Error {
219    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
220        match self {
221            Error::Invalid => write!(f, "xdr value invalid"),
222            Error::Unsupported => write!(f, "xdr value unsupported"),
223            Error::LengthExceedsMax => write!(f, "xdr value max length exceeded"),
224            Error::LengthMismatch => write!(f, "xdr value length does not match"),
225            Error::NonZeroPadding => write!(f, "xdr padding contains non-zero bytes"),
226            Error::Utf8Error(e) => write!(f, "{e}"),
227
228            #[cfg(feature = "alloc")]
229            Error::InvalidHex => write!(f, "hex invalid"),
230
231            #[cfg(feature = "std")]
232            Error::Io(e) => write!(f, "{e}"),
233
234            Error::DepthLimitExceeded => write!(f, "depth limit exceeded"),
235
236            #[cfg(feature = "serde_json")]
237            Error::Json(e) => write!(f, "{e}"),
238
239            Error::LengthLimitExceeded => write!(f, "length limit exceeded"),
240
241            #[cfg(feature = "arbitrary")]
242            Error::Arbitrary(e) => write!(f, "{e}"),
243        }
244    }
245}
246
247/// The error returned by the borrowing `Const` types' `try_from_slice` and
248/// `try_from_str` constructors when the input length exceeds the type's `MAX`.
249///
250/// Unlike [`Error`] it is `Copy` and free of any destructor, so a
251/// `Result<_, ErrorLengthExceedsMax>` can be matched in a const context (a
252/// `Result<_, Error>` cannot, because `Error` owns fields that have
253/// destructors). It converts into [`Error::LengthExceedsMax`] via [`From`], so
254/// runtime callers can still propagate it with `?`.
255#[derive(Debug, Clone, Copy, PartialEq, Eq)]
256pub struct ErrorLengthExceedsMax;
257
258impl From<ErrorLengthExceedsMax> for Error {
259    #[must_use]
260    fn from(_: ErrorLengthExceedsMax) -> Self {
261        Error::LengthExceedsMax
262    }
263}
264
265impl fmt::Display for ErrorLengthExceedsMax {
266    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
267        write!(f, "xdr value max length exceeded")
268    }
269}
270
271#[cfg(feature = "std")]
272impl error::Error for ErrorLengthExceedsMax {}
273
274impl From<TryFromSliceError> for Error {
275    fn from(_: TryFromSliceError) -> Error {
276        Error::LengthMismatch
277    }
278}
279
280impl From<core::str::Utf8Error> for Error {
281    #[must_use]
282    fn from(e: core::str::Utf8Error) -> Self {
283        Error::Utf8Error(e)
284    }
285}
286
287#[cfg(feature = "alloc")]
288impl From<FromUtf8Error> for Error {
289    #[must_use]
290    fn from(e: FromUtf8Error) -> Self {
291        Error::Utf8Error(e.utf8_error())
292    }
293}
294
295#[cfg(feature = "std")]
296impl From<io::Error> for Error {
297    #[must_use]
298    fn from(e: io::Error) -> Self {
299        Error::Io(e)
300    }
301}
302
303#[cfg(feature = "serde_json")]
304impl From<serde_json::Error> for Error {
305    #[must_use]
306    fn from(e: serde_json::Error) -> Self {
307        Error::Json(e)
308    }
309}
310
311#[cfg(feature = "arbitrary")]
312impl From<arbitrary::Error> for Error {
313    #[must_use]
314    fn from(e: arbitrary::Error) -> Self {
315        Error::Arbitrary(e)
316    }
317}
318
319impl From<Error> for () {
320    fn from(_: Error) {}
321}
322
323/// Name defines types that assign a static name to their value, such as the
324/// name given to an identifier in an XDR enum, or the name given to the case in
325/// a union.
326pub trait Name {
327    fn name(&self) -> &'static str;
328}
329
330/// Discriminant defines types that may contain a one-of value determined
331/// according to the discriminant, and exposes the value of the discriminant for
332/// that type, such as in an XDR union.
333pub trait Discriminant<D> {
334    fn discriminant(&self) -> D;
335}
336
337/// Iter defines types that have variants that can be iterated.
338pub trait Variants<V> {
339    fn variants() -> slice::Iter<'static, V>
340    where
341        V: Sized;
342}
343
344// Enum defines a type that is represented as an XDR enumeration when encoded.
345pub trait Enum: Name + Variants<Self> + Sized {}
346
347// Union defines a type that is represented as an XDR union when encoded.
348pub trait Union<D>: Name + Discriminant<D> + Variants<D>
349where
350    D: Sized,
351{
352}
353
354/// `Limits` contains the limits that a limited reader or writer will be
355/// constrained to.
356#[cfg(feature = "std")]
357#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
358pub struct Limits {
359    /// Defines the maximum depth for recursive calls in `Read/WriteXdr` to
360    /// prevent stack overflow.
361    ///
362    /// The depth limit is akin to limiting stack depth. Its purpose is to
363    /// prevent the program from hitting the maximum stack size allowed by Rust,
364    /// which would result in an unrecoverable `SIGABRT`.  For more information
365    /// about Rust's stack size limit, refer to the [Rust
366    /// documentation](https://doc.rust-lang.org/std/thread/#stack-size).
367    pub depth: u32,
368
369    /// Defines the maximum number of bytes that will be read or written.
370    pub len: usize,
371}
372
373#[cfg(feature = "std")]
374impl Limits {
375    #[must_use]
376    pub fn none() -> Self {
377        Self {
378            depth: u32::MAX,
379            len: usize::MAX,
380        }
381    }
382
383    #[must_use]
384    pub fn depth(depth: u32) -> Self {
385        Limits {
386            depth,
387            ..Limits::none()
388        }
389    }
390
391    #[must_use]
392    pub fn len(len: usize) -> Self {
393        Limits {
394            len,
395            ..Limits::none()
396        }
397    }
398}
399
400/// `Limited` wraps an object and provides functions for enforcing limits.
401///
402/// Intended for use with readers and writers and limiting their reads and
403/// writes.
404#[cfg(feature = "std")]
405pub struct Limited<L> {
406    pub inner: L,
407    pub(crate) limits: Limits,
408}
409
410#[cfg(feature = "std")]
411impl<L> Limited<L> {
412    /// Constructs a new `Limited`.
413    ///
414    /// - `inner`: The value being limited.
415    /// - `limits`: The limits to enforce.
416    pub fn new(inner: L, limits: Limits) -> Self {
417        Limited { inner, limits }
418    }
419
420    /// Consume the given length from the internal remaining length limit.
421    ///
422    /// ### Errors
423    ///
424    /// If the length would consume more length than the remaining length limit
425    /// allows.
426    pub(crate) fn consume_len(&mut self, len: usize) -> Result<(), Error> {
427        if let Some(len) = self.limits.len.checked_sub(len) {
428            self.limits.len = len;
429            Ok(())
430        } else {
431            Err(Error::LengthLimitExceeded)
432        }
433    }
434
435    /// Consumes a single depth for the duration of the given function.
436    ///
437    /// ### Errors
438    ///
439    /// If the depth limit is already exhausted.
440    pub(crate) fn with_limited_depth<T, F>(&mut self, f: F) -> Result<T, Error>
441    where
442        F: FnOnce(&mut Self) -> Result<T, Error>,
443    {
444        if let Some(depth) = self.limits.depth.checked_sub(1) {
445            self.limits.depth = depth;
446            let res = f(self);
447            self.limits.depth = self.limits.depth.saturating_add(1);
448            res
449        } else {
450            Err(Error::DepthLimitExceeded)
451        }
452    }
453}
454
455#[cfg(feature = "std")]
456impl<R: Read> Read for Limited<R> {
457    /// Forwards the read operation to the wrapped object.
458    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
459        self.inner.read(buf)
460    }
461}
462
463#[cfg(feature = "std")]
464impl<R: BufRead> BufRead for Limited<R> {
465    /// Forwards the read operation to the wrapped object.
466    fn fill_buf(&mut self) -> std::io::Result<&[u8]> {
467        self.inner.fill_buf()
468    }
469
470    /// Forwards the read operation to the wrapped object.
471    fn consume(&mut self, amt: usize) {
472        self.inner.consume(amt);
473    }
474}
475
476#[cfg(feature = "std")]
477impl<W: Write> Write for Limited<W> {
478    /// Forwards the write operation to the wrapped object.
479    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
480        self.inner.write(buf)
481    }
482
483    /// Forwards the flush operation to the wrapped object.
484    fn flush(&mut self) -> std::io::Result<()> {
485        self.inner.flush()
486    }
487}
488
489#[cfg(feature = "std")]
490pub struct ReadXdrIter<R: Read, S: ReadXdr> {
491    reader: Limited<BufReader<R>>,
492    _s: PhantomData<S>,
493}
494
495#[cfg(feature = "std")]
496impl<R: Read, S: ReadXdr> ReadXdrIter<R, S> {
497    fn new(r: R, limits: Limits) -> Self {
498        Self {
499            reader: Limited {
500                inner: BufReader::new(r),
501                limits,
502            },
503            _s: PhantomData,
504        }
505    }
506}
507
508#[cfg(feature = "std")]
509impl<R: Read, S: ReadXdr> Iterator for ReadXdrIter<R, S> {
510    type Item = Result<S, Error>;
511
512    // Next reads the internal reader and XDR decodes it into the Self type. If
513    // the EOF is reached without reading any new bytes `None` is returned. If
514    // EOF is reached after reading some bytes a truncated entry is assumed an
515    // an `Error::Io` containing an `UnexpectedEof`. If any other IO error
516    // occurs it is returned. Iteration of this iterator stops naturally when
517    // `None` is returned, but not when a `Some(Err(...))` is returned. The
518    // caller is responsible for checking each Result.
519    fn next(&mut self) -> Option<Self::Item> {
520        // Try to fill the buffer to see if the EOF has been reached or not.
521        // This happens to effectively peek to see if the stream has finished
522        // and there are no more items.  It is necessary to do this because the
523        // xdr types in this crate heavily use the `std::io::Read::read_exact`
524        // method that doesn't distinguish between an EOF at the beginning of a
525        // read and an EOF after a partial fill of a read_exact.
526        match self.reader.fill_buf() {
527            // If the reader has no more data and is unable to fill any new data
528            // into its internal buf, then the EOF has been reached.
529            Ok([]) => return None,
530            // If an error occurs filling the buffer, treat that as an error and stop.
531            Err(e) => return Some(Err(Error::Io(e))),
532            // If there is data in the buf available for reading, continue.
533            Ok([..]) => (),
534        }
535        // Read the buf into the type.
536        let r = self.reader.with_limited_depth(|dlr| S::read_xdr(dlr));
537        match r {
538            Ok(s) => Some(Ok(s)),
539            Err(e) => Some(Err(e)),
540        }
541    }
542}
543
544pub trait ReadXdr
545where
546    Self: Sized,
547{
548    /// Read the XDR and construct the type.
549    ///
550    /// Read bytes from the given read implementation, decoding the bytes as
551    /// XDR, and construct the type implementing this interface from those
552    /// bytes.
553    ///
554    /// Just enough bytes are read from the read implementation to construct the
555    /// type. Any residual bytes remain in the read implementation.
556    ///
557    /// All implementations should continue if the read implementation returns
558    /// [`ErrorKind::Interrupted`](std::io::ErrorKind::Interrupted).
559    ///
560    /// Use [`ReadXdR: Read_xdr_to_end`] when the intent is for all bytes in the
561    /// read implementation to be consumed by the read.
562    #[cfg(feature = "std")]
563    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error>;
564
565    /// Construct the type from the XDR bytes base64 encoded.
566    ///
567    /// An error is returned if the bytes are not completely consumed by the
568    /// deserialization.
569    #[cfg(feature = "base64")]
570    fn read_xdr_base64<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
571        let mut dec = Limited::new(
572            base64::read::DecoderReader::new(
573                SkipWhitespace::new(&mut r.inner),
574                &base64::engine::general_purpose::STANDARD,
575            ),
576            r.limits.clone(),
577        );
578        let t = Self::read_xdr(&mut dec)?;
579        Ok(t)
580    }
581
582    /// Read the XDR and construct the type, and consider it an error if the
583    /// read does not completely consume the read implementation.
584    ///
585    /// Read bytes from the given read implementation, decoding the bytes as
586    /// XDR, and construct the type implementing this interface from those
587    /// bytes.
588    ///
589    /// Just enough bytes are read from the read implementation to construct the
590    /// type, and then confirm that no further bytes remain. To confirm no
591    /// further bytes remain additional bytes are attempted to be read from the
592    /// read implementation. If it is possible to read any residual bytes from
593    /// the read implementation an error is returned. The read implementation
594    /// may not be exhaustively read if there are residual bytes, and it is
595    /// considered undefined how many residual bytes or how much of the residual
596    /// buffer are consumed in this case.
597    ///
598    /// All implementations should continue if the read implementation returns
599    /// [`ErrorKind::Interrupted`](std::io::ErrorKind::Interrupted).
600    #[cfg(feature = "std")]
601    fn read_xdr_to_end<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
602        let s = Self::read_xdr(r)?;
603        // Check that any further reads, such as this read of one byte, read no
604        // data, indicating EOF. If a byte is read the data is invalid.
605        if r.read(&mut [0u8; 1])? == 0 {
606            Ok(s)
607        } else {
608            Err(Error::Invalid)
609        }
610    }
611
612    /// Construct the type from the XDR bytes base64 encoded.
613    ///
614    /// An error is returned if the bytes are not completely consumed by the
615    /// deserialization.
616    #[cfg(feature = "base64")]
617    fn read_xdr_base64_to_end<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
618        let mut dec = Limited::new(
619            base64::read::DecoderReader::new(
620                SkipWhitespace::new(&mut r.inner),
621                &base64::engine::general_purpose::STANDARD,
622            ),
623            r.limits.clone(),
624        );
625        let t = Self::read_xdr_to_end(&mut dec)?;
626        Ok(t)
627    }
628
629    /// Read the XDR and construct the type.
630    ///
631    /// Read bytes from the given read implementation, decoding the bytes as
632    /// XDR, and construct the type implementing this interface from those
633    /// bytes.
634    ///
635    /// Just enough bytes are read from the read implementation to construct the
636    /// type. Any residual bytes remain in the read implementation.
637    ///
638    /// All implementations should continue if the read implementation returns
639    /// [`ErrorKind::Interrupted`](std::io::ErrorKind::Interrupted).
640    ///
641    /// Use [`ReadXdR: Read_xdr_into_to_end`] when the intent is for all bytes
642    /// in the read implementation to be consumed by the read.
643    #[cfg(feature = "std")]
644    fn read_xdr_into<R: Read>(&mut self, r: &mut Limited<R>) -> Result<(), Error> {
645        *self = Self::read_xdr(r)?;
646        Ok(())
647    }
648
649    /// Read the XDR into the existing value, and consider it an error if the
650    /// read does not completely consume the read implementation.
651    ///
652    /// Read bytes from the given read implementation, decoding the bytes as
653    /// XDR, and construct the type implementing this interface from those
654    /// bytes.
655    ///
656    /// Just enough bytes are read from the read implementation to construct the
657    /// type, and then confirm that no further bytes remain. To confirm no
658    /// further bytes remain additional bytes are attempted to be read from the
659    /// read implementation. If it is possible to read any residual bytes from
660    /// the read implementation an error is returned. The read implementation
661    /// may not be exhaustively read if there are residual bytes, and it is
662    /// considered undefined how many residual bytes or how much of the residual
663    /// buffer are consumed in this case.
664    ///
665    /// All implementations should continue if the read implementation returns
666    /// [`ErrorKind::Interrupted`](std::io::ErrorKind::Interrupted).
667    #[cfg(feature = "std")]
668    fn read_xdr_into_to_end<R: Read>(&mut self, r: &mut Limited<R>) -> Result<(), Error> {
669        Self::read_xdr_into(self, r)?;
670        // Check that any further reads, such as this read of one byte, read no
671        // data, indicating EOF. If a byte is read the data is invalid.
672        if r.read(&mut [0u8; 1])? == 0 {
673            Ok(())
674        } else {
675            Err(Error::Invalid)
676        }
677    }
678
679    /// Create an iterator that reads the read implementation as a stream of
680    /// values that are read into the implementing type.
681    ///
682    /// Read bytes from the given read implementation, decoding the bytes as
683    /// XDR, and construct the type implementing this interface from those
684    /// bytes.
685    ///
686    /// Just enough bytes are read from the read implementation to construct the
687    /// type, and then confirm that no further bytes remain. To confirm no
688    /// further bytes remain additional bytes are attempted to be read from the
689    /// read implementation. If it is possible to read any residual bytes from
690    /// the read implementation an error is returned. The read implementation
691    /// may not be exhaustively read if there are residual bytes, and it is
692    /// considered undefined how many residual bytes or how much of the residual
693    /// buffer are consumed in this case.
694    ///
695    /// All implementations should continue if the read implementation returns
696    /// [`ErrorKind::Interrupted`](std::io::ErrorKind::Interrupted).
697    #[cfg(feature = "std")]
698    fn read_xdr_iter<R: Read>(r: &mut Limited<R>) -> ReadXdrIter<&mut R, Self> {
699        ReadXdrIter::new(&mut r.inner, r.limits.clone())
700    }
701
702    /// Create an iterator that reads the read implementation as a stream of
703    /// values that are read into the implementing type.
704    #[cfg(feature = "base64")]
705    fn read_xdr_base64_iter<R: Read>(
706        r: &mut Limited<R>,
707    ) -> ReadXdrIter<
708        base64::read::DecoderReader<
709            '_,
710            base64::engine::general_purpose::GeneralPurpose,
711            SkipWhitespace<&mut R>,
712        >,
713        Self,
714    > {
715        let dec = base64::read::DecoderReader::new(
716            SkipWhitespace::new(&mut r.inner),
717            &base64::engine::general_purpose::STANDARD,
718        );
719        ReadXdrIter::new(dec, r.limits.clone())
720    }
721
722    /// Construct the type from the XDR bytes.
723    ///
724    /// An error is returned if the bytes are not completely consumed by the
725    /// deserialization.
726    #[cfg(feature = "std")]
727    fn from_xdr(bytes: impl AsRef<[u8]>, limits: Limits) -> Result<Self, Error> {
728        let mut cursor = Limited::new(Cursor::new(bytes.as_ref()), limits);
729        let t = Self::read_xdr_to_end(&mut cursor)?;
730        Ok(t)
731    }
732
733    /// Construct the type from the XDR bytes base64 encoded.
734    ///
735    /// An error is returned if the bytes are not completely consumed by the
736    /// deserialization.
737    #[cfg(feature = "base64")]
738    fn from_xdr_base64(b64: impl AsRef<[u8]>, limits: Limits) -> Result<Self, Error> {
739        let b64_reader = Cursor::new(b64);
740        let mut dec = Limited::new(
741            base64::read::DecoderReader::new(
742                SkipWhitespace::new(b64_reader),
743                &base64::engine::general_purpose::STANDARD,
744            ),
745            limits,
746        );
747        let t = Self::read_xdr_to_end(&mut dec)?;
748        Ok(t)
749    }
750}
751
752pub trait WriteXdr {
753    #[cfg(feature = "std")]
754    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error>;
755
756    #[cfg(feature = "std")]
757    fn to_xdr(&self, limits: Limits) -> Result<Vec<u8>, Error> {
758        let mut cursor = Limited::new(Cursor::new(vec![]), limits);
759        self.write_xdr(&mut cursor)?;
760        let bytes = cursor.inner.into_inner();
761        Ok(bytes)
762    }
763
764    #[cfg(feature = "base64")]
765    fn to_xdr_base64(&self, limits: Limits) -> Result<String, Error> {
766        let mut enc = Limited::new(
767            base64::write::EncoderStringWriter::new(&base64::engine::general_purpose::STANDARD),
768            limits,
769        );
770        self.write_xdr(&mut enc)?;
771        let b64 = enc.inner.into_inner();
772        Ok(b64)
773    }
774}
775
776/// `Pad_len` returns the number of bytes to pad an XDR value of the given
777/// length to make the final serialized size a multiple of 4.
778#[cfg(any(feature = "std", feature = "const"))]
779const fn pad_len(len: usize) -> usize {
780    (4 - (len % 4)) % 4
781}
782
783impl ReadXdr for i32 {
784    #[cfg(feature = "std")]
785    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
786        let mut b = [0u8; 4];
787        r.with_limited_depth(|r| {
788            r.consume_len(b.len())?;
789            r.read_exact(&mut b)?;
790            Ok(i32::from_be_bytes(b))
791        })
792    }
793}
794
795impl WriteXdr for i32 {
796    #[cfg(feature = "std")]
797    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
798        let b: [u8; 4] = self.to_be_bytes();
799        w.with_limited_depth(|w| {
800            w.consume_len(b.len())?;
801            Ok(w.write_all(&b)?)
802        })
803    }
804}
805
806impl ReadXdr for u32 {
807    #[cfg(feature = "std")]
808    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
809        let mut b = [0u8; 4];
810        r.with_limited_depth(|r| {
811            r.consume_len(b.len())?;
812            r.read_exact(&mut b)?;
813            Ok(u32::from_be_bytes(b))
814        })
815    }
816}
817
818impl WriteXdr for u32 {
819    #[cfg(feature = "std")]
820    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
821        let b: [u8; 4] = self.to_be_bytes();
822        w.with_limited_depth(|w| {
823            w.consume_len(b.len())?;
824            Ok(w.write_all(&b)?)
825        })
826    }
827}
828
829impl ReadXdr for i64 {
830    #[cfg(feature = "std")]
831    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
832        let mut b = [0u8; 8];
833        r.with_limited_depth(|r| {
834            r.consume_len(b.len())?;
835            r.read_exact(&mut b)?;
836            Ok(i64::from_be_bytes(b))
837        })
838    }
839}
840
841impl WriteXdr for i64 {
842    #[cfg(feature = "std")]
843    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
844        let b: [u8; 8] = self.to_be_bytes();
845        w.with_limited_depth(|w| {
846            w.consume_len(b.len())?;
847            Ok(w.write_all(&b)?)
848        })
849    }
850}
851
852impl ReadXdr for u64 {
853    #[cfg(feature = "std")]
854    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
855        let mut b = [0u8; 8];
856        r.with_limited_depth(|r| {
857            r.consume_len(b.len())?;
858            r.read_exact(&mut b)?;
859            Ok(u64::from_be_bytes(b))
860        })
861    }
862}
863
864impl WriteXdr for u64 {
865    #[cfg(feature = "std")]
866    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
867        let b: [u8; 8] = self.to_be_bytes();
868        w.with_limited_depth(|w| {
869            w.consume_len(b.len())?;
870            Ok(w.write_all(&b)?)
871        })
872    }
873}
874
875impl ReadXdr for f32 {
876    #[cfg(feature = "std")]
877    fn read_xdr<R: Read>(_r: &mut Limited<R>) -> Result<Self, Error> {
878        todo!()
879    }
880}
881
882impl WriteXdr for f32 {
883    #[cfg(feature = "std")]
884    fn write_xdr<W: Write>(&self, _w: &mut Limited<W>) -> Result<(), Error> {
885        todo!()
886    }
887}
888
889impl ReadXdr for f64 {
890    #[cfg(feature = "std")]
891    fn read_xdr<R: Read>(_r: &mut Limited<R>) -> Result<Self, Error> {
892        todo!()
893    }
894}
895
896impl WriteXdr for f64 {
897    #[cfg(feature = "std")]
898    fn write_xdr<W: Write>(&self, _w: &mut Limited<W>) -> Result<(), Error> {
899        todo!()
900    }
901}
902
903impl ReadXdr for bool {
904    #[cfg(feature = "std")]
905    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
906        r.with_limited_depth(|r| {
907            let i = u32::read_xdr(r)?;
908            let b = i == 1;
909            Ok(b)
910        })
911    }
912}
913
914impl WriteXdr for bool {
915    #[cfg(feature = "std")]
916    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
917        w.with_limited_depth(|w| {
918            let i = u32::from(*self); // true = 1, false = 0
919            i.write_xdr(w)
920        })
921    }
922}
923
924impl<T: ReadXdr> ReadXdr for Option<T> {
925    #[cfg(feature = "std")]
926    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
927        r.with_limited_depth(|r| {
928            let i = u32::read_xdr(r)?;
929            match i {
930                0 => Ok(None),
931                1 => {
932                    let t = T::read_xdr(r)?;
933                    Ok(Some(t))
934                }
935                _ => Err(Error::Invalid),
936            }
937        })
938    }
939}
940
941impl<T: WriteXdr> WriteXdr for Option<T> {
942    #[cfg(feature = "std")]
943    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
944        w.with_limited_depth(|w| {
945            if let Some(t) = self {
946                1u32.write_xdr(w)?;
947                t.write_xdr(w)?;
948            } else {
949                0u32.write_xdr(w)?;
950            }
951            Ok(())
952        })
953    }
954}
955
956impl<T: ReadXdr> ReadXdr for Box<T> {
957    #[cfg(feature = "std")]
958    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
959        r.with_limited_depth(|r| Ok(Box::new(T::read_xdr(r)?)))
960    }
961}
962
963impl<T: WriteXdr> WriteXdr for Box<T> {
964    #[cfg(feature = "std")]
965    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
966        w.with_limited_depth(|w| T::write_xdr(self, w))
967    }
968}
969
970impl ReadXdr for () {
971    #[cfg(feature = "std")]
972    fn read_xdr<R: Read>(_r: &mut Limited<R>) -> Result<Self, Error> {
973        Ok(())
974    }
975}
976
977impl WriteXdr for () {
978    #[cfg(feature = "std")]
979    fn write_xdr<W: Write>(&self, _w: &mut Limited<W>) -> Result<(), Error> {
980        Ok(())
981    }
982}
983
984impl<const N: usize> ReadXdr for [u8; N] {
985    #[cfg(feature = "std")]
986    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
987        r.with_limited_depth(|r| {
988            r.consume_len(N)?;
989            let padding = pad_len(N);
990            r.consume_len(padding)?;
991            let mut arr = [0u8; N];
992            r.read_exact(&mut arr)?;
993            let pad = &mut [0u8; 3][..padding];
994            r.read_exact(pad)?;
995            if pad.iter().any(|b| *b != 0) {
996                return Err(Error::NonZeroPadding);
997            }
998            Ok(arr)
999        })
1000    }
1001}
1002
1003impl<const N: usize> WriteXdr for [u8; N] {
1004    #[cfg(feature = "std")]
1005    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
1006        w.with_limited_depth(|w| {
1007            w.consume_len(N)?;
1008            let padding = pad_len(N);
1009            w.consume_len(padding)?;
1010            w.write_all(self)?;
1011            w.write_all(&[0u8; 3][..padding])?;
1012            Ok(())
1013        })
1014    }
1015}
1016
1017impl<T: ReadXdr, const N: usize> ReadXdr for [T; N] {
1018    #[cfg(feature = "std")]
1019    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
1020        r.with_limited_depth(|r| {
1021            let mut vec = Vec::with_capacity(N);
1022            for _ in 0..N {
1023                let t = T::read_xdr(r)?;
1024                vec.push(t);
1025            }
1026            let arr: [T; N] = vec.try_into().unwrap_or_else(|_: Vec<T>| unreachable!());
1027            Ok(arr)
1028        })
1029    }
1030}
1031
1032impl<T: WriteXdr, const N: usize> WriteXdr for [T; N] {
1033    #[cfg(feature = "std")]
1034    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
1035        w.with_limited_depth(|w| {
1036            for t in self {
1037                t.write_xdr(w)?;
1038            }
1039            Ok(())
1040        })
1041    }
1042}
1043
1044// VecM ------------------------------------------------------------------------
1045
1046#[cfg(feature = "alloc")]
1047#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
1048#[cfg_attr(
1049    feature = "serde",
1050    serde_with::serde_as,
1051    derive(serde::Serialize, serde::Deserialize),
1052    serde(try_from = "Vec<T>")
1053)]
1054pub struct VecM<T, const MAX: u32 = { u32::MAX }>(Vec<T>);
1055
1056#[cfg(not(feature = "alloc"))]
1057#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
1058pub struct VecM<T, const MAX: u32 = { u32::MAX }>(Vec<T>)
1059where
1060    T: 'static;
1061
1062/// `MAX` as a length, saturating where `usize` is narrower than `u32`.
1063///
1064/// Shared with the const types' `Arbitrary` impls, which must truncate exactly
1065/// as these do for the two forms to hold the same value.
1066#[cfg(feature = "arbitrary")]
1067pub(crate) const fn arbitrary_max_len(max: u32) -> usize {
1068    if max as u64 > usize::MAX as u64 {
1069        usize::MAX
1070    } else {
1071        max as usize
1072    }
1073}
1074
1075/// The length limit is an invariant of the type, and a derived impl would
1076/// produce values outside it, because `MAX` lives in a const parameter the
1077/// derive cannot see.
1078///
1079/// `Vec`'s own impl reads a continuation byte before each element, so capping
1080/// the iterator stops at `MAX` without reading, and then discarding, the
1081/// elements past it.
1082#[cfg(feature = "arbitrary")]
1083impl<'a, T: Arbitrary<'a>, const MAX: u32> Arbitrary<'a> for VecM<T, MAX> {
1084    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
1085        Ok(Self(
1086            u.arbitrary_iter()?
1087                .take(arbitrary_max_len(MAX))
1088                .collect::<arbitrary::Result<Vec<T>>>()?,
1089        ))
1090    }
1091
1092    fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
1093        Ok(Self(
1094            u.arbitrary_take_rest_iter()?
1095                .take(arbitrary_max_len(MAX))
1096                .collect::<arbitrary::Result<Vec<T>>>()?,
1097        ))
1098    }
1099
1100    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1101        Vec::<T>::size_hint(depth)
1102    }
1103}
1104
1105impl<T, const MAX: u32> Deref for VecM<T, MAX> {
1106    type Target = Vec<T>;
1107
1108    fn deref(&self) -> &Self::Target {
1109        &self.0
1110    }
1111}
1112
1113impl<T, const MAX: u32> Default for VecM<T, MAX> {
1114    fn default() -> Self {
1115        Self(Vec::default())
1116    }
1117}
1118
1119#[cfg(feature = "schemars")]
1120impl<T: schemars::JsonSchema, const MAX: u32> schemars::JsonSchema for VecM<T, MAX> {
1121    fn schema_name() -> String {
1122        format!("VecM<{}, {}>", T::schema_name(), MAX)
1123    }
1124
1125    fn is_referenceable() -> bool {
1126        false
1127    }
1128
1129    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
1130        let schema = Vec::<T>::json_schema(gen);
1131        if let schemars::schema::Schema::Object(mut schema) = schema {
1132            if let Some(array) = schema.array.clone() {
1133                schema.array = Some(Box::new(schemars::schema::ArrayValidation {
1134                    max_items: Some(MAX),
1135                    ..*array
1136                }));
1137            }
1138            schema.into()
1139        } else {
1140            schema
1141        }
1142    }
1143}
1144
1145#[cfg(feature = "schemars")]
1146impl<T, TA, const MAX: u32> serde_with::schemars_0_8::JsonSchemaAs<VecM<T, MAX>> for VecM<TA, MAX>
1147where
1148    TA: serde_with::schemars_0_8::JsonSchemaAs<T>,
1149{
1150    fn schema_name() -> String {
1151        <VecM<serde_with::Schema<T, TA>, MAX> as schemars::JsonSchema>::schema_name()
1152    }
1153
1154    fn schema_id() -> Cow<'static, str> {
1155        <VecM<serde_with::Schema<T, TA>, MAX> as schemars::JsonSchema>::schema_id()
1156    }
1157
1158    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
1159        <VecM<serde_with::Schema<T, TA>, MAX> as schemars::JsonSchema>::json_schema(gen)
1160    }
1161
1162    fn is_referenceable() -> bool {
1163        <VecM<serde_with::Schema<T, TA>, MAX> as schemars::JsonSchema>::is_referenceable()
1164    }
1165}
1166
1167#[cfg(feature = "serde")]
1168impl<T, U, const MAX: u32> serde_with::SerializeAs<VecM<T, MAX>> for VecM<U, MAX>
1169where
1170    U: serde_with::SerializeAs<T>,
1171{
1172    fn serialize_as<S>(source: &VecM<T, MAX>, serializer: S) -> Result<S::Ok, S::Error>
1173    where
1174        S: serde::Serializer,
1175    {
1176        serializer.collect_seq(
1177            source
1178                .iter()
1179                .map(|item| serde_with::ser::SerializeAsWrap::<T, U>::new(item)),
1180        )
1181    }
1182}
1183
1184#[cfg(feature = "serde")]
1185impl<'de, T, U, const MAX: u32> serde_with::DeserializeAs<'de, VecM<T, MAX>> for VecM<U, MAX>
1186where
1187    U: serde_with::DeserializeAs<'de, T>,
1188{
1189    fn deserialize_as<D>(deserializer: D) -> Result<VecM<T, MAX>, D::Error>
1190    where
1191        D: serde::Deserializer<'de>,
1192    {
1193        let vec = <Vec<U> as serde_with::DeserializeAs<Vec<T>>>::deserialize_as(deserializer)?;
1194        vec.try_into().map_err(serde::de::Error::custom)
1195    }
1196}
1197
1198impl<T, const MAX: u32> VecM<T, MAX> {
1199    pub const MAX_LEN: usize = { MAX as usize };
1200
1201    #[must_use]
1202    #[allow(clippy::unused_self)]
1203    pub fn max_len(&self) -> usize {
1204        Self::MAX_LEN
1205    }
1206
1207    #[must_use]
1208    pub fn as_vec(&self) -> &Vec<T> {
1209        self.as_ref()
1210    }
1211}
1212
1213#[cfg(feature = "alloc")]
1214impl<T, const MAX: u32> VecM<T, MAX> {
1215    pub fn iter_mut(&mut self) -> core::slice::IterMut<'_, T> {
1216        self.0.iter_mut()
1217    }
1218}
1219
1220#[cfg(feature = "alloc")]
1221impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a mut VecM<T, MAX> {
1222    type Item = &'a mut T;
1223    type IntoIter = core::slice::IterMut<'a, T>;
1224    fn into_iter(self) -> Self::IntoIter {
1225        self.iter_mut()
1226    }
1227}
1228
1229#[cfg(feature = "alloc")]
1230impl<T, const MAX: u32> core::iter::IntoIterator for VecM<T, MAX> {
1231    type Item = T;
1232    type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
1233    fn into_iter(self) -> Self::IntoIter {
1234        self.0.into_iter()
1235    }
1236}
1237
1238impl<'a, T, const MAX: u32> core::iter::IntoIterator for &'a VecM<T, MAX> {
1239    type Item = &'a T;
1240    type IntoIter = core::slice::Iter<'a, T>;
1241    fn into_iter(self) -> Self::IntoIter {
1242        self.iter()
1243    }
1244}
1245
1246impl<T: Clone, const MAX: u32> VecM<T, MAX> {
1247    #[must_use]
1248    #[cfg(feature = "alloc")]
1249    pub fn to_vec(&self) -> Vec<T> {
1250        self.into()
1251    }
1252
1253    #[must_use]
1254    pub fn into_vec(self) -> Vec<T> {
1255        self.into()
1256    }
1257}
1258
1259impl<const MAX: u32> VecM<u8, MAX> {
1260    #[cfg(feature = "alloc")]
1261    pub fn to_string(&self) -> Result<String, Error> {
1262        self.try_into()
1263    }
1264
1265    #[cfg(feature = "alloc")]
1266    pub fn into_string(self) -> Result<String, Error> {
1267        self.try_into()
1268    }
1269
1270    #[cfg(feature = "alloc")]
1271    #[must_use]
1272    pub fn to_string_lossy(&self) -> String {
1273        String::from_utf8_lossy(&self.0).into_owned()
1274    }
1275
1276    #[cfg(feature = "alloc")]
1277    #[must_use]
1278    pub fn into_string_lossy(self) -> String {
1279        String::from_utf8_lossy(&self.0).into_owned()
1280    }
1281}
1282
1283impl<T: Clone> VecM<T, 1> {
1284    #[must_use]
1285    pub fn to_option(&self) -> Option<T> {
1286        if self.len() > 0 {
1287            Some(self.0[0].clone())
1288        } else {
1289            None
1290        }
1291    }
1292}
1293
1294#[cfg(not(feature = "alloc"))]
1295impl<T: Clone> From<VecM<T, 1>> for Option<T> {
1296    #[must_use]
1297    fn from(v: VecM<T, 1>) -> Self {
1298        v.to_option()
1299    }
1300}
1301
1302#[cfg(feature = "alloc")]
1303impl<T> VecM<T, 1> {
1304    #[must_use]
1305    pub fn into_option(mut self) -> Option<T> {
1306        self.0.drain(..).next()
1307    }
1308}
1309
1310#[cfg(feature = "alloc")]
1311impl<T> From<VecM<T, 1>> for Option<T> {
1312    #[must_use]
1313    fn from(v: VecM<T, 1>) -> Self {
1314        v.into_option()
1315    }
1316}
1317
1318impl<T, const MAX: u32> TryFrom<Vec<T>> for VecM<T, MAX> {
1319    type Error = Error;
1320
1321    fn try_from(v: Vec<T>) -> Result<Self, Error> {
1322        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1323        if len <= MAX {
1324            Ok(VecM(v))
1325        } else {
1326            Err(Error::LengthExceedsMax)
1327        }
1328    }
1329}
1330
1331impl<T, const MAX: u32> From<VecM<T, MAX>> for Vec<T> {
1332    #[must_use]
1333    fn from(v: VecM<T, MAX>) -> Self {
1334        v.0
1335    }
1336}
1337
1338#[cfg(feature = "alloc")]
1339impl<T: Clone, const MAX: u32> From<&VecM<T, MAX>> for Vec<T> {
1340    #[must_use]
1341    fn from(v: &VecM<T, MAX>) -> Self {
1342        v.0.clone()
1343    }
1344}
1345
1346impl<T, const MAX: u32> AsRef<Vec<T>> for VecM<T, MAX> {
1347    #[must_use]
1348    fn as_ref(&self) -> &Vec<T> {
1349        &self.0
1350    }
1351}
1352
1353#[cfg(feature = "alloc")]
1354impl<T: Clone, const MAX: u32> TryFrom<&Vec<T>> for VecM<T, MAX> {
1355    type Error = Error;
1356
1357    fn try_from(v: &Vec<T>) -> Result<Self, Error> {
1358        v.as_slice().try_into()
1359    }
1360}
1361
1362#[cfg(feature = "alloc")]
1363impl<T: Clone, const MAX: u32> TryFrom<&[T]> for VecM<T, MAX> {
1364    type Error = Error;
1365
1366    fn try_from(v: &[T]) -> Result<Self, Error> {
1367        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1368        if len <= MAX {
1369            Ok(VecM(v.to_vec()))
1370        } else {
1371            Err(Error::LengthExceedsMax)
1372        }
1373    }
1374}
1375
1376impl<T, const MAX: u32> AsRef<[T]> for VecM<T, MAX> {
1377    #[cfg(feature = "alloc")]
1378    #[must_use]
1379    fn as_ref(&self) -> &[T] {
1380        self.0.as_ref()
1381    }
1382    #[cfg(not(feature = "alloc"))]
1383    #[must_use]
1384    fn as_ref(&self) -> &[T] {
1385        self.0
1386    }
1387}
1388
1389#[cfg(feature = "alloc")]
1390impl<T: Clone, const N: usize, const MAX: u32> TryFrom<[T; N]> for VecM<T, MAX> {
1391    type Error = Error;
1392
1393    fn try_from(v: [T; N]) -> Result<Self, Error> {
1394        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1395        if len <= MAX {
1396            Ok(VecM(v.to_vec()))
1397        } else {
1398            Err(Error::LengthExceedsMax)
1399        }
1400    }
1401}
1402
1403#[cfg(feature = "alloc")]
1404impl<T: Clone, const N: usize, const MAX: u32> TryFrom<VecM<T, MAX>> for [T; N] {
1405    type Error = VecM<T, MAX>;
1406
1407    fn try_from(v: VecM<T, MAX>) -> core::result::Result<Self, Self::Error> {
1408        let s: [T; N] = v.0.try_into().map_err(|v: Vec<T>| VecM::<T, MAX>(v))?;
1409        Ok(s)
1410    }
1411}
1412
1413#[cfg(feature = "alloc")]
1414impl<T: Clone, const N: usize, const MAX: u32> TryFrom<&[T; N]> for VecM<T, MAX> {
1415    type Error = Error;
1416
1417    fn try_from(v: &[T; N]) -> Result<Self, Error> {
1418        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1419        if len <= MAX {
1420            Ok(VecM(v.to_vec()))
1421        } else {
1422            Err(Error::LengthExceedsMax)
1423        }
1424    }
1425}
1426
1427#[cfg(not(feature = "alloc"))]
1428impl<T: Clone, const N: usize, const MAX: u32> TryFrom<&'static [T; N]> for VecM<T, MAX> {
1429    type Error = Error;
1430
1431    fn try_from(v: &'static [T; N]) -> Result<Self, Error> {
1432        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1433        if len <= MAX {
1434            Ok(VecM(v))
1435        } else {
1436            Err(Error::LengthExceedsMax)
1437        }
1438    }
1439}
1440
1441#[cfg(feature = "alloc")]
1442impl<const MAX: u32> TryFrom<&String> for VecM<u8, MAX> {
1443    type Error = Error;
1444
1445    fn try_from(v: &String) -> Result<Self, Error> {
1446        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1447        if len <= MAX {
1448            Ok(VecM(v.as_bytes().to_vec()))
1449        } else {
1450            Err(Error::LengthExceedsMax)
1451        }
1452    }
1453}
1454
1455#[cfg(feature = "alloc")]
1456impl<const MAX: u32> TryFrom<String> for VecM<u8, MAX> {
1457    type Error = Error;
1458
1459    fn try_from(v: String) -> Result<Self, Error> {
1460        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1461        if len <= MAX {
1462            Ok(VecM(v.into()))
1463        } else {
1464            Err(Error::LengthExceedsMax)
1465        }
1466    }
1467}
1468
1469#[cfg(feature = "alloc")]
1470impl<const MAX: u32> TryFrom<VecM<u8, MAX>> for String {
1471    type Error = Error;
1472
1473    fn try_from(v: VecM<u8, MAX>) -> Result<Self, Error> {
1474        Ok(String::from_utf8(v.0)?)
1475    }
1476}
1477
1478#[cfg(feature = "alloc")]
1479impl<const MAX: u32> TryFrom<&VecM<u8, MAX>> for String {
1480    type Error = Error;
1481
1482    fn try_from(v: &VecM<u8, MAX>) -> Result<Self, Error> {
1483        Ok(core::str::from_utf8(v.as_ref())?.to_owned())
1484    }
1485}
1486
1487#[cfg(feature = "alloc")]
1488impl<const MAX: u32> TryFrom<&str> for VecM<u8, MAX> {
1489    type Error = Error;
1490
1491    fn try_from(v: &str) -> Result<Self, Error> {
1492        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1493        if len <= MAX {
1494            Ok(VecM(v.into()))
1495        } else {
1496            Err(Error::LengthExceedsMax)
1497        }
1498    }
1499}
1500
1501#[cfg(not(feature = "alloc"))]
1502impl<const MAX: u32> TryFrom<&'static str> for VecM<u8, MAX> {
1503    type Error = Error;
1504
1505    fn try_from(v: &'static str) -> Result<Self, Error> {
1506        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1507        if len <= MAX {
1508            Ok(VecM(v.as_bytes()))
1509        } else {
1510            Err(Error::LengthExceedsMax)
1511        }
1512    }
1513}
1514
1515impl<'a, const MAX: u32> TryFrom<&'a VecM<u8, MAX>> for &'a str {
1516    type Error = Error;
1517
1518    fn try_from(v: &'a VecM<u8, MAX>) -> Result<Self, Error> {
1519        Ok(core::str::from_utf8(v.as_ref())?)
1520    }
1521}
1522
1523impl<const MAX: u32> ReadXdr for VecM<u8, MAX> {
1524    #[cfg(feature = "std")]
1525    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
1526        r.with_limited_depth(|r| {
1527            let len: u32 = u32::read_xdr(r)?;
1528            if len > MAX {
1529                return Err(Error::LengthExceedsMax);
1530            }
1531
1532            r.consume_len(len as usize)?;
1533            let padding = pad_len(len as usize);
1534            r.consume_len(padding)?;
1535
1536            let mut vec = vec![0u8; len as usize];
1537            r.read_exact(&mut vec)?;
1538
1539            let pad = &mut [0u8; 3][..padding];
1540            r.read_exact(pad)?;
1541            if pad.iter().any(|b| *b != 0) {
1542                return Err(Error::NonZeroPadding);
1543            }
1544
1545            Ok(VecM(vec))
1546        })
1547    }
1548}
1549
1550impl<const MAX: u32> WriteXdr for VecM<u8, MAX> {
1551    #[cfg(feature = "std")]
1552    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
1553        w.with_limited_depth(|w| {
1554            let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1555            len.write_xdr(w)?;
1556
1557            w.consume_len(self.len())?;
1558            let padding = pad_len(self.len());
1559            w.consume_len(padding)?;
1560
1561            w.write_all(&self.0)?;
1562
1563            w.write_all(&[0u8; 3][..padding])?;
1564
1565            Ok(())
1566        })
1567    }
1568}
1569
1570impl<T: ReadXdr, const MAX: u32> ReadXdr for VecM<T, MAX> {
1571    #[cfg(feature = "std")]
1572    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
1573        r.with_limited_depth(|r| {
1574            let len = u32::read_xdr(r)?;
1575            if len > MAX {
1576                return Err(Error::LengthExceedsMax);
1577            }
1578
1579            let mut vec = Vec::new();
1580            for _ in 0..len {
1581                let t = T::read_xdr(r)?;
1582                if vec.len() == vec.capacity() {
1583                    let cap = vec.capacity();
1584                    let next = if cap == 0 {
1585                        // Mirror Vec's own minimum non-zero capacity, which is
1586                        // a single element for elements larger than 1024 bytes.
1587                        const {
1588                            if size_of::<T>() > 1024 {
1589                                1
1590                            } else {
1591                                4
1592                            }
1593                        }
1594                    } else {
1595                        cap.saturating_mul(2)
1596                    };
1597                    let next = next.min(len as usize);
1598                    vec.reserve_exact(next - vec.len());
1599                }
1600                vec.push(t);
1601            }
1602
1603            Ok(VecM(vec))
1604        })
1605    }
1606}
1607
1608impl<T: WriteXdr, const MAX: u32> WriteXdr for VecM<T, MAX> {
1609    #[cfg(feature = "std")]
1610    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
1611        w.with_limited_depth(|w| {
1612            let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1613            len.write_xdr(w)?;
1614
1615            for t in &self.0 {
1616                t.write_xdr(w)?;
1617            }
1618
1619            Ok(())
1620        })
1621    }
1622}
1623
1624// BytesM ------------------------------------------------------------------------
1625
1626#[cfg(feature = "alloc")]
1627#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
1628#[cfg_attr(
1629    feature = "serde",
1630    derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
1631)]
1632pub struct BytesM<const MAX: u32 = { u32::MAX }>(Vec<u8>);
1633
1634#[cfg(not(feature = "alloc"))]
1635#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
1636pub struct BytesM<const MAX: u32 = { u32::MAX }>(Vec<u8>);
1637
1638/// Length limited to `MAX`, as for [`VecM`].
1639#[cfg(feature = "arbitrary")]
1640impl<'a, const MAX: u32> Arbitrary<'a> for BytesM<MAX> {
1641    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
1642        Ok(Self(
1643            u.arbitrary_iter()?
1644                .take(arbitrary_max_len(MAX))
1645                .collect::<arbitrary::Result<Vec<u8>>>()?,
1646        ))
1647    }
1648
1649    fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
1650        Ok(Self(
1651            u.arbitrary_take_rest_iter()?
1652                .take(arbitrary_max_len(MAX))
1653                .collect::<arbitrary::Result<Vec<u8>>>()?,
1654        ))
1655    }
1656
1657    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1658        Vec::<u8>::size_hint(depth)
1659    }
1660}
1661
1662impl<const MAX: u32> core::fmt::Display for BytesM<MAX> {
1663    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1664        #[cfg(feature = "alloc")]
1665        let v = &self.0;
1666        #[cfg(not(feature = "alloc"))]
1667        let v = self.0;
1668        for b in v {
1669            write!(f, "{b:02x}")?;
1670        }
1671        Ok(())
1672    }
1673}
1674
1675impl<const MAX: u32> core::fmt::Debug for BytesM<MAX> {
1676    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1677        #[cfg(feature = "alloc")]
1678        let v = &self.0;
1679        #[cfg(not(feature = "alloc"))]
1680        let v = self.0;
1681        write!(f, "BytesM(")?;
1682        for b in v {
1683            write!(f, "{b:02x}")?;
1684        }
1685        write!(f, ")")?;
1686        Ok(())
1687    }
1688}
1689
1690#[cfg(feature = "alloc")]
1691impl<const MAX: u32> core::str::FromStr for BytesM<MAX> {
1692    type Err = Error;
1693    fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
1694        hex::decode(s).map_err(|_| Error::InvalidHex)?.try_into()
1695    }
1696}
1697
1698impl<const MAX: u32> Deref for BytesM<MAX> {
1699    type Target = Vec<u8>;
1700
1701    fn deref(&self) -> &Self::Target {
1702        &self.0
1703    }
1704}
1705
1706#[cfg(feature = "schemars")]
1707impl<const MAX: u32> schemars::JsonSchema for BytesM<MAX> {
1708    fn schema_name() -> String {
1709        format!("BytesM<{MAX}>")
1710    }
1711
1712    fn is_referenceable() -> bool {
1713        false
1714    }
1715
1716    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
1717        let schema = String::json_schema(gen);
1718        if let schemars::schema::Schema::Object(mut schema) = schema {
1719            schema.extensions.insert(
1720                "contentEncoding".to_owned(),
1721                serde_json::Value::String("hex".to_string()),
1722            );
1723            schema.extensions.insert(
1724                "contentMediaType".to_owned(),
1725                serde_json::Value::String("application/binary".to_string()),
1726            );
1727            let string = *schema.string.unwrap_or_default().clone();
1728            schema.string = Some(Box::new(schemars::schema::StringValidation {
1729                max_length: MAX.checked_mul(2).map(Some).unwrap_or_default(),
1730                min_length: None,
1731                ..string
1732            }));
1733            schema.into()
1734        } else {
1735            schema
1736        }
1737    }
1738}
1739
1740impl<const MAX: u32> Default for BytesM<MAX> {
1741    fn default() -> Self {
1742        Self(Vec::default())
1743    }
1744}
1745
1746impl<const MAX: u32> BytesM<MAX> {
1747    pub const MAX_LEN: usize = { MAX as usize };
1748
1749    #[must_use]
1750    #[allow(clippy::unused_self)]
1751    pub fn max_len(&self) -> usize {
1752        Self::MAX_LEN
1753    }
1754
1755    #[must_use]
1756    pub fn as_vec(&self) -> &Vec<u8> {
1757        self.as_ref()
1758    }
1759}
1760
1761impl<const MAX: u32> BytesM<MAX> {
1762    #[must_use]
1763    #[cfg(feature = "alloc")]
1764    pub fn to_vec(&self) -> Vec<u8> {
1765        self.into()
1766    }
1767
1768    #[must_use]
1769    pub fn into_vec(self) -> Vec<u8> {
1770        self.into()
1771    }
1772}
1773
1774impl<const MAX: u32> BytesM<MAX> {
1775    #[cfg(feature = "alloc")]
1776    pub fn to_string(&self) -> Result<String, Error> {
1777        self.try_into()
1778    }
1779
1780    #[cfg(feature = "alloc")]
1781    pub fn into_string(self) -> Result<String, Error> {
1782        self.try_into()
1783    }
1784
1785    #[cfg(feature = "alloc")]
1786    #[must_use]
1787    pub fn to_string_lossy(&self) -> String {
1788        String::from_utf8_lossy(&self.0).into_owned()
1789    }
1790
1791    #[cfg(feature = "alloc")]
1792    #[must_use]
1793    pub fn into_string_lossy(self) -> String {
1794        String::from_utf8_lossy(&self.0).into_owned()
1795    }
1796}
1797
1798impl<const MAX: u32> TryFrom<Vec<u8>> for BytesM<MAX> {
1799    type Error = Error;
1800
1801    fn try_from(v: Vec<u8>) -> Result<Self, Error> {
1802        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1803        if len <= MAX {
1804            Ok(BytesM(v))
1805        } else {
1806            Err(Error::LengthExceedsMax)
1807        }
1808    }
1809}
1810
1811impl<const MAX: u32> From<BytesM<MAX>> for Vec<u8> {
1812    #[must_use]
1813    fn from(v: BytesM<MAX>) -> Self {
1814        v.0
1815    }
1816}
1817
1818#[cfg(feature = "alloc")]
1819impl<const MAX: u32> From<&BytesM<MAX>> for Vec<u8> {
1820    #[must_use]
1821    fn from(v: &BytesM<MAX>) -> Self {
1822        v.0.clone()
1823    }
1824}
1825
1826impl<const MAX: u32> AsRef<Vec<u8>> for BytesM<MAX> {
1827    #[must_use]
1828    fn as_ref(&self) -> &Vec<u8> {
1829        &self.0
1830    }
1831}
1832
1833#[cfg(feature = "alloc")]
1834impl<const MAX: u32> TryFrom<&Vec<u8>> for BytesM<MAX> {
1835    type Error = Error;
1836
1837    fn try_from(v: &Vec<u8>) -> Result<Self, Error> {
1838        v.as_slice().try_into()
1839    }
1840}
1841
1842#[cfg(feature = "alloc")]
1843impl<const MAX: u32> TryFrom<&[u8]> for BytesM<MAX> {
1844    type Error = Error;
1845
1846    fn try_from(v: &[u8]) -> Result<Self, Error> {
1847        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1848        if len <= MAX {
1849            Ok(BytesM(v.to_vec()))
1850        } else {
1851            Err(Error::LengthExceedsMax)
1852        }
1853    }
1854}
1855
1856impl<const MAX: u32> AsRef<[u8]> for BytesM<MAX> {
1857    #[cfg(feature = "alloc")]
1858    #[must_use]
1859    fn as_ref(&self) -> &[u8] {
1860        self.0.as_ref()
1861    }
1862    #[cfg(not(feature = "alloc"))]
1863    #[must_use]
1864    fn as_ref(&self) -> &[u8] {
1865        self.0
1866    }
1867}
1868
1869#[cfg(feature = "alloc")]
1870impl<const N: usize, const MAX: u32> TryFrom<[u8; N]> for BytesM<MAX> {
1871    type Error = Error;
1872
1873    fn try_from(v: [u8; N]) -> Result<Self, Error> {
1874        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1875        if len <= MAX {
1876            Ok(BytesM(v.to_vec()))
1877        } else {
1878            Err(Error::LengthExceedsMax)
1879        }
1880    }
1881}
1882
1883#[cfg(feature = "alloc")]
1884impl<const N: usize, const MAX: u32> TryFrom<BytesM<MAX>> for [u8; N] {
1885    type Error = BytesM<MAX>;
1886
1887    fn try_from(v: BytesM<MAX>) -> core::result::Result<Self, Self::Error> {
1888        let s: [u8; N] = v.0.try_into().map_err(BytesM::<MAX>)?;
1889        Ok(s)
1890    }
1891}
1892
1893#[cfg(feature = "alloc")]
1894impl<const N: usize, const MAX: u32> TryFrom<&[u8; N]> for BytesM<MAX> {
1895    type Error = Error;
1896
1897    fn try_from(v: &[u8; N]) -> Result<Self, Error> {
1898        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1899        if len <= MAX {
1900            Ok(BytesM(v.to_vec()))
1901        } else {
1902            Err(Error::LengthExceedsMax)
1903        }
1904    }
1905}
1906
1907#[cfg(not(feature = "alloc"))]
1908impl<const N: usize, const MAX: u32> TryFrom<&'static [u8; N]> for BytesM<MAX> {
1909    type Error = Error;
1910
1911    fn try_from(v: &'static [u8; N]) -> Result<Self, Error> {
1912        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1913        if len <= MAX {
1914            Ok(BytesM(v))
1915        } else {
1916            Err(Error::LengthExceedsMax)
1917        }
1918    }
1919}
1920
1921#[cfg(feature = "alloc")]
1922impl<const MAX: u32> TryFrom<&String> for BytesM<MAX> {
1923    type Error = Error;
1924
1925    fn try_from(v: &String) -> Result<Self, Error> {
1926        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1927        if len <= MAX {
1928            Ok(BytesM(v.as_bytes().to_vec()))
1929        } else {
1930            Err(Error::LengthExceedsMax)
1931        }
1932    }
1933}
1934
1935#[cfg(feature = "alloc")]
1936impl<const MAX: u32> TryFrom<String> for BytesM<MAX> {
1937    type Error = Error;
1938
1939    fn try_from(v: String) -> Result<Self, Error> {
1940        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1941        if len <= MAX {
1942            Ok(BytesM(v.into()))
1943        } else {
1944            Err(Error::LengthExceedsMax)
1945        }
1946    }
1947}
1948
1949#[cfg(feature = "alloc")]
1950impl<const MAX: u32> TryFrom<BytesM<MAX>> for String {
1951    type Error = Error;
1952
1953    fn try_from(v: BytesM<MAX>) -> Result<Self, Error> {
1954        Ok(String::from_utf8(v.0)?)
1955    }
1956}
1957
1958#[cfg(feature = "alloc")]
1959impl<const MAX: u32> TryFrom<&BytesM<MAX>> for String {
1960    type Error = Error;
1961
1962    fn try_from(v: &BytesM<MAX>) -> Result<Self, Error> {
1963        Ok(core::str::from_utf8(v.as_ref())?.to_owned())
1964    }
1965}
1966
1967#[cfg(feature = "alloc")]
1968impl<const MAX: u32> TryFrom<&str> for BytesM<MAX> {
1969    type Error = Error;
1970
1971    fn try_from(v: &str) -> Result<Self, Error> {
1972        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1973        if len <= MAX {
1974            Ok(BytesM(v.into()))
1975        } else {
1976            Err(Error::LengthExceedsMax)
1977        }
1978    }
1979}
1980
1981#[cfg(not(feature = "alloc"))]
1982impl<const MAX: u32> TryFrom<&'static str> for BytesM<MAX> {
1983    type Error = Error;
1984
1985    fn try_from(v: &'static str) -> Result<Self, Error> {
1986        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
1987        if len <= MAX {
1988            Ok(BytesM(v.as_bytes()))
1989        } else {
1990            Err(Error::LengthExceedsMax)
1991        }
1992    }
1993}
1994
1995impl<'a, const MAX: u32> TryFrom<&'a BytesM<MAX>> for &'a str {
1996    type Error = Error;
1997
1998    fn try_from(v: &'a BytesM<MAX>) -> Result<Self, Error> {
1999        Ok(core::str::from_utf8(v.as_ref())?)
2000    }
2001}
2002
2003impl<const MAX: u32> ReadXdr for BytesM<MAX> {
2004    #[cfg(feature = "std")]
2005    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
2006        r.with_limited_depth(|r| {
2007            let len: u32 = u32::read_xdr(r)?;
2008            if len > MAX {
2009                return Err(Error::LengthExceedsMax);
2010            }
2011
2012            r.consume_len(len as usize)?;
2013            let padding = pad_len(len as usize);
2014            r.consume_len(padding)?;
2015
2016            let mut vec = vec![0u8; len as usize];
2017            r.read_exact(&mut vec)?;
2018
2019            let pad = &mut [0u8; 3][..padding];
2020            r.read_exact(pad)?;
2021            if pad.iter().any(|b| *b != 0) {
2022                return Err(Error::NonZeroPadding);
2023            }
2024
2025            Ok(BytesM(vec))
2026        })
2027    }
2028}
2029
2030impl<const MAX: u32> WriteXdr for BytesM<MAX> {
2031    #[cfg(feature = "std")]
2032    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
2033        w.with_limited_depth(|w| {
2034            let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2035            len.write_xdr(w)?;
2036
2037            w.consume_len(self.len())?;
2038            let padding = pad_len(self.len());
2039            w.consume_len(padding)?;
2040
2041            w.write_all(&self.0)?;
2042
2043            w.write_all(&[0u8; 3][..pad_len(len as usize)])?;
2044
2045            Ok(())
2046        })
2047    }
2048}
2049
2050// StringM ------------------------------------------------------------------------
2051
2052/// A string type that contains arbitrary bytes.
2053///
2054/// Convertible, fallibly, to/from a Rust UTF-8 String using
2055/// [`TryFrom`]/[`TryInto`]/[`StringM::to_utf8_string`].
2056///
2057/// Convertible, lossyly, to a Rust UTF-8 String using
2058/// [`StringM::to_utf8_string_lossy`].
2059///
2060/// Convertible to/from escaped printable-ASCII using
2061/// [`Display`]/[`ToString`]/[`FromStr`].
2062
2063#[cfg(feature = "alloc")]
2064#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
2065#[cfg_attr(
2066    feature = "serde",
2067    derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
2068)]
2069pub struct StringM<const MAX: u32 = { u32::MAX }>(Vec<u8>);
2070
2071#[cfg(not(feature = "alloc"))]
2072#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
2073pub struct StringM<const MAX: u32 = { u32::MAX }>(Vec<u8>);
2074
2075/// Length limited to `MAX`, as for [`VecM`]. The type holds
2076/// arbitrary bytes rather than UTF-8, so truncating cannot split a character.
2077#[cfg(feature = "arbitrary")]
2078impl<'a, const MAX: u32> Arbitrary<'a> for StringM<MAX> {
2079    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
2080        Ok(Self(
2081            u.arbitrary_iter()?
2082                .take(arbitrary_max_len(MAX))
2083                .collect::<arbitrary::Result<Vec<u8>>>()?,
2084        ))
2085    }
2086
2087    fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
2088        Ok(Self(
2089            u.arbitrary_take_rest_iter()?
2090                .take(arbitrary_max_len(MAX))
2091                .collect::<arbitrary::Result<Vec<u8>>>()?,
2092        ))
2093    }
2094
2095    fn size_hint(depth: usize) -> (usize, Option<usize>) {
2096        Vec::<u8>::size_hint(depth)
2097    }
2098}
2099
2100impl<const MAX: u32> core::fmt::Display for StringM<MAX> {
2101    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2102        #[cfg(feature = "alloc")]
2103        let v = &self.0;
2104        #[cfg(not(feature = "alloc"))]
2105        let v = self.0;
2106        for b in escape_bytes::Escape::new(v) {
2107            write!(f, "{}", b as char)?;
2108        }
2109        Ok(())
2110    }
2111}
2112
2113impl<const MAX: u32> core::fmt::Debug for StringM<MAX> {
2114    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2115        #[cfg(feature = "alloc")]
2116        let v = &self.0;
2117        #[cfg(not(feature = "alloc"))]
2118        let v = self.0;
2119        write!(f, "StringM(")?;
2120        for b in escape_bytes::Escape::new(v) {
2121            write!(f, "{}", b as char)?;
2122        }
2123        write!(f, ")")?;
2124        Ok(())
2125    }
2126}
2127
2128#[cfg(feature = "alloc")]
2129impl<const MAX: u32> core::str::FromStr for StringM<MAX> {
2130    type Err = Error;
2131    fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
2132        let b = escape_bytes::unescape(s.as_bytes()).map_err(|_| Error::Invalid)?;
2133        b.try_into()
2134    }
2135}
2136
2137impl<const MAX: u32> Deref for StringM<MAX> {
2138    type Target = Vec<u8>;
2139
2140    fn deref(&self) -> &Self::Target {
2141        &self.0
2142    }
2143}
2144
2145impl<const MAX: u32> Default for StringM<MAX> {
2146    fn default() -> Self {
2147        Self(Vec::default())
2148    }
2149}
2150
2151#[cfg(feature = "schemars")]
2152impl<const MAX: u32> schemars::JsonSchema for StringM<MAX> {
2153    fn schema_name() -> String {
2154        format!("StringM<{MAX}>")
2155    }
2156
2157    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
2158        let schema = String::json_schema(gen);
2159        if let schemars::schema::Schema::Object(mut schema) = schema {
2160            let string = *schema.string.unwrap_or_default().clone();
2161            schema.string = Some(Box::new(schemars::schema::StringValidation {
2162                max_length: Some(MAX),
2163                ..string
2164            }));
2165            schema.into()
2166        } else {
2167            schema
2168        }
2169    }
2170}
2171
2172impl<const MAX: u32> StringM<MAX> {
2173    pub const MAX_LEN: usize = { MAX as usize };
2174
2175    #[must_use]
2176    #[allow(clippy::unused_self)]
2177    pub fn max_len(&self) -> usize {
2178        Self::MAX_LEN
2179    }
2180
2181    #[must_use]
2182    pub fn as_vec(&self) -> &Vec<u8> {
2183        self.as_ref()
2184    }
2185}
2186
2187impl<const MAX: u32> StringM<MAX> {
2188    #[must_use]
2189    #[cfg(feature = "alloc")]
2190    pub fn to_vec(&self) -> Vec<u8> {
2191        self.into()
2192    }
2193
2194    #[must_use]
2195    pub fn into_vec(self) -> Vec<u8> {
2196        self.into()
2197    }
2198}
2199
2200impl<const MAX: u32> StringM<MAX> {
2201    #[cfg(feature = "alloc")]
2202    pub fn to_utf8_string(&self) -> Result<String, Error> {
2203        self.try_into()
2204    }
2205
2206    #[cfg(feature = "alloc")]
2207    pub fn into_utf8_string(self) -> Result<String, Error> {
2208        self.try_into()
2209    }
2210
2211    #[cfg(feature = "alloc")]
2212    #[must_use]
2213    pub fn to_utf8_string_lossy(&self) -> String {
2214        String::from_utf8_lossy(&self.0).into_owned()
2215    }
2216
2217    #[cfg(feature = "alloc")]
2218    #[must_use]
2219    pub fn into_utf8_string_lossy(self) -> String {
2220        String::from_utf8_lossy(&self.0).into_owned()
2221    }
2222}
2223
2224impl<const MAX: u32> TryFrom<Vec<u8>> for StringM<MAX> {
2225    type Error = Error;
2226
2227    fn try_from(v: Vec<u8>) -> Result<Self, Error> {
2228        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2229        if len <= MAX {
2230            Ok(StringM(v))
2231        } else {
2232            Err(Error::LengthExceedsMax)
2233        }
2234    }
2235}
2236
2237impl<const MAX: u32> From<StringM<MAX>> for Vec<u8> {
2238    #[must_use]
2239    fn from(v: StringM<MAX>) -> Self {
2240        v.0
2241    }
2242}
2243
2244#[cfg(feature = "alloc")]
2245impl<const MAX: u32> From<&StringM<MAX>> for Vec<u8> {
2246    #[must_use]
2247    fn from(v: &StringM<MAX>) -> Self {
2248        v.0.clone()
2249    }
2250}
2251
2252impl<const MAX: u32> AsRef<Vec<u8>> for StringM<MAX> {
2253    #[must_use]
2254    fn as_ref(&self) -> &Vec<u8> {
2255        &self.0
2256    }
2257}
2258
2259#[cfg(feature = "alloc")]
2260impl<const MAX: u32> TryFrom<&Vec<u8>> for StringM<MAX> {
2261    type Error = Error;
2262
2263    fn try_from(v: &Vec<u8>) -> Result<Self, Error> {
2264        v.as_slice().try_into()
2265    }
2266}
2267
2268#[cfg(feature = "alloc")]
2269impl<const MAX: u32> TryFrom<&[u8]> for StringM<MAX> {
2270    type Error = Error;
2271
2272    fn try_from(v: &[u8]) -> Result<Self, Error> {
2273        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2274        if len <= MAX {
2275            Ok(StringM(v.to_vec()))
2276        } else {
2277            Err(Error::LengthExceedsMax)
2278        }
2279    }
2280}
2281
2282impl<const MAX: u32> AsRef<[u8]> for StringM<MAX> {
2283    #[cfg(feature = "alloc")]
2284    #[must_use]
2285    fn as_ref(&self) -> &[u8] {
2286        self.0.as_ref()
2287    }
2288    #[cfg(not(feature = "alloc"))]
2289    #[must_use]
2290    fn as_ref(&self) -> &[u8] {
2291        self.0
2292    }
2293}
2294
2295impl<const MAX: u32> PartialEq<[u8]> for StringM<MAX> {
2296    fn eq(&self, other: &[u8]) -> bool {
2297        self.0[..] == other[..]
2298    }
2299}
2300
2301impl<const MAX: u32> PartialEq<&[u8]> for StringM<MAX> {
2302    fn eq(&self, other: &&[u8]) -> bool {
2303        self.0[..] == other[..]
2304    }
2305}
2306
2307impl<const N: usize, const MAX: u32> PartialEq<[u8; N]> for StringM<MAX> {
2308    fn eq(&self, other: &[u8; N]) -> bool {
2309        self.0[..] == other[..]
2310    }
2311}
2312
2313impl<const N: usize, const MAX: u32> PartialEq<&[u8; N]> for StringM<MAX> {
2314    fn eq(&self, other: &&[u8; N]) -> bool {
2315        self.0[..] == other[..]
2316    }
2317}
2318
2319impl<const MAX: u32> PartialEq<StringM<MAX>> for [u8] {
2320    fn eq(&self, other: &StringM<MAX>) -> bool {
2321        self[..] == other.0[..]
2322    }
2323}
2324
2325impl<const MAX: u32> PartialEq<StringM<MAX>> for &[u8] {
2326    fn eq(&self, other: &StringM<MAX>) -> bool {
2327        self[..] == other.0[..]
2328    }
2329}
2330
2331impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for [u8; N] {
2332    fn eq(&self, other: &StringM<MAX>) -> bool {
2333        self[..] == other.0[..]
2334    }
2335}
2336
2337impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for &[u8; N] {
2338    fn eq(&self, other: &StringM<MAX>) -> bool {
2339        self[..] == other.0[..]
2340    }
2341}
2342
2343#[cfg(feature = "alloc")]
2344impl<const N: usize, const MAX: u32> TryFrom<[u8; N]> for StringM<MAX> {
2345    type Error = Error;
2346
2347    fn try_from(v: [u8; N]) -> Result<Self, Error> {
2348        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2349        if len <= MAX {
2350            Ok(StringM(v.to_vec()))
2351        } else {
2352            Err(Error::LengthExceedsMax)
2353        }
2354    }
2355}
2356
2357#[cfg(feature = "alloc")]
2358impl<const N: usize, const MAX: u32> TryFrom<StringM<MAX>> for [u8; N] {
2359    type Error = StringM<MAX>;
2360
2361    fn try_from(v: StringM<MAX>) -> core::result::Result<Self, Self::Error> {
2362        let s: [u8; N] = v.0.try_into().map_err(StringM::<MAX>)?;
2363        Ok(s)
2364    }
2365}
2366
2367#[cfg(feature = "alloc")]
2368impl<const N: usize, const MAX: u32> TryFrom<&[u8; N]> for StringM<MAX> {
2369    type Error = Error;
2370
2371    fn try_from(v: &[u8; N]) -> Result<Self, Error> {
2372        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2373        if len <= MAX {
2374            Ok(StringM(v.to_vec()))
2375        } else {
2376            Err(Error::LengthExceedsMax)
2377        }
2378    }
2379}
2380
2381#[cfg(not(feature = "alloc"))]
2382impl<const N: usize, const MAX: u32> TryFrom<&'static [u8; N]> for StringM<MAX> {
2383    type Error = Error;
2384
2385    fn try_from(v: &'static [u8; N]) -> Result<Self, Error> {
2386        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2387        if len <= MAX {
2388            Ok(StringM(v))
2389        } else {
2390            Err(Error::LengthExceedsMax)
2391        }
2392    }
2393}
2394
2395#[cfg(feature = "alloc")]
2396impl<const MAX: u32> TryFrom<&String> for StringM<MAX> {
2397    type Error = Error;
2398
2399    fn try_from(v: &String) -> Result<Self, Error> {
2400        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2401        if len <= MAX {
2402            Ok(StringM(v.as_bytes().to_vec()))
2403        } else {
2404            Err(Error::LengthExceedsMax)
2405        }
2406    }
2407}
2408
2409#[cfg(feature = "alloc")]
2410impl<const MAX: u32> TryFrom<String> for StringM<MAX> {
2411    type Error = Error;
2412
2413    fn try_from(v: String) -> Result<Self, Error> {
2414        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2415        if len <= MAX {
2416            Ok(StringM(v.into()))
2417        } else {
2418            Err(Error::LengthExceedsMax)
2419        }
2420    }
2421}
2422
2423#[cfg(feature = "alloc")]
2424impl<const MAX: u32> TryFrom<StringM<MAX>> for String {
2425    type Error = Error;
2426
2427    fn try_from(v: StringM<MAX>) -> Result<Self, Error> {
2428        Ok(String::from_utf8(v.0)?)
2429    }
2430}
2431
2432#[cfg(feature = "alloc")]
2433impl<const MAX: u32> TryFrom<&StringM<MAX>> for String {
2434    type Error = Error;
2435
2436    fn try_from(v: &StringM<MAX>) -> Result<Self, Error> {
2437        Ok(core::str::from_utf8(v.as_ref())?.to_owned())
2438    }
2439}
2440
2441#[cfg(feature = "alloc")]
2442impl<const MAX: u32> TryFrom<&str> for StringM<MAX> {
2443    type Error = Error;
2444
2445    fn try_from(v: &str) -> Result<Self, Error> {
2446        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2447        if len <= MAX {
2448            Ok(StringM(v.into()))
2449        } else {
2450            Err(Error::LengthExceedsMax)
2451        }
2452    }
2453}
2454
2455#[cfg(not(feature = "alloc"))]
2456impl<const MAX: u32> TryFrom<&'static str> for StringM<MAX> {
2457    type Error = Error;
2458
2459    fn try_from(v: &'static str) -> Result<Self, Error> {
2460        let len: u32 = v.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2461        if len <= MAX {
2462            Ok(StringM(v.as_bytes()))
2463        } else {
2464            Err(Error::LengthExceedsMax)
2465        }
2466    }
2467}
2468
2469impl<'a, const MAX: u32> TryFrom<&'a StringM<MAX>> for &'a str {
2470    type Error = Error;
2471
2472    fn try_from(v: &'a StringM<MAX>) -> Result<Self, Error> {
2473        Ok(core::str::from_utf8(v.as_ref())?)
2474    }
2475}
2476
2477impl<const MAX: u32> ReadXdr for StringM<MAX> {
2478    #[cfg(feature = "std")]
2479    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
2480        r.with_limited_depth(|r| {
2481            let len: u32 = u32::read_xdr(r)?;
2482            if len > MAX {
2483                return Err(Error::LengthExceedsMax);
2484            }
2485
2486            r.consume_len(len as usize)?;
2487            let padding = pad_len(len as usize);
2488            r.consume_len(padding)?;
2489
2490            let mut vec = vec![0u8; len as usize];
2491            r.read_exact(&mut vec)?;
2492
2493            let pad = &mut [0u8; 3][..padding];
2494            r.read_exact(pad)?;
2495            if pad.iter().any(|b| *b != 0) {
2496                return Err(Error::NonZeroPadding);
2497            }
2498
2499            Ok(StringM(vec))
2500        })
2501    }
2502}
2503
2504impl<const MAX: u32> WriteXdr for StringM<MAX> {
2505    #[cfg(feature = "std")]
2506    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
2507        w.with_limited_depth(|w| {
2508            let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?;
2509            len.write_xdr(w)?;
2510
2511            w.consume_len(self.len())?;
2512            let padding = pad_len(self.len());
2513            w.consume_len(padding)?;
2514
2515            w.write_all(&self.0)?;
2516
2517            w.write_all(&[0u8; 3][..padding])?;
2518
2519            Ok(())
2520        })
2521    }
2522}
2523
2524// Frame ------------------------------------------------------------------------
2525
2526/// Frame wraps an XDR object with the framing defined by the Record Marking
2527/// Standard in [RFC 5531 Section 11].
2528///
2529/// Each frame begins with a 4-byte big-endian header where:
2530///  - Bit 31 (high bit) is the last-fragment flag (`1` = last fragment).
2531///  - Bits 0-30 contain the byte length of the fragment data that follows.
2532///
2533/// A record is composed of one or more fragments. In Stellar's usage each
2534/// record contains exactly one XDR object encoded as a single fragment with
2535/// the last-fragment bit set.
2536///
2537/// [RFC 5531 Section 11]: https://www.rfc-editor.org/rfc/rfc5531#section-11
2538#[derive(Default, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
2539#[cfg_attr(
2540    all(feature = "serde", feature = "alloc"),
2541    derive(serde::Serialize, serde::Deserialize),
2542    serde(rename_all = "snake_case")
2543)]
2544pub struct Frame<T>(pub T)
2545where
2546    T: ReadXdr;
2547
2548#[cfg(feature = "schemars")]
2549impl<T: schemars::JsonSchema + ReadXdr> schemars::JsonSchema for Frame<T> {
2550    fn schema_name() -> String {
2551        format!("Frame<{}>", T::schema_name())
2552    }
2553
2554    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
2555        T::json_schema(gen)
2556    }
2557}
2558
2559impl<T> ReadXdr for Frame<T>
2560where
2561    T: ReadXdr,
2562{
2563    #[cfg(feature = "std")]
2564    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
2565        // Read the 4-byte fragment header defined by the Record Marking
2566        // Standard in RFC 5531 Section 11
2567        // (https://www.rfc-editor.org/rfc/rfc5531#section-11).
2568        //  - Bit 31 (high bit) is the last-fragment flag: 1 if this is the
2569        //    last fragment of the record, 0 if more fragments follow.
2570        //  - Bits 0-30 contain the byte length of the fragment data that
2571        //    follows the header.
2572        let header = u32::read_xdr(r)?;
2573        // TODO: Use the length and cap the length we'll read from `r`.
2574        let last_record = header >> 31 == 1;
2575        if last_record {
2576            // Read the record in the frame.
2577            Ok(Self(T::read_xdr(r)?))
2578        } else {
2579            // TODO: Support reading those additional frames for the same
2580            // record.
2581            Err(Error::Unsupported)
2582        }
2583    }
2584}
2585
2586/// Forwards read operations to the wrapped object, skipping over any
2587/// whitespace.
2588#[cfg(feature = "std")]
2589pub struct SkipWhitespace<R: Read> {
2590    pub inner: R,
2591}
2592
2593#[cfg(feature = "std")]
2594impl<R: Read> SkipWhitespace<R> {
2595    pub fn new(inner: R) -> Self {
2596        SkipWhitespace { inner }
2597    }
2598}
2599
2600#[cfg(feature = "std")]
2601impl<R: Read> Read for SkipWhitespace<R> {
2602    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
2603        let n = self.inner.read(buf)?;
2604
2605        let mut written = 0;
2606        for read in 0..n {
2607            if !buf[read].is_ascii_whitespace() {
2608                buf[written] = buf[read];
2609                written += 1;
2610            }
2611        }
2612
2613        Ok(written)
2614    }
2615}
2616
2617#[cfg(all(test, feature = "std"))]
2618mod test_skip_whitespace {
2619    use super::*;
2620
2621    #[test]
2622    fn test() {
2623        struct Test {
2624            input: &'static [u8],
2625            output: &'static [u8],
2626        }
2627        let tests = [
2628            Test {
2629                input: b"",
2630                output: b"",
2631            },
2632            Test {
2633                input: b" \n\t\r",
2634                output: b"",
2635            },
2636            Test {
2637                input: b"a c",
2638                output: b"ac",
2639            },
2640            Test {
2641                input: b"ab cd",
2642                output: b"abcd",
2643            },
2644            Test {
2645                input: b" ab \n cd ",
2646                output: b"abcd",
2647            },
2648        ];
2649        for (i, t) in tests.iter().enumerate() {
2650            let mut skip = SkipWhitespace::new(t.input);
2651            let mut output = Vec::new();
2652            skip.read_to_end(&mut output).unwrap();
2653            assert_eq!(output, t.output, "#{i}");
2654        }
2655    }
2656}
2657
2658// NumberOrString ---------------------------------------------------------------
2659
2660/// NumberOrString is a serde_as serializer/deserializer.
2661///
2662/// It deserializers any integer that fits into a 64-bit value into an i64 or u64 field from either
2663/// a JSON Number or JSON String value.
2664///
2665/// It serializes always to a string.
2666///
2667/// It has a JsonSchema implementation that only advertises that the allowed format is a String.
2668/// This is because the type is intended to soften the changing of fields from JSON Number to JSON
2669/// String by permitting deserialization, but discourage new uses of JSON Number.
2670#[cfg(feature = "serde")]
2671struct NumberOrString;
2672
2673#[cfg(feature = "serde")]
2674impl<'de> serde_with::DeserializeAs<'de, i64> for NumberOrString {
2675    fn deserialize_as<D>(deserializer: D) -> Result<i64, D::Error>
2676    where
2677        D: serde::Deserializer<'de>,
2678    {
2679        use serde::Deserialize;
2680        #[derive(Deserialize)]
2681        #[serde(untagged)]
2682        enum I64OrString<'a> {
2683            Str(&'a str),
2684            String(String),
2685            I64(i64),
2686        }
2687        match I64OrString::deserialize(deserializer)? {
2688            I64OrString::Str(s) => s.parse().map_err(serde::de::Error::custom),
2689            I64OrString::String(s) => s.parse().map_err(serde::de::Error::custom),
2690            I64OrString::I64(v) => Ok(v),
2691        }
2692    }
2693}
2694
2695#[cfg(feature = "serde")]
2696impl<'de> serde_with::DeserializeAs<'de, u64> for NumberOrString {
2697    fn deserialize_as<D>(deserializer: D) -> Result<u64, D::Error>
2698    where
2699        D: serde::Deserializer<'de>,
2700    {
2701        use serde::Deserialize;
2702        #[derive(Deserialize)]
2703        #[serde(untagged)]
2704        enum U64OrString<'a> {
2705            Str(&'a str),
2706            String(String),
2707            U64(u64),
2708        }
2709        match U64OrString::deserialize(deserializer)? {
2710            U64OrString::Str(s) => s.parse().map_err(serde::de::Error::custom),
2711            U64OrString::String(s) => s.parse().map_err(serde::de::Error::custom),
2712            U64OrString::U64(v) => Ok(v),
2713        }
2714    }
2715}
2716
2717#[cfg(feature = "serde")]
2718impl serde_with::SerializeAs<i64> for NumberOrString {
2719    fn serialize_as<S>(source: &i64, serializer: S) -> Result<S::Ok, S::Error>
2720    where
2721        S: serde::Serializer,
2722    {
2723        serializer.collect_str(source)
2724    }
2725}
2726
2727#[cfg(feature = "serde")]
2728impl serde_with::SerializeAs<u64> for NumberOrString {
2729    fn serialize_as<S>(source: &u64, serializer: S) -> Result<S::Ok, S::Error>
2730    where
2731        S: serde::Serializer,
2732    {
2733        serializer.collect_str(source)
2734    }
2735}
2736
2737#[cfg(feature = "schemars")]
2738impl<T> serde_with::schemars_0_8::JsonSchemaAs<T> for NumberOrString {
2739    fn schema_name() -> String {
2740        <String as schemars::JsonSchema>::schema_name()
2741    }
2742
2743    fn schema_id() -> std::borrow::Cow<'static, str> {
2744        <String as schemars::JsonSchema>::schema_id()
2745    }
2746
2747    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
2748        <String as schemars::JsonSchema>::json_schema(gen)
2749    }
2750
2751    fn is_referenceable() -> bool {
2752        <String as schemars::JsonSchema>::is_referenceable()
2753    }
2754}
2755
2756// Tests ------------------------------------------------------------------------
2757
2758#[cfg(all(test, feature = "std"))]
2759mod tests {
2760    use std::io::Cursor;
2761
2762    use super::*;
2763
2764    #[test]
2765    pub fn vec_u8_read_without_padding() {
2766        let buf = Cursor::new(vec![0, 0, 0, 4, 2, 2, 2, 2]);
2767        let v = VecM::<u8, 8>::read_xdr(&mut Limited::new(buf, Limits::none())).unwrap();
2768        assert_eq!(v.to_vec(), vec![2, 2, 2, 2]);
2769    }
2770
2771    #[test]
2772    pub fn vec_u8_read_with_padding() {
2773        let buf = Cursor::new(vec![0, 0, 0, 1, 2, 0, 0, 0]);
2774        let v = VecM::<u8, 8>::read_xdr(&mut Limited::new(buf, Limits::none())).unwrap();
2775        assert_eq!(v.to_vec(), vec![2]);
2776    }
2777
2778    #[test]
2779    pub fn vec_u8_read_with_insufficient_padding() {
2780        let buf = Cursor::new(vec![0, 0, 0, 1, 2, 0, 0]);
2781        let res = VecM::<u8, 8>::read_xdr(&mut Limited::new(buf, Limits::none()));
2782        match res {
2783            Err(Error::Io(_)) => (),
2784            _ => panic!("expected IO error got {res:?}"),
2785        }
2786    }
2787
2788    #[test]
2789    pub fn vec_u8_read_with_non_zero_padding() {
2790        let buf = Cursor::new(vec![0, 0, 0, 1, 2, 3, 0, 0]);
2791        let res = VecM::<u8, 8>::read_xdr(&mut Limited::new(buf, Limits::none()));
2792        match res {
2793            Err(Error::NonZeroPadding) => (),
2794            _ => panic!("expected NonZeroPadding got {res:?}"),
2795        }
2796    }
2797
2798    #[test]
2799    pub fn vec_u8_write_without_padding() {
2800        let mut buf = vec![];
2801        let v: VecM<u8, 8> = vec![2, 2, 2, 2].try_into().unwrap();
2802
2803        v.write_xdr(&mut Limited::new(Cursor::new(&mut buf), Limits::none()))
2804            .unwrap();
2805        assert_eq!(buf, vec![0, 0, 0, 4, 2, 2, 2, 2]);
2806    }
2807
2808    #[test]
2809    pub fn vec_u8_write_with_padding() {
2810        let mut buf = vec![];
2811        let v: VecM<u8, 8> = vec![2].try_into().unwrap();
2812        v.write_xdr(&mut Limited::new(Cursor::new(&mut buf), Limits::none()))
2813            .unwrap();
2814        assert_eq!(buf, vec![0, 0, 0, 1, 2, 0, 0, 0]);
2815    }
2816
2817    #[test]
2818    pub fn arr_u8_read_without_padding() {
2819        let buf = Cursor::new(vec![2, 2, 2, 2]);
2820        let v = <[u8; 4]>::read_xdr(&mut Limited::new(buf, Limits::none())).unwrap();
2821        assert_eq!(v, [2, 2, 2, 2]);
2822    }
2823
2824    #[test]
2825    pub fn arr_u8_read_with_padding() {
2826        let buf = Cursor::new(vec![2, 0, 0, 0]);
2827        let v = <[u8; 1]>::read_xdr(&mut Limited::new(buf, Limits::none())).unwrap();
2828        assert_eq!(v, [2]);
2829    }
2830
2831    #[test]
2832    pub fn arr_u8_read_with_insufficient_padding() {
2833        let buf = Cursor::new(vec![2, 0, 0]);
2834        let res = <[u8; 1]>::read_xdr(&mut Limited::new(buf, Limits::none()));
2835        match res {
2836            Err(Error::Io(_)) => (),
2837            _ => panic!("expected IO error got {res:?}"),
2838        }
2839    }
2840
2841    #[test]
2842    pub fn arr_u8_read_with_non_zero_padding() {
2843        let buf = Cursor::new(vec![2, 3, 0, 0]);
2844        let res = <[u8; 1]>::read_xdr(&mut Limited::new(buf, Limits::none()));
2845        match res {
2846            Err(Error::NonZeroPadding) => (),
2847            _ => panic!("expected NonZeroPadding got {res:?}"),
2848        }
2849    }
2850
2851    #[test]
2852    pub fn arr_u8_write_without_padding() {
2853        let mut buf = vec![];
2854        [2u8, 2, 2, 2]
2855            .write_xdr(&mut Limited::new(Cursor::new(&mut buf), Limits::none()))
2856            .unwrap();
2857        assert_eq!(buf, vec![2, 2, 2, 2]);
2858    }
2859
2860    #[test]
2861    pub fn arr_u8_write_with_padding() {
2862        let mut buf = vec![];
2863        [2u8]
2864            .write_xdr(&mut Limited::new(Cursor::new(&mut buf), Limits::none()))
2865            .unwrap();
2866        assert_eq!(buf, vec![2, 0, 0, 0]);
2867    }
2868}
2869
2870#[cfg(all(test, feature = "std"))]
2871mod test {
2872    use super::*;
2873
2874    #[test]
2875    fn into_option_none() {
2876        let v: VecM<u32, 1> = vec![].try_into().unwrap();
2877        assert_eq!(v.into_option(), None);
2878    }
2879
2880    #[test]
2881    fn into_option_some() {
2882        let v: VecM<_, 1> = vec![1].try_into().unwrap();
2883        assert_eq!(v.into_option(), Some(1));
2884    }
2885
2886    #[test]
2887    fn to_option_none() {
2888        let v: VecM<u32, 1> = vec![].try_into().unwrap();
2889        assert_eq!(v.to_option(), None);
2890    }
2891
2892    #[test]
2893    fn to_option_some() {
2894        let v: VecM<_, 1> = vec![1].try_into().unwrap();
2895        assert_eq!(v.to_option(), Some(1));
2896    }
2897
2898    #[test]
2899    fn depth_limited_read_write_under_the_limit_success() {
2900        let a: Option<Option<Option<u32>>> = Some(Some(Some(5)));
2901        let mut buf = Limited::new(Vec::new(), Limits::depth(4));
2902        a.write_xdr(&mut buf).unwrap();
2903
2904        let mut dlr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::depth(4));
2905        let a_back: Option<Option<Option<u32>>> = ReadXdr::read_xdr(&mut dlr).unwrap();
2906        assert_eq!(a, a_back);
2907    }
2908
2909    #[test]
2910    fn write_over_depth_limit_fail() {
2911        let a: Option<Option<Option<u32>>> = Some(Some(Some(5)));
2912        let mut buf = Limited::new(Vec::new(), Limits::depth(3));
2913        let res = a.write_xdr(&mut buf);
2914        match res {
2915            Err(Error::DepthLimitExceeded) => (),
2916            _ => panic!("expected DepthLimitExceeded got {res:?}"),
2917        }
2918    }
2919
2920    #[test]
2921    fn read_over_depth_limit_fail() {
2922        let read_limits = Limits::depth(3);
2923        let write_limits = Limits::depth(5);
2924        let a: Option<Option<Option<u32>>> = Some(Some(Some(5)));
2925        let mut buf = Limited::new(Vec::new(), write_limits);
2926        a.write_xdr(&mut buf).unwrap();
2927
2928        let mut dlr = Limited::new(Cursor::new(buf.inner.as_slice()), read_limits);
2929        let res: Result<Option<Option<Option<u32>>>, _> = ReadXdr::read_xdr(&mut dlr);
2930        match res {
2931            Err(Error::DepthLimitExceeded) => (),
2932            _ => panic!("expected DepthLimitExceeded got {res:?}"),
2933        }
2934    }
2935
2936    #[test]
2937    fn length_limited_read_write_i32() {
2938        // Exact limit, success
2939        let v = 123i32;
2940        let mut buf = Limited::new(Vec::new(), Limits::len(4));
2941        v.write_xdr(&mut buf).unwrap();
2942        assert_eq!(buf.limits.len, 0);
2943        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(4));
2944        let v_back: i32 = ReadXdr::read_xdr(&mut lr).unwrap();
2945        assert_eq!(buf.limits.len, 0);
2946        assert_eq!(v, v_back);
2947
2948        // Over limit, success
2949        let v = 123i32;
2950        let mut buf = Limited::new(Vec::new(), Limits::len(5));
2951        v.write_xdr(&mut buf).unwrap();
2952        assert_eq!(buf.limits.len, 1);
2953        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(5));
2954        let v_back: i32 = ReadXdr::read_xdr(&mut lr).unwrap();
2955        assert_eq!(buf.limits.len, 1);
2956        assert_eq!(v, v_back);
2957
2958        // Write under limit, failure
2959        let v = 123i32;
2960        let mut buf = Limited::new(Vec::new(), Limits::len(3));
2961        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
2962
2963        // Read under limit, failure
2964        let v = 123i32;
2965        let mut buf = Limited::new(Vec::new(), Limits::len(4));
2966        v.write_xdr(&mut buf).unwrap();
2967        assert_eq!(buf.limits.len, 0);
2968        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(3));
2969        assert_eq!(
2970            <i32 as ReadXdr>::read_xdr(&mut lr),
2971            Err(Error::LengthLimitExceeded)
2972        );
2973    }
2974
2975    #[test]
2976    fn length_limited_read_write_u32() {
2977        // Exact limit, success
2978        let v = 123u32;
2979        let mut buf = Limited::new(Vec::new(), Limits::len(4));
2980        v.write_xdr(&mut buf).unwrap();
2981        assert_eq!(buf.limits.len, 0);
2982        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(4));
2983        let v_back: u32 = ReadXdr::read_xdr(&mut lr).unwrap();
2984        assert_eq!(buf.limits.len, 0);
2985        assert_eq!(v, v_back);
2986
2987        // Over limit, success
2988        let v = 123u32;
2989        let mut buf = Limited::new(Vec::new(), Limits::len(5));
2990        v.write_xdr(&mut buf).unwrap();
2991        assert_eq!(buf.limits.len, 1);
2992        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(5));
2993        let v_back: u32 = ReadXdr::read_xdr(&mut lr).unwrap();
2994        assert_eq!(buf.limits.len, 1);
2995        assert_eq!(v, v_back);
2996
2997        // Write under limit, failure
2998        let v = 123u32;
2999        let mut buf = Limited::new(Vec::new(), Limits::len(3));
3000        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3001
3002        // Read under limit, failure
3003        let v = 123u32;
3004        let mut buf = Limited::new(Vec::new(), Limits::len(4));
3005        v.write_xdr(&mut buf).unwrap();
3006        assert_eq!(buf.limits.len, 0);
3007        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(3));
3008        assert_eq!(
3009            <u32 as ReadXdr>::read_xdr(&mut lr),
3010            Err(Error::LengthLimitExceeded)
3011        );
3012    }
3013
3014    #[test]
3015    fn length_limited_read_write_i64() {
3016        // Exact limit, success
3017        let v = 123i64;
3018        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3019        v.write_xdr(&mut buf).unwrap();
3020        assert_eq!(buf.limits.len, 0);
3021        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(8));
3022        let v_back: i64 = ReadXdr::read_xdr(&mut lr).unwrap();
3023        assert_eq!(buf.limits.len, 0);
3024        assert_eq!(v, v_back);
3025
3026        // Over limit, success
3027        let v = 123i64;
3028        let mut buf = Limited::new(Vec::new(), Limits::len(9));
3029        v.write_xdr(&mut buf).unwrap();
3030        assert_eq!(buf.limits.len, 1);
3031        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(9));
3032        let v_back: i64 = ReadXdr::read_xdr(&mut lr).unwrap();
3033        assert_eq!(buf.limits.len, 1);
3034        assert_eq!(v, v_back);
3035
3036        // Write under limit, failure
3037        let v = 123i64;
3038        let mut buf = Limited::new(Vec::new(), Limits::len(7));
3039        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3040
3041        // Read under limit, failure
3042        let v = 123i64;
3043        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3044        v.write_xdr(&mut buf).unwrap();
3045        assert_eq!(buf.limits.len, 0);
3046        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(7));
3047        assert_eq!(
3048            <i64 as ReadXdr>::read_xdr(&mut lr),
3049            Err(Error::LengthLimitExceeded)
3050        );
3051    }
3052
3053    #[test]
3054    fn length_limited_read_write_u64() {
3055        // Exact limit, success
3056        let v = 123u64;
3057        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3058        v.write_xdr(&mut buf).unwrap();
3059        assert_eq!(buf.limits.len, 0);
3060        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(8));
3061        let v_back: u64 = ReadXdr::read_xdr(&mut lr).unwrap();
3062        assert_eq!(buf.limits.len, 0);
3063        assert_eq!(v, v_back);
3064
3065        // Over limit, success
3066        let v = 123u64;
3067        let mut buf = Limited::new(Vec::new(), Limits::len(9));
3068        v.write_xdr(&mut buf).unwrap();
3069        assert_eq!(buf.limits.len, 1);
3070        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(9));
3071        let v_back: u64 = ReadXdr::read_xdr(&mut lr).unwrap();
3072        assert_eq!(buf.limits.len, 1);
3073        assert_eq!(v, v_back);
3074
3075        // Write under limit, failure
3076        let v = 123u64;
3077        let mut buf = Limited::new(Vec::new(), Limits::len(7));
3078        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3079
3080        // Read under limit, failure
3081        let v = 123u64;
3082        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3083        v.write_xdr(&mut buf).unwrap();
3084        assert_eq!(buf.limits.len, 0);
3085        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(7));
3086        assert_eq!(
3087            <u64 as ReadXdr>::read_xdr(&mut lr),
3088            Err(Error::LengthLimitExceeded)
3089        );
3090    }
3091
3092    #[test]
3093    fn length_limited_read_write_bool() {
3094        // Exact limit, success
3095        let v = true;
3096        let mut buf = Limited::new(Vec::new(), Limits::len(4));
3097        v.write_xdr(&mut buf).unwrap();
3098        assert_eq!(buf.limits.len, 0);
3099        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(4));
3100        let v_back: bool = ReadXdr::read_xdr(&mut lr).unwrap();
3101        assert_eq!(buf.limits.len, 0);
3102        assert_eq!(v, v_back);
3103
3104        // Over limit, success
3105        let v = true;
3106        let mut buf = Limited::new(Vec::new(), Limits::len(5));
3107        v.write_xdr(&mut buf).unwrap();
3108        assert_eq!(buf.limits.len, 1);
3109        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(5));
3110        let v_back: bool = ReadXdr::read_xdr(&mut lr).unwrap();
3111        assert_eq!(buf.limits.len, 1);
3112        assert_eq!(v, v_back);
3113
3114        // Write under limit, failure
3115        let v = true;
3116        let mut buf = Limited::new(Vec::new(), Limits::len(3));
3117        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3118
3119        // Read under limit, failure
3120        let v = true;
3121        let mut buf = Limited::new(Vec::new(), Limits::len(4));
3122        v.write_xdr(&mut buf).unwrap();
3123        assert_eq!(buf.limits.len, 0);
3124        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(3));
3125        assert_eq!(
3126            <bool as ReadXdr>::read_xdr(&mut lr),
3127            Err(Error::LengthLimitExceeded)
3128        );
3129    }
3130
3131    #[test]
3132    fn length_limited_read_write_option() {
3133        // Exact limit, success
3134        let v = Some(true);
3135        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3136        v.write_xdr(&mut buf).unwrap();
3137        assert_eq!(buf.limits.len, 0);
3138        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(8));
3139        let v_back: Option<bool> = ReadXdr::read_xdr(&mut lr).unwrap();
3140        assert_eq!(buf.limits.len, 0);
3141        assert_eq!(v, v_back);
3142
3143        // Over limit, success
3144        let v = Some(true);
3145        let mut buf = Limited::new(Vec::new(), Limits::len(9));
3146        v.write_xdr(&mut buf).unwrap();
3147        assert_eq!(buf.limits.len, 1);
3148        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(9));
3149        let v_back: Option<bool> = ReadXdr::read_xdr(&mut lr).unwrap();
3150        assert_eq!(buf.limits.len, 1);
3151        assert_eq!(v, v_back);
3152
3153        // Write under limit, failure
3154        let v = Some(true);
3155        let mut buf = Limited::new(Vec::new(), Limits::len(7));
3156        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3157
3158        // Read under limit, failure
3159        let v = Some(true);
3160        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3161        v.write_xdr(&mut buf).unwrap();
3162        assert_eq!(buf.limits.len, 0);
3163        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(7));
3164        assert_eq!(
3165            <Option<bool> as ReadXdr>::read_xdr(&mut lr),
3166            Err(Error::LengthLimitExceeded)
3167        );
3168    }
3169
3170    #[test]
3171    fn length_limited_read_write_array_u8() {
3172        // Exact limit, success
3173        let v = [1u8, 2, 3];
3174        let mut buf = Limited::new(Vec::new(), Limits::len(4));
3175        v.write_xdr(&mut buf).unwrap();
3176        assert_eq!(buf.limits.len, 0);
3177        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(4));
3178        let v_back: [u8; 3] = ReadXdr::read_xdr(&mut lr).unwrap();
3179        assert_eq!(buf.limits.len, 0);
3180        assert_eq!(v, v_back);
3181
3182        // Over limit, success
3183        let v = [1u8, 2, 3];
3184        let mut buf = Limited::new(Vec::new(), Limits::len(5));
3185        v.write_xdr(&mut buf).unwrap();
3186        assert_eq!(buf.limits.len, 1);
3187        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(5));
3188        let v_back: [u8; 3] = ReadXdr::read_xdr(&mut lr).unwrap();
3189        assert_eq!(buf.limits.len, 1);
3190        assert_eq!(v, v_back);
3191
3192        // Write under limit, failure
3193        let v = [1u8, 2, 3];
3194        let mut buf = Limited::new(Vec::new(), Limits::len(3));
3195        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3196
3197        // Read under limit, failure
3198        let v = [1u8, 2, 3];
3199        let mut buf = Limited::new(Vec::new(), Limits::len(4));
3200        v.write_xdr(&mut buf).unwrap();
3201        assert_eq!(buf.limits.len, 0);
3202        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(3));
3203        assert_eq!(
3204            <[u8; 3] as ReadXdr>::read_xdr(&mut lr),
3205            Err(Error::LengthLimitExceeded)
3206        );
3207    }
3208
3209    #[test]
3210    fn length_limited_read_write_array_type() {
3211        // Exact limit, success
3212        let v = [true, false, true];
3213        let mut buf = Limited::new(Vec::new(), Limits::len(12));
3214        v.write_xdr(&mut buf).unwrap();
3215        assert_eq!(buf.limits.len, 0);
3216        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(12));
3217        let v_back: [bool; 3] = ReadXdr::read_xdr(&mut lr).unwrap();
3218        assert_eq!(buf.limits.len, 0);
3219        assert_eq!(v, v_back);
3220
3221        // Over limit, success
3222        let v = [true, false, true];
3223        let mut buf = Limited::new(Vec::new(), Limits::len(13));
3224        v.write_xdr(&mut buf).unwrap();
3225        assert_eq!(buf.limits.len, 1);
3226        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(13));
3227        let v_back: [bool; 3] = ReadXdr::read_xdr(&mut lr).unwrap();
3228        assert_eq!(buf.limits.len, 1);
3229        assert_eq!(v, v_back);
3230
3231        // Write under limit, failure
3232        let v = [true, false, true];
3233        let mut buf = Limited::new(Vec::new(), Limits::len(11));
3234        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3235
3236        // Read under limit, failure
3237        let v = [true, false, true];
3238        let mut buf = Limited::new(Vec::new(), Limits::len(12));
3239        v.write_xdr(&mut buf).unwrap();
3240        assert_eq!(buf.limits.len, 0);
3241        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(11));
3242        assert_eq!(
3243            <[bool; 3] as ReadXdr>::read_xdr(&mut lr),
3244            Err(Error::LengthLimitExceeded)
3245        );
3246    }
3247
3248    #[test]
3249    fn length_limited_read_write_vec() {
3250        // Exact limit, success
3251        let v = VecM::<i32, 3>::try_from([1i32, 2, 3]).unwrap();
3252        let mut buf = Limited::new(Vec::new(), Limits::len(16));
3253        v.write_xdr(&mut buf).unwrap();
3254        assert_eq!(buf.limits.len, 0);
3255        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(16));
3256        let v_back: VecM<i32, 3> = ReadXdr::read_xdr(&mut lr).unwrap();
3257        assert_eq!(buf.limits.len, 0);
3258        assert_eq!(v, v_back);
3259
3260        // Over limit, success
3261        let v = VecM::<i32, 3>::try_from([1i32, 2, 3]).unwrap();
3262        let mut buf = Limited::new(Vec::new(), Limits::len(17));
3263        v.write_xdr(&mut buf).unwrap();
3264        assert_eq!(buf.limits.len, 1);
3265        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(17));
3266        let v_back: VecM<i32, 3> = ReadXdr::read_xdr(&mut lr).unwrap();
3267        assert_eq!(buf.limits.len, 1);
3268        assert_eq!(v, v_back);
3269
3270        // Write under limit, failure
3271        let v = VecM::<i32, 3>::try_from([1i32, 2, 3]).unwrap();
3272        let mut buf = Limited::new(Vec::new(), Limits::len(15));
3273        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3274
3275        // Read under limit, failure
3276        let v = VecM::<i32, 3>::try_from([1i32, 2, 3]).unwrap();
3277        let mut buf = Limited::new(Vec::new(), Limits::len(16));
3278        v.write_xdr(&mut buf).unwrap();
3279        assert_eq!(buf.limits.len, 0);
3280        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(15));
3281        assert_eq!(
3282            <VecM<i32, 3> as ReadXdr>::read_xdr(&mut lr),
3283            Err(Error::LengthLimitExceeded)
3284        );
3285    }
3286
3287    #[test]
3288    fn length_limited_read_write_bytes() {
3289        // Exact limit, success
3290        let v = BytesM::<3>::try_from([1u8, 2, 3]).unwrap();
3291        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3292        v.write_xdr(&mut buf).unwrap();
3293        assert_eq!(buf.limits.len, 0);
3294        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(8));
3295        let v_back: BytesM<3> = ReadXdr::read_xdr(&mut lr).unwrap();
3296        assert_eq!(buf.limits.len, 0);
3297        assert_eq!(v, v_back);
3298
3299        // Over limit, success
3300        let v = BytesM::<3>::try_from([1u8, 2, 3]).unwrap();
3301        let mut buf = Limited::new(Vec::new(), Limits::len(9));
3302        v.write_xdr(&mut buf).unwrap();
3303        assert_eq!(buf.limits.len, 1);
3304        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(9));
3305        let v_back: BytesM<3> = ReadXdr::read_xdr(&mut lr).unwrap();
3306        assert_eq!(buf.limits.len, 1);
3307        assert_eq!(v, v_back);
3308
3309        // Write under limit, failure
3310        let v = BytesM::<3>::try_from([1u8, 2, 3]).unwrap();
3311        let mut buf = Limited::new(Vec::new(), Limits::len(7));
3312        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3313
3314        // Read under limit, failure
3315        let v = BytesM::<3>::try_from([1u8, 2, 3]).unwrap();
3316        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3317        v.write_xdr(&mut buf).unwrap();
3318        assert_eq!(buf.limits.len, 0);
3319        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(7));
3320        assert_eq!(
3321            <BytesM<3> as ReadXdr>::read_xdr(&mut lr),
3322            Err(Error::LengthLimitExceeded)
3323        );
3324    }
3325
3326    #[test]
3327    fn stringm_eq_byte_strings() {
3328        let v = StringM::<3>::try_from("123").unwrap();
3329        assert_eq!(v, *b"123");
3330        assert_eq!(v, b"123");
3331        assert_eq!(v, b"123"[..]);
3332        assert_eq!(v, &b"123"[..]);
3333        assert_ne!(v, *b"124");
3334        assert_ne!(v, b"124");
3335        assert_ne!(v, b"124"[..]);
3336        assert_ne!(v, &b"124"[..]);
3337        assert_ne!(v, b"12");
3338        assert_ne!(v, &b"1234"[..]);
3339        assert_ne!(v, b"");
3340        assert_ne!(StringM::<3>::default(), b"1");
3341        assert_eq!(*b"123", v);
3342        assert_eq!(b"123", v);
3343        assert_eq!(b"123"[..], v);
3344        assert_eq!(&b"123"[..], v);
3345        assert_ne!(*b"124", v);
3346        assert_ne!(b"124", v);
3347        assert_ne!(b"124"[..], v);
3348        assert_ne!(&b"124"[..], v);
3349        assert_ne!(b"12", v);
3350        assert_ne!(&b"1234"[..], v);
3351        assert_ne!(b"", v);
3352        assert_ne!(b"1", StringM::<3>::default());
3353    }
3354
3355    #[test]
3356    fn length_limited_read_write_string() {
3357        // Exact limit, success
3358        let v = StringM::<3>::try_from("123").unwrap();
3359        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3360        v.write_xdr(&mut buf).unwrap();
3361        assert_eq!(buf.limits.len, 0);
3362        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(8));
3363        let v_back: StringM<3> = ReadXdr::read_xdr(&mut lr).unwrap();
3364        assert_eq!(buf.limits.len, 0);
3365        assert_eq!(v, v_back);
3366
3367        // Over limit, success
3368        let v = StringM::<3>::try_from("123").unwrap();
3369        let mut buf = Limited::new(Vec::new(), Limits::len(9));
3370        v.write_xdr(&mut buf).unwrap();
3371        assert_eq!(buf.limits.len, 1);
3372        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(9));
3373        let v_back: StringM<3> = ReadXdr::read_xdr(&mut lr).unwrap();
3374        assert_eq!(buf.limits.len, 1);
3375        assert_eq!(v, v_back);
3376
3377        // Write under limit, failure
3378        let v = StringM::<3>::try_from("123").unwrap();
3379        let mut buf = Limited::new(Vec::new(), Limits::len(7));
3380        assert_eq!(v.write_xdr(&mut buf), Err(Error::LengthLimitExceeded));
3381
3382        // Read under limit, failure
3383        let v = StringM::<3>::try_from("123").unwrap();
3384        let mut buf = Limited::new(Vec::new(), Limits::len(8));
3385        v.write_xdr(&mut buf).unwrap();
3386        assert_eq!(buf.limits.len, 0);
3387        let mut lr = Limited::new(Cursor::new(buf.inner.as_slice()), Limits::len(7));
3388        assert_eq!(
3389            <StringM<3> as ReadXdr>::read_xdr(&mut lr),
3390            Err(Error::LengthLimitExceeded)
3391        );
3392    }
3393}
3394
3395#[cfg(all(test, not(feature = "alloc")))]
3396mod test {
3397    use super::VecM;
3398
3399    #[test]
3400    fn to_option_none() {
3401        let v: VecM<u32, 1> = (&[]).try_into().unwrap();
3402        assert_eq!(v.to_option(), None);
3403    }
3404
3405    #[test]
3406    fn to_option_some() {
3407        let v: VecM<_, 1> = (&[1]).try_into().unwrap();
3408        assert_eq!(v.to_option(), Some(1));
3409    }
3410}
3411
3412#[cfg(all(test, feature = "serde"))]
3413mod tests_for_number_or_string {
3414    use super::*;
3415    use serde::{Deserialize, Serialize};
3416    use serde_with::serde_as;
3417
3418    // --- Helper Structs ---
3419    #[serde_as]
3420    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3421    struct TestI64 {
3422        #[serde_as(as = "NumberOrString")]
3423        val: i64,
3424    }
3425
3426    #[serde_as]
3427    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3428    struct TestU64 {
3429        #[serde_as(as = "NumberOrString")]
3430        val: u64,
3431    }
3432
3433    #[serde_as]
3434    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3435    struct TestOptionI64 {
3436        #[serde_as(as = "Option<NumberOrString>")]
3437        val: Option<i64>,
3438    }
3439
3440    #[serde_as]
3441    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3442    struct TestOptionU64 {
3443        #[serde_as(as = "Option<NumberOrString>")]
3444        val: Option<u64>,
3445    }
3446
3447    #[serde_as]
3448    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3449    struct TestVecI64 {
3450        #[serde_as(as = "Vec<NumberOrString>")]
3451        val: Vec<i64>,
3452    }
3453
3454    #[serde_as]
3455    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3456    struct TestVecU64 {
3457        #[serde_as(as = "Vec<NumberOrString>")]
3458        val: Vec<u64>,
3459    }
3460
3461    // Helper Enum for testing field access within variants
3462    #[serde_as]
3463    #[derive(Debug, PartialEq, Deserialize, Serialize)]
3464    #[serde(rename_all = "camelCase")] // Added to make JSON keys distinct for variants
3465    enum TestEnum {
3466        VariantA {
3467            #[serde(rename = "numVal")]
3468            #[serde_as(as = "NumberOrString")]
3469            num_val: i64,
3470            #[serde(rename = "otherData")]
3471            other_data: String,
3472        },
3473        VariantB {
3474            #[serde_as(as = "NumberOrString")]
3475            count: u64,
3476        },
3477        SimpleVariant,
3478    }
3479
3480    // --- i64 Deserialization Tests ---
3481    #[test]
3482    fn deserialize_i64_from_json_reader() {
3483        let json = r#"{"val": "123"}"#;
3484        let expected = TestI64 { val: 123 };
3485        assert_eq!(
3486            serde_json::from_reader::<_, TestI64>(Cursor::new(json)).unwrap(),
3487            expected
3488        );
3489    }
3490
3491    #[test]
3492    fn deserialize_i64_from_json_number_positive() {
3493        let json = r#"{"val": 123}"#;
3494        let expected = TestI64 { val: 123 };
3495        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3496    }
3497
3498    #[test]
3499    fn deserialize_i64_from_json_number_negative() {
3500        let json = r#"{"val": -456}"#;
3501        let expected = TestI64 { val: -456 };
3502        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3503    }
3504
3505    #[test]
3506    fn deserialize_i64_from_json_number_zero() {
3507        let json = r#"{"val": 0}"#;
3508        let expected = TestI64 { val: 0 };
3509        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3510    }
3511
3512    #[test]
3513    fn deserialize_i64_from_json_number_max() {
3514        let json = format!(r#"{{"val": {}}}"#, i64::MAX);
3515        let expected = TestI64 { val: i64::MAX };
3516        assert_eq!(serde_json::from_str::<TestI64>(&json).unwrap(), expected);
3517    }
3518
3519    #[test]
3520    fn deserialize_i64_from_json_number_min() {
3521        let json = format!(r#"{{"val": {}}}"#, i64::MIN);
3522        let expected = TestI64 { val: i64::MIN };
3523        assert_eq!(serde_json::from_str::<TestI64>(&json).unwrap(), expected);
3524    }
3525
3526    #[test]
3527    fn deserialize_i64_from_json_string_positive() {
3528        let json = r#"{"val": "789"}"#;
3529        let expected = TestI64 { val: 789 };
3530        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3531    }
3532
3533    #[test]
3534    fn deserialize_i64_from_json_string_negative() {
3535        let json = r#"{"val": "-101"}"#;
3536        let expected = TestI64 { val: -101 };
3537        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3538    }
3539
3540    #[test]
3541    fn deserialize_i64_from_json_string_zero() {
3542        let json = r#"{"val": "0"}"#;
3543        let expected = TestI64 { val: 0 };
3544        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3545    }
3546
3547    #[test]
3548    fn deserialize_i64_from_json_string_max() {
3549        let json = format!(r#"{{"val": "{}"}}"#, i64::MAX);
3550        let expected = TestI64 { val: i64::MAX };
3551        assert_eq!(serde_json::from_str::<TestI64>(&json).unwrap(), expected);
3552    }
3553
3554    #[test]
3555    fn deserialize_i64_from_json_string_min() {
3556        let json = format!(r#"{{"val": "{}"}}"#, i64::MIN);
3557        let expected = TestI64 { val: i64::MIN };
3558        assert_eq!(serde_json::from_str::<TestI64>(&json).unwrap(), expected);
3559    }
3560
3561    #[test]
3562    fn deserialize_i64_from_json_string_with_plus_prefix() {
3563        let json = r#"{"val": "+123"}"#;
3564        let expected = TestI64 { val: 123 };
3565        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3566    }
3567
3568    #[test]
3569    fn deserialize_i64_from_json_string_with_plus_zero() {
3570        let json = r#"{"val": "+0"}"#;
3571        let expected = TestI64 { val: 0 };
3572        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3573    }
3574
3575    #[test]
3576    fn deserialize_i64_from_json_string_with_minus_zero() {
3577        let json = r#"{"val": "-0"}"#;
3578        let expected = TestI64 { val: 0 };
3579        assert_eq!(serde_json::from_str::<TestI64>(json).unwrap(), expected);
3580    }
3581
3582    #[test]
3583    fn deserialize_i64_error_from_json_string_with_leading_whitespace() {
3584        let json = r#"{"val": " 123"}"#;
3585        assert!(serde_json::from_str::<TestI64>(json).is_err());
3586    }
3587
3588    #[test]
3589    fn deserialize_i64_error_from_json_string_with_trailing_whitespace() {
3590        let json = r#"{"val": "123 "}"#;
3591        assert!(serde_json::from_str::<TestI64>(json).is_err());
3592    }
3593
3594    #[test]
3595    fn deserialize_i64_error_from_json_string_with_both_whitespace() {
3596        let json = r#"{"val": " 123 "}"#;
3597        assert!(serde_json::from_str::<TestI64>(json).is_err());
3598    }
3599
3600    #[test]
3601    fn deserialize_i64_error_from_json_string_with_invalid_plus_prefix() {
3602        let json = r#"{"val": "++123"}"#;
3603        assert!(serde_json::from_str::<TestI64>(json).is_err());
3604    }
3605
3606    #[test]
3607    fn deserialize_i64_error_from_json_string_with_invalid_minus_prefix() {
3608        let json = r#"{"val": "--123"}"#;
3609        assert!(serde_json::from_str::<TestI64>(json).is_err());
3610    }
3611
3612    #[test]
3613    fn deserialize_i64_error_from_json_string_with_invalid_mixed_prefix() {
3614        let json = r#"{"val": "+-123"}"#;
3615        assert!(serde_json::from_str::<TestI64>(json).is_err());
3616    }
3617
3618    #[test]
3619    fn deserialize_i64_error_from_string_not_a_number() {
3620        let json = r#"{"val": "abc"}"#;
3621        assert!(serde_json::from_str::<TestI64>(json).is_err());
3622    }
3623
3624    #[test]
3625    fn deserialize_i64_error_from_string_float() {
3626        let json = r#"{"val": "123.45"}"#; // Not an integer
3627        assert!(serde_json::from_str::<TestI64>(json).is_err());
3628    }
3629
3630    #[test]
3631    fn deserialize_i64_error_from_string_empty() {
3632        let json = r#"{"val": ""}"#;
3633        assert!(serde_json::from_str::<TestI64>(json).is_err());
3634    }
3635
3636    #[test]
3637    fn deserialize_i64_error_from_string_overflow() {
3638        let overflow_val = i128::from(i64::MAX) + 1;
3639        let json = format!(r#"{{"val": "{overflow_val}"}}"#);
3640        assert!(serde_json::from_str::<TestI64>(&json).is_err());
3641    }
3642
3643    #[test]
3644    fn deserialize_i64_error_from_string_underflow() {
3645        let underflow_val = i128::from(i64::MIN) - 1;
3646        let json = format!(r#"{{"val": "{underflow_val}"}}"#);
3647        assert!(serde_json::from_str::<TestI64>(&json).is_err());
3648    }
3649
3650    #[test]
3651    fn deserialize_i64_error_from_json_float_number() {
3652        let json = r#"{"val": 123.45}"#;
3653        assert!(serde_json::from_str::<TestI64>(json).is_err());
3654    }
3655
3656    #[test]
3657    fn deserialize_i64_error_from_json_bool_true() {
3658        let json = r#"{"val": true}"#;
3659        assert!(serde_json::from_str::<TestI64>(json).is_err());
3660    }
3661
3662    #[test]
3663    fn deserialize_i64_error_from_json_array() {
3664        let json = r#"{"val": []}"#;
3665        assert!(serde_json::from_str::<TestI64>(json).is_err());
3666    }
3667
3668    #[test]
3669    fn deserialize_i64_error_from_json_object() {
3670        let json = r#"{"val": {}}"#;
3671        assert!(serde_json::from_str::<TestI64>(json).is_err());
3672    }
3673
3674    #[test]
3675    fn deserialize_i64_error_from_json_null() {
3676        let json = r#"{"val": null}"#;
3677        assert!(serde_json::from_str::<TestI64>(json).is_err());
3678    }
3679
3680    // -- Additional i64 String Format Tests --
3681    #[test]
3682    fn deserialize_i64_error_from_hex_string() {
3683        let json = r#"{"val": "0x1A"}"#; // Hex "26"
3684                                         // std::primitive::i64.from_str() does not support "0x"
3685        assert!(
3686            serde_json::from_str::<TestI64>(json).is_err(),
3687            "Hex string should fail parsing to i64"
3688        );
3689    }
3690
3691    #[test]
3692    fn deserialize_i64_error_from_octal_string() {
3693        let json = r#"{"val": "0o77"}"#; // Octal "63"
3694                                         // std::primitive::i64.from_str() does not support "0o"
3695        assert!(
3696            serde_json::from_str::<TestI64>(json).is_err(),
3697            "Octal string should fail parsing to i64"
3698        );
3699    }
3700
3701    #[test]
3702    fn deserialize_i64_error_from_scientific_notation_string() {
3703        let json = r#"{"val": "1e3"}"#; // "1000" in scientific
3704                                        // std::primitive::i64.from_str() does not support scientific notation
3705        assert!(
3706            serde_json::from_str::<TestI64>(json).is_err(),
3707            "Scientific notation string should fail parsing to i64"
3708        );
3709    }
3710
3711    #[test]
3712    fn deserialize_i64_error_from_invalid_scientific_notation_string() {
3713        let json = r#"{"val": "1e"}"#;
3714        assert!(
3715            serde_json::from_str::<TestI64>(json).is_err(),
3716            "Invalid scientific notation string should fail"
3717        );
3718    }
3719
3720    #[test]
3721    fn deserialize_i64_error_from_string_with_underscores() {
3722        let json = r#"{"val": "1_000_000"}"#;
3723        // std::primitive::i64.from_str() does not support underscores
3724        assert!(
3725            serde_json::from_str::<TestI64>(json).is_err(),
3726            "String with underscores should fail parsing to i64"
3727        );
3728    }
3729
3730    #[test]
3731    fn deserialize_i64_from_string_with_leading_zeros() {
3732        let json = r#"{"val": "000123"}"#;
3733        let expected = TestI64 { val: 123 };
3734        // std::primitive::i64.from_str() supports leading zeros
3735        assert_eq!(
3736            serde_json::from_str::<TestI64>(json).unwrap(),
3737            expected,
3738            "String with leading zeros should parse"
3739        );
3740    }
3741
3742    #[test]
3743    fn deserialize_i64_from_string_with_leading_zeros_negative() {
3744        let json = r#"{"val": "-000123"}"#;
3745        let expected = TestI64 { val: -123 };
3746        assert_eq!(
3747            serde_json::from_str::<TestI64>(json).unwrap(),
3748            expected,
3749            "Negative string with leading zeros should parse"
3750        );
3751    }
3752
3753    #[test]
3754    fn deserialize_i64_error_from_string_with_decimal_zeros() {
3755        let json = r#"{"val": "123.000"}"#;
3756        // std::primitive::i64.from_str() does not support decimals
3757        assert!(
3758            serde_json::from_str::<TestI64>(json).is_err(),
3759            "String with decimal part should fail parsing to i64"
3760        );
3761    }
3762
3763    #[test]
3764    fn deserialize_i64_error_from_string_with_internal_decimal() {
3765        let json = r#"{"val": "12.345"}"#;
3766        assert!(
3767            serde_json::from_str::<TestI64>(json).is_err(),
3768            "String with internal decimal point should fail"
3769        );
3770    }
3771
3772    #[test]
3773    fn deserialize_i64_error_from_localized_string_commas() {
3774        let json = r#"{"val": "1,234"}"#;
3775        // std::primitive::i64.from_str() does not support commas
3776        assert!(
3777            serde_json::from_str::<TestI64>(json).is_err(),
3778            "Localized string with commas should fail parsing to i64"
3779        );
3780    }
3781
3782    // --- u64 Deserialization Tests ---
3783    #[test]
3784    fn deserialize_u64_from_json_reader() {
3785        let json = r#"{"val": "123"}"#;
3786        let expected = TestU64 { val: 123 };
3787        assert_eq!(
3788            serde_json::from_reader::<_, TestU64>(Cursor::new(json)).unwrap(),
3789            expected
3790        );
3791    }
3792
3793    #[test]
3794    fn deserialize_u64_from_json_number() {
3795        let json = r#"{"val": 123}"#;
3796        let expected = TestU64 { val: 123 };
3797        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3798    }
3799
3800    #[test]
3801    fn deserialize_u64_from_json_number_zero() {
3802        let json = r#"{"val": 0}"#;
3803        let expected = TestU64 { val: 0 };
3804        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3805    }
3806
3807    #[test]
3808    fn deserialize_u64_from_json_number_max() {
3809        let json = format!(r#"{{"val": {}}}"#, u64::MAX);
3810        let expected = TestU64 { val: u64::MAX };
3811        assert_eq!(serde_json::from_str::<TestU64>(&json).unwrap(), expected);
3812    }
3813
3814    #[test]
3815    fn deserialize_u64_from_json_string() {
3816        let json = r#"{"val": "789"}"#;
3817        let expected = TestU64 { val: 789 };
3818        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3819    }
3820
3821    #[test]
3822    fn deserialize_u64_from_json_string_zero() {
3823        let json = r#"{"val": "0"}"#;
3824        let expected = TestU64 { val: 0 };
3825        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3826    }
3827
3828    #[test]
3829    fn deserialize_u64_from_json_string_max() {
3830        let json = format!(r#"{{"val": "{}"}}"#, u64::MAX);
3831        let expected = TestU64 { val: u64::MAX };
3832        assert_eq!(serde_json::from_str::<TestU64>(&json).unwrap(), expected);
3833    }
3834
3835    #[test]
3836    fn deserialize_u64_from_json_string_with_plus_prefix() {
3837        let json = r#"{"val": "+123"}"#;
3838        let expected = TestU64 { val: 123 };
3839        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3840    }
3841
3842    #[test]
3843    fn deserialize_u64_from_json_string_with_plus_zero() {
3844        let json = r#"{"val": "+0"}"#;
3845        let expected = TestU64 { val: 0 };
3846        assert_eq!(serde_json::from_str::<TestU64>(json).unwrap(), expected);
3847    }
3848
3849    #[test]
3850    fn deserialize_u64_error_from_json_string_with_leading_whitespace() {
3851        let json = r#"{"val": " 123"}"#;
3852        assert!(serde_json::from_str::<TestU64>(json).is_err());
3853    }
3854
3855    #[test]
3856    fn deserialize_u64_error_from_json_string_with_trailing_whitespace() {
3857        let json = r#"{"val": "123 "}"#;
3858        assert!(serde_json::from_str::<TestU64>(json).is_err());
3859    }
3860
3861    #[test]
3862    fn deserialize_u64_error_from_json_string_with_invalid_plus_prefix() {
3863        let json = r#"{"val": "++123"}"#;
3864        assert!(serde_json::from_str::<TestU64>(json).is_err());
3865    }
3866
3867    #[test]
3868    fn deserialize_u64_error_from_string_negative() {
3869        let json = r#"{"val": "-123"}"#; // Negative not allowed for u64 string parse
3870        assert!(serde_json::from_str::<TestU64>(json).is_err());
3871    }
3872
3873    #[test]
3874    fn deserialize_u64_error_from_json_number_negative() {
3875        let json = r#"{"val": -1}"#; // Negative not allowed for u64
3876        assert!(serde_json::from_str::<TestU64>(json).is_err());
3877    }
3878
3879    #[test]
3880    fn deserialize_u64_error_from_string_not_a_number() {
3881        let json = r#"{"val": "abc"}"#;
3882        assert!(serde_json::from_str::<TestU64>(json).is_err());
3883    }
3884
3885    #[test]
3886    fn deserialize_u64_error_from_string_float() {
3887        let json = r#"{"val": "123.45"}"#;
3888        assert!(serde_json::from_str::<TestU64>(json).is_err());
3889    }
3890
3891    #[test]
3892    fn deserialize_u64_error_from_string_empty() {
3893        let json = r#"{"val": ""}"#;
3894        assert!(serde_json::from_str::<TestU64>(json).is_err());
3895    }
3896
3897    #[test]
3898    fn deserialize_u64_error_from_string_overflow() {
3899        let overflow_val = u128::from(u64::MAX) + 1;
3900        let json = format!(r#"{{"val": "{overflow_val}"}}"#);
3901        assert!(serde_json::from_str::<TestU64>(&json).is_err());
3902    }
3903
3904    #[test]
3905    fn deserialize_u64_error_from_json_float_number() {
3906        let json = r#"{"val": 123.45}"#;
3907        assert!(serde_json::from_str::<TestU64>(json).is_err());
3908    }
3909
3910    #[test]
3911    fn deserialize_u64_error_from_json_bool_true() {
3912        let json = r#"{"val": true}"#;
3913        assert!(serde_json::from_str::<TestU64>(json).is_err());
3914    }
3915
3916    #[test]
3917    fn deserialize_u64_error_from_json_array() {
3918        let json = r#"{"val": []}"#;
3919        assert!(serde_json::from_str::<TestU64>(json).is_err());
3920    }
3921
3922    #[test]
3923    fn deserialize_u64_error_from_json_object() {
3924        let json = r#"{"val": {}}"#;
3925        assert!(serde_json::from_str::<TestU64>(json).is_err());
3926    }
3927
3928    #[test]
3929    fn deserialize_u64_error_from_json_null() {
3930        let json = r#"{"val": null}"#;
3931        assert!(serde_json::from_str::<TestU64>(json).is_err());
3932    }
3933
3934    // -- Additional u64 String Format Tests --
3935    #[test]
3936    fn deserialize_u64_error_from_hex_string() {
3937        let json = r#"{"val": "0x1A"}"#; // Hex "26"
3938        assert!(
3939            serde_json::from_str::<TestU64>(json).is_err(),
3940            "Hex string should fail parsing to u64"
3941        );
3942    }
3943
3944    #[test]
3945    fn deserialize_u64_error_from_octal_string() {
3946        let json = r#"{"val": "0o77"}"#; // Octal "63"
3947        assert!(
3948            serde_json::from_str::<TestU64>(json).is_err(),
3949            "Octal string should fail parsing to u64"
3950        );
3951    }
3952
3953    #[test]
3954    fn deserialize_u64_error_from_scientific_notation_string() {
3955        let json = r#"{"val": "1e3"}"#;
3956        assert!(
3957            serde_json::from_str::<TestU64>(json).is_err(),
3958            "Scientific notation string should fail parsing to u64"
3959        );
3960    }
3961
3962    #[test]
3963    fn deserialize_u64_error_from_string_with_underscores() {
3964        let json = r#"{"val": "1_000_000"}"#;
3965        assert!(
3966            serde_json::from_str::<TestU64>(json).is_err(),
3967            "String with underscores should fail parsing to u64"
3968        );
3969    }
3970
3971    #[test]
3972    fn deserialize_u64_from_string_with_leading_zeros() {
3973        let json = r#"{"val": "000123"}"#;
3974        let expected = TestU64 { val: 123 };
3975        assert_eq!(
3976            serde_json::from_str::<TestU64>(json).unwrap(),
3977            expected,
3978            "String with leading zeros should parse to u64"
3979        );
3980    }
3981
3982    #[test]
3983    fn deserialize_u64_error_from_string_with_decimal_zeros() {
3984        let json = r#"{"val": "123.000"}"#;
3985        assert!(
3986            serde_json::from_str::<TestU64>(json).is_err(),
3987            "String with decimal part should fail parsing to u64"
3988        );
3989    }
3990
3991    #[test]
3992    fn deserialize_u64_error_from_localized_string_commas() {
3993        let json = r#"{"val": "1,234"}"#;
3994        assert!(
3995            serde_json::from_str::<TestU64>(json).is_err(),
3996            "Localized string with commas should fail parsing to u64"
3997        );
3998    }
3999
4000    // --- i64 Serialization Tests ---
4001    #[test]
4002    fn serialize_i64_positive() {
4003        let data = TestI64 { val: 123 };
4004        let expected_json = r#"{"val":"123"}"#;
4005        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4006    }
4007
4008    #[test]
4009    fn serialize_i64_negative() {
4010        let data = TestI64 { val: -456 };
4011        let expected_json = r#"{"val":"-456"}"#;
4012        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4013    }
4014
4015    #[test]
4016    fn serialize_i64_zero() {
4017        let data = TestI64 { val: 0 };
4018        let expected_json = r#"{"val":"0"}"#;
4019        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4020    }
4021
4022    #[test]
4023    fn serialize_i64_max() {
4024        let data = TestI64 { val: i64::MAX };
4025        let expected_json = format!(r#"{{"val":"{}"}}"#, i64::MAX);
4026        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4027    }
4028
4029    #[test]
4030    fn serialize_i64_min() {
4031        let data = TestI64 { val: i64::MIN };
4032        let expected_json = format!(r#"{{"val":"{}"}}"#, i64::MIN);
4033        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4034    }
4035
4036    // --- u64 Serialization Tests ---
4037    #[test]
4038    fn serialize_u64_positive() {
4039        let data = TestU64 { val: 789 };
4040        let expected_json = r#"{"val":"789"}"#;
4041        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4042    }
4043
4044    #[test]
4045    fn serialize_u64_zero() {
4046        let data = TestU64 { val: 0 };
4047        let expected_json = r#"{"val":"0"}"#;
4048        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4049    }
4050
4051    #[test]
4052    fn serialize_u64_max() {
4053        let data = TestU64 { val: u64::MAX };
4054        let expected_json = format!(r#"{{"val":"{}"}}"#, u64::MAX);
4055        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4056    }
4057
4058    // --- Option<i64> Tests ---
4059    #[test]
4060    fn deserialize_option_i64_some_from_json_number() {
4061        let json = r#"{"val": 123}"#;
4062        let expected = TestOptionI64 { val: Some(123) };
4063        assert_eq!(
4064            serde_json::from_str::<TestOptionI64>(json).unwrap(),
4065            expected
4066        );
4067    }
4068
4069    #[test]
4070    fn deserialize_option_i64_some_from_json_string() {
4071        let json = r#"{"val": "456"}"#;
4072        let expected = TestOptionI64 { val: Some(456) };
4073        assert_eq!(
4074            serde_json::from_str::<TestOptionI64>(json).unwrap(),
4075            expected
4076        );
4077    }
4078
4079    #[test]
4080    fn deserialize_option_i64_none_from_json_null() {
4081        let json = r#"{"val": null}"#;
4082        let expected = TestOptionI64 { val: None };
4083        assert_eq!(
4084            serde_json::from_str::<TestOptionI64>(json).unwrap(),
4085            expected
4086        );
4087    }
4088
4089    #[test]
4090    fn deserialize_option_i64_error_from_invalid_string() {
4091        let json = r#"{"val": "abc"}"#;
4092        assert!(serde_json::from_str::<TestOptionI64>(json).is_err());
4093    }
4094
4095    #[test]
4096    fn deserialize_option_i64_error_from_invalid_type() {
4097        let json = r#"{"val": true}"#;
4098        assert!(serde_json::from_str::<TestOptionI64>(json).is_err());
4099    }
4100
4101    #[test]
4102    fn serialize_option_i64_some() {
4103        let data = TestOptionI64 { val: Some(123) };
4104        let expected_json = r#"{"val":"123"}"#;
4105        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4106    }
4107
4108    #[test]
4109    fn serialize_option_i64_none() {
4110        let data = TestOptionI64 { val: None };
4111        let expected_json = r#"{"val":null}"#;
4112        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4113    }
4114
4115    // --- Option<u64> Tests ---
4116    #[test]
4117    fn deserialize_option_u64_some_from_json_number() {
4118        let json = r#"{"val": 123}"#;
4119        let expected = TestOptionU64 { val: Some(123) };
4120        assert_eq!(
4121            serde_json::from_str::<TestOptionU64>(json).unwrap(),
4122            expected
4123        );
4124    }
4125
4126    #[test]
4127    fn deserialize_option_u64_some_from_json_string() {
4128        let json = r#"{"val": "456"}"#;
4129        let expected = TestOptionU64 { val: Some(456) };
4130        assert_eq!(
4131            serde_json::from_str::<TestOptionU64>(json).unwrap(),
4132            expected
4133        );
4134    }
4135
4136    #[test]
4137    fn deserialize_option_u64_none_from_json_null() {
4138        let json = r#"{"val": null}"#;
4139        let expected = TestOptionU64 { val: None };
4140        assert_eq!(
4141            serde_json::from_str::<TestOptionU64>(json).unwrap(),
4142            expected
4143        );
4144    }
4145
4146    #[test]
4147    fn deserialize_option_u64_error_from_invalid_string() {
4148        let json = r#"{"val": "abc"}"#;
4149        assert!(serde_json::from_str::<TestOptionU64>(json).is_err());
4150    }
4151
4152    #[test]
4153    fn deserialize_option_u64_error_from_negative_string() {
4154        let json = r#"{"val": "-1"}"#; // Invalid for u64
4155        assert!(serde_json::from_str::<TestOptionU64>(json).is_err());
4156    }
4157
4158    #[test]
4159    fn serialize_option_u64_some() {
4160        let data = TestOptionU64 { val: Some(123) };
4161        let expected_json = r#"{"val":"123"}"#;
4162        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4163    }
4164
4165    #[test]
4166    fn serialize_option_u64_none() {
4167        let data = TestOptionU64 { val: None };
4168        let expected_json = r#"{"val":null}"#;
4169        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4170    }
4171
4172    // --- Vec<i64> Tests ---
4173    #[test]
4174    fn deserialize_vec_i64_empty() {
4175        let json = r#"{"val": []}"#;
4176        let expected = TestVecI64 { val: vec![] };
4177        assert_eq!(serde_json::from_str::<TestVecI64>(json).unwrap(), expected);
4178    }
4179
4180    #[test]
4181    fn deserialize_vec_i64_from_numbers_and_strings() {
4182        let json = r#"{"val": [1, "2", -3, "-4"]}"#;
4183        let expected = TestVecI64 {
4184            val: vec![1, 2, -3, -4],
4185        };
4186        assert_eq!(serde_json::from_str::<TestVecI64>(json).unwrap(), expected);
4187    }
4188
4189    #[test]
4190    fn deserialize_vec_i64_error_if_item_is_invalid_string() {
4191        let json = r#"{"val": [1, "abc", 3]}"#;
4192        let err = serde_json::from_str::<TestVecI64>(json).unwrap_err();
4193        // The error will point to the specific failing element
4194        assert!(err.to_string().contains("invalid digit found in string")); // From parse error
4195    }
4196
4197    #[test]
4198    fn deserialize_vec_i64_error_if_item_is_invalid_type() {
4199        let json = r#"{"val": [1, true, 3]}"#;
4200        assert!(serde_json::from_str::<TestVecI64>(json).is_err());
4201    }
4202
4203    #[test]
4204    fn serialize_vec_i64_empty() {
4205        let data = TestVecI64 { val: vec![] };
4206        let expected_json = r#"{"val":[]}"#;
4207        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4208    }
4209
4210    #[test]
4211    fn serialize_vec_i64_with_values() {
4212        let data = TestVecI64 {
4213            val: vec![1, -2, 0],
4214        };
4215        let expected_json = r#"{"val":["1","-2","0"]}"#;
4216        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4217    }
4218
4219    // --- Vec<u64> Tests ---
4220    #[test]
4221    fn deserialize_vec_u64_empty() {
4222        let json = r#"{"val": []}"#;
4223        let expected = TestVecU64 { val: vec![] };
4224        assert_eq!(serde_json::from_str::<TestVecU64>(json).unwrap(), expected);
4225    }
4226
4227    #[test]
4228    fn deserialize_vec_u64_from_numbers_and_strings() {
4229        let json = r#"{"val": [1, "2", 3, "4"]}"#;
4230        let expected = TestVecU64 {
4231            val: vec![1, 2, 3, 4],
4232        };
4233        assert_eq!(serde_json::from_str::<TestVecU64>(json).unwrap(), expected);
4234    }
4235
4236    #[test]
4237    fn deserialize_vec_u64_error_if_item_is_invalid_string() {
4238        let json = r#"{"val": [1, "abc", 3]}"#;
4239        let err = serde_json::from_str::<TestVecU64>(json).unwrap_err();
4240        assert!(err.to_string().contains("invalid digit found in string"));
4241    }
4242
4243    #[test]
4244    fn deserialize_vec_u64_error_if_item_is_negative_string() {
4245        let json = r#"{"val": [1, "-2", 3]}"#;
4246        let err = serde_json::from_str::<TestVecU64>(json).unwrap_err();
4247        assert!(err.to_string().contains("invalid digit found in string")); // u64 parse error
4248    }
4249
4250    #[test]
4251    fn deserialize_vec_u64_error_if_item_is_negative_number() {
4252        let json = r#"{"val": [1, -2, 3]}"#;
4253        assert!(serde_json::from_str::<TestVecU64>(json).is_err());
4254    }
4255
4256    #[test]
4257    fn serialize_vec_u64_empty() {
4258        let data = TestVecU64 { val: vec![] };
4259        let expected_json = r#"{"val":[]}"#;
4260        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4261    }
4262
4263    #[test]
4264    fn serialize_vec_u64_with_values() {
4265        let data = TestVecU64 { val: vec![1, 2, 0] };
4266        let expected_json = r#"{"val":["1","2","0"]}"#;
4267        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4268    }
4269
4270    // --- Enum with NumberOrString field Tests ---
4271    #[test]
4272    fn deserialize_enum_variant_a_with_number() {
4273        let json = r#"{"variantA": {"numVal": 123, "otherData": "test"}}"#;
4274        let expected = TestEnum::VariantA {
4275            num_val: 123,
4276            other_data: "test".to_string(),
4277        };
4278        assert_eq!(serde_json::from_str::<TestEnum>(json).unwrap(), expected);
4279    }
4280
4281    #[test]
4282    fn deserialize_enum_variant_a_with_string_number() {
4283        let json = r#"{"variantA": {"numVal": "-45", "otherData": "data"}}"#;
4284        let expected = TestEnum::VariantA {
4285            num_val: -45,
4286            other_data: "data".to_string(),
4287        };
4288        assert_eq!(serde_json::from_str::<TestEnum>(json).unwrap(), expected);
4289    }
4290
4291    #[test]
4292    fn deserialize_enum_variant_b_with_number() {
4293        let json = r#"{"variantB": {"count": 7890}}"#;
4294        let expected = TestEnum::VariantB { count: 7890 };
4295        assert_eq!(serde_json::from_str::<TestEnum>(json).unwrap(), expected);
4296    }
4297
4298    #[test]
4299    fn deserialize_enum_variant_b_with_string_number() {
4300        let json = r#"{"variantB": {"count": "1234567890"}}"#;
4301        let expected = TestEnum::VariantB { count: 1234567890 };
4302        assert_eq!(serde_json::from_str::<TestEnum>(json).unwrap(), expected);
4303    }
4304
4305    #[test]
4306    fn deserialize_enum_variant_a_error_invalid_num_string() {
4307        let json = r#"{"variantA": {"numVal": "abc", "otherData": "test"}}"#;
4308        assert!(serde_json::from_str::<TestEnum>(json).is_err());
4309    }
4310
4311    #[test]
4312    fn serialize_enum_variant_a() {
4313        let data = TestEnum::VariantA {
4314            num_val: 123,
4315            other_data: "test".to_string(),
4316        };
4317        // Note: num_val will be serialized as a string by NumberOrString
4318        let expected_json = r#"{"variantA":{"numVal":"123","otherData":"test"}}"#;
4319        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4320    }
4321
4322    #[test]
4323    fn serialize_enum_variant_b() {
4324        let data = TestEnum::VariantB { count: 7890 };
4325        let expected_json = r#"{"variantB":{"count":"7890"}}"#;
4326        assert_eq!(serde_json::to_string(&data).unwrap(), expected_json);
4327    }
4328}
4329
4330mod value;
4331#[allow(unused_imports)]
4332pub use value::*;
4333mod scp_ballot;
4334#[allow(unused_imports)]
4335pub use scp_ballot::*;
4336mod scp_statement_type;
4337#[allow(unused_imports)]
4338pub use scp_statement_type::*;
4339mod scp_nomination;
4340#[allow(unused_imports)]
4341pub use scp_nomination::*;
4342mod scp_statement_prepare;
4343#[allow(unused_imports)]
4344pub use scp_statement_prepare::*;
4345mod scp_statement_confirm;
4346#[allow(unused_imports)]
4347pub use scp_statement_confirm::*;
4348mod scp_statement_externalize;
4349#[allow(unused_imports)]
4350pub use scp_statement_externalize::*;
4351mod scp_statement_pledges;
4352#[allow(unused_imports)]
4353pub use scp_statement_pledges::*;
4354mod scp_statement;
4355#[allow(unused_imports)]
4356pub use scp_statement::*;
4357mod scp_envelope;
4358#[allow(unused_imports)]
4359pub use scp_envelope::*;
4360mod scp_quorum_set;
4361#[allow(unused_imports)]
4362pub use scp_quorum_set::*;
4363mod encoded_ledger_key;
4364#[allow(unused_imports)]
4365pub use encoded_ledger_key::*;
4366mod config_setting_contract_execution_lanes_v0;
4367#[allow(unused_imports)]
4368pub use config_setting_contract_execution_lanes_v0::*;
4369mod config_setting_contract_compute_v0;
4370#[allow(unused_imports)]
4371pub use config_setting_contract_compute_v0::*;
4372mod config_setting_contract_parallel_compute_v0;
4373#[allow(unused_imports)]
4374pub use config_setting_contract_parallel_compute_v0::*;
4375mod config_setting_contract_ledger_cost_v0;
4376#[allow(unused_imports)]
4377pub use config_setting_contract_ledger_cost_v0::*;
4378mod config_setting_contract_ledger_cost_ext_v0;
4379#[allow(unused_imports)]
4380pub use config_setting_contract_ledger_cost_ext_v0::*;
4381mod config_setting_contract_historical_data_v0;
4382#[allow(unused_imports)]
4383pub use config_setting_contract_historical_data_v0::*;
4384mod config_setting_contract_events_v0;
4385#[allow(unused_imports)]
4386pub use config_setting_contract_events_v0::*;
4387mod config_setting_contract_bandwidth_v0;
4388#[allow(unused_imports)]
4389pub use config_setting_contract_bandwidth_v0::*;
4390mod contract_cost_type;
4391#[allow(unused_imports)]
4392pub use contract_cost_type::*;
4393mod contract_cost_param_entry;
4394#[allow(unused_imports)]
4395pub use contract_cost_param_entry::*;
4396mod state_archival_settings;
4397#[allow(unused_imports)]
4398pub use state_archival_settings::*;
4399mod eviction_iterator;
4400#[allow(unused_imports)]
4401pub use eviction_iterator::*;
4402mod config_setting_scp_timing;
4403#[allow(unused_imports)]
4404pub use config_setting_scp_timing::*;
4405mod frozen_ledger_keys;
4406#[allow(unused_imports)]
4407pub use frozen_ledger_keys::*;
4408mod frozen_ledger_keys_delta;
4409#[allow(unused_imports)]
4410pub use frozen_ledger_keys_delta::*;
4411mod freeze_bypass_txs;
4412#[allow(unused_imports)]
4413pub use freeze_bypass_txs::*;
4414mod freeze_bypass_txs_delta;
4415#[allow(unused_imports)]
4416pub use freeze_bypass_txs_delta::*;
4417mod contract_cost_count_limit;
4418#[allow(unused_imports)]
4419pub use contract_cost_count_limit::*;
4420mod contract_cost_params;
4421#[allow(unused_imports)]
4422pub use contract_cost_params::*;
4423mod config_setting_id;
4424#[allow(unused_imports)]
4425pub use config_setting_id::*;
4426mod config_setting_entry;
4427#[allow(unused_imports)]
4428pub use config_setting_entry::*;
4429mod sc_env_meta_kind;
4430#[allow(unused_imports)]
4431pub use sc_env_meta_kind::*;
4432mod sc_env_meta_entry_interface_version;
4433#[allow(unused_imports)]
4434pub use sc_env_meta_entry_interface_version::*;
4435mod sc_env_meta_entry;
4436#[allow(unused_imports)]
4437pub use sc_env_meta_entry::*;
4438mod sc_meta_v0;
4439#[allow(unused_imports)]
4440pub use sc_meta_v0::*;
4441mod sc_meta_kind;
4442#[allow(unused_imports)]
4443pub use sc_meta_kind::*;
4444mod sc_meta_entry;
4445#[allow(unused_imports)]
4446pub use sc_meta_entry::*;
4447mod sc_spec_doc_limit;
4448#[allow(unused_imports)]
4449pub use sc_spec_doc_limit::*;
4450mod sc_spec_type_name_limit;
4451#[allow(unused_imports)]
4452pub use sc_spec_type_name_limit::*;
4453mod sc_spec_type;
4454#[allow(unused_imports)]
4455pub use sc_spec_type::*;
4456mod sc_spec_type_option;
4457#[allow(unused_imports)]
4458pub use sc_spec_type_option::*;
4459mod sc_spec_type_result;
4460#[allow(unused_imports)]
4461pub use sc_spec_type_result::*;
4462mod sc_spec_type_vec;
4463#[allow(unused_imports)]
4464pub use sc_spec_type_vec::*;
4465mod sc_spec_type_map;
4466#[allow(unused_imports)]
4467pub use sc_spec_type_map::*;
4468mod sc_spec_type_tuple;
4469#[allow(unused_imports)]
4470pub use sc_spec_type_tuple::*;
4471mod sc_spec_type_bytes_n;
4472#[allow(unused_imports)]
4473pub use sc_spec_type_bytes_n::*;
4474mod sc_spec_type_udt;
4475#[allow(unused_imports)]
4476pub use sc_spec_type_udt::*;
4477mod sc_spec_type_def;
4478#[allow(unused_imports)]
4479pub use sc_spec_type_def::*;
4480mod sc_spec_udt_struct_field_v0;
4481#[allow(unused_imports)]
4482pub use sc_spec_udt_struct_field_v0::*;
4483mod sc_spec_udt_struct_v0;
4484#[allow(unused_imports)]
4485pub use sc_spec_udt_struct_v0::*;
4486mod sc_spec_udt_union_case_void_v0;
4487#[allow(unused_imports)]
4488pub use sc_spec_udt_union_case_void_v0::*;
4489mod sc_spec_udt_union_case_tuple_v0;
4490#[allow(unused_imports)]
4491pub use sc_spec_udt_union_case_tuple_v0::*;
4492mod sc_spec_udt_union_case_v0_kind;
4493#[allow(unused_imports)]
4494pub use sc_spec_udt_union_case_v0_kind::*;
4495mod sc_spec_udt_union_case_v0;
4496#[allow(unused_imports)]
4497pub use sc_spec_udt_union_case_v0::*;
4498mod sc_spec_udt_union_v0;
4499#[allow(unused_imports)]
4500pub use sc_spec_udt_union_v0::*;
4501mod sc_spec_udt_enum_case_v0;
4502#[allow(unused_imports)]
4503pub use sc_spec_udt_enum_case_v0::*;
4504mod sc_spec_udt_enum_v0;
4505#[allow(unused_imports)]
4506pub use sc_spec_udt_enum_v0::*;
4507mod sc_spec_udt_error_enum_case_v0;
4508#[allow(unused_imports)]
4509pub use sc_spec_udt_error_enum_case_v0::*;
4510mod sc_spec_udt_error_enum_v0;
4511#[allow(unused_imports)]
4512pub use sc_spec_udt_error_enum_v0::*;
4513mod sc_spec_function_input_v0;
4514#[allow(unused_imports)]
4515pub use sc_spec_function_input_v0::*;
4516mod sc_spec_function_v0;
4517#[allow(unused_imports)]
4518pub use sc_spec_function_v0::*;
4519mod sc_spec_event_param_location_v0;
4520#[allow(unused_imports)]
4521pub use sc_spec_event_param_location_v0::*;
4522mod sc_spec_event_param_v0;
4523#[allow(unused_imports)]
4524pub use sc_spec_event_param_v0::*;
4525mod sc_spec_event_data_format;
4526#[allow(unused_imports)]
4527pub use sc_spec_event_data_format::*;
4528mod sc_spec_event_v0;
4529#[allow(unused_imports)]
4530pub use sc_spec_event_v0::*;
4531mod sc_spec_entry_kind;
4532#[allow(unused_imports)]
4533pub use sc_spec_entry_kind::*;
4534mod sc_spec_entry;
4535#[allow(unused_imports)]
4536pub use sc_spec_entry::*;
4537mod sc_bytes;
4538#[allow(unused_imports)]
4539pub use sc_bytes::*;
4540mod sc_string;
4541#[allow(unused_imports)]
4542pub use sc_string::*;
4543mod scsymbol_limit;
4544#[allow(unused_imports)]
4545pub use scsymbol_limit::*;
4546mod sc_symbol;
4547#[allow(unused_imports)]
4548pub use sc_symbol::*;
4549mod sc_val_type;
4550#[allow(unused_imports)]
4551pub use sc_val_type::*;
4552mod sc_error_type;
4553#[allow(unused_imports)]
4554pub use sc_error_type::*;
4555mod sc_error_code;
4556#[allow(unused_imports)]
4557pub use sc_error_code::*;
4558mod sc_error;
4559#[allow(unused_imports)]
4560pub use sc_error::*;
4561mod u_int128_parts;
4562#[allow(unused_imports)]
4563pub use u_int128_parts::*;
4564mod int128_parts;
4565#[allow(unused_imports)]
4566pub use int128_parts::*;
4567mod u_int256_parts;
4568#[allow(unused_imports)]
4569pub use u_int256_parts::*;
4570mod int256_parts;
4571#[allow(unused_imports)]
4572pub use int256_parts::*;
4573mod contract_executable_type;
4574#[allow(unused_imports)]
4575pub use contract_executable_type::*;
4576mod sc_address_type;
4577#[allow(unused_imports)]
4578pub use sc_address_type::*;
4579mod muxed_ed25519_account;
4580#[allow(unused_imports)]
4581pub use muxed_ed25519_account::*;
4582mod muxed_contract;
4583#[allow(unused_imports)]
4584pub use muxed_contract::*;
4585mod sc_address;
4586#[allow(unused_imports)]
4587pub use sc_address::*;
4588mod contract_executable_external_ref;
4589#[allow(unused_imports)]
4590pub use contract_executable_external_ref::*;
4591mod contract_executable;
4592#[allow(unused_imports)]
4593pub use contract_executable::*;
4594mod sc_vec;
4595#[allow(unused_imports)]
4596pub use sc_vec::*;
4597mod sc_map;
4598#[allow(unused_imports)]
4599pub use sc_map::*;
4600mod sc_nonce_key;
4601#[allow(unused_imports)]
4602pub use sc_nonce_key::*;
4603mod sc_contract_instance;
4604#[allow(unused_imports)]
4605pub use sc_contract_instance::*;
4606mod sc_val;
4607#[allow(unused_imports)]
4608pub use sc_val::*;
4609mod sc_map_entry;
4610#[allow(unused_imports)]
4611pub use sc_map_entry::*;
4612mod ledger_close_meta_batch;
4613#[allow(unused_imports)]
4614pub use ledger_close_meta_batch::*;
4615mod stored_transaction_set;
4616#[allow(unused_imports)]
4617pub use stored_transaction_set::*;
4618mod stored_debug_transaction_set;
4619#[allow(unused_imports)]
4620pub use stored_debug_transaction_set::*;
4621mod persisted_scp_state_v0;
4622#[allow(unused_imports)]
4623pub use persisted_scp_state_v0::*;
4624mod persisted_scp_state_v1;
4625#[allow(unused_imports)]
4626pub use persisted_scp_state_v1::*;
4627mod persisted_scp_state;
4628#[allow(unused_imports)]
4629pub use persisted_scp_state::*;
4630mod thresholds;
4631#[allow(unused_imports)]
4632pub use thresholds::*;
4633mod string32;
4634#[allow(unused_imports)]
4635pub use string32::*;
4636mod string64;
4637#[allow(unused_imports)]
4638pub use string64::*;
4639mod sequence_number;
4640#[allow(unused_imports)]
4641pub use sequence_number::*;
4642mod data_value;
4643#[allow(unused_imports)]
4644pub use data_value::*;
4645mod asset_code4;
4646#[allow(unused_imports)]
4647pub use asset_code4::*;
4648mod asset_code12;
4649#[allow(unused_imports)]
4650pub use asset_code12::*;
4651mod asset_type;
4652#[allow(unused_imports)]
4653pub use asset_type::*;
4654mod asset_code;
4655#[allow(unused_imports)]
4656pub use asset_code::*;
4657mod alpha_num4;
4658#[allow(unused_imports)]
4659pub use alpha_num4::*;
4660mod alpha_num12;
4661#[allow(unused_imports)]
4662pub use alpha_num12::*;
4663mod asset;
4664#[allow(unused_imports)]
4665pub use asset::*;
4666mod price;
4667#[allow(unused_imports)]
4668pub use price::*;
4669mod liabilities;
4670#[allow(unused_imports)]
4671pub use liabilities::*;
4672mod threshold_indexes;
4673#[allow(unused_imports)]
4674pub use threshold_indexes::*;
4675mod ledger_entry_type;
4676#[allow(unused_imports)]
4677pub use ledger_entry_type::*;
4678mod signer;
4679#[allow(unused_imports)]
4680pub use signer::*;
4681mod account_flags;
4682#[allow(unused_imports)]
4683pub use account_flags::*;
4684mod mask_account_flags;
4685#[allow(unused_imports)]
4686pub use mask_account_flags::*;
4687mod mask_account_flags_v17;
4688#[allow(unused_imports)]
4689pub use mask_account_flags_v17::*;
4690mod max_signers;
4691#[allow(unused_imports)]
4692pub use max_signers::*;
4693mod sponsorship_descriptor;
4694#[allow(unused_imports)]
4695pub use sponsorship_descriptor::*;
4696mod account_entry_extension_v3;
4697#[allow(unused_imports)]
4698pub use account_entry_extension_v3::*;
4699mod account_entry_extension_v2_ext;
4700#[allow(unused_imports)]
4701pub use account_entry_extension_v2_ext::*;
4702mod account_entry_extension_v2;
4703#[allow(unused_imports)]
4704pub use account_entry_extension_v2::*;
4705mod account_entry_extension_v1_ext;
4706#[allow(unused_imports)]
4707pub use account_entry_extension_v1_ext::*;
4708mod account_entry_extension_v1;
4709#[allow(unused_imports)]
4710pub use account_entry_extension_v1::*;
4711mod account_entry_ext;
4712#[allow(unused_imports)]
4713pub use account_entry_ext::*;
4714mod account_entry;
4715#[allow(unused_imports)]
4716pub use account_entry::*;
4717mod trust_line_flags;
4718#[allow(unused_imports)]
4719pub use trust_line_flags::*;
4720mod mask_trustline_flags;
4721#[allow(unused_imports)]
4722pub use mask_trustline_flags::*;
4723mod mask_trustline_flags_v13;
4724#[allow(unused_imports)]
4725pub use mask_trustline_flags_v13::*;
4726mod mask_trustline_flags_v17;
4727#[allow(unused_imports)]
4728pub use mask_trustline_flags_v17::*;
4729mod liquidity_pool_type;
4730#[allow(unused_imports)]
4731pub use liquidity_pool_type::*;
4732mod trust_line_asset;
4733#[allow(unused_imports)]
4734pub use trust_line_asset::*;
4735mod trust_line_entry_extension_v2_ext;
4736#[allow(unused_imports)]
4737pub use trust_line_entry_extension_v2_ext::*;
4738mod trust_line_entry_extension_v2;
4739#[allow(unused_imports)]
4740pub use trust_line_entry_extension_v2::*;
4741mod trust_line_entry_v1_ext;
4742#[allow(unused_imports)]
4743pub use trust_line_entry_v1_ext::*;
4744mod trust_line_entry_v1;
4745#[allow(unused_imports)]
4746pub use trust_line_entry_v1::*;
4747mod trust_line_entry_ext;
4748#[allow(unused_imports)]
4749pub use trust_line_entry_ext::*;
4750mod trust_line_entry;
4751#[allow(unused_imports)]
4752pub use trust_line_entry::*;
4753mod offer_entry_flags;
4754#[allow(unused_imports)]
4755pub use offer_entry_flags::*;
4756mod mask_offerentry_flags;
4757#[allow(unused_imports)]
4758pub use mask_offerentry_flags::*;
4759mod offer_entry_ext;
4760#[allow(unused_imports)]
4761pub use offer_entry_ext::*;
4762mod offer_entry;
4763#[allow(unused_imports)]
4764pub use offer_entry::*;
4765mod data_entry_ext;
4766#[allow(unused_imports)]
4767pub use data_entry_ext::*;
4768mod data_entry;
4769#[allow(unused_imports)]
4770pub use data_entry::*;
4771mod claim_predicate_type;
4772#[allow(unused_imports)]
4773pub use claim_predicate_type::*;
4774mod claim_predicate;
4775#[allow(unused_imports)]
4776pub use claim_predicate::*;
4777mod claimant_type;
4778#[allow(unused_imports)]
4779pub use claimant_type::*;
4780mod claimant_v0;
4781#[allow(unused_imports)]
4782pub use claimant_v0::*;
4783mod claimant;
4784#[allow(unused_imports)]
4785pub use claimant::*;
4786mod claimable_balance_flags;
4787#[allow(unused_imports)]
4788pub use claimable_balance_flags::*;
4789mod mask_claimable_balance_flags;
4790#[allow(unused_imports)]
4791pub use mask_claimable_balance_flags::*;
4792mod claimable_balance_entry_extension_v1_ext;
4793#[allow(unused_imports)]
4794pub use claimable_balance_entry_extension_v1_ext::*;
4795mod claimable_balance_entry_extension_v1;
4796#[allow(unused_imports)]
4797pub use claimable_balance_entry_extension_v1::*;
4798mod claimable_balance_entry_ext;
4799#[allow(unused_imports)]
4800pub use claimable_balance_entry_ext::*;
4801mod claimable_balance_entry;
4802#[allow(unused_imports)]
4803pub use claimable_balance_entry::*;
4804mod liquidity_pool_constant_product_parameters;
4805#[allow(unused_imports)]
4806pub use liquidity_pool_constant_product_parameters::*;
4807mod liquidity_pool_entry_constant_product;
4808#[allow(unused_imports)]
4809pub use liquidity_pool_entry_constant_product::*;
4810mod liquidity_pool_entry_body;
4811#[allow(unused_imports)]
4812pub use liquidity_pool_entry_body::*;
4813mod liquidity_pool_entry;
4814#[allow(unused_imports)]
4815pub use liquidity_pool_entry::*;
4816mod contract_data_durability;
4817#[allow(unused_imports)]
4818pub use contract_data_durability::*;
4819mod contract_data_entry;
4820#[allow(unused_imports)]
4821pub use contract_data_entry::*;
4822mod contract_code_cost_inputs;
4823#[allow(unused_imports)]
4824pub use contract_code_cost_inputs::*;
4825mod contract_code_entry_v1;
4826#[allow(unused_imports)]
4827pub use contract_code_entry_v1::*;
4828mod contract_code_entry_ext;
4829#[allow(unused_imports)]
4830pub use contract_code_entry_ext::*;
4831mod contract_code_entry;
4832#[allow(unused_imports)]
4833pub use contract_code_entry::*;
4834mod ttl_entry;
4835#[allow(unused_imports)]
4836pub use ttl_entry::*;
4837mod ledger_entry_extension_v1_ext;
4838#[allow(unused_imports)]
4839pub use ledger_entry_extension_v1_ext::*;
4840mod ledger_entry_extension_v1;
4841#[allow(unused_imports)]
4842pub use ledger_entry_extension_v1::*;
4843mod ledger_entry_data;
4844#[allow(unused_imports)]
4845pub use ledger_entry_data::*;
4846mod ledger_entry_ext;
4847#[allow(unused_imports)]
4848pub use ledger_entry_ext::*;
4849mod ledger_entry;
4850#[allow(unused_imports)]
4851pub use ledger_entry::*;
4852mod ledger_key_account;
4853#[allow(unused_imports)]
4854pub use ledger_key_account::*;
4855mod ledger_key_trust_line;
4856#[allow(unused_imports)]
4857pub use ledger_key_trust_line::*;
4858mod ledger_key_offer;
4859#[allow(unused_imports)]
4860pub use ledger_key_offer::*;
4861mod ledger_key_data;
4862#[allow(unused_imports)]
4863pub use ledger_key_data::*;
4864mod ledger_key_claimable_balance;
4865#[allow(unused_imports)]
4866pub use ledger_key_claimable_balance::*;
4867mod ledger_key_liquidity_pool;
4868#[allow(unused_imports)]
4869pub use ledger_key_liquidity_pool::*;
4870mod ledger_key_contract_data;
4871#[allow(unused_imports)]
4872pub use ledger_key_contract_data::*;
4873mod ledger_key_contract_code;
4874#[allow(unused_imports)]
4875pub use ledger_key_contract_code::*;
4876mod ledger_key_config_setting;
4877#[allow(unused_imports)]
4878pub use ledger_key_config_setting::*;
4879mod ledger_key_ttl;
4880#[allow(unused_imports)]
4881pub use ledger_key_ttl::*;
4882mod ledger_key;
4883#[allow(unused_imports)]
4884pub use ledger_key::*;
4885mod envelope_type;
4886#[allow(unused_imports)]
4887pub use envelope_type::*;
4888mod bucket_list_type;
4889#[allow(unused_imports)]
4890pub use bucket_list_type::*;
4891mod bucket_entry_type;
4892#[allow(unused_imports)]
4893pub use bucket_entry_type::*;
4894mod hot_archive_bucket_entry_type;
4895#[allow(unused_imports)]
4896pub use hot_archive_bucket_entry_type::*;
4897mod bucket_metadata_ext;
4898#[allow(unused_imports)]
4899pub use bucket_metadata_ext::*;
4900mod bucket_metadata;
4901#[allow(unused_imports)]
4902pub use bucket_metadata::*;
4903mod bucket_entry;
4904#[allow(unused_imports)]
4905pub use bucket_entry::*;
4906mod hot_archive_bucket_entry;
4907#[allow(unused_imports)]
4908pub use hot_archive_bucket_entry::*;
4909mod upgrade_type;
4910#[allow(unused_imports)]
4911pub use upgrade_type::*;
4912mod stellar_value_type;
4913#[allow(unused_imports)]
4914pub use stellar_value_type::*;
4915mod ledger_close_value_signature;
4916#[allow(unused_imports)]
4917pub use ledger_close_value_signature::*;
4918mod stellar_value_proposed_value;
4919#[allow(unused_imports)]
4920pub use stellar_value_proposed_value::*;
4921mod stellar_value_signed_ms_value;
4922#[allow(unused_imports)]
4923pub use stellar_value_signed_ms_value::*;
4924mod stellar_value_proposed_ms_value;
4925#[allow(unused_imports)]
4926pub use stellar_value_proposed_ms_value::*;
4927mod stellar_value_ext;
4928#[allow(unused_imports)]
4929pub use stellar_value_ext::*;
4930mod stellar_value;
4931#[allow(unused_imports)]
4932pub use stellar_value::*;
4933mod mask_ledger_header_flags;
4934#[allow(unused_imports)]
4935pub use mask_ledger_header_flags::*;
4936mod ledger_header_flags;
4937#[allow(unused_imports)]
4938pub use ledger_header_flags::*;
4939mod ledger_header_extension_v1_ext;
4940#[allow(unused_imports)]
4941pub use ledger_header_extension_v1_ext::*;
4942mod ledger_header_extension_v1;
4943#[allow(unused_imports)]
4944pub use ledger_header_extension_v1::*;
4945mod ledger_header_ext;
4946#[allow(unused_imports)]
4947pub use ledger_header_ext::*;
4948mod ledger_header;
4949#[allow(unused_imports)]
4950pub use ledger_header::*;
4951mod ledger_upgrade_type;
4952#[allow(unused_imports)]
4953pub use ledger_upgrade_type::*;
4954mod config_upgrade_set_key;
4955#[allow(unused_imports)]
4956pub use config_upgrade_set_key::*;
4957mod ledger_upgrade;
4958#[allow(unused_imports)]
4959pub use ledger_upgrade::*;
4960mod config_upgrade_set;
4961#[allow(unused_imports)]
4962pub use config_upgrade_set::*;
4963mod tx_set_component_type;
4964#[allow(unused_imports)]
4965pub use tx_set_component_type::*;
4966mod dependent_tx_cluster;
4967#[allow(unused_imports)]
4968pub use dependent_tx_cluster::*;
4969mod parallel_tx_execution_stage;
4970#[allow(unused_imports)]
4971pub use parallel_tx_execution_stage::*;
4972mod parallel_txs_component;
4973#[allow(unused_imports)]
4974pub use parallel_txs_component::*;
4975mod tx_set_component_txs_maybe_discounted_fee;
4976#[allow(unused_imports)]
4977pub use tx_set_component_txs_maybe_discounted_fee::*;
4978mod tx_set_component;
4979#[allow(unused_imports)]
4980pub use tx_set_component::*;
4981mod transaction_phase;
4982#[allow(unused_imports)]
4983pub use transaction_phase::*;
4984mod transaction_set;
4985#[allow(unused_imports)]
4986pub use transaction_set::*;
4987mod transaction_set_v1;
4988#[allow(unused_imports)]
4989pub use transaction_set_v1::*;
4990mod generalized_transaction_set;
4991#[allow(unused_imports)]
4992pub use generalized_transaction_set::*;
4993mod transaction_result_pair;
4994#[allow(unused_imports)]
4995pub use transaction_result_pair::*;
4996mod transaction_result_set;
4997#[allow(unused_imports)]
4998pub use transaction_result_set::*;
4999mod transaction_history_entry_ext;
5000#[allow(unused_imports)]
5001pub use transaction_history_entry_ext::*;
5002mod transaction_history_entry;
5003#[allow(unused_imports)]
5004pub use transaction_history_entry::*;
5005mod transaction_history_result_entry_ext;
5006#[allow(unused_imports)]
5007pub use transaction_history_result_entry_ext::*;
5008mod transaction_history_result_entry;
5009#[allow(unused_imports)]
5010pub use transaction_history_result_entry::*;
5011mod ledger_header_history_entry_ext;
5012#[allow(unused_imports)]
5013pub use ledger_header_history_entry_ext::*;
5014mod ledger_header_history_entry;
5015#[allow(unused_imports)]
5016pub use ledger_header_history_entry::*;
5017mod ledger_scp_messages;
5018#[allow(unused_imports)]
5019pub use ledger_scp_messages::*;
5020mod scp_history_entry_v0;
5021#[allow(unused_imports)]
5022pub use scp_history_entry_v0::*;
5023mod scp_history_entry;
5024#[allow(unused_imports)]
5025pub use scp_history_entry::*;
5026mod ledger_entry_change_type;
5027#[allow(unused_imports)]
5028pub use ledger_entry_change_type::*;
5029mod ledger_entry_change;
5030#[allow(unused_imports)]
5031pub use ledger_entry_change::*;
5032mod ledger_entry_changes;
5033#[allow(unused_imports)]
5034pub use ledger_entry_changes::*;
5035mod operation_meta;
5036#[allow(unused_imports)]
5037pub use operation_meta::*;
5038mod transaction_meta_v1;
5039#[allow(unused_imports)]
5040pub use transaction_meta_v1::*;
5041mod transaction_meta_v2;
5042#[allow(unused_imports)]
5043pub use transaction_meta_v2::*;
5044mod contract_event_type;
5045#[allow(unused_imports)]
5046pub use contract_event_type::*;
5047mod contract_event_v0;
5048#[allow(unused_imports)]
5049pub use contract_event_v0::*;
5050mod contract_event_body;
5051#[allow(unused_imports)]
5052pub use contract_event_body::*;
5053mod contract_event;
5054#[allow(unused_imports)]
5055pub use contract_event::*;
5056mod diagnostic_event;
5057#[allow(unused_imports)]
5058pub use diagnostic_event::*;
5059mod soroban_transaction_meta_ext_v1;
5060#[allow(unused_imports)]
5061pub use soroban_transaction_meta_ext_v1::*;
5062mod soroban_transaction_meta_ext;
5063#[allow(unused_imports)]
5064pub use soroban_transaction_meta_ext::*;
5065mod soroban_transaction_meta;
5066#[allow(unused_imports)]
5067pub use soroban_transaction_meta::*;
5068mod transaction_meta_v3;
5069#[allow(unused_imports)]
5070pub use transaction_meta_v3::*;
5071mod operation_meta_v2;
5072#[allow(unused_imports)]
5073pub use operation_meta_v2::*;
5074mod soroban_transaction_meta_v2;
5075#[allow(unused_imports)]
5076pub use soroban_transaction_meta_v2::*;
5077mod transaction_event_stage;
5078#[allow(unused_imports)]
5079pub use transaction_event_stage::*;
5080mod transaction_event;
5081#[allow(unused_imports)]
5082pub use transaction_event::*;
5083mod transaction_meta_v4;
5084#[allow(unused_imports)]
5085pub use transaction_meta_v4::*;
5086mod invoke_host_function_success_pre_image;
5087#[allow(unused_imports)]
5088pub use invoke_host_function_success_pre_image::*;
5089mod transaction_meta;
5090#[allow(unused_imports)]
5091pub use transaction_meta::*;
5092mod transaction_result_meta;
5093#[allow(unused_imports)]
5094pub use transaction_result_meta::*;
5095mod transaction_result_meta_v1;
5096#[allow(unused_imports)]
5097pub use transaction_result_meta_v1::*;
5098mod upgrade_entry_meta;
5099#[allow(unused_imports)]
5100pub use upgrade_entry_meta::*;
5101mod ledger_close_meta_v0;
5102#[allow(unused_imports)]
5103pub use ledger_close_meta_v0::*;
5104mod ledger_close_meta_ext_v1;
5105#[allow(unused_imports)]
5106pub use ledger_close_meta_ext_v1::*;
5107mod ledger_close_meta_ext;
5108#[allow(unused_imports)]
5109pub use ledger_close_meta_ext::*;
5110mod ledger_close_meta_v1;
5111#[allow(unused_imports)]
5112pub use ledger_close_meta_v1::*;
5113mod ledger_close_meta_v2;
5114#[allow(unused_imports)]
5115pub use ledger_close_meta_v2::*;
5116mod ledger_close_meta;
5117#[allow(unused_imports)]
5118pub use ledger_close_meta::*;
5119mod error_code;
5120#[allow(unused_imports)]
5121pub use error_code::*;
5122mod s_error;
5123#[allow(unused_imports)]
5124pub use s_error::*;
5125mod send_more;
5126#[allow(unused_imports)]
5127pub use send_more::*;
5128mod send_more_extended;
5129#[allow(unused_imports)]
5130pub use send_more_extended::*;
5131mod auth_cert;
5132#[allow(unused_imports)]
5133pub use auth_cert::*;
5134mod hello;
5135#[allow(unused_imports)]
5136pub use hello::*;
5137mod auth_msg_flag_flow_control_bytes_requested;
5138#[allow(unused_imports)]
5139pub use auth_msg_flag_flow_control_bytes_requested::*;
5140mod auth;
5141#[allow(unused_imports)]
5142pub use auth::*;
5143mod ip_addr_type;
5144#[allow(unused_imports)]
5145pub use ip_addr_type::*;
5146mod peer_address_ip;
5147#[allow(unused_imports)]
5148pub use peer_address_ip::*;
5149mod peer_address;
5150#[allow(unused_imports)]
5151pub use peer_address::*;
5152mod message_type;
5153#[allow(unused_imports)]
5154pub use message_type::*;
5155mod dont_have;
5156#[allow(unused_imports)]
5157pub use dont_have::*;
5158mod survey_message_command_type;
5159#[allow(unused_imports)]
5160pub use survey_message_command_type::*;
5161mod survey_message_response_type;
5162#[allow(unused_imports)]
5163pub use survey_message_response_type::*;
5164mod time_sliced_survey_start_collecting_message;
5165#[allow(unused_imports)]
5166pub use time_sliced_survey_start_collecting_message::*;
5167mod signed_time_sliced_survey_start_collecting_message;
5168#[allow(unused_imports)]
5169pub use signed_time_sliced_survey_start_collecting_message::*;
5170mod time_sliced_survey_stop_collecting_message;
5171#[allow(unused_imports)]
5172pub use time_sliced_survey_stop_collecting_message::*;
5173mod signed_time_sliced_survey_stop_collecting_message;
5174#[allow(unused_imports)]
5175pub use signed_time_sliced_survey_stop_collecting_message::*;
5176mod survey_request_message;
5177#[allow(unused_imports)]
5178pub use survey_request_message::*;
5179mod time_sliced_survey_request_message;
5180#[allow(unused_imports)]
5181pub use time_sliced_survey_request_message::*;
5182mod signed_time_sliced_survey_request_message;
5183#[allow(unused_imports)]
5184pub use signed_time_sliced_survey_request_message::*;
5185mod encrypted_body;
5186#[allow(unused_imports)]
5187pub use encrypted_body::*;
5188mod survey_response_message;
5189#[allow(unused_imports)]
5190pub use survey_response_message::*;
5191mod time_sliced_survey_response_message;
5192#[allow(unused_imports)]
5193pub use time_sliced_survey_response_message::*;
5194mod signed_time_sliced_survey_response_message;
5195#[allow(unused_imports)]
5196pub use signed_time_sliced_survey_response_message::*;
5197mod peer_stats;
5198#[allow(unused_imports)]
5199pub use peer_stats::*;
5200mod time_sliced_node_data;
5201#[allow(unused_imports)]
5202pub use time_sliced_node_data::*;
5203mod time_sliced_peer_data;
5204#[allow(unused_imports)]
5205pub use time_sliced_peer_data::*;
5206mod time_sliced_peer_data_list;
5207#[allow(unused_imports)]
5208pub use time_sliced_peer_data_list::*;
5209mod topology_response_body_v2;
5210#[allow(unused_imports)]
5211pub use topology_response_body_v2::*;
5212mod survey_response_body;
5213#[allow(unused_imports)]
5214pub use survey_response_body::*;
5215mod tx_advert_vector_max_size;
5216#[allow(unused_imports)]
5217pub use tx_advert_vector_max_size::*;
5218mod tx_advert_vector;
5219#[allow(unused_imports)]
5220pub use tx_advert_vector::*;
5221mod flood_advert;
5222#[allow(unused_imports)]
5223pub use flood_advert::*;
5224mod tx_demand_vector_max_size;
5225#[allow(unused_imports)]
5226pub use tx_demand_vector_max_size::*;
5227mod tx_demand_vector;
5228#[allow(unused_imports)]
5229pub use tx_demand_vector::*;
5230mod flood_demand;
5231#[allow(unused_imports)]
5232pub use flood_demand::*;
5233mod stellar_message;
5234#[allow(unused_imports)]
5235pub use stellar_message::*;
5236mod authenticated_message_v0;
5237#[allow(unused_imports)]
5238pub use authenticated_message_v0::*;
5239mod authenticated_message;
5240#[allow(unused_imports)]
5241pub use authenticated_message::*;
5242mod max_ops_per_tx;
5243#[allow(unused_imports)]
5244pub use max_ops_per_tx::*;
5245mod liquidity_pool_parameters;
5246#[allow(unused_imports)]
5247pub use liquidity_pool_parameters::*;
5248mod muxed_account_med25519;
5249#[allow(unused_imports)]
5250pub use muxed_account_med25519::*;
5251mod muxed_account;
5252#[allow(unused_imports)]
5253pub use muxed_account::*;
5254mod decorated_signature;
5255#[allow(unused_imports)]
5256pub use decorated_signature::*;
5257mod operation_type;
5258#[allow(unused_imports)]
5259pub use operation_type::*;
5260mod create_account_op;
5261#[allow(unused_imports)]
5262pub use create_account_op::*;
5263mod payment_op;
5264#[allow(unused_imports)]
5265pub use payment_op::*;
5266mod path_payment_strict_receive_op;
5267#[allow(unused_imports)]
5268pub use path_payment_strict_receive_op::*;
5269mod path_payment_strict_send_op;
5270#[allow(unused_imports)]
5271pub use path_payment_strict_send_op::*;
5272mod manage_sell_offer_op;
5273#[allow(unused_imports)]
5274pub use manage_sell_offer_op::*;
5275mod manage_buy_offer_op;
5276#[allow(unused_imports)]
5277pub use manage_buy_offer_op::*;
5278mod create_passive_sell_offer_op;
5279#[allow(unused_imports)]
5280pub use create_passive_sell_offer_op::*;
5281mod set_options_op;
5282#[allow(unused_imports)]
5283pub use set_options_op::*;
5284mod change_trust_asset;
5285#[allow(unused_imports)]
5286pub use change_trust_asset::*;
5287mod change_trust_op;
5288#[allow(unused_imports)]
5289pub use change_trust_op::*;
5290mod allow_trust_op;
5291#[allow(unused_imports)]
5292pub use allow_trust_op::*;
5293mod manage_data_op;
5294#[allow(unused_imports)]
5295pub use manage_data_op::*;
5296mod bump_sequence_op;
5297#[allow(unused_imports)]
5298pub use bump_sequence_op::*;
5299mod create_claimable_balance_op;
5300#[allow(unused_imports)]
5301pub use create_claimable_balance_op::*;
5302mod claim_claimable_balance_op;
5303#[allow(unused_imports)]
5304pub use claim_claimable_balance_op::*;
5305mod begin_sponsoring_future_reserves_op;
5306#[allow(unused_imports)]
5307pub use begin_sponsoring_future_reserves_op::*;
5308mod revoke_sponsorship_type;
5309#[allow(unused_imports)]
5310pub use revoke_sponsorship_type::*;
5311mod revoke_sponsorship_op_signer;
5312#[allow(unused_imports)]
5313pub use revoke_sponsorship_op_signer::*;
5314mod revoke_sponsorship_op;
5315#[allow(unused_imports)]
5316pub use revoke_sponsorship_op::*;
5317mod clawback_op;
5318#[allow(unused_imports)]
5319pub use clawback_op::*;
5320mod clawback_claimable_balance_op;
5321#[allow(unused_imports)]
5322pub use clawback_claimable_balance_op::*;
5323mod set_trust_line_flags_op;
5324#[allow(unused_imports)]
5325pub use set_trust_line_flags_op::*;
5326mod liquidity_pool_fee_v18;
5327#[allow(unused_imports)]
5328pub use liquidity_pool_fee_v18::*;
5329mod liquidity_pool_deposit_op;
5330#[allow(unused_imports)]
5331pub use liquidity_pool_deposit_op::*;
5332mod liquidity_pool_withdraw_op;
5333#[allow(unused_imports)]
5334pub use liquidity_pool_withdraw_op::*;
5335mod host_function_type;
5336#[allow(unused_imports)]
5337pub use host_function_type::*;
5338mod contract_id_preimage_type;
5339#[allow(unused_imports)]
5340pub use contract_id_preimage_type::*;
5341mod contract_id_preimage_from_address;
5342#[allow(unused_imports)]
5343pub use contract_id_preimage_from_address::*;
5344mod contract_id_preimage;
5345#[allow(unused_imports)]
5346pub use contract_id_preimage::*;
5347mod create_contract_args;
5348#[allow(unused_imports)]
5349pub use create_contract_args::*;
5350mod create_contract_args_v2;
5351#[allow(unused_imports)]
5352pub use create_contract_args_v2::*;
5353mod invoke_contract_args;
5354#[allow(unused_imports)]
5355pub use invoke_contract_args::*;
5356mod host_function;
5357#[allow(unused_imports)]
5358pub use host_function::*;
5359mod soroban_authorized_function_type;
5360#[allow(unused_imports)]
5361pub use soroban_authorized_function_type::*;
5362mod soroban_authorized_function;
5363#[allow(unused_imports)]
5364pub use soroban_authorized_function::*;
5365mod soroban_authorized_invocation;
5366#[allow(unused_imports)]
5367pub use soroban_authorized_invocation::*;
5368mod soroban_address_credentials;
5369#[allow(unused_imports)]
5370pub use soroban_address_credentials::*;
5371mod soroban_delegate_signature;
5372#[allow(unused_imports)]
5373pub use soroban_delegate_signature::*;
5374mod soroban_address_credentials_with_delegates;
5375#[allow(unused_imports)]
5376pub use soroban_address_credentials_with_delegates::*;
5377mod soroban_credentials_type;
5378#[allow(unused_imports)]
5379pub use soroban_credentials_type::*;
5380mod soroban_credentials;
5381#[allow(unused_imports)]
5382pub use soroban_credentials::*;
5383mod soroban_authorization_entry;
5384#[allow(unused_imports)]
5385pub use soroban_authorization_entry::*;
5386mod soroban_authorization_entries;
5387#[allow(unused_imports)]
5388pub use soroban_authorization_entries::*;
5389mod invoke_host_function_op;
5390#[allow(unused_imports)]
5391pub use invoke_host_function_op::*;
5392mod extend_footprint_ttl_op;
5393#[allow(unused_imports)]
5394pub use extend_footprint_ttl_op::*;
5395mod restore_footprint_op;
5396#[allow(unused_imports)]
5397pub use restore_footprint_op::*;
5398mod operation_body;
5399#[allow(unused_imports)]
5400pub use operation_body::*;
5401mod operation;
5402#[allow(unused_imports)]
5403pub use operation::*;
5404mod hash_id_preimage_operation_id;
5405#[allow(unused_imports)]
5406pub use hash_id_preimage_operation_id::*;
5407mod hash_id_preimage_revoke_id;
5408#[allow(unused_imports)]
5409pub use hash_id_preimage_revoke_id::*;
5410mod hash_id_preimage_contract_id;
5411#[allow(unused_imports)]
5412pub use hash_id_preimage_contract_id::*;
5413mod hash_id_preimage_soroban_authorization;
5414#[allow(unused_imports)]
5415pub use hash_id_preimage_soroban_authorization::*;
5416mod hash_id_preimage_soroban_authorization_with_address;
5417#[allow(unused_imports)]
5418pub use hash_id_preimage_soroban_authorization_with_address::*;
5419mod hash_id_preimage;
5420#[allow(unused_imports)]
5421pub use hash_id_preimage::*;
5422mod memo_type;
5423#[allow(unused_imports)]
5424pub use memo_type::*;
5425mod memo;
5426#[allow(unused_imports)]
5427pub use memo::*;
5428mod time_bounds;
5429#[allow(unused_imports)]
5430pub use time_bounds::*;
5431mod ledger_bounds;
5432#[allow(unused_imports)]
5433pub use ledger_bounds::*;
5434mod preconditions_v2;
5435#[allow(unused_imports)]
5436pub use preconditions_v2::*;
5437mod precondition_type;
5438#[allow(unused_imports)]
5439pub use precondition_type::*;
5440mod preconditions;
5441#[allow(unused_imports)]
5442pub use preconditions::*;
5443mod ledger_footprint;
5444#[allow(unused_imports)]
5445pub use ledger_footprint::*;
5446mod soroban_resources;
5447#[allow(unused_imports)]
5448pub use soroban_resources::*;
5449mod soroban_resources_ext_v0;
5450#[allow(unused_imports)]
5451pub use soroban_resources_ext_v0::*;
5452mod soroban_transaction_data_ext;
5453#[allow(unused_imports)]
5454pub use soroban_transaction_data_ext::*;
5455mod soroban_transaction_data;
5456#[allow(unused_imports)]
5457pub use soroban_transaction_data::*;
5458mod transaction_v0_ext;
5459#[allow(unused_imports)]
5460pub use transaction_v0_ext::*;
5461mod transaction_v0;
5462#[allow(unused_imports)]
5463pub use transaction_v0::*;
5464mod transaction_v0_envelope;
5465#[allow(unused_imports)]
5466pub use transaction_v0_envelope::*;
5467mod transaction_ext;
5468#[allow(unused_imports)]
5469pub use transaction_ext::*;
5470mod transaction;
5471#[allow(unused_imports)]
5472pub use transaction::*;
5473mod transaction_v1_envelope;
5474#[allow(unused_imports)]
5475pub use transaction_v1_envelope::*;
5476mod fee_bump_transaction_inner_tx;
5477#[allow(unused_imports)]
5478pub use fee_bump_transaction_inner_tx::*;
5479mod fee_bump_transaction_ext;
5480#[allow(unused_imports)]
5481pub use fee_bump_transaction_ext::*;
5482mod fee_bump_transaction;
5483#[allow(unused_imports)]
5484pub use fee_bump_transaction::*;
5485mod fee_bump_transaction_envelope;
5486#[allow(unused_imports)]
5487pub use fee_bump_transaction_envelope::*;
5488mod transaction_envelope;
5489#[allow(unused_imports)]
5490pub use transaction_envelope::*;
5491mod transaction_signature_payload_tagged_transaction;
5492#[allow(unused_imports)]
5493pub use transaction_signature_payload_tagged_transaction::*;
5494mod transaction_signature_payload;
5495#[allow(unused_imports)]
5496pub use transaction_signature_payload::*;
5497mod claim_atom_type;
5498#[allow(unused_imports)]
5499pub use claim_atom_type::*;
5500mod claim_offer_atom_v0;
5501#[allow(unused_imports)]
5502pub use claim_offer_atom_v0::*;
5503mod claim_offer_atom;
5504#[allow(unused_imports)]
5505pub use claim_offer_atom::*;
5506mod claim_liquidity_atom;
5507#[allow(unused_imports)]
5508pub use claim_liquidity_atom::*;
5509mod claim_atom;
5510#[allow(unused_imports)]
5511pub use claim_atom::*;
5512mod create_account_result_code;
5513#[allow(unused_imports)]
5514pub use create_account_result_code::*;
5515mod create_account_result;
5516#[allow(unused_imports)]
5517pub use create_account_result::*;
5518mod payment_result_code;
5519#[allow(unused_imports)]
5520pub use payment_result_code::*;
5521mod payment_result;
5522#[allow(unused_imports)]
5523pub use payment_result::*;
5524mod path_payment_strict_receive_result_code;
5525#[allow(unused_imports)]
5526pub use path_payment_strict_receive_result_code::*;
5527mod simple_payment_result;
5528#[allow(unused_imports)]
5529pub use simple_payment_result::*;
5530mod path_payment_strict_receive_result_success;
5531#[allow(unused_imports)]
5532pub use path_payment_strict_receive_result_success::*;
5533mod path_payment_strict_receive_result;
5534#[allow(unused_imports)]
5535pub use path_payment_strict_receive_result::*;
5536mod path_payment_strict_send_result_code;
5537#[allow(unused_imports)]
5538pub use path_payment_strict_send_result_code::*;
5539mod path_payment_strict_send_result_success;
5540#[allow(unused_imports)]
5541pub use path_payment_strict_send_result_success::*;
5542mod path_payment_strict_send_result;
5543#[allow(unused_imports)]
5544pub use path_payment_strict_send_result::*;
5545mod manage_sell_offer_result_code;
5546#[allow(unused_imports)]
5547pub use manage_sell_offer_result_code::*;
5548mod manage_offer_effect;
5549#[allow(unused_imports)]
5550pub use manage_offer_effect::*;
5551mod manage_offer_success_result_offer;
5552#[allow(unused_imports)]
5553pub use manage_offer_success_result_offer::*;
5554mod manage_offer_success_result;
5555#[allow(unused_imports)]
5556pub use manage_offer_success_result::*;
5557mod manage_sell_offer_result;
5558#[allow(unused_imports)]
5559pub use manage_sell_offer_result::*;
5560mod manage_buy_offer_result_code;
5561#[allow(unused_imports)]
5562pub use manage_buy_offer_result_code::*;
5563mod manage_buy_offer_result;
5564#[allow(unused_imports)]
5565pub use manage_buy_offer_result::*;
5566mod set_options_result_code;
5567#[allow(unused_imports)]
5568pub use set_options_result_code::*;
5569mod set_options_result;
5570#[allow(unused_imports)]
5571pub use set_options_result::*;
5572mod change_trust_result_code;
5573#[allow(unused_imports)]
5574pub use change_trust_result_code::*;
5575mod change_trust_result;
5576#[allow(unused_imports)]
5577pub use change_trust_result::*;
5578mod allow_trust_result_code;
5579#[allow(unused_imports)]
5580pub use allow_trust_result_code::*;
5581mod allow_trust_result;
5582#[allow(unused_imports)]
5583pub use allow_trust_result::*;
5584mod account_merge_result_code;
5585#[allow(unused_imports)]
5586pub use account_merge_result_code::*;
5587mod account_merge_result;
5588#[allow(unused_imports)]
5589pub use account_merge_result::*;
5590mod inflation_result_code;
5591#[allow(unused_imports)]
5592pub use inflation_result_code::*;
5593mod inflation_payout;
5594#[allow(unused_imports)]
5595pub use inflation_payout::*;
5596mod inflation_result;
5597#[allow(unused_imports)]
5598pub use inflation_result::*;
5599mod manage_data_result_code;
5600#[allow(unused_imports)]
5601pub use manage_data_result_code::*;
5602mod manage_data_result;
5603#[allow(unused_imports)]
5604pub use manage_data_result::*;
5605mod bump_sequence_result_code;
5606#[allow(unused_imports)]
5607pub use bump_sequence_result_code::*;
5608mod bump_sequence_result;
5609#[allow(unused_imports)]
5610pub use bump_sequence_result::*;
5611mod create_claimable_balance_result_code;
5612#[allow(unused_imports)]
5613pub use create_claimable_balance_result_code::*;
5614mod create_claimable_balance_result;
5615#[allow(unused_imports)]
5616pub use create_claimable_balance_result::*;
5617mod claim_claimable_balance_result_code;
5618#[allow(unused_imports)]
5619pub use claim_claimable_balance_result_code::*;
5620mod claim_claimable_balance_result;
5621#[allow(unused_imports)]
5622pub use claim_claimable_balance_result::*;
5623mod begin_sponsoring_future_reserves_result_code;
5624#[allow(unused_imports)]
5625pub use begin_sponsoring_future_reserves_result_code::*;
5626mod begin_sponsoring_future_reserves_result;
5627#[allow(unused_imports)]
5628pub use begin_sponsoring_future_reserves_result::*;
5629mod end_sponsoring_future_reserves_result_code;
5630#[allow(unused_imports)]
5631pub use end_sponsoring_future_reserves_result_code::*;
5632mod end_sponsoring_future_reserves_result;
5633#[allow(unused_imports)]
5634pub use end_sponsoring_future_reserves_result::*;
5635mod revoke_sponsorship_result_code;
5636#[allow(unused_imports)]
5637pub use revoke_sponsorship_result_code::*;
5638mod revoke_sponsorship_result;
5639#[allow(unused_imports)]
5640pub use revoke_sponsorship_result::*;
5641mod clawback_result_code;
5642#[allow(unused_imports)]
5643pub use clawback_result_code::*;
5644mod clawback_result;
5645#[allow(unused_imports)]
5646pub use clawback_result::*;
5647mod clawback_claimable_balance_result_code;
5648#[allow(unused_imports)]
5649pub use clawback_claimable_balance_result_code::*;
5650mod clawback_claimable_balance_result;
5651#[allow(unused_imports)]
5652pub use clawback_claimable_balance_result::*;
5653mod set_trust_line_flags_result_code;
5654#[allow(unused_imports)]
5655pub use set_trust_line_flags_result_code::*;
5656mod set_trust_line_flags_result;
5657#[allow(unused_imports)]
5658pub use set_trust_line_flags_result::*;
5659mod liquidity_pool_deposit_result_code;
5660#[allow(unused_imports)]
5661pub use liquidity_pool_deposit_result_code::*;
5662mod liquidity_pool_deposit_result;
5663#[allow(unused_imports)]
5664pub use liquidity_pool_deposit_result::*;
5665mod liquidity_pool_withdraw_result_code;
5666#[allow(unused_imports)]
5667pub use liquidity_pool_withdraw_result_code::*;
5668mod liquidity_pool_withdraw_result;
5669#[allow(unused_imports)]
5670pub use liquidity_pool_withdraw_result::*;
5671mod invoke_host_function_result_code;
5672#[allow(unused_imports)]
5673pub use invoke_host_function_result_code::*;
5674mod invoke_host_function_result;
5675#[allow(unused_imports)]
5676pub use invoke_host_function_result::*;
5677mod extend_footprint_ttl_result_code;
5678#[allow(unused_imports)]
5679pub use extend_footprint_ttl_result_code::*;
5680mod extend_footprint_ttl_result;
5681#[allow(unused_imports)]
5682pub use extend_footprint_ttl_result::*;
5683mod restore_footprint_result_code;
5684#[allow(unused_imports)]
5685pub use restore_footprint_result_code::*;
5686mod restore_footprint_result;
5687#[allow(unused_imports)]
5688pub use restore_footprint_result::*;
5689mod operation_result_code;
5690#[allow(unused_imports)]
5691pub use operation_result_code::*;
5692mod operation_result_tr;
5693#[allow(unused_imports)]
5694pub use operation_result_tr::*;
5695mod operation_result;
5696#[allow(unused_imports)]
5697pub use operation_result::*;
5698mod transaction_result_code;
5699#[allow(unused_imports)]
5700pub use transaction_result_code::*;
5701mod inner_transaction_result_result;
5702#[allow(unused_imports)]
5703pub use inner_transaction_result_result::*;
5704mod inner_transaction_result_ext;
5705#[allow(unused_imports)]
5706pub use inner_transaction_result_ext::*;
5707mod inner_transaction_result;
5708#[allow(unused_imports)]
5709pub use inner_transaction_result::*;
5710mod inner_transaction_result_pair;
5711#[allow(unused_imports)]
5712pub use inner_transaction_result_pair::*;
5713mod transaction_result_result;
5714#[allow(unused_imports)]
5715pub use transaction_result_result::*;
5716mod transaction_result_ext;
5717#[allow(unused_imports)]
5718pub use transaction_result_ext::*;
5719mod transaction_result;
5720#[allow(unused_imports)]
5721pub use transaction_result::*;
5722mod hash;
5723#[allow(unused_imports)]
5724pub use hash::*;
5725mod uint256;
5726#[allow(unused_imports)]
5727pub use uint256::*;
5728mod uint32;
5729#[allow(unused_imports)]
5730pub use uint32::*;
5731mod int32;
5732#[allow(unused_imports)]
5733pub use int32::*;
5734mod uint64;
5735#[allow(unused_imports)]
5736pub use uint64::*;
5737mod int64;
5738#[allow(unused_imports)]
5739pub use int64::*;
5740mod time_point;
5741#[allow(unused_imports)]
5742pub use time_point::*;
5743mod duration;
5744#[allow(unused_imports)]
5745pub use duration::*;
5746mod time_point_ms;
5747#[allow(unused_imports)]
5748pub use time_point_ms::*;
5749mod extension_point;
5750#[allow(unused_imports)]
5751pub use extension_point::*;
5752mod crypto_key_type;
5753#[allow(unused_imports)]
5754pub use crypto_key_type::*;
5755mod public_key_type;
5756#[allow(unused_imports)]
5757pub use public_key_type::*;
5758mod signer_key_type;
5759#[allow(unused_imports)]
5760pub use signer_key_type::*;
5761mod public_key;
5762#[allow(unused_imports)]
5763pub use public_key::*;
5764mod signer_key_ed25519_signed_payload;
5765#[allow(unused_imports)]
5766pub use signer_key_ed25519_signed_payload::*;
5767mod signer_key;
5768#[allow(unused_imports)]
5769pub use signer_key::*;
5770mod signature;
5771#[allow(unused_imports)]
5772pub use signature::*;
5773mod signature_hint;
5774#[allow(unused_imports)]
5775pub use signature_hint::*;
5776mod node_id;
5777#[allow(unused_imports)]
5778pub use node_id::*;
5779mod account_id;
5780#[allow(unused_imports)]
5781pub use account_id::*;
5782mod contract_id;
5783#[allow(unused_imports)]
5784pub use contract_id::*;
5785mod curve25519_secret;
5786#[allow(unused_imports)]
5787pub use curve25519_secret::*;
5788mod curve25519_public;
5789#[allow(unused_imports)]
5790pub use curve25519_public::*;
5791mod hmac_sha256_key;
5792#[allow(unused_imports)]
5793pub use hmac_sha256_key::*;
5794mod hmac_sha256_mac;
5795#[allow(unused_imports)]
5796pub use hmac_sha256_mac::*;
5797mod short_hash_seed;
5798#[allow(unused_imports)]
5799pub use short_hash_seed::*;
5800mod binary_fuse_filter_type;
5801#[allow(unused_imports)]
5802pub use binary_fuse_filter_type::*;
5803mod serialized_binary_fuse_filter;
5804#[allow(unused_imports)]
5805pub use serialized_binary_fuse_filter::*;
5806mod pool_id;
5807#[allow(unused_imports)]
5808pub use pool_id::*;
5809mod claimable_balance_id_type;
5810#[allow(unused_imports)]
5811pub use claimable_balance_id_type::*;
5812mod claimable_balance_id;
5813#[allow(unused_imports)]
5814pub use claimable_balance_id::*;
5815mod test_next_type;
5816#[allow(unused_imports)]
5817pub use test_next_type::*;
5818mod type_enum;
5819#[allow(unused_imports)]
5820pub use type_enum::*;
5821
5822#[cfg(feature = "const")]
5823pub mod r#const;