stellar_xdr/generated/const/time_point_ms.rs
1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4impl TimePointMs {
5 /// The exact XDR-encoded length of this value, in bytes.
6 ///
7 /// Evaluable in a const context, so a caller (such as a proc-macro) can
8 /// size a buffer for [`Self::const_to_xdr`] at compile time.
9 #[must_use]
10 pub const fn const_xdr_len(&self) -> usize {
11 let mut empty: [u8; 0] = [];
12 let mut w = ConstWriter::new(&mut empty);
13 w.write_type_time_point_ms(self);
14 w.len()
15 }
16
17 /// Serialize this value as XDR into a fixed-size `[u8; N]` using only const
18 /// operations. This is the const counterpart to
19 /// [`WriteXdr::to_xdr`](super::super::WriteXdr::to_xdr).
20 ///
21 /// `N` must equal [`Self::const_xdr_len`]. It is intended for callers, such
22 /// as a proc-macro, that compute the length with `const_xdr_len` and pass
23 /// it as `N`; `const_to_xdr` itself does not need to call `const_xdr_len`.
24 ///
25 /// # Panics
26 ///
27 /// Panics if `N` does not equal the value's [`Self::const_xdr_len`].
28 #[must_use]
29 pub const fn const_to_xdr<const N: usize>(&self) -> [u8; N] {
30 let mut buf = [0u8; N];
31 let mut w = ConstWriter::new(&mut buf);
32 w.write_type_time_point_ms(self);
33 assert!(
34 w.len() == N,
35 "const_to_xdr: N does not equal the XDR-encoded length"
36 );
37 buf
38 }
39}
40
41impl ConstWriter<'_> {
42 /// Serializes a [`TimePointMs`], mirroring `<TimePointMs as WriteXdr>::write_xdr`.
43 pub const fn write_type_time_point_ms(&mut self, v: &TimePointMs) {
44 self.write_u64(v.0);
45 }
46}