================
@@ -28,22 +31,119 @@ using namespace lldb_private;
 
 namespace {
 
-struct JSONTestType {
-  std::string str;
+namespace test_protocol {
+
+struct Req {
+  std::string name;
 };
+json::Value toJSON(const Req &T) { return json::Object{{"req", T.name}}; }
+bool fromJSON(const json::Value &V, Req &T, json::Path P) {
+  json::ObjectMapper O(V, P);
+  return O && O.map("req", T.name);
+}
+bool operator==(const Req &a, const Req &b) { return a.name == b.name; }
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Req &V) {
+  OS << toJSON(V);
+  return OS;
+}
+void PrintTo(const Req &message, std::ostream *os) {
+  std::string O;
+  llvm::raw_string_ostream OS(O);
+  OS << message;
+  *os << O;
+}
 
-json::Value toJSON(const JSONTestType &T) {
-  return json::Object{{"str", T.str}};
+struct Resp {
+  std::string name;
+};
+json::Value toJSON(const Resp &T) { return json::Object{{"resp", T.name}}; }
+bool fromJSON(const json::Value &V, Resp &T, json::Path P) {
+  json::ObjectMapper O(V, P);
+  return O && O.map("resp", T.name);
+}
+bool operator==(const Resp &a, const Resp &b) { return a.name == b.name; }
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Resp &V) {
+  OS << toJSON(V);
+  return OS;
+}
+void PrintTo(const Resp &message, std::ostream *os) {
+  std::string O;
+  llvm::raw_string_ostream OS(O);
+  OS << message;
+  *os << O;
 }
 
-bool fromJSON(const json::Value &V, JSONTestType &T, json::Path P) {
+struct Evt {
+  std::string name;
+};
+json::Value toJSON(const Evt &T) { return json::Object{{"evt", T.name}}; }
+bool fromJSON(const json::Value &V, Evt &T, json::Path P) {
   json::ObjectMapper O(V, P);
-  return O && O.map("str", T.str);
+  return O && O.map("evt", T.name);
+}
+bool operator==(const Evt &a, const Evt &b) { return a.name == b.name; }
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Evt &V) {
+  OS << toJSON(V);
+  return OS;
+}
+void PrintTo(const Evt &message, std::ostream *os) {
+  std::string O;
+  llvm::raw_string_ostream OS(O);
+  OS << message;
+  *os << O;
+}
+
+using Message = std::variant<Req, Resp, Evt>;
+json::Value toJSON(const Message &T) {
+  if (const Req *req = std::get_if<Req>(&T))
+    return toJSON(*req);
+  if (const Resp *resp = std::get_if<Resp>(&T))
+    return toJSON(*resp);
+  if (const Evt *evt = std::get_if<Evt>(&T))
+    return toJSON(*evt);
+  llvm_unreachable("unknown message type");
----------------
labath wrote:

```suggestion
return std::visit(T, [](const auto &msg) { return toJSON(msg); });
```

https://github.com/llvm/llvm-project/pull/153121
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to