DiameterMessage

Struct DiameterMessage 

Source
pub struct DiameterMessage { /* private fields */ }

Implementations§

Source§

impl DiameterMessage

Source

pub fn new( command_flag: CommandFlag, command_code: CommandCode, application_id: ApplicationId, hop_by_hop: u32, end_to_end: u32, ) -> Self

Examples found in repository?
example/client.rs (lines 20-26)
17fn main() -> DiameterResult<()> {
18    let dict = Arc::new(Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]));
19
20    let mut ccr: DiameterMessage = DiameterMessage::new(
21        CommandFlag::Request,
22        CommandCode::CreditControl,
23        ApplicationId::Gx,
24        1123158611,
25        3102381851,
26    );
27
28    ccr.add(Avp::new(263, M, None, UTF8String::from_str("a")));
29    ccr.add_avp(264, M, None, Identity::from_str("host.example.com"));
30    ccr.add(Avp::new(
31        296,
32        M,
33        None,
34        Identity::from_str("realm.example.com"),
35    ));
36    ccr.add(Avp::new(263, M, None, UTF8String::from_str("ses;12345888")));
37    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
38    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
39    ccr.add(Avp::new(
40        264,
41        M,
42        None,
43        Identity::from_str("host.example.com"),
44    ));
45    ccr.add(Avp::new(
46        296,
47        M,
48        None,
49        Identity::from_str("realm.example.com"),
50    ));
51    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
52    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
53
54    let mut client = DiameterClient::new("127.0.0.1:3868");
55    client.connect()?;
56    let cca: DiameterMessage = client.send_message(&mut ccr, dict)?;
57    let avp = match cca.get_avp(268) {
58        Some(avp) => {
59            match avp.get_value() {
60                AvpValue::Unsigned32(value) => {
61                    if *value.value() != 2001 {
62                        println!("invalid response status");
63                    } else {
64                        println!("success response status {}", value.value());
65                    }
66                },
67                _ => {
68                    
69                }
70            }
71        },
72        None => Err(ClientError("avp 268 not found"))?
73    };
74    client.close()?;
75    println!("{:?}", cca);
76    Ok(())
77}
Source

pub fn get_version(&self) -> u8

Source

pub fn get_length(&self) -> u32

Source

pub fn get_command_flag(&self) -> u8

Source

pub fn get_command_code(&self) -> &CommandCode

Source

pub fn get_application_id(&self) -> &ApplicationId

Source

pub fn get_hop_by_hop(&self) -> u32

Source

pub fn get_end_to_end(&self) -> u32

Source

pub fn get_avps(&self) -> &Vec<Avp>

Source

pub fn get_avp(&self, code: u32) -> Option<&Avp>

Examples found in repository?
example/client.rs (line 57)
17fn main() -> DiameterResult<()> {
18    let dict = Arc::new(Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]));
19
20    let mut ccr: DiameterMessage = DiameterMessage::new(
21        CommandFlag::Request,
22        CommandCode::CreditControl,
23        ApplicationId::Gx,
24        1123158611,
25        3102381851,
26    );
27
28    ccr.add(Avp::new(263, M, None, UTF8String::from_str("a")));
29    ccr.add_avp(264, M, None, Identity::from_str("host.example.com"));
30    ccr.add(Avp::new(
31        296,
32        M,
33        None,
34        Identity::from_str("realm.example.com"),
35    ));
36    ccr.add(Avp::new(263, M, None, UTF8String::from_str("ses;12345888")));
37    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
38    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
39    ccr.add(Avp::new(
40        264,
41        M,
42        None,
43        Identity::from_str("host.example.com"),
44    ));
45    ccr.add(Avp::new(
46        296,
47        M,
48        None,
49        Identity::from_str("realm.example.com"),
50    ));
51    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
52    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
53
54    let mut client = DiameterClient::new("127.0.0.1:3868");
55    client.connect()?;
56    let cca: DiameterMessage = client.send_message(&mut ccr, dict)?;
57    let avp = match cca.get_avp(268) {
58        Some(avp) => {
59            match avp.get_value() {
60                AvpValue::Unsigned32(value) => {
61                    if *value.value() != 2001 {
62                        println!("invalid response status");
63                    } else {
64                        println!("success response status {}", value.value());
65                    }
66                },
67                _ => {
68                    
69                }
70            }
71        },
72        None => Err(ClientError("avp 268 not found"))?
73    };
74    client.close()?;
75    println!("{:?}", cca);
76    Ok(())
77}
Source

pub fn add(&mut self, avp: Avp)

Examples found in repository?
example/client.rs (line 28)
17fn main() -> DiameterResult<()> {
18    let dict = Arc::new(Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]));
19
20    let mut ccr: DiameterMessage = DiameterMessage::new(
21        CommandFlag::Request,
22        CommandCode::CreditControl,
23        ApplicationId::Gx,
24        1123158611,
25        3102381851,
26    );
27
28    ccr.add(Avp::new(263, M, None, UTF8String::from_str("a")));
29    ccr.add_avp(264, M, None, Identity::from_str("host.example.com"));
30    ccr.add(Avp::new(
31        296,
32        M,
33        None,
34        Identity::from_str("realm.example.com"),
35    ));
36    ccr.add(Avp::new(263, M, None, UTF8String::from_str("ses;12345888")));
37    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
38    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
39    ccr.add(Avp::new(
40        264,
41        M,
42        None,
43        Identity::from_str("host.example.com"),
44    ));
45    ccr.add(Avp::new(
46        296,
47        M,
48        None,
49        Identity::from_str("realm.example.com"),
50    ));
51    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
52    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
53
54    let mut client = DiameterClient::new("127.0.0.1:3868");
55    client.connect()?;
56    let cca: DiameterMessage = client.send_message(&mut ccr, dict)?;
57    let avp = match cca.get_avp(268) {
58        Some(avp) => {
59            match avp.get_value() {
60                AvpValue::Unsigned32(value) => {
61                    if *value.value() != 2001 {
62                        println!("invalid response status");
63                    } else {
64                        println!("success response status {}", value.value());
65                    }
66                },
67                _ => {
68                    
69                }
70            }
71        },
72        None => Err(ClientError("avp 268 not found"))?
73    };
74    client.close()?;
75    println!("{:?}", cca);
76    Ok(())
77}
Source

pub fn add_avp<T: Into<AvpValue>>( &mut self, code: u32, flags: AvpFlags, vendor_id: Option<u32>, value: T, )

Examples found in repository?
example/client.rs (line 29)
17fn main() -> DiameterResult<()> {
18    let dict = Arc::new(Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]));
19
20    let mut ccr: DiameterMessage = DiameterMessage::new(
21        CommandFlag::Request,
22        CommandCode::CreditControl,
23        ApplicationId::Gx,
24        1123158611,
25        3102381851,
26    );
27
28    ccr.add(Avp::new(263, M, None, UTF8String::from_str("a")));
29    ccr.add_avp(264, M, None, Identity::from_str("host.example.com"));
30    ccr.add(Avp::new(
31        296,
32        M,
33        None,
34        Identity::from_str("realm.example.com"),
35    ));
36    ccr.add(Avp::new(263, M, None, UTF8String::from_str("ses;12345888")));
37    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
38    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
39    ccr.add(Avp::new(
40        264,
41        M,
42        None,
43        Identity::from_str("host.example.com"),
44    ));
45    ccr.add(Avp::new(
46        296,
47        M,
48        None,
49        Identity::from_str("realm.example.com"),
50    ));
51    ccr.add(Avp::new(416, M, None, Enumerated::new(1)));
52    ccr.add(Avp::new(415, M, None, Unsigned32::new(1000)));
53
54    let mut client = DiameterClient::new("127.0.0.1:3868");
55    client.connect()?;
56    let cca: DiameterMessage = client.send_message(&mut ccr, dict)?;
57    let avp = match cca.get_avp(268) {
58        Some(avp) => {
59            match avp.get_value() {
60                AvpValue::Unsigned32(value) => {
61                    if *value.value() != 2001 {
62                        println!("invalid response status");
63                    } else {
64                        println!("success response status {}", value.value());
65                    }
66                },
67                _ => {
68                    
69                }
70            }
71        },
72        None => Err(ClientError("avp 268 not found"))?
73    };
74    client.close()?;
75    println!("{:?}", cca);
76    Ok(())
77}
Source

pub fn encode_to<W: Write>(&mut self, writer: &mut W) -> DiameterResult<()>

Source

pub fn decode_from<R: Read>( reader: &mut R, dict: Arc<Dictionary>, ) -> DiameterResult<DiameterMessage>

Trait Implementations§

Source§

impl Debug for DiameterMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.