@@ -99,6 +99,64 @@ pub trait AttributeHeader {
99
99
}
100
100
101
101
102
+ //------------ OwnedPathAttributes -------------------------------------------
103
+
104
+
105
+ #[ derive( Clone , Debug , Eq , PartialEq , serde:: Serialize ) ]
106
+ pub struct OwnedPathAttributes {
107
+ ppi : PduParseInfo ,
108
+ raw : Vec < u8 >
109
+ }
110
+
111
+ impl OwnedPathAttributes {
112
+ pub fn new ( ppi : PduParseInfo , raw : Vec < u8 > ) -> Self {
113
+ Self { ppi, raw }
114
+ }
115
+
116
+ pub fn iter ( & self ) -> PathAttributes < Vec < u8 > > {
117
+ let parser = Parser :: from_ref ( & self . raw ) ;
118
+ PathAttributes :: new ( parser, self . ppi )
119
+ }
120
+
121
+ pub fn pdu_parse_info ( & self ) -> PduParseInfo {
122
+ self . ppi
123
+ }
124
+
125
+ pub fn into_vec ( self ) -> Vec < u8 > {
126
+ self . raw
127
+ }
128
+
129
+ pub fn get < A : FromAttribute > ( & self ) -> Option < A > {
130
+ if let Some ( attr_type) = A :: attribute_type ( ) {
131
+ self . iter ( ) . get ( attr_type)
132
+ . and_then ( |a| a. to_owned ( ) . ok ( ) )
133
+ . and_then ( |a| A :: from_attribute ( a) )
134
+ } else {
135
+ None
136
+ }
137
+ }
138
+ }
139
+
140
+ impl < ' a , O > From < PathAttributes < ' a , O > > for OwnedPathAttributes
141
+ where
142
+ O : AsRef < [ u8 ] >
143
+ {
144
+ fn from ( value : PathAttributes < ' a , O > ) -> Self {
145
+ OwnedPathAttributes {
146
+ ppi : value. pdu_parse_info ,
147
+ raw : value. parser . as_slice ( ) . to_owned ( )
148
+ }
149
+ }
150
+ }
151
+
152
+ impl From < ( PduParseInfo , Vec < u8 > ) > for OwnedPathAttributes {
153
+ fn from ( value : ( PduParseInfo , Vec < u8 > ) ) -> Self {
154
+ Self :: new ( value. 0 , value. 1 )
155
+ }
156
+ }
157
+
158
+
159
+
102
160
//------------ PathAttributesBuilder -----------------------------------------
103
161
104
162
pub type AttributesMap = BTreeMap < u8 , PathAttribute > ;
0 commit comments