amqp_codec/
framing.rs

1use super::protocol;
2
3/// Length in bytes of the fixed frame header
4pub const HEADER_LEN: usize = 8;
5
6/// AMQP Frame type marker (0)
7pub const FRAME_TYPE_AMQP: u8 = 0x00;
8pub const FRAME_TYPE_SASL: u8 = 0x01;
9
10/// Represents an AMQP Frame
11#[derive(Clone, Debug, PartialEq)]
12pub struct AmqpFrame {
13    channel_id: u16,
14    performative: protocol::Frame,
15}
16
17impl AmqpFrame {
18    pub fn new(channel_id: u16, performative: protocol::Frame) -> AmqpFrame {
19        AmqpFrame {
20            channel_id,
21            performative,
22        }
23    }
24
25    #[inline]
26    pub fn channel_id(&self) -> u16 {
27        self.channel_id
28    }
29
30    #[inline]
31    pub fn performative(&self) -> &protocol::Frame {
32        &self.performative
33    }
34
35    #[inline]
36    pub fn into_parts(self) -> (u16, protocol::Frame) {
37        (self.channel_id, self.performative)
38    }
39}
40
41#[derive(Clone, Debug, PartialEq)]
42pub struct SaslFrame {
43    pub body: protocol::SaslFrameBody,
44}
45
46impl SaslFrame {
47    pub fn new(body: protocol::SaslFrameBody) -> SaslFrame {
48        SaslFrame { body }
49    }
50}
51
52impl From<protocol::SaslMechanisms> for SaslFrame {
53    fn from(item: protocol::SaslMechanisms) -> SaslFrame {
54        SaslFrame::new(protocol::SaslFrameBody::SaslMechanisms(item))
55    }
56}
57
58impl From<protocol::SaslInit> for SaslFrame {
59    fn from(item: protocol::SaslInit) -> SaslFrame {
60        SaslFrame::new(protocol::SaslFrameBody::SaslInit(item))
61    }
62}
63
64impl From<protocol::SaslChallenge> for SaslFrame {
65    fn from(item: protocol::SaslChallenge) -> SaslFrame {
66        SaslFrame::new(protocol::SaslFrameBody::SaslChallenge(item))
67    }
68}
69
70impl From<protocol::SaslResponse> for SaslFrame {
71    fn from(item: protocol::SaslResponse) -> SaslFrame {
72        SaslFrame::new(protocol::SaslFrameBody::SaslResponse(item))
73    }
74}
75
76impl From<protocol::SaslOutcome> for SaslFrame {
77    fn from(item: protocol::SaslOutcome) -> SaslFrame {
78        SaslFrame::new(protocol::SaslFrameBody::SaslOutcome(item))
79    }
80}