MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_field_string

Function extract_field_string

nodedb/src/data/executor/handlers/recursive.rs:292–307  ·  view source on GitHub ↗

Extract a field value from a msgpack document as a string for hash lookup.

(msgpack_doc: &[u8], field_name: &str)

Source from the content-addressed store, hash-verified

290
291/// Extract a field value from a msgpack document as a string for hash lookup.
292fn 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}

Callers 1

Calls 5

value_from_msgpackFunction · 0.85
to_stringMethod · 0.80
okMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected