Skip to content

Commit 437ca92

Browse files
committed
Avp::fmt() no longer needs dictionary arg
1 parent 2db9258 commit 437ca92

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

src/avp/group.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::avp::Avp;
2-
use crate::dictionary::{self, Dictionary};
2+
use crate::dictionary::Dictionary;
33
use crate::error::{Error, Result};
44
use std::io::Read;
55
use std::io::Seek;
@@ -72,10 +72,9 @@ impl Grouped {
7272
}
7373

7474
pub fn fmt(&self, f: &mut std::fmt::Formatter<'_>, depth: usize) -> std::fmt::Result {
75-
let dict = Dictionary::new(&[&dictionary::DEFAULT_DICT_XML]);
7675
for avp in &self.avps {
7776
write!(f, "\n")?;
78-
avp.fmt(f, depth + 1, &dict)?;
77+
avp.fmt(f, depth + 1)?;
7978
}
8079
Ok(())
8180
}

src/avp/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct Avp {
8181
header: AvpHeader,
8282
value: AvpValue,
8383
padding: u8,
84-
dictionary: Arc<Dictionary>,
84+
dict: Arc<Dictionary>,
8585
}
8686

8787
#[derive(Debug, Clone)]
@@ -392,7 +392,7 @@ impl Avp {
392392
header,
393393
value,
394394
padding,
395-
dictionary: dict,
395+
dict,
396396
};
397397
}
398398

@@ -489,7 +489,7 @@ impl Avp {
489489
header,
490490
value,
491491
padding,
492-
dictionary: dict,
492+
dict,
493493
});
494494
}
495495

@@ -639,12 +639,11 @@ impl Avp {
639639
}
640640
}
641641

642-
pub fn fmt(&self, f: &mut fmt::Formatter<'_>, depth: usize, dict: &Dictionary) -> fmt::Result {
642+
pub fn fmt(&self, f: &mut fmt::Formatter<'_>, depth: usize) -> fmt::Result {
643643
let indent = " ".repeat(depth.max(0));
644644

645-
// let dict = dictionary::DEFAULT_DICT.read().unwrap();
646-
647-
let avp_name = dict
645+
let avp_name = self
646+
.dict
648647
.get_avp_name(self.get_code() as u32, self.get_vendor_id())
649648
.unwrap_or("Unknown");
650649

@@ -681,8 +680,7 @@ fn get_bool_unicode(v: bool) -> &'static str {
681680

682681
impl fmt::Display for Avp {
683682
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
684-
let dict = self.dictionary.as_ref();
685-
self.fmt(f, 0, &dict)
683+
self.fmt(f, 0)
686684
}
687685
}
688686

src/diameter.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub mod flags {
5959
pub struct DiameterMessage {
6060
header: DiameterHeader,
6161
avps: Vec<Avp>,
62-
dictionary: Arc<Dictionary>,
62+
dict: Arc<Dictionary>,
6363
}
6464

6565
/// Represents the header part of a Diameter message.
@@ -115,7 +115,7 @@ impl DiameterMessage {
115115
flags: u8,
116116
hop_by_hop_id: u32,
117117
end_to_end_id: u32,
118-
dictionary: Arc<Dictionary>,
118+
dict: Arc<Dictionary>,
119119
) -> DiameterMessage {
120120
let header = DiameterHeader {
121121
version: 1,
@@ -127,11 +127,7 @@ impl DiameterMessage {
127127
end_to_end_id,
128128
};
129129
let avps = Vec::new();
130-
DiameterMessage {
131-
header,
132-
avps,
133-
dictionary,
134-
}
130+
DiameterMessage { header, avps, dict }
135131
}
136132

137133
/// Returns a reference to the AVP with the specified code,
@@ -153,13 +149,13 @@ impl DiameterMessage {
153149

154150
// Adds an AVP to the message with the specified parameters.
155151
pub fn add_avp(&mut self, code: u32, vendor_id: Option<u32>, flags: u8, value: AvpValue) {
156-
let avp = Avp::new(code, vendor_id, flags, value, Arc::clone(&self.dictionary));
152+
let avp = Avp::new(code, vendor_id, flags, value, Arc::clone(&self.dict));
157153
self.add(avp);
158154
}
159155

160156
/// Adds an AVP to the message by name.
161157
pub fn add_avp_by_name(&mut self, avp_name: &str, value: AvpValue) -> Result<()> {
162-
let avp = Avp::from_name(avp_name, value, Arc::clone(&self.dictionary))?;
158+
let avp = Avp::from_name(avp_name, value, Arc::clone(&self.dict))?;
163159
self.add(avp);
164160
Ok(())
165161
}
@@ -218,11 +214,7 @@ impl DiameterMessage {
218214
));
219215
}
220216

221-
Ok(DiameterMessage {
222-
header,
223-
avps,
224-
dictionary: dict,
225-
})
217+
Ok(DiameterMessage { header, avps, dict })
226218
}
227219

228220
/// Encodes the Diameter message to the given writer.
@@ -247,7 +239,7 @@ impl DiameterMessage {
247239
)?;
248240

249241
for avp in &self.avps {
250-
avp.fmt(f, depth, self.dictionary.as_ref())?;
242+
avp.fmt(f, depth)?;
251243
write!(f, "\n")?;
252244
}
253245

0 commit comments

Comments
 (0)