Decode a variable-length raw byte slice into a Value.
(col_type: &ColumnType, raw: &[u8])
| 443 | |
| 444 | /// Decode a variable-length raw byte slice into a Value. |
| 445 | fn 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)] |
| 474 | mod tests { |
no test coverage detected