================
@@ -45,6 +46,28 @@ class StreamGDBRemote : public StreamString {
 
   /// Equivalent to PutEscapedBytes(str.data(), str.size());
   int PutEscapedBytes(llvm::StringRef str);
+
+  template <class T> int PutAsJSON(const T &obj, bool hex_ascii) {
+    std::string json_string;
+    llvm::raw_string_ostream os(json_string);
+    os << llvm::json::Value(toJSON(obj));
+    if (hex_ascii)
+      return PutStringAsRawHex8(json_string);
+    return PutEscapedBytes(json_string.c_str(), json_string.size());
+  }
+
+  template <class T> int PutAsJSONArray(const std::vector<T> &array) {
+    std::string json_string;
+    llvm::raw_string_ostream os(json_string);
+    os << "[";
+    for (size_t i = 0; i < array.size(); ++i) {
+      if (i > 0)
+        os << ",";
----------------
DavidSpickett wrote:

This feels like llvm::join with more steps, see if you could use that.

Also there is llvm::json::array and I assume you could construct one of those 
from the vector and it would be easier to format. I assume, I could be wrong 
but formatting as an array seems like a thing we'd have already written.

https://github.com/llvm/llvm-project/pull/198907
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to