| 70 | } |
| 71 | |
| 72 | Status ParseTextFormatFromString(absl::string_view input, |
| 73 | protobuf::Message* output) { |
| 74 | DCHECK(output != nullptr) << "output must be non NULL"; |
| 75 | // When checks are disabled, instead log the error and return an error status. |
| 76 | if (output == nullptr) { |
| 77 | LOG(ERROR) << "output must be non NULL"; |
| 78 | return Status(error::INVALID_ARGUMENT, "output must be non NULL"); |
| 79 | } |
| 80 | string err; |
| 81 | StringErrorCollector err_collector(&err, /*one-indexing=*/true); |
| 82 | protobuf::TextFormat::Parser parser; |
| 83 | parser.RecordErrorsTo(&err_collector); |
| 84 | if (!parser.ParseFromString(string(input), output)) { |
| 85 | return Status(error::INVALID_ARGUMENT, err); |
| 86 | } |
| 87 | return Status::OK(); |
| 88 | } |
| 89 | |
| 90 | StringErrorCollector::StringErrorCollector(string* error_text) |
| 91 | : StringErrorCollector(error_text, false) {} |