zaun_community_protocol/signed/descriptor/
parts.rs1use crate::encoding::{Decode, DecodeError, Encode, EncodeError, Reader, Writer};
4
5macro_rules! byte_enum {
6 ($(#[$doc:meta])* $name:ident, $field:literal { $($(#[$vdoc:meta])* $variant:ident = $value:literal),* $(,)? }) => {
7 $(#[$doc])*
8 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9 #[repr(u8)]
10 pub enum $name {
11 $($(#[$vdoc])* $variant = $value),*
12 }
13
14 impl Encode for $name {
15 fn encode(&self, w: &mut Writer) -> Result<(), EncodeError> {
16 w.u8(*self as u8);
17 Ok(())
18 }
19 }
20
21 impl Decode for $name {
22 fn decode(r: &mut Reader<'_>) -> Result<Self, DecodeError> {
23 match r.u8()? {
24 $($value => Ok(Self::$variant),)*
25 _ => Err(DecodeError::Invalid($field)),
26 }
27 }
28 }
29 };
30}
31
32byte_enum!(
33 Discovery, "discovery" {
35 Private = 0,
37 Unlisted = 1,
39 Listed = 2,
41 }
42);
43
44byte_enum!(
45 AdmissionMode, "admission_summary.mode" {
47 InvitationOnly = 0,
49 ApprovalRequired = 1,
51 Open = 2,
53 }
54);
55
56byte_enum!(
57 VerificationLevel, "admission_summary.level" {
59 None = 0,
61 Low = 1,
63 Medium = 2,
65 High = 3,
67 Highest = 4,
69 }
70);
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
75pub struct AdmissionSummary {
76 pub mode: AdmissionMode,
78 pub level: VerificationLevel,
80}
81
82impl Encode for AdmissionSummary {
83 fn encode(&self, w: &mut Writer) -> Result<(), EncodeError> {
84 w.put(&self.mode)?;
85 w.put(&self.level)
86 }
87}
88
89impl Decode for AdmissionSummary {
90 fn decode(r: &mut Reader<'_>) -> Result<Self, DecodeError> {
91 Ok(Self {
92 mode: r.get()?,
93 level: r.get()?,
94 })
95 }
96}
97
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
101pub struct DelegationRef {
102 pub epoch: u64,
104 pub delegation_hash: [u8; 32],
106}
107
108impl Encode for DelegationRef {
109 fn encode(&self, w: &mut Writer) -> Result<(), EncodeError> {
110 w.u64(self.epoch);
111 w.put(&self.delegation_hash)
112 }
113}
114
115impl Decode for DelegationRef {
116 fn decode(r: &mut Reader<'_>) -> Result<Self, DecodeError> {
117 Ok(Self {
118 epoch: r.u64()?,
119 delegation_hash: r.get()?,
120 })
121 }
122}