Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T01:33:38.971Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

macros.rs

74 lines · 2.4 KB · rust
1#[macro_export]
2macro_rules! messages {
3    ($(($name:ident, $priority:ident)),* $(,)?) => {
4        pub fn build_typed_envelope(sender_id: ConnectionId, received_at: Instant, envelope: Envelope) -> Option<Box<dyn AnyTypedEnvelope>> {
5            match envelope.payload {
6                $(Some(envelope::Payload::$name(payload)) => {
7                    Some(Box::new(TypedEnvelope {
8                        sender_id,
9                        original_sender_id: envelope.original_sender_id.map(|original_sender| PeerId {
10                            owner_id: original_sender.owner_id,
11                            id: original_sender.id
12                        }),
13                        message_id: envelope.id,
14                        payload,
15                        received_at,
16                    }))
17                }, )*
18                _ => None
19            }
20        }
21
22        $(
23            impl EnvelopedMessage for $name {
24                const NAME: &'static str = std::stringify!($name);
25                const PRIORITY: MessagePriority = MessagePriority::$priority;
26
27                fn into_envelope(
28                    self,
29                    id: u32,
30                    responding_to: Option<u32>,
31                    original_sender_id: Option<PeerId>,
32                ) -> Envelope {
33                    Envelope {
34                        id,
35                        responding_to,
36                        original_sender_id,
37                        payload: Some(envelope::Payload::$name(self)),
38                    }
39                }
40
41                fn from_envelope(envelope: Envelope) -> Option<Self> {
42                    if let Some(envelope::Payload::$name(msg)) = envelope.payload {
43                        Some(msg)
44                    } else {
45                        None
46                    }
47                }
48            }
49        )*
50    };
51}
52
53#[macro_export]
54macro_rules! request_messages {
55    ($(($request_name:ident, $response_name:ident)),* $(,)?) => {
56        $(impl RequestMessage for $request_name {
57            type Response = $response_name;
58        })*
59    };
60}
61
62#[macro_export]
63macro_rules! entity_messages {
64    ({$id_field:ident, $entity_type:ty}, $($name:ident),* $(,)?) => {
65        $(impl EntityMessage for $name {
66            type Entity = $entity_type;
67
68            fn remote_entity_id(&self) -> u64 {
69                self.$id_field
70            }
71        })*
72    };
73}
74
Served at tenant.openagents/omega Member data and write actions are omitted.