15 #ifndef THIRD_PARTY_TENSORFLOW_SERVING_UTIL_PROTO_UTIL_H_
16 #define THIRD_PARTY_TENSORFLOW_SERVING_UTIL_PROTO_UTIL_H_
18 #include "tensorflow/core/lib/core/errors.h"
19 #include "tensorflow/core/lib/core/status.h"
20 #include "tensorflow/core/platform/env.h"
21 #include "tensorflow/core/platform/protobuf.h"
23 namespace tensorflow {
26 template <
typename ProtoType>
27 tensorflow::Status ParseProtoTextFile(
const string& file, ProtoType* proto) {
28 std::unique_ptr<tensorflow::ReadOnlyMemoryRegion> file_data;
30 tensorflow::Env::Default()->NewReadOnlyMemoryRegionFromFile(file,
32 string file_data_str(
static_cast<const char*
>(file_data->data()),
34 if (tensorflow::protobuf::TextFormat::ParseFromString(file_data_str, proto)) {
35 return tensorflow::OkStatus();
37 return tensorflow::errors::InvalidArgument(
"Invalid protobuf file: '", file,