| 115 | } |
| 116 | |
| 117 | Result<bool> GetBool(const char* key) { |
| 118 | document_.rewind(); |
| 119 | |
| 120 | auto object = document_.get_object(); |
| 121 | |
| 122 | auto field = object.find_field(key); |
| 123 | |
| 124 | if (field.error() == simdjson::NO_SUCH_FIELD) { |
| 125 | return Status::KeyError("Key '", key, "' does not exist"); |
| 126 | } |
| 127 | if (field.error()) { |
| 128 | return Status::Invalid("Error accessing key '", key, |
| 129 | "': ", simdjson::error_message(field.error())); |
| 130 | } |
| 131 | |
| 132 | auto bool_result = field.get_bool(); |
| 133 | if (bool_result.error() == simdjson::INCORRECT_TYPE) { |
| 134 | return Status::TypeError("Key '", key, "' is not a boolean"); |
| 135 | } |
| 136 | if (bool_result.error()) { |
| 137 | return Status::Invalid("Error getting bool for key '", key, |
| 138 | "': ", simdjson::error_message(bool_result.error())); |
| 139 | } |
| 140 | |
| 141 | bool value; |
| 142 | if (auto error = std::move(bool_result).get(value)) { |
| 143 | return Status::Invalid("Error getting bool for key '", key, |
| 144 | "': ", simdjson::error_message(error)); |
| 145 | } |
| 146 | |
| 147 | return value; |
| 148 | } |
| 149 | |
| 150 | private: |
| 151 | simdjson::ondemand::parser parser_; |
nothing calls this directly
no test coverage detected