MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Deserialize

Method Deserialize

cpp/webdriver-server/command.cc:30–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30void Command::Deserialize(const std::string& json) {
31 LOG(TRACE) << "Entering Command::Deserialize";
32
33 // Clear the existing maps.
34 this->command_parameters_.clear();
35
36 LOG(DEBUG) << "Raw JSON command: " << json;
37
38 Json::Value root;
39 std::string parse_errors;
40 std::stringstream json_stream;
41 json_stream.str(json);
42 bool successful_parse = Json::parseFromStream(Json::CharReaderBuilder(),
43 json_stream,
44 &root,
45 &parse_errors);
46
47 if (!successful_parse) {
48 // report to the user the failure and their locations in the document.
49 LOG(WARN) << "Failed to parse configuration due to "
50 << parse_errors << std::endl
51 << "JSON command: '" << json << "'";
52 }
53
54 this->command_type_ = root.get("name", webdriver::CommandType::NoCommand).asString();
55 if (this->command_type_ != webdriver::CommandType::NoCommand) {
56 Json::Value locator_parameter_object = root["locator"];
57 Json::Value::iterator it = locator_parameter_object.begin();
58 Json::Value::iterator end = locator_parameter_object.end();
59 for (; it != end; ++it) {
60 std::string key = it.key().asString();
61 std::string value = locator_parameter_object[key].asString();
62 if (key == "sessionid") {
63 this->session_id_ = value;
64 } else {
65 this->command_parameters_[key] = value;
66 }
67 }
68
69 this->is_valid_parameters_ = true;
70 Json::Value command_parameter_object = root["parameters"];
71 if (!command_parameter_object.isObject()) {
72 LOG(WARN) << "The value of the 'parameters' attribute is not a JSON "
73 << "object. This is invalid for the WebDriver JSON Wire "
74 << "Protocol.";
75 this->is_valid_parameters_ = false;
76 } else {
77 it = command_parameter_object.begin();
78 end = command_parameter_object.end();
79 for (; it != end; ++it) {
80 std::string key = it.key().asString();
81 Json::Value value = command_parameter_object[key];
82 this->command_parameters_[key] = value;
83 }
84 }
85 } else {
86 LOG(DEBUG) << "Command type is zero, no 'name' attribute in JSON object";
87 }

Callers 15

OnSetCommandMethod · 0.45
DispatchCommandMethod · 0.45
ListSessionsMethod · 0.45
SendResponseToClientMethod · 0.45
FromJsonMethod · 0.45
FromErrorJsonMethod · 0.45
RunCommandAsyncMethod · 0.45
SendCommandMethod · 0.45
ReadMethod · 0.45
ReadMethod · 0.45

Calls 6

asStringMethod · 0.80
endMethod · 0.80
LOGClass · 0.70
clearMethod · 0.65
getMethod · 0.65
keyMethod · 0.45

Tested by

no test coverage detected