Extract a field value from a msgpack document as a string for hash lookup.
(msgpack_doc: &[u8], field_name: &str)
| 290 | |
| 291 | /// Extract a field value from a msgpack document as a string for hash lookup. |
| 292 | fn extract_field_string(msgpack_doc: &[u8], field_name: &str) -> Option<String> { |
| 293 | let value = nodedb_types::value_from_msgpack(msgpack_doc).ok()?; |
| 294 | match &value { |
| 295 | nodedb_types::Value::Object(map) => { |
| 296 | let v = map.get(field_name)?; |
| 297 | match v { |
| 298 | nodedb_types::Value::String(s) => Some(s.clone()), |
| 299 | nodedb_types::Value::Integer(i) => Some(i.to_string()), |
| 300 | nodedb_types::Value::Float(f) => Some(f.to_string()), |
| 301 | nodedb_types::Value::Bool(b) => Some(b.to_string()), |
| 302 | _ => Some(format!("{v:?}")), |
| 303 | } |
| 304 | } |
| 305 | _ => None, |
| 306 | } |
| 307 | } |
no test coverage detected