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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use super::protocol;

/// Length in bytes of the fixed frame header
pub const HEADER_LEN: usize = 8;

/// AMQP Frame type marker (0)
pub const FRAME_TYPE_AMQP: u8 = 0x00;
pub const FRAME_TYPE_SASL: u8 = 0x01;

/// Represents an AMQP Frame
#[derive(Clone, Debug, PartialEq)]
pub struct AmqpFrame {
    channel_id: u16,
    performative: protocol::Frame,
}

impl AmqpFrame {
    pub fn new(channel_id: u16, performative: protocol::Frame) -> AmqpFrame {
        AmqpFrame {
            channel_id,
            performative,
        }
    }

    #[inline]
    pub fn channel_id(&self) -> u16 {
        self.channel_id
    }

    #[inline]
    pub fn performative(&self) -> &protocol::Frame {
        &self.performative
    }

    #[inline]
    pub fn into_parts(self) -> (u16, protocol::Frame) {
        (self.channel_id, self.performative)
    }
}

#[derive(Clone, Debug, PartialEq)]
pub struct SaslFrame {
    pub body: protocol::SaslFrameBody,
}

impl SaslFrame {
    pub fn new(body: protocol::SaslFrameBody) -> SaslFrame {
        SaslFrame { body }
    }
}

impl From<protocol::SaslMechanisms> for SaslFrame {
    fn from(item: protocol::SaslMechanisms) -> SaslFrame {
        SaslFrame::new(protocol::SaslFrameBody::SaslMechanisms(item))
    }
}

impl From<protocol::SaslInit> for SaslFrame {
    fn from(item: protocol::SaslInit) -> SaslFrame {
        SaslFrame::new(protocol::SaslFrameBody::SaslInit(item))
    }
}

impl From<protocol::SaslChallenge> for SaslFrame {
    fn from(item: protocol::SaslChallenge) -> SaslFrame {
        SaslFrame::new(protocol::SaslFrameBody::SaslChallenge(item))
    }
}

impl From<protocol::SaslResponse> for SaslFrame {
    fn from(item: protocol::SaslResponse) -> SaslFrame {
        SaslFrame::new(protocol::SaslFrameBody::SaslResponse(item))
    }
}

impl From<protocol::SaslOutcome> for SaslFrame {
    fn from(item: protocol::SaslOutcome) -> SaslFrame {
        SaslFrame::new(protocol::SaslFrameBody::SaslOutcome(item))
    }
}