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

Function decode_document_value

nodedb/src/data/executor/doc_format.rs:52–67  ·  view source on GitHub ↗

Convert a document byte blob to `nodedb_types::Value`. Preserves all native types (Geometry, DateTime, Decimal, etc.) that would be lost when decoding to `serde_json::Value`. Auto-detects msgpack vs JSON. Binary Tuple requires schema — callers should use `strict_format::binary_tuple_to_value` for strict collections.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

50/// Auto-detects msgpack vs JSON. Binary Tuple requires schema — callers
51/// should use `strict_format::binary_tuple_to_value` for strict collections.
52pub(super) fn decode_document_value(bytes: &[u8]) -> Option<nodedb_types::Value> {
53 if bytes.is_empty() {
54 return None;
55 }
56
57 let first = bytes[0];
58 if ((0x80..=0x8F).contains(&first) || first == 0xDE || first == 0xDF)
59 && let Ok(val) = nodedb_types::value_from_msgpack(bytes)
60 {
61 return Some(val);
62 }
63
64 // JSON input boundary: parse then convert.
65 let json: serde_json::Value = sonic_rs::from_slice(bytes).ok()?;
66 Some(nodedb_types::Value::from(json))
67}
68
69/// Encode a JSON value as MessagePack bytes for storage.
70///

Callers 2

execute_spatial_scanMethod · 0.85
spatial_full_scanMethod · 0.85

Calls 4

value_from_msgpackFunction · 0.85
is_emptyMethod · 0.45
containsMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected