Insert a TLV record (replaces if type already exists).
(&mut self, type_: u64, value: Vec<u8>)
| 133 | |
| 134 | /// Insert a TLV record (replaces if type already exists). |
| 135 | pub fn insert(&mut self, type_: u64, value: Vec<u8>) { |
| 136 | // If the type already exists, replace its value. |
| 137 | if let Some(rec) = self.0.iter_mut().find(|rec| rec.type_ == type_) { |
| 138 | rec.value = value; |
| 139 | return; |
| 140 | } |
| 141 | // Otherwise push and re-sort to maintain canonical order. |
| 142 | self.0.push(TlvRecord { type_, value }); |
| 143 | self.0.sort_by_key(|r| r.type_); |
| 144 | } |
| 145 | |
| 146 | /// Remove a record by type. |
| 147 | pub fn remove(&mut self, type_: u64) -> Option<Vec<u8>> { |
no outgoing calls