1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-FileCopyrightText: 2024-2026 Cloudflare Inc., Luke Curley, Mike English and contributors
// SPDX-FileCopyrightText: 2023-2024 Luke Curley and contributors
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::message::{self, Message};
use std::fmt;
macro_rules! publisher_msgs {
{$($name:ident,)*} => {
#[derive(Clone)]
pub enum Publisher {
$($name(message::$name)),*
}
$(impl From<message::$name> for Publisher {
fn from(msg: message::$name) -> Self {
Publisher::$name(msg)
}
})*
impl From<Publisher> for Message {
fn from(p: Publisher) -> Self {
match p {
$(Publisher::$name(m) => Message::$name(m),)*
}
}
}
impl TryFrom<Message> for Publisher {
type Error = Message;
fn try_from(m: Message) -> Result<Self, Self::Error> {
match m {
$(Message::$name(m) => Ok(Publisher::$name(m)),)*
_ => Err(m),
}
}
}
impl fmt::Debug for Publisher {
// Delegate to the message formatter
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
$(Self::$name(ref m) => m.fmt(f),)*
}
}
}
}
}
// Defines messages that a PUBLISHER would send, or that a SUBSCRIBER would handle.
// RequestOk and RequestError are shared responses (draft-16 §9.7 / §9.8).
publisher_msgs! {
// Namespace advertisement and termination.
PublishNamespace,
PublishNamespaceDone,
// Publisher-initiated subscriptions.
Publish,
PublishDone,
// Responses to subscriber-initiated requests.
SubscribeOk,
RequestOk,
RequestError,
// FETCH response; FETCH itself is still unsupported by the session layer.
FetchOk,
}