Decode a Binary Tuple to a JSON object using the schema (for pgwire output).
(
tuple_bytes: &[u8],
schema: &StrictSchema,
)
| 72 | |
| 73 | /// Decode a Binary Tuple to a JSON object using the schema (for pgwire output). |
| 74 | pub fn binary_tuple_to_json( |
| 75 | tuple_bytes: &[u8], |
| 76 | schema: &StrictSchema, |
| 77 | ) -> Option<serde_json::Value> { |
| 78 | // Delegate to binary_tuple_to_value (which handles version-aware decoding) |
| 79 | // then convert Value → JSON. |
| 80 | let val = binary_tuple_to_value(tuple_bytes, schema)?; |
| 81 | match val { |
| 82 | Value::Object(map) => { |
| 83 | let mut obj = serde_json::Map::with_capacity(map.len()); |
| 84 | for col in &schema.columns { |
| 85 | let v = map.get(&col.name).unwrap_or(&Value::Null); |
| 86 | obj.insert(col.name.clone(), value_to_json(v)); |
| 87 | } |
| 88 | Some(serde_json::Value::Object(obj)) |
| 89 | } |
| 90 | _ => None, |
| 91 | } |
| 92 | } |