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])
| 50 | /// Auto-detects msgpack vs JSON. Binary Tuple requires schema — callers |
| 51 | /// should use `strict_format::binary_tuple_to_value` for strict collections. |
| 52 | pub(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 | /// |
no test coverage detected