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

Function decode_variable_value

nodedb-strict/src/decode.rs:445–471  ·  view source on GitHub ↗

Decode a variable-length raw byte slice into a Value.

(col_type: &ColumnType, raw: &[u8])

Source from the content-addressed store, hash-verified

443
444/// Decode a variable-length raw byte slice into a Value.
445fn decode_variable_value(col_type: &ColumnType, raw: &[u8]) -> Value {
446 match col_type {
447 ColumnType::String => {
448 Value::String(std::str::from_utf8(raw).unwrap_or_default().to_string())
449 }
450 ColumnType::Bytes => Value::Bytes(raw.to_vec()),
451 ColumnType::Geometry => {
452 // Try JSON (native Geometry encoding), fall back to string (WKT passthrough).
453 if let Ok(geom) = sonic_rs::from_slice::<nodedb_types::geometry::Geometry>(raw) {
454 Value::Geometry(geom)
455 } else {
456 Value::String(std::str::from_utf8(raw).unwrap_or_default().to_string())
457 }
458 }
459 ColumnType::Json => {
460 // Deserialize MessagePack bytes back to Value.
461 match nodedb_types::value_from_msgpack(raw) {
462 Ok(val) => val,
463 Err(e) => {
464 tracing::warn!(len = raw.len(), error = %e, "corrupted JSON msgpack in tuple");
465 Value::Null
466 }
467 }
468 }
469 _ => Value::Null,
470 }
471}
472
473#[cfg(test)]
474mod tests {

Callers 1

extract_valueMethod · 0.85

Calls 4

GeometryEnum · 0.85
value_from_msgpackFunction · 0.85
to_stringMethod · 0.80
to_vecMethod · 0.45

Tested by

no test coverage detected