[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 6 15:02:13 PST 2025
================
@@ -237,65 +238,25 @@ void DAP::StopEventHandlers() {
}
}
-// Send the JSON in "json_str" to the "out" stream. Correctly send the
-// "Content-Length:" field followed by the length, followed by the raw
-// JSON bytes.
-void DAP::SendJSON(const std::string &json_str) {
- output.write_full("Content-Length: ");
- output.write_full(llvm::utostr(json_str.size()));
- output.write_full("\r\n\r\n");
- output.write_full(json_str);
-}
-
// Serialize the JSON value into a string and send the JSON packet to
// the "out" stream.
void DAP::SendJSON(const llvm::json::Value &json) {
- std::string json_str;
- llvm::raw_string_ostream strm(json_str);
- strm << json;
- static std::mutex mutex;
- std::lock_guard<std::mutex> locker(mutex);
- SendJSON(json_str);
-
- if (log) {
- auto now = std::chrono::duration<double>(
- std::chrono::system_clock::now().time_since_epoch());
- *log << llvm::formatv("{0:f9} {1} <-- ", now.count(), name).str()
- << std::endl
- << "Content-Length: " << json_str.size() << "\r\n\r\n"
- << llvm::formatv("{0:2}", json).str() << std::endl;
- }
-}
-
-// Read a JSON packet from the "in" stream.
-std::string DAP::ReadJSON() {
- std::string length_str;
- std::string json_str;
- int length;
-
- if (!input.read_expected(log, "Content-Length: "))
- return json_str;
-
- if (!input.read_line(log, length_str))
- return json_str;
-
- if (!llvm::to_integer(length_str, length))
- return json_str;
-
- if (!input.read_expected(log, "\r\n"))
- return json_str;
-
- if (!input.read_full(log, length, json_str))
- return json_str;
-
- if (log) {
- auto now = std::chrono::duration<double>(
- std::chrono::system_clock::now().time_since_epoch());
- *log << llvm::formatv("{0:f9} {1} --> ", now.count(), name).str()
- << std::endl
- << "Content-Length: " << length << "\r\n\r\n";
+ protocol::Message M;
+ llvm::json::Path::Root root;
+ if (!protocol::fromJSON(json, M, root)) {
----------------
ashgti wrote:
Yea, in my other PRs I have changes to start using `protocol::Message` directly in places to reduce the need for this incremental step.
https://github.com/llvm/llvm-project/pull/130026
More information about the lldb-commits
mailing list