| 243 | } |
| 244 | |
| 245 | void DebuggerClientDap::asyncRead( const char* bytes, size_t n, const SessionId& sessionId ) { |
| 246 | std::string_view read( bytes, n ); |
| 247 | auto& buffer = mSessions[sessionId].buffer; |
| 248 | buffer += read; |
| 249 | |
| 250 | while ( true ) { |
| 251 | const auto info = readHeader( buffer ); |
| 252 | if ( !info ) |
| 253 | break; |
| 254 | if ( info->payloadStart >= buffer.size() ) { |
| 255 | Log::debug( "DebuggerClientDap::asyncRead: Out of range payloadStart access. Current " |
| 256 | "buffer was:\n%s\nPayload started at %" PRIu64 "", |
| 257 | buffer.data(), info->payloadStart ); |
| 258 | break; |
| 259 | } |
| 260 | const auto data = buffer.substr( info->payloadStart, info->payloadLength ); |
| 261 | if ( data.size() < info->payloadLength ) |
| 262 | break; |
| 263 | buffer.erase( 0, info->payloadStart + info->payloadLength ); |
| 264 | |
| 265 | #ifndef EE_DEBUG |
| 266 | try { |
| 267 | #endif |
| 268 | auto message = nlohmann::json::parse( data ); |
| 269 | if ( mDebug ) { |
| 270 | Log::debug( "DebuggerClientDap::asyncRead:" ); |
| 271 | Log::debug( message.dump() ); |
| 272 | } |
| 273 | processProtocolMessage( message ); |
| 274 | #ifndef EE_DEBUG |
| 275 | } catch ( const nlohmann::json::exception& e ) { |
| 276 | Log::error( "DebuggerClientDap::asyncRead: JSON bad format: %s", e.what() ); |
| 277 | } |
| 278 | #endif |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | void DebuggerClientDap::processProtocolMessage( const nlohmann::json& msg ) { |
| 283 | const auto type = msg.value( DAP_TYPE, "" ); |