Skip to main content

stellar_xdr/generated/
authenticated_message.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// AuthenticatedMessage is an XDR Union defined as:
5///
6/// ```text
7/// union AuthenticatedMessage switch (uint32 v)
8/// {
9/// case 0:
10///     struct
11///     {
12///         uint64 sequence;
13///         StellarMessage message;
14///         HmacSha256Mac mac;
15///     } v0;
16/// };
17/// ```
18///
19// union with discriminant u32
20#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
21#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
22#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
23#[cfg_attr(
24    all(feature = "serde", feature = "alloc"),
25    serde_with::serde_as,
26    derive(serde::Serialize, serde::Deserialize),
27    serde(rename_all = "snake_case")
28)]
29#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
30#[allow(clippy::large_enum_variant)]
31pub enum AuthenticatedMessage {
32    V0(AuthenticatedMessageV0),
33}
34
35#[cfg(feature = "alloc")]
36impl Default for AuthenticatedMessage {
37    fn default() -> Self {
38        Self::V0(AuthenticatedMessageV0::default())
39    }
40}
41
42impl AuthenticatedMessage {
43    const _VARIANTS: &[u32] = &[0];
44    pub const VARIANTS: [u32; Self::_VARIANTS.len()] = {
45        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
46        let mut i = 1;
47        while i < Self::_VARIANTS.len() {
48            arr[i] = Self::_VARIANTS[i];
49            i += 1;
50        }
51        arr
52    };
53    const _VARIANTS_STR: &[&str] = &["V0"];
54    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
55        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
56        let mut i = 1;
57        while i < Self::_VARIANTS_STR.len() {
58            arr[i] = Self::_VARIANTS_STR[i];
59            i += 1;
60        }
61        arr
62    };
63
64    #[must_use]
65    pub const fn name(&self) -> &'static str {
66        match self {
67            Self::V0(_) => "V0",
68        }
69    }
70
71    #[must_use]
72    pub const fn discriminant(&self) -> u32 {
73        #[allow(clippy::match_same_arms)]
74        match self {
75            Self::V0(_) => 0,
76        }
77    }
78
79    #[must_use]
80    pub const fn variants() -> [u32; Self::_VARIANTS.len()] {
81        Self::VARIANTS
82    }
83}
84
85impl Name for AuthenticatedMessage {
86    #[must_use]
87    fn name(&self) -> &'static str {
88        Self::name(self)
89    }
90}
91
92impl Discriminant<u32> for AuthenticatedMessage {
93    #[must_use]
94    fn discriminant(&self) -> u32 {
95        Self::discriminant(self)
96    }
97}
98
99impl Variants<u32> for AuthenticatedMessage {
100    fn variants() -> slice::Iter<'static, u32> {
101        Self::VARIANTS.iter()
102    }
103}
104
105impl Union<u32> for AuthenticatedMessage {}
106
107impl ReadXdr for AuthenticatedMessage {
108    #[cfg(feature = "std")]
109    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
110        r.with_limited_depth(|r| {
111            let dv: u32 = <u32 as ReadXdr>::read_xdr(r)?;
112            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
113            let v = match dv {
114                0 => Self::V0(AuthenticatedMessageV0::read_xdr(r)?),
115                #[allow(unreachable_patterns)]
116                _ => return Err(Error::Invalid),
117            };
118            Ok(v)
119        })
120    }
121}
122
123impl WriteXdr for AuthenticatedMessage {
124    #[cfg(feature = "std")]
125    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
126        w.with_limited_depth(|w| {
127            self.discriminant().write_xdr(w)?;
128            #[allow(clippy::match_same_arms)]
129            match self {
130                Self::V0(v) => v.write_xdr(w)?,
131            };
132            Ok(())
133        })
134    }
135}