8#include "absl/strings/str_cat.h"
9#include "google/protobuf/io/tokenizer.h"
10#include "google/protobuf/text_format.h"
16class Errors :
public google::protobuf::io::ErrorCollector {
18 void RecordError(
int line, google::protobuf::io::ColumnNumber ,
19 absl::string_view message)
override {
21 absl::StrAppend(&text_,
"line ", line + 1,
": ", message);
24 const std::string& text()
const {
return text_; }
33 google::protobuf::Message& message) {
35 google::protobuf::TextFormat::Parser parser;
36 parser.RecordErrorsTo(&errors);
37 if (!parser.ParseFromString(text, &message)) {
38 return absl::InvalidArgumentError(errors.text());
40 return absl::OkStatus();
43absl::StatusOr<std::string>
ReadFile(
const std::string& path) {
44 std::ifstream file(path);
46 return absl::NotFoundError(absl::StrCat(
"couldn't read ", path));
48 std::ostringstream text;
absl::Status ParseText(std::string_view text, google::protobuf::Message &message)
absl::StatusOr< std::string > ReadFile(const std::string &path)