use crate::bridge::envelope::PhysicalPlan;
use crate::bridge::physical_plan::KvOp;
use nodedb_query::msgpack_scan;
pub(super) fn maybe_wrap_kv_point_get(plan: &PhysicalPlan, payload: &[u8]) -> Vec<u8> {
if payload.is_empty() {
return payload.to_vec();
}
let PhysicalPlan::Kv(KvOp::Get { key, .. }) = plan else {
return payload.to_vec();
};
let key_str = String::from_utf8_lossy(key);
if msgpack_scan::map_header(payload, 0).is_some() {
msgpack_scan::inject_str_field(payload, "key", &key_str)
} else {
let mut buf = Vec::with_capacity(payload.len() + key_str.len() + 16);
msgpack_scan::write_map_header(&mut buf, 2);
msgpack_scan::write_str(&mut buf, "key");
msgpack_scan::write_str(&mut buf, &key_str);
msgpack_scan::write_str(&mut buf, "value");
msgpack_scan::write_str(&mut buf, &String::from_utf8_lossy(payload));
buf
}
}